From a811e58a93f326a3f645d0a4ae84dd5ffe2dfe0d Mon Sep 17 00:00:00 2001 From: H8H Date: Sun, 1 Feb 2015 18:01:33 +0100 Subject: [PATCH 1/3] Fixes #309, removed hardcoded /home directory to apply the existing configuration options for STORAGE_USER/ROOT if they exist --- setup/start.sh | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/setup/start.sh b/setup/start.sh index 22759c60..022600d3 100755 --- a/setup/start.sh +++ b/setup/start.sh @@ -87,17 +87,28 @@ 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 [ -z "$STORAGE_ROOT" ]; then - STORAGE_USER=user-data - if [ ! -d /home/$STORAGE_USER ]; then useradd -m $STORAGE_USER; fi - STORAGE_ROOT=/home/$STORAGE_USER - mkdir -p $STORAGE_ROOT - echo $(setup/migrate.py --current) > $STORAGE_ROOT/mailinabox.version - chown $STORAGE_USER.$STORAGE_USER $STORAGE_ROOT/mailinabox.version +# +# If the config file exists: +# Apply the existing configuration options for STORAGE_USER/ROOT +STORAGE_USER=$([[ -z "$DEFAULT_STORAGE_USER" ]] && echo "user-data" || echo "$DEFAULT_STORAGE_USER") +STORAGE_ROOT=$([[ -z "$DEFAULT_STORAGE_ROOT" ]] && echo "/home/$STORAGE_USER" || echo "$DEFAULT_STORAGE_ROOT") + +# 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 +fi + +echo $(setup/migrate.py --current) > $STORAGE_ROOT/mailinabox.version +chown $STORAGE_USER.$STORAGE_USER $STORAGE_ROOT/mailinabox.version + # Save the global options in /etc/mailinabox.conf so that standalone # tools know where to look for data. cat > /etc/mailinabox.conf << EOF; From 794a52d042a3d6f6de89f94675fbb0d716a5a911 Mon Sep 17 00:00:00 2001 From: H8H Date: Sun, 1 Feb 2015 19:10:23 +0100 Subject: [PATCH 2/3] Highest priority: the pre set STORAGE_ROOT/USER, midmost priority: the config settings, lowest priority: the default one. --- setup/start.sh | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/setup/start.sh b/setup/start.sh index 022600d3..e61b058c 100755 --- a/setup/start.sh +++ b/setup/start.sh @@ -93,8 +93,13 @@ fi # # If the config file exists: # Apply the existing configuration options for STORAGE_USER/ROOT -STORAGE_USER=$([[ -z "$DEFAULT_STORAGE_USER" ]] && echo "user-data" || echo "$DEFAULT_STORAGE_USER") -STORAGE_ROOT=$([[ -z "$DEFAULT_STORAGE_ROOT" ]] && echo "/home/$STORAGE_USER" || echo "$DEFAULT_STORAGE_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_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 @@ -104,10 +109,10 @@ 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 -echo $(setup/migrate.py --current) > $STORAGE_ROOT/mailinabox.version -chown $STORAGE_USER.$STORAGE_USER $STORAGE_ROOT/mailinabox.version # Save the global options in /etc/mailinabox.conf so that standalone # tools know where to look for data. From 8c38ba1f009ce11ab80715408a69b4b199ca97b2 Mon Sep 17 00:00:00 2001 From: H8H Date: Tue, 3 Feb 2015 17:27:28 +0100 Subject: [PATCH 3/3] Fixed wrong condition, thanks @joshdata --- setup/start.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup/start.sh b/setup/start.sh index e61b058c..fe9d3080 100755 --- a/setup/start.sh +++ b/setup/start.sh @@ -102,7 +102,7 @@ if [ -z "$STORAGE_ROOT" ]; then fi # Create the STORAGE_USER if it not exists -if [ ! $(id -u $STORAGE_USER >/dev/null 2>&1;) ]; then +if ! id -u $STORAGE_USER >/dev/null 2>&1; then useradd -m $STORAGE_USER fi