Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ USER_GID=${USER_GID:-1000}

BROWSER_BOX_USER=${BROWSER_BOX_USER:-browser}
BROWSER_BOX_REPO=${BROWSER_BOX_REPO:-sameersbn}
BROWSER_BOX_VERSION=${BROWSER_BOX_VERSION:-1.0.1}

install_browser_box() {
echo "Installing browser-box..."
Expand All @@ -26,6 +27,10 @@ install_browser_box() {
echo "Updating user to ${BROWSER_BOX_USER}..."
sed -i -e s%"BROWSER_BOX_USER:-browser"%"BROWSER_BOX_USER:-${BROWSER_BOX_USER}"%1 /target/browser-box
fi
if [[ -n "${BROWSER_BOX_VERSION}" ]]; then
echo "Updating version to ${BROWSER_BOX_VERSION}..."
sed -i -e s%"BROWSER_BOX_VERSION:-.*$"%"BROWSER_BOX_VERSION:-${BROWSER_BOX_VERSION}}"%1 /target/browser-box
fi
if [[ -n "${CHROME_USERDATA}" ]]; then
echo "Updating Chrome user volume..."
sed -i -e s%"CHROME_USERDATA=.*$"%"CHROME_USERDATA\=${CHROME_USERDATA}"%1 /target/browser-box
Expand Down Expand Up @@ -56,6 +61,14 @@ uninstall_browser_box() {
}

create_user() {
exist=$(getent passwd ${USER_UID} >/dev/null 2>&1 || echo false)
if [ x${exist} != "xfalse" ]; then
echo "Warning: User ID ${USER_UID} exists in Browser Box"
BROWSER_BOX_USER=$(getent passwd ${USER_UID} | cut -d ":" -f 1)
if [ ! -d /home/${BROWSER_BOX_USER} ]; then
mkdir /home/${BROWSER_BOX_USER}
fi
fi
# ensure home directory is owned by browser
# and that profile files exist
if [[ -d /home/${BROWSER_BOX_USER} ]]; then
Expand All @@ -65,9 +78,9 @@ create_user() {
cp /etc/skel/.bash_logout /home/${BROWSER_BOX_USER}
cp /etc/skel/.profile /home/${BROWSER_BOX_USER}
chown ${USER_UID}:${USER_GID} \
/home/${BROWSER_BOX_USER}/.bashrc \
/home/${BROWSER_BOX_USER}/.profile \
/home/${BROWSER_BOX_USER}/.bash_logout
/home/${BROWSER_BOX_USER}/.bashrc \
/home/${BROWSER_BOX_USER}/.profile \
/home/${BROWSER_BOX_USER}/.bash_logout
fi
# create group with USER_GID
if ! getent group ${BROWSER_BOX_USER} >/dev/null; then
Expand Down
6 changes: 4 additions & 2 deletions scripts/browser-box
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ PATH=/usr/sbin:/usr/bin:/sbin:/bin
# TODO: ensure this gets updated by entrypoint script on install
BROWSER_BOX_USER=${BROWSER_BOX_USER:-browser}
BROWSER_BOX_REPO=${BROWSER_BOX_REPO:-sameersbn}
BROWSER_BOX_VERSION=${BROWSER_BOX_VERSION:-1.0.1-1}
BROWSERS=(chromium-browser firefox google-chrome google-chrome-stable tor-browser)
# Persistant data directories CHROME_USERDATA="" FIREFOX_USERDATA=""
# do we need to use sudo to start docker containers?
Expand Down Expand Up @@ -31,7 +32,7 @@ cleanup_stopped_browser_box_instances() {
for c in $(${SUDO} docker ps -a -q)
do
image=$(${SUDO} docker inspect -f {{.Config.Image}} ${c})
if [[ ${image} == "${BROWSER_BOX_REPO}/browser-box:latest" ]]; then
if [[ ${image} == "${BROWSER_BOX_REPO}/browser-box:${BROWSER_BOX_VERSION}" ]]; then
running=$(${SUDO} docker inspect -f {{.State.Running}} ${c})
if [[ ${running} != true ]]; then
${SUDO} docker rm -v "${c}" >/dev/null
Expand Down Expand Up @@ -150,4 +151,5 @@ ${SUDO} docker run -d \
${VIDEO_DEVICES} \
${VOLUMES} \
--name="${prog}" \
${BROWSER_BOX_REPO}/browser-box:1.0.1-1 ${prog} $@ >/dev/null

${BROWSER_BOX_REPO}/browser-box:${BROWSER_BOX_VERSION} ${prog} $@ >/dev/null