Skip to content

Commit

Permalink
Set root as default Unison user and refactor user creation to sync.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
davide committed Aug 15, 2017
1 parent cc816f0 commit 7e94d17
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
16 changes: 6 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,14 @@ RUN apk add --no-cache --virtual .build-dependencies build-base curl && \
apk del .build-dependencies ocaml && \
rm -rf /tmp/unison-${UNISON_VERSION}

ENV HOME="/home/auser" \
UNISON_USER="auser" \
UNISON_GROUP="auser" \
UNISON_UID="100" \
UNISON_GID="101"
ENV HOME="/root" \
UNISON_USER="root" \
UNISON_GROUP="root" \
UNISON_UID="0" \
UNISON_GID="0"

# Copy the bg-sync script into the container.
COPY sync.sh /usr/local/bin/bg-sync
RUN chmod +x /usr/local/bin/bg-sync

CMD addgroup -g $UNISON_GID -S $UNISON_GROUP \
&& adduser -u $UNISON_UID -D -S -G $UNISON_GROUP $UNISON_USER \
&& mkdir -p ${HOME}/.unison \
&& chown -R ${UNISON_USER}:${UNISON_GROUP} ${HOME} \
&& bg-sync
CMD ["bg-sync"]
14 changes: 12 additions & 2 deletions sync.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ log_error_exit() {
exit 1
}

# Create non-root user
if [ "$UNISON_USER" != "root" ]; then
log_heading "Setting up non-root user ${UNISON_USER}."
HOME="/home/${UNISON_USER}"
addgroup -g $UNISON_GID -S $UNISON_GROUP
adduser -u $UNISON_UID -D -S -G $UNISON_GROUP $UNISON_USER
mkdir -p ${HOME}/.unison
chown -R ${UNISON_USER}:${UNISON_GROUP} ${HOME}
fi

#
# Set defaults for all variables that we depend on (if they aren't already set in env).
#
Expand Down Expand Up @@ -109,7 +119,7 @@ fi
# Generate a unison profile so that we don't have a million options being passed
# to the unison command.
log_heading "Generating Unison profile"
[ -d "/home/${UNISON_USER}/.unison" ] || mkdir -p /home/${UNISON_USER}/.unison
[ -d "${HOME}/.unison" ] || mkdir -p ${HOME}/.unison

unisonsilent="true"
if [[ "$SYNC_VERBOSE" == "0" ]]; then
Expand Down Expand Up @@ -153,7 +163,7 @@ ignore = Name *___jb_tmp___*
# Additional user configuration
$SYNC_EXTRA_UNISON_PROFILE_OPTS
" > /home/${UNISON_USER}/.unison/default.prf
" > ${HOME}/.unison/default.prf

# Fix permissions
log_heading "Override folder permissions."
Expand Down

0 comments on commit 7e94d17

Please sign in to comment.