diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..a01ee289f --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.*.swp diff --git a/fail2ban.sh b/fail2ban.sh index 6ca3f5311..2477a8727 100755 --- a/fail2ban.sh +++ b/fail2ban.sh @@ -19,10 +19,10 @@ set -xe sudo su -NCLOG=/var/www/nextcloud/data/nextcloud.log # location of Nextcloud logs -BANTIME=600 # time to ban an IP that exceeded attempts -FINDTIME=600 # cooldown time for incorrect passwords -MAXRETRY=6 # bad attempts before banning an IP +NCLOG_=/var/www/nextcloud/data/nextcloud.log # location of Nextcloud logs +BANTIME_=600 # time to ban an IP that exceeded attempts +FINDTIME_=600 # cooldown time for incorrect passwords +MAXRETRY_=6 # bad attempts before banning an IP set -xe @@ -39,7 +39,7 @@ chown -R www-data /var/www/nextcloud/data cd /var/www/nextcloud sudo -u www-data php occ config:system:set loglevel --value=2 sudo -u www-data php occ config:system:set log_type --value=file -sudo -u www-data php occ config:system:set logfile --value=$NCLOG +sudo -u www-data php occ config:system:set logfile --value=$NCLOG_ cat > /etc/fail2ban/filter.d/nextcloud.conf <<'EOF' [INCLUDES] @@ -62,12 +62,12 @@ cat > /etc/fail2ban/jail.conf < # GPL licensed (see end of file) * Use at your own risk! # # Usage: -# ./install-nextcloud.sh # Use the IP of your running QEMU Raspbian image +# ./installer.sh # # Notes: -# Set DOWNLOAD=0 if you have already downloaded an image. Rename it to nextcloudpi.img +# Use a Raspbian image to be run on QEMU +# Use any script that would run locally on the image +# Use the IP of your running QEMU Raspbian image (DHCP should assign always the same) INSTALL_SCRIPT=$1 IMGFILE=$2 # First argument is the image file to start from @@ -20,7 +28,7 @@ IP=$3 # Second argument is the QEMU Raspbian IP address source library.sh # initializes $IMGOUT launch_install_qemu $INSTALL_SCRIPT $IMGFILE $IP || exit -pack_image $IMGFILE $IMGOUT +pack_image $IMGFILE $IMGOUT # License diff --git a/library.sh b/library.sh index 75e7c9a89..bfd416a38 100755 --- a/library.sh +++ b/library.sh @@ -7,8 +7,9 @@ IMGOUT=$( basename $IMGFILE .img )_$( basename $INSTALL_SCRIPT .sh ).img +CFGOUT=config_$( basename $INSTALL_SCRIPT .sh ).txt -SSH=( ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o ServerAliveInterval=5 -o ConnectTimeout=1 -o LogLevel=quiet ) +SSH=( ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o ServerAliveInterval=5 -o ConnectTimeout=20 -o LogLevel=quiet ) function launch_install_qemu() { @@ -31,8 +32,8 @@ function launch_install_qemu() launch_qemu $IMGFILE & sleep 10 wait_SSH $IP - sleep 120 # FIXME for some reason, SSH is ready but blocks for PIXEL image - launch_installation $INSTALL_SCRIPT + sleep 120 # FIXME for some reason, SSH is ready but fails if CPU still busy + launch_installation $INSTALL_SCRIPT $IP wait NUM_REBOOTS=$(( NUM_REBOOTS-1 )) done @@ -63,9 +64,108 @@ function wait_SSH() function launch_installation() { local INSTALL_SCRIPT=$1 + local IP=$2 test -f $1 || { echo "File $INSTALL_SCRIPT not found"; return 1; } echo "Launching installation" - cat $INSTALL_SCRIPT | sshpass -praspberry ${SSH[@]} pi@$IP + config $INSTALL_SCRIPT 4>&1 1>&2 2>&4 4>&- | sshpass -praspberry ${SSH[@]} pi@$IP | sed 1,7d + echo "configuration saved to $CFGOUT" +} + +function config() +{ + local INSTALL_SCRIPT="$1" + local BACKTITLE="NextCloudPi installer configuration" + + test -f "$INSTALL_SCRIPT" || { echo "file "$INSTALL_SCRIPT" not found"; return 1; } + local VARS=( $( grep "^[[:alpha:]]\+_=" "$INSTALL_SCRIPT" | cut -d= -f1 | sed 's|_$||' ) ) + local VALS=( $( grep "^[[:alpha:]]\+_=" "$INSTALL_SCRIPT" | cut -d= -f2 ) ) + + test ${#VARS[@]} -eq 0 && { echo here; cat "$INSTALL_SCRIPT" >&2; return; } + + for i in `seq 1 1 ${#VARS[@]} `; do + local PARAM+="${VARS[$((i-1))]} $i 1 ${VALS[$((i-1))]} $i 15 30 0 " + done + + local DIALOG_OK=0 + local DIALOG_CANCEL=1 + local DIALOG_HELP=2 + local DIALOG_EXTRA=3 + local DIALOG_ITEM_HELP=4 + local DIALOG_ERROR=254 + local DIALOG_ESC=255 + local returncode=0 + + while test $returncode != 1 && test $returncode != 250; do + exec 3>&1 + local value + value=$( dialog --ok-label "Submit" \ + --backtitle "$BACKTITLE" \ + --form "Enter the desired configuration" \ + 20 50 0 $PARAM \ + 2>&1 1>&3 ) + returncode=$? + exec 3>&- + + case $returncode in + $DIALOG_CANCEL) + dialog \ + --clear \ + --backtitle "$BACKTITLE" \ + --yesno "Really quit?" 10 30 + case $? in + $DIALOG_OK) + break + ;; + $DIALOG_CANCEL) + returncode=99 + ;; + esac + ;; + $DIALOG_OK) + dialog \ + --clear \ + --backtitle "$BACKTITLE" --no-collapse --cr-wrap \ + --yesno "The following configuration will be used\n\n$value" 10 60 + case $? in + $DIALOG_OK) + local RET=( $value ) + for i in `seq 0 1 $(( ${#RET[@]} - 1 )) `; do + local SEDRULE+="s|^${VARS[$i]}_=.*|${VARS[$i]}_=${RET[$i]}|;" + local CONFIG+="${VARS[$i]}=${RET[$i]}\n" + done + break + ;; + $DIALOG_CANCEL) + returncode=99 + ;; + esac + ;; + $DIALOG_HELP) + echo "Button 2 (Help) pressed." + return + ;; + $DIALOG_EXTRA) + echo "Button 3 (Extra) pressed." + return + ;; + $DIALOG_ERROR) + echo "ERROR!$value" + return + ;; + $DIALOG_ESC) + echo "ESC pressed." + return + ;; + *) + echo "Return code was $returncode" + return + ;; + esac + done + + sed $SEDRULE "$INSTALL_SCRIPT" >&2 + echo -e "$CONFIG" > $CFGOUT + clear } function pack_image() diff --git a/nextcloud.sh b/nextcloud.sh index bffdee547..ca121e655 100755 --- a/nextcloud.sh +++ b/nextcloud.sh @@ -23,10 +23,10 @@ set -xe sudo su VER=11.0.1 -ADMINUSER=admin -DBADMIN=ncadmin -DBPASSWD=ownyourbits -MAX_FILESIZE=1G +ADMINUSER_=admin +DBADMIN_=ncadmin +DBPASSWD_=ownyourbits +MAX_FILESIZE_=1G STATE_FILE=/home/pi/.installation_state set -xe @@ -79,8 +79,8 @@ EOF apt-get install php7.0-APC -y apt-get install libxml2-dev php-zip php-dom php-xmlwriter php-xmlreader php-gd php-curl php-mbstring -y - debconf-set-selections <<< "mariadb-server-5.5 mysql-server/root_password password $DBPASSWD" - debconf-set-selections <<< "mariadb-server-5.5 mysql-server/root_password_again password $DBPASSWD" + debconf-set-selections <<< "mariadb-server-5.5 mysql-server/root_password password $DBPASSWD_" + debconf-set-selections <<< "mariadb-server-5.5 mysql-server/root_password_again password $DBPASSWD_" apt-get install mariadb-server php7.0-mysql -y # CONFIGURE APACHE AND PHP7 @@ -212,10 +212,10 @@ cat > /etc/apache2/sites-available/nextcloud.conf <<'EOF' EOF a2ensite nextcloud - mysql -u root -p$DBPASSWD < '\''\\OC\\Memcache\\APCu'\'',\n);=' /var/www/nextcloud/config/config.php - sed -i "s/post_max_size=.*/post_max_size=$MAX_FILESIZE/" /var/www/nextcloud/.user.ini - sed -i "s/post_max_size=.*/upload_max_filesize=$MAX_FILESIZE/" /var/www/nextcloud/.user.ini - sed -i "s/post_max_size=.*/post_max_size=$MAX_FILESIZE/" /var/www/nextcloud/.htaccess - sed -i "s/post_max_size=.*/upload_max_filesize=$MAX_FILESIZE/" /var/www/nextcloud/.htaccess + sed -i "s/post_max_size=.*/post_max_size=$MAX_FILESIZE_/" /var/www/nextcloud/.user.ini + sed -i "s/post_max_size=.*/upload_max_filesize=$MAX_FILESIZE_/" /var/www/nextcloud/.user.ini + sed -i "s/post_max_size=.*/post_max_size=$MAX_FILESIZE_/" /var/www/nextcloud/.htaccess + sed -i "s/post_max_size=.*/upload_max_filesize=$MAX_FILESIZE_/" /var/www/nextcloud/.htaccess echo "*/15 * * * * php -f /var/www/nextcloud/cron.php" > /tmp/crontab_http crontab -u www-data /tmp/crontab_http