Commit 9e86c675 authored by Joshua Tauberer's avatar Joshua Tauberer

make setup/owncloud.sh idempotent: don't wreck user data on second run

parent 6e380ade
...@@ -22,10 +22,13 @@ if [ ! -d /usr/local/lib/owncloud ]; then ...@@ -22,10 +22,13 @@ if [ ! -d /usr/local/lib/owncloud ]; then
rm -f /tmp/owncloud.zip rm -f /tmp/owncloud.zip
fi fi
# Create a configuration file. # Setup ownCloud if the ownCloud database does not yet exist. Running setup when
TIMEZONE=`cat /etc/timezone` # the database does exist wipes the database and user data.
instanceid=oc$(echo $PRIMARY_HOSTNAME | sha1sum | fold -w 10 | head -n 1) if [ ! -f $STORAGE_ROOT/owncloud/owncloud.db ]; then
cat - > /usr/local/lib/owncloud/config/config.php <<EOF; # Create a configuration file.
TIMEZONE=`cat /etc/timezone`
instanceid=oc$(echo $PRIMARY_HOSTNAME | sha1sum | fold -w 10 | head -n 1)
cat - > /usr/local/lib/owncloud/config/config.php <<EOF;
<?php <?php
\$CONFIG = array ( \$CONFIG = array (
'datadirectory' => '$STORAGE_ROOT/owncloud', 'datadirectory' => '$STORAGE_ROOT/owncloud',
...@@ -63,9 +66,11 @@ cat - > /usr/local/lib/owncloud/config/config.php <<EOF; ...@@ -63,9 +66,11 @@ cat - > /usr/local/lib/owncloud/config/config.php <<EOF;
?> ?>
EOF EOF
# Create an auto-configuration file to fill in database settings. # Create an auto-configuration file to fill in database settings
adminpassword=$(dd if=/dev/random bs=40 count=1 2>/dev/null | sha1sum | fold -w 30 | head -n 1) # when the install script is run. Make an administrator account
cat - > /usr/local/lib/owncloud/config/autoconfig.php <<EOF; # here or else the install can't finish.
adminpassword=$(dd if=/dev/random bs=40 count=1 2>/dev/null | sha1sum | fold -w 30 | head -n 1)
cat - > /usr/local/lib/owncloud/config/autoconfig.php <<EOF;
<?php <?php
\$AUTOCONFIG = array ( \$AUTOCONFIG = array (
# storage/database # storage/database
...@@ -80,13 +85,14 @@ cat - > /usr/local/lib/owncloud/config/autoconfig.php <<EOF; ...@@ -80,13 +85,14 @@ cat - > /usr/local/lib/owncloud/config/autoconfig.php <<EOF;
?> ?>
EOF EOF
# Set permissions # Create user data directory and set permissions
mkdir -p $STORAGE_ROOT/owncloud mkdir -p $STORAGE_ROOT/owncloud
chown -R www-data.www-data $STORAGE_ROOT/owncloud /usr/local/lib/owncloud chown -R www-data.www-data $STORAGE_ROOT/owncloud /usr/local/lib/owncloud
# Execute ownCloud's setup step, which creates the ownCloud sqlite database. # Execute ownCloud's setup step, which creates the ownCloud sqlite database.
# It also wipes it if it exists. And it deletes the autoconfig.php file. # It also wipes it if it exists. And it deletes the autoconfig.php file.
(cd /usr/local/lib/owncloud; sudo -u www-data php /usr/local/lib/owncloud/index.php;) (cd /usr/local/lib/owncloud; sudo -u www-data php /usr/local/lib/owncloud/index.php;)
fi
# Enable/disable apps. Note that this must be done after the ownCloud setup. # Enable/disable apps. Note that this must be done after the ownCloud setup.
# The firstrunwizard gave Josh all sorts of problems, so disabling that. # The firstrunwizard gave Josh all sorts of problems, so disabling that.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment