entrypoint.sh: moved codeblocks into functions

pull/3/merge
Sameer Naik 9 years ago
parent d6af5ed0b6
commit 2d6cffcfe2

@ -1,66 +1,82 @@
#!/bin/bash
set -e
case "$1" in
install)
echo "Installing browser-box..."
install -m 0755 /scripts/browser-box /target/
echo "Installing google-chrome..."
ln -sf browser-box /target/google-chrome
echo "Installing google-chrome-stable..."
ln -sf browser-box /target/google-chrome-stable
echo "Installing tor-browser..."
ln -sf browser-box /target/tor-browser
echo "Installing chromium-browser..."
ln -sf browser-box /target/chromium-browser
echo "Installing firefox..."
ln -sf browser-box /target/firefox
;;
uninstall)
echo "Uninstalling browser-box..."
rm -rf /target/browser-box
echo "Uninstalling google-chrome..."
rm -rf /target/google-chrome
echo "Uninstalling google-chrome-stable..."
rm -rf /target/google-chrome-stable
echo "Uninstalling tor-browser..."
rm -rf /target/tor-browser
echo "Uninstalling chromium-browser..."
rm -rf /target/chromium-browser
echo "Uninstalling firefox..."
rm -rf /target/firefox
;;
google-chrome|google-chrome-stable|tor-browser|chromium-browser|firefox)
# uid and gid of host user
USER_UID=${USER_UID:-1000}
USER_GID=${USER_GID:-1000}
USER_UID=${USER_UID:-1000}
USER_GID=${USER_GID:-1000}
# create user group
if ! getent group ${WEB_BROWSER_USER} >/dev/null; then
groupadd -f -g ${USER_GID} ${WEB_BROWSER_USER}
fi
install_browser_box() {
echo "Installing browser-box..."
install -m 0755 /scripts/browser-box /target/
echo "Installing google-chrome..."
ln -sf browser-box /target/google-chrome
echo "Installing google-chrome-stable..."
ln -sf browser-box /target/google-chrome-stable
echo "Installing tor-browser..."
ln -sf browser-box /target/tor-browser
echo "Installing chromium-browser..."
ln -sf browser-box /target/chromium-browser
echo "Installing firefox..."
ln -sf browser-box /target/firefox
}
# create user with uid and gid matching that of the host user
if ! getent passwd ${WEB_BROWSER_USER} >/dev/null; then
adduser --disabled-login --uid ${USER_UID} --gid ${USER_GID} \
--gecos 'Browser Box' ${WEB_BROWSER_USER}
fi
uninstall_browser_box() {
echo "Uninstalling browser-box..."
rm -rf /target/browser-box
echo "Uninstalling google-chrome..."
rm -rf /target/google-chrome
echo "Uninstalling google-chrome-stable..."
rm -rf /target/google-chrome-stable
echo "Uninstalling tor-browser..."
rm -rf /target/tor-browser
echo "Uninstalling chromium-browser..."
rm -rf /target/chromium-browser
echo "Uninstalling firefox..."
rm -rf /target/firefox
}
create_user() {
# create group with USER_GID
if ! getent group ${WEB_BROWSER_USER} >/dev/null; then
groupadd -f -g ${USER_GID} ${WEB_BROWSER_USER}
fi
# grant access to video devices
for device in /dev/video*
do
if [[ -c $device ]]; then
VIDEO_GID=$(stat -c %g $device)
break
fi
done
# create user with USER_UID
if ! getent passwd ${WEB_BROWSER_USER} >/dev/null; then
adduser --disabled-login --uid ${USER_UID} --gid ${USER_GID} \
--gecos 'Browser Box' ${WEB_BROWSER_USER}
fi
}
if [[ -n $VIDEO_GID ]]; then
usermod -a -G $VIDEO_GID ${WEB_BROWSER_USER}
grant_access_to_video_devices() {
for device in /dev/video*
do
if [[ -c $device ]]; then
VIDEO_GID=$(stat -c %g $device)
break
fi
done
cd /home/${WEB_BROWSER_USER}
exec sudo -u ${WEB_BROWSER_USER} -H PULSE_SERVER=/run/pulse/native $@ ${extra_opts}
if [[ -n $VIDEO_GID ]]; then
usermod -a -G $VIDEO_GID ${WEB_BROWSER_USER}
fi
}
launch_browser() {
cd /home/${WEB_BROWSER_USER}
exec sudo -u ${WEB_BROWSER_USER} -H PULSE_SERVER=/run/pulse/native $@ ${extra_opts}
}
case "$1" in
install)
install_browser_box
;;
uninstall)
uninstall_browser_box
;;
google-chrome|google-chrome-stable|tor-browser|chromium-browser|firefox)
create_user
grant_access_to_video_devices
launch_browser $@
;;
bash)
exec $@

Loading…
Cancel
Save