From 005315cd2915ad9c403bf1adf72adf3fd138bf02 Mon Sep 17 00:00:00 2001 From: H8H Date: Sun, 1 Feb 2015 18:01:33 +0100 Subject: [PATCH] removed hardcoded /home directory to apply the existing configuration options for STORAGE_USER/ROOT if they exist Highest priority: the pre set STORAGE_ROOT/USER, midmost priority: the config settings, lowest priority: the default one. fixes #309; closes #311 --- setup/start.sh | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/setup/start.sh b/setup/start.sh index 22759c60..fe9d3080 100755 --- a/setup/start.sh +++ b/setup/start.sh @@ -87,17 +87,33 @@ if [ -z "$SKIP_NETWORK_CHECKS" ]; then . setup/network-checks.sh fi +# For the first time (if the config file (/etc/mailinabox.conf) not exists): # Create the user named "user-data" and store all persistent user # data (mailboxes, etc.) in that user's home directory. +# +# If the config file exists: +# Apply the existing configuration options for STORAGE_USER/ROOT +if [ -z "$STORAGE_USER" ]; then + STORAGE_USER=$([[ -z "$DEFAULT_STORAGE_USER" ]] && echo "user-data" || echo "$DEFAULT_STORAGE_USER") +fi + if [ -z "$STORAGE_ROOT" ]; then - STORAGE_USER=user-data - if [ ! -d /home/$STORAGE_USER ]; then useradd -m $STORAGE_USER; fi - STORAGE_ROOT=/home/$STORAGE_USER + STORAGE_ROOT=$([[ -z "$DEFAULT_STORAGE_ROOT" ]] && echo "/home/$STORAGE_USER" || echo "$DEFAULT_STORAGE_ROOT") +fi + +# Create the STORAGE_USER if it not exists +if ! id -u $STORAGE_USER >/dev/null 2>&1; then + useradd -m $STORAGE_USER +fi + +# Create the STORAGE_ROOT if it not exists +if [ ! -d $STORAGE_ROOT ]; then mkdir -p $STORAGE_ROOT echo $(setup/migrate.py --current) > $STORAGE_ROOT/mailinabox.version chown $STORAGE_USER.$STORAGE_USER $STORAGE_ROOT/mailinabox.version fi + # Save the global options in /etc/mailinabox.conf so that standalone # tools know where to look for data. cat > /etc/mailinabox.conf << EOF;