diff options
author | nachoparker <nacho@ownyourbits.com> | 2017-08-31 09:45:56 +0300 |
---|---|---|
committer | nachoparker <nacho@ownyourbits.com> | 2017-09-02 00:32:16 +0300 |
commit | 009c82e6cfb82cc40c49a9e253fe41bbbf779b13 (patch) | |
tree | 8213b20f68cfbe2941013eef540ec95a379bfb02 | |
parent | cfc759969a9f0afdde35689e7185d49533e6c78f (diff) |
shellcheck style fixesv0.24.12
28 files changed, 167 insertions, 172 deletions
@@ -22,14 +22,14 @@ IMGBASE="NextCloudPi_$( date "+%m-%d-%y" )_base.img" export NO_CONFIG=1 # skip interactive configuration -download_resize_raspbian_img 1G $IMGBASE || exit 1 +download_resize_raspbian_img 1G "$IMGBASE" || exit 1 -NO_HALT_STEP=1 ./installer.sh prepare.sh $IP $IMGBASE || exit 1 - ./installer.sh lamp.sh $IP $( ls -1t *.img | head -1 ) || exit 1 - ./installer.sh $NC_INSTALL $IP $( ls -1t *.img | head -1 ) || exit 1 - ./installer.sh $NC_CONFIG $IP $( ls -1t *.img | head -1 ) || exit 1 - ./installer.sh nextcloudpi.sh $IP $( ls -1t *.img | head -1 ) || exit 1 -# ./installer.sh build-devel.sh $IP $( ls -1t *.img | head -1 ) || exit 1 +NO_HALT_STEP=1 ./installer.sh prepare.sh "$IP" "$IMGBASE" || exit 1 + ./installer.sh lamp.sh "$IP" "$( ls -1t *.img | head -1 )" || exit 1 + ./installer.sh $NC_INSTALL "$IP" "$( ls -1t *.img | head -1 )" || exit 1 + ./installer.sh $NC_CONFIG "$IP" "$( ls -1t *.img | head -1 )" || exit 1 + ./installer.sh nextcloudpi.sh "$IP" "$( ls -1t *.img | head -1 )" || exit 1 +# ./installer.sh build-devel.sh "$IP" "$( ls -1t *.img | head -1 )" || exit 1 IMGFILE=$( ls -1t *.img | head -1 ) IMGNAME=$( basename "$IMGFILE" _base_prepare_lamp_nc-nextcloud_nc-init_nextcloudpi.img ) @@ -39,22 +39,22 @@ IMGNAME=$( basename "$IMGFILE" _base_prepare_lamp_nc-nextcloud_nc-init_nextcloud ## PACKING pack_image "$IMGFILE" "$IMGNAME.img" -md5sum $IMGNAME.tar.bz2 +md5sum "$IMGNAME.tar.bz2" -rm -rf torrent/$IMGNAME -mkdir -p torrent/$IMGNAME && cp $IMGNAME.tar.bz2 torrent/$IMGNAME -create_torrent torrent/$IMGNAME +rm -rf torrent/"$IMGNAME" +mkdir -p torrent/"$IMGNAME" && cp "$IMGNAME.tar.bz2" torrent/"$IMGNAME" +create_torrent torrent/"$IMGNAME" mkdir -p partial && mv NextCloudPi*.bz2 partial ## TESTING launch_qemu "$IMGNAME.img" & sleep 10 -wait_SSH $IP +wait_SSH "$IP" sleep 180 # Wait for the services to start. Improve this ( wait HTTP && trusted domains ) -tests/tests.py $IP +tests/tests.py "$IP" -ssh_pi $IP sudo halt +ssh_pi "$IP" sudo halt rm -f *.img diff --git a/bin/ncp-check-version b/bin/ncp-check-version index 3cb25c18..5075edfb 100755 --- a/bin/ncp-check-version +++ b/bin/ncp-check-version @@ -8,11 +8,11 @@ ping -W 2 -w 1 -q github.com &>/dev/null || { echo "No internet connectivity"; git clone --depth 20 -q --bare https://github.com/nextcloud/nextcloudpi.git /tmp/ncp-check-tmp || exit 1 -cd /tmp/ncp-check-tmp +cd /tmp/ncp-check-tmp || exit 1 VER=$( git describe --always --tags | grep -oP "v\d+\.\d+\.\d+" ) -grep -qP "v\d+\.\d+\.\d+" <<< $VER && { # check format - echo $VER > /var/run/.ncp-latest-version +grep -qP "v\d+\.\d+\.\d+" <<< "$VER" && { # check format + echo "$VER" > /var/run/.ncp-latest-version } -cd / +cd / || exit 1 rm -rf /tmp/ncp-check-tmp diff --git a/bin/ncp-test-updates b/bin/ncp-test-updates index b0f79ab1..1a362401 100755 --- a/bin/ncp-test-updates +++ b/bin/ncp-test-updates @@ -15,11 +15,11 @@ if test -f $VERFILE && grep -qP "v\d+\.\d+\.\d+" $VERFILE; then MIN=$( grep -oP "\d+\.\d+\.\d+" /usr/local/etc/ncp-version | cut -d. -f2 ) PAT=$( grep -oP "\d+\.\d+\.\d+" /usr/local/etc/ncp-version | cut -d. -f3 ) - if [ $MAJOR -gt $MAJ ]; then + if [ "$MAJOR" -gt "$MAJ" ]; then NEED_UPDATE=true - elif [ $MAJOR -eq $MAJ ] && [ $MINOR -gt $MIN ]; then + elif [ "$MAJOR" -eq "$MAJ" ] && [ "$MINOR" -gt "$MIN" ]; then NEED_UPDATE=true - elif [ $MAJOR -eq $MAJ ] && [ $MINOR -eq $MIN ] && [ $PATCH -gt $PAT ]; then + elif [ "$MAJOR" -eq "$MAJ" ] && [ "$MINOR" -eq "$MIN" ] && [ "$PATCH" -gt "$PAT" ]; then NEED_UPDATE=true fi fi diff --git a/bin/ncp-update b/bin/ncp-update index 32bcd2d8..615595f0 100755 --- a/bin/ncp-update +++ b/bin/ncp-update @@ -3,7 +3,7 @@ # update latest NextCloudPi code from github { - [ $(id -u) -ne 0 ] && { printf "Must be run as root. Try 'sudo $0'\n"; exit 1; } + [ "$(id -u)" -ne 0 ] && { printf "Must be run as root. Try 'sudo $0'\n"; exit 1; } ping -W 2 -w 1 -q github.com &>/dev/null || { echo "No internet connectivity"; exit 1; } echo -e "Downloading updates" rm -rf /tmp/ncp-update-tmp @@ -14,9 +14,9 @@ ./update.sh VER=$( git describe --always --tags | grep -oP "v\d+\.\d+\.\d+" ) - grep -qP "v\d+\.\d+\.\d+" <<< $VER && { # check format - echo $VER > /usr/local/etc/ncp-version - echo $VER > /var/run/.ncp-latest-version + grep -qP "v\d+\.\d+\.\d+" <<< "$VER" && { # check format + echo "$VER" > /usr/local/etc/ncp-version + echo "$VER" > /var/run/.ncp-latest-version } cd / diff --git a/bin/nextcloudpi-config b/bin/nextcloudpi-config index 598329e2..a21336a8 100755 --- a/bin/nextcloudpi-config +++ b/bin/nextcloudpi-config @@ -20,6 +20,7 @@ function nextcloud-config() local VERFILE=/var/run/.ncp-latest-version local BACKTITLE="NextCloudPi configuration ver. " local CONFDIR=/usr/local/etc/nextcloudpi-config.d/ + local DESC # save latest version if it has never done before test -f $VERFILE || ncp-check-version @@ -36,9 +37,9 @@ function nextcloud-config() # fill options local LIST=() for item in $CONFDIR/*.sh; do - local DESC=$( grep "DESCRIPTION=" $item | sed 's|^DESCRIPTION="||;s|"$||' ) - grep -q "^ACTIVE_=yes" $item && local ON="✓" || local ON=" " - LIST+=( "$ON $( basename $item .sh )" "$DESC" ) + DESC=$( grep "DESCRIPTION=" "$item" | sed 's|^DESCRIPTION="||;s|"$||' ) + grep -q "^ACTIVE_=yes" "$item" && local ON="✓" || local ON=" " + LIST+=( "$ON $( basename "$item" .sh )" "$DESC" ) done # launch the selection menu @@ -56,8 +57,8 @@ function nextcloud-config() script=$( sed 's=✓\| ==g' <<< "$script" ) # launch selected script - info_script $script.sh || continue; - configure_script $script.sh && { echo "Done. Press any key..."; read; } + info_script "$script".sh || continue; + configure_script "$script".sh && { echo "Done. Press any key..."; read -r; } done } diff --git a/build-devel.sh b/build-devel.sh index fbcf9aa8..f83d5ddf 100644 --- a/build-devel.sh +++ b/build-devel.sh @@ -20,18 +20,18 @@ install() echo -e "Downloading updates" rm -rf /tmp/ncp-update-tmp git clone --depth 20 -q -b devel https://github.com/nextcloud/nextcloudpi.git /tmp/ncp-update-tmp - cd /tmp/ncp-update-tmp + cd /tmp/ncp-update-tmp || return 1 echo -e "Performing updates" ./update.sh VER=$( git describe --always --tags | grep -oP "v\d+\.\d+\.\d+" ) grep -qP "v\d+\.\d+\.\d+" <<< $VER && { # check format - echo $VER > /usr/local/etc/ncp-version - echo $VER > /var/run/.ncp-latest-version + echo "$VER" > /usr/local/etc/ncp-version + echo "$VER" > /var/run/.ncp-latest-version } - cd / + cd / || return 1 rm -rf /tmp/ncp-update-tmp echo -e "NextCloudPi updated to version $VER" diff --git a/docker/build-container.sh b/docker/build-container.sh index 7ac041e2..7080ae0b 100644 --- a/docker/build-container.sh +++ b/docker/build-container.sh @@ -1,4 +1,4 @@ -#!/bin/bish +#!/bin/bash # Build NextCloudPi ARM docker container in a QEMU Raspbian with docker # diff --git a/docker/docker-env.sh b/docker/docker-env.sh index 0ef112ce..70c9bc04 100644 --- a/docker/docker-env.sh +++ b/docker/docker-env.sh @@ -1,4 +1,4 @@ -#!/bin/bish +#!/bin/bash # Install docker ARM on Raspbian # diff --git a/docker/run-nc.sh b/docker/run-nc.sh index eed13840..6f3dcd34 100755 --- a/docker/run-nc.sh +++ b/docker/run-nc.sh @@ -1,5 +1,8 @@ #!/bin/bash +NCDIR=/var/www/nextcloud +OCC="$NCDIR/www/nextcloud/occ" + cleanup() { apachectl graceful-stop @@ -34,29 +37,26 @@ test -d /data/app || { activate_script /usr/local/etc/nextcloudpi-config.d/nc-init.sh # COPY DATADIR TO /data, WHICH WILL BE IN A PERSISTENT VOLUME - cd /var/www/nextcloud/ echo "Setting up persistent data dir..." - cp -ra /var/www/nextcloud/data /data/app - sudo -u www-data php occ config:system:set datadirectory --value=/data/app + cp -ra /"$NCDIR"/data /data/app + sudo -u www-data php $OCC config:system:set datadirectory --value=/data/app # COPY CONFIG TO /data, WHICH WILL BE IN A PERSISTENT VOLUME echo "Setting up persistent configuration..." - test -e /data/config || mv /var/www/nextcloud/config /data + test -e /data/config || mv /"$NCDIR"/config /data } # Use persistent configuration test -e /data/config && { - rm -rf /var/www/nextcloud/config - ln -s /data/config /var/www/nextcloud/config + rm -rf /"$NCDIR"/config + ln -s /data/config /"$NCDIR"/config } -cd /var/www/nextcloud/ - # Trusted Domain ( as an argument ) [[ "$@" != "" ]] && { IP=$( grep -oP '\d{1,3}(\.\d{1,3}){3}' <<< "$1" ) # validate that the first argument is a valid IP if [[ "$IP" != "" ]]; then - sudo -u www-data php occ config:system:set trusted_domains 1 --value=$IP + sudo -u www-data php $OCC config:system:set trusted_domains 1 --value="$IP" else echo "First argument must be an IP address to include as a Trusted domain. Ignoring" fi @@ -65,7 +65,7 @@ cd /var/www/nextcloud/ # Trusted Domain ( local IP ) IFACE=$( ip r | grep "default via" | awk '{ print $5 }' ) IP=$( ip a | grep "global $IFACE" | grep -oP '\d{1,3}(.\d{1,3}){3}' | head -1 ) -sudo -u www-data php occ config:system:set trusted_domains 2 --value=$IP +sudo -u www-data php $OCC config:system:set trusted_domains 2 --value="$IP" echo "Starting Apache" /usr/sbin/apache2ctl start diff --git a/etc/library.sh b/etc/library.sh index b89bc76d..79d77d9f 100755 --- a/etc/library.sh +++ b/etc/library.sh @@ -9,8 +9,8 @@ # -IMGNAME=$( basename $IMGFILE .img )_$( basename $INSTALL_SCRIPT .sh ).img -CFGOUT=config_$( basename $INSTALL_SCRIPT .sh ).txt +IMGNAME=$( basename "$IMGFILE" .img )_$( basename "$INSTALL_SCRIPT" .sh ).img +CFGOUT=config_$( basename "$INSTALL_SCRIPT" .sh ).txt DBG=x # $IMGOUT will contain the name of the last step @@ -19,23 +19,23 @@ function launch_install_qemu() local IMG=$1 local IP=$2 [[ "$IP" == "" ]] && { echo "usage: launch_install_qemu <script> <img> <IP>"; return 1; } - test -f $IMG || { echo "input file $IMG not found"; return 1; } + test -f "$IMG" || { echo "input file $IMG not found"; return 1; } - local BASE=$( sed 's=-stage[[:digit:]]==' <<< $IMG ) - local NUM=$( sed 's=.*-stage\([[:digit:]]\)=\1=' <<< $IMG ) + local BASE=$( sed 's=-stage[[:digit:]]==' <<< "$IMG" ) + local NUM=$( sed 's=.*-stage\([[:digit:]]\)=\1=' <<< "$IMG" ) [[ "$BASE" == "$IMG" ]] && NUM=0 - local NUM_REBOOTS=$( grep -c reboot $INSTALL_SCRIPT ) + local NUM_REBOOTS=$( grep -c reboot "$INSTALL_SCRIPT" ) while [[ $NUM_REBOOTS != -1 ]]; do NUM=$(( NUM+1 )) IMGOUT="$BASE-stage$NUM" - cp -v $IMG $IMGOUT || return 1 # take a copy of the input image for processing ( append "-stage1" ) + cp -v "$IMG" "$IMGOUT" || return 1 # take a copy of the input image for processing ( append "-stage1" ) pgrep qemu-system-arm &>/dev/null && { echo -e "QEMU instance already running. Abort..."; return 1; } - launch_qemu $IMGOUT & + launch_qemu "$IMGOUT" & sleep 10 - wait_SSH $IP - launch_installation_qemu $IP || return 1 + wait_SSH "$IP" + launch_installation_qemu "$IP" || return 1 wait IMG="$IMGOUT" NUM_REBOOTS=$(( NUM_REBOOTS-1 )) @@ -46,12 +46,12 @@ function launch_install_qemu() function launch_qemu() { local IMG=$1 - test -f $1 || { echo "Image $IMG not found"; return 1; } + test -f "$1" || { echo "Image $IMG not found"; return 1; } test -d qemu-raspbian-network || git clone https://github.com/nachoparker/qemu-raspbian-network.git sed -i '30s/NO_NETWORK=1/NO_NETWORK=0/' qemu-raspbian-network/qemu-pi.sh sed -i '35s/NO_GRAPHIC=0/NO_GRAPHIC=1/' qemu-raspbian-network/qemu-pi.sh echo "Starting QEMU image $IMG" - ( cd qemu-raspbian-network && sudo ./qemu-pi.sh ../$IMG 2>/dev/null ) + ( cd qemu-raspbian-network && sudo ./qemu-pi.sh ../"$IMG" 2>/dev/null ) } function ssh_pi() @@ -81,7 +81,7 @@ function wait_SSH() local IP=$1 echo "Waiting for SSH to be up on $IP..." while true; do - ssh_pi $IP : && break + ssh_pi "$IP" : && break sleep 1 done echo "SSH is up" @@ -98,7 +98,7 @@ sudo su set -e$DBG " echo "Launching installation" - echo -e "$PREINST_CODE\n$INSTALLATION_CODE\n$INSTALLATION_STEPS" | ssh_pi $IP || { echo "Installation to $IP failed" && return 1; } + echo -e "$PREINST_CODE\n$INSTALLATION_CODE\n$INSTALLATION_STEPS" | ssh_pi "$IP" || { echo "Installation to $IP failed" && return 1; } echo "configuration saved to $CFGOUT" } @@ -114,7 +114,7 @@ $CFG_STEP $CLEANUP_STEP $HALT_STEP " - launch_installation $IP + launch_installation "$IP" } function launch_installation_online() @@ -125,7 +125,7 @@ function launch_installation_online() install $CFG_STEP " - launch_installation $IP + launch_installation "$IP" } # Initializes $INSTALLATION_CODE @@ -136,13 +136,13 @@ function config() type dialog &>/dev/null || { echo "please, install dialog for interactive configuration"; return 1; } - test -f "$INSTALL_SCRIPT" || { echo "file "$INSTALL_SCRIPT" not found"; return 1; } + 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 ) ) [[ "$NO_CONFIG" == "1" ]] || test ${#VARS[@]} -eq 0 && { INSTALLATION_CODE="$( cat "$INSTALL_SCRIPT" )"; return; } - for i in `seq 1 1 ${#VARS[@]} `; do + for i in $( seq 1 1 ${#VARS[@]} ); do local PARAM+="${VARS[$((i-1))]} $i 1 ${VALS[$((i-1))]} $i 15 60 0 " done @@ -167,7 +167,7 @@ function config() ;; $DIALOG_OK) local RET=( $value ) - for i in `seq 0 1 $(( ${#RET[@]} - 1 )) `; do + 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 @@ -188,7 +188,7 @@ function config() esac done - INSTALLATION_CODE="$( sed $SEDRULE "$INSTALL_SCRIPT" )" + INSTALLATION_CODE="$( sed "$SEDRULE" "$INSTALL_SCRIPT" )" [[ "$CFGOUT" != "" ]] && echo -e "$CONFIG" > "$CFGOUT" } @@ -196,8 +196,8 @@ function install_script() { ( local SCRIPT=$1 - source ./$SCRIPT - echo -e "Installing $( basename $SCRIPT .sh )" + source ./"$SCRIPT" + echo -e "Installing $( basename "$SCRIPT" .sh )" set +x install ) @@ -206,15 +206,15 @@ function install_script() function activate_script() { local SCRIPT=$1 - echo -e "Activating $( basename $SCRIPT .sh )" - launch_script $SCRIPT + echo -e "Activating $( basename "$SCRIPT" .sh )" + launch_script "$SCRIPT" } function launch_script() { ( local SCRIPT=$1 - source ./$SCRIPT + source ./"$SCRIPT" set +x configure ) @@ -224,9 +224,9 @@ function info_script() { ( local SCRIPT=$1 - cd /usr/local/etc/nextcloudpi-config.d/ + cd /usr/local/etc/nextcloudpi-config.d/ || return 1 unset show_info - source ./$SCRIPT + source ./"$SCRIPT" [[ $( type -t show_info ) == function ]] || return 0 [[ $( type -t show_info ) == function ]] && show_info ) @@ -236,12 +236,12 @@ function configure_script() { ( local SCRIPT=$1 - cd /usr/local/etc/nextcloudpi-config.d/ - config $SCRIPT || return 1 # writes "$INSTALLATION_CODE" - echo -e "$INSTALLATION_CODE" > $SCRIPT # save configuration - source ./$SCRIPT # load configuration - printf '\033[2J' && tput cup 0 0 # clear screen, don't clear scroll, cursor on top - echo -e "Launching $( basename $SCRIPT .sh )" + cd /usr/local/etc/nextcloudpi-config.d/ || return 1 + config "$SCRIPT" || return 1 # writes "$INSTALLATION_CODE" + echo -e "$INSTALLATION_CODE" > "$SCRIPT" # save configuration + source ./"$SCRIPT" # load configuration + printf '\033[2J' && tput cup 0 0 # clear screen, don't clear scroll, cursor on top + echo -e "Launching $( basename "$SCRIPT" .sh )" set +x configure return 0 @@ -253,13 +253,15 @@ function copy_to_image() local IMG=$1 local DST=$2 local SRC=${@: 3 } - local SECTOR=$( fdisk -l $IMG | grep Linux | awk '{ print $2 }' ) - local OFFSET=$(( SECTOR * 512 )) + local SECTOR + local OFFSET + SECTOR=$( fdisk -l "$IMG" | grep Linux | awk '{ print $2 }' ) + OFFSET=$(( SECTOR * 512 )) [ -f "$IMG" ] || { echo "no image"; return 1; } mkdir -p tmpmnt - sudo mount $IMG -o offset=$OFFSET tmpmnt || return 1 - sudo cp -v $SRC tmpmnt/$DST || return 1 + sudo mount "$IMG" -o offset="$OFFSET" tmpmnt || return 1 + sudo cp -v "$SRC" tmpmnt/"$DST" || return 1 sudo umount -l tmpmnt rmdir tmpmnt &>/dev/null } @@ -270,15 +272,15 @@ function download_resize_raspbian_img() local IMGFILE=$2 local IMG=raspbian_lite_latest - test -f $IMGFILE && \ + test -f "$IMGFILE" && \ echo -e "INFO: $IMGFILE already exists. Skipping download ..." && return 0 test -f $IMG.zip || \ wget https://downloads.raspberrypi.org/$IMG -O $IMG.zip || return 1 unzip -o $IMG.zip && \ - mv *-raspbian-*.img $IMGFILE && \ - qemu-img resize -f raw $IMGFILE +$SIZE && \ + mv *-raspbian-*.img "$IMGFILE" && \ + qemu-img resize -f raw "$IMGFILE" +"$SIZE" && \ return 0 } @@ -290,18 +292,18 @@ function pack_image() echo "copying $IMGOUT → $IMGNAME" cp "$IMGOUT" "$IMGNAME" || return 1 echo "packing $IMGNAME → $TARNAME" - tar -I pbzip2 -cvf $TARNAME "$IMGNAME" &>/dev/null && \ + tar -I pbzip2 -cvf "$TARNAME" "$IMGNAME" &>/dev/null && \ echo -e "$TARNAME packed successfully" } function create_torrent() { [[ "$1" == "" ]] && { echo "No directory specified"; exit 1; } - test -d $1 || { echo "$1 not found or is not a directory" ; exit 1; } + test -d "$1" || { echo "$1 not found or is not a directory" ; exit 1; } - md5sum $1/*.bz2 > $1/md5sum + md5sum "$1"/*.bz2 > "$1"/md5sum - createtorrent -a udp://tracker.opentrackr.org -p 1337 -c "NextCloudPi. Nextcloud for Raspberry Pi image" $1 $1.torrent + createtorrent -a udp://tracker.opentrackr.org -p 1337 -c "NextCloudPi. Nextcloud for Raspberry Pi image" "$1" "$1".torrent } # License # diff --git a/etc/nextcloudpi-config.d/fail2ban.sh b/etc/nextcloudpi-config.d/fail2ban.sh index d077fed8..54ac9ad2 100644 --- a/etc/nextcloudpi-config.d/fail2ban.sh +++ b/etc/nextcloudpi-config.d/fail2ban.sh @@ -42,15 +42,15 @@ configure() [[ $ACTIVE_ != "yes" ]] && { service fail2ban stop; update-rc.d fail2ban disable; return; } local BASEDIR=$( dirname "$NCLOG_" ) - [ -d $BASEDIR ] || { echo -e "directory $BASEDIR not found"; return 1; } + [ -d "$BASEDIR" ] || { echo -e "directory $BASEDIR not found"; return 1; } - sudo -u www-data touch $NCLOG_ || { echo -e "ERROR: user www-data does not have write permissions on $NCLOG_"; return 1; } - chown -R www-data $BASEDIR + sudo -u www-data touch "$NCLOG_" || { echo -e "ERROR: user www-data does not have write permissions on $NCLOG_"; return 1; } + chown -R www-data "$BASEDIR" 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] diff --git a/etc/nextcloudpi-config.d/letsencrypt.sh b/etc/nextcloudpi-config.d/letsencrypt.sh index 8ca0f82c..ed64592f 100644 --- a/etc/nextcloudpi-config.d/letsencrypt.sh +++ b/etc/nextcloudpi-config.d/letsencrypt.sh @@ -17,13 +17,14 @@ DOMAIN_=mycloud.ownyourbits.com EMAIL_=mycloud@ownyourbits.com NCDIR=/var/www/nextcloud +OCC="$NCDIR/www/nextcloud/occ" VHOSTCFG=/etc/apache2/sites-available/nextcloud.conf VHOSTCFG2=/etc/apache2/sites-available/ncp.conf DESCRIPTION="Automatic signed SSL certificates" install() { - cd /etc + cd /etc || return 1 git clone https://github.com/letsencrypt/letsencrypt /etc/letsencrypt/letsencrypt-auto --help # do not actually run certbot, only install packages } @@ -59,9 +60,8 @@ configure() /etc/letsencrypt/letsencrypt-auto certonly -n --no-self-upgrade --webroot -w $NCDIR --hsts --agree-tos -m $EMAIL_ -d $DOMAIN_ && { echo "* 1 * * 1 root /etc/letsencrypt/certbot-auto renew --quiet" > /etc/cron.d/letsencrypt-ncp - cd /var/www/nextcloud - sudo -u www-data php occ config:system:set trusted_domains 4 --value=$DOMAIN_ - sudo -u www-data php occ config:system:set overwrite.cli.url --value=https://$DOMAIN_ + sudo -u www-data php $OCC config:system:set trusted_domains 4 --value=$DOMAIN_ + sudo -u www-data php $OCC config:system:set overwrite.cli.url --value=https://$DOMAIN_ # delayed in bg so it does not kill the connection, and we get AJAX response ( sleep 2 && systemctl restart apache2 ) &>/dev/null & diff --git a/etc/nextcloudpi-config.d/nc-backup-auto.sh b/etc/nextcloudpi-config.d/nc-backup-auto.sh index a5afbdbe..f016b5d1 100644 --- a/etc/nextcloudpi-config.d/nc-backup-auto.sh +++ b/etc/nextcloudpi-config.d/nc-backup-auto.sh @@ -40,7 +40,7 @@ EOF configure() { - [[ $ACTIVE_ != "yes" ]] && { + [[ $ACTIVE_ != "yes" ]] && { systemctl stop nc-backup.timer systemctl disable nc-backup.timer echo "automatic backups disabled" @@ -67,7 +67,7 @@ mysqldump -u root --single-transaction nextcloud > \$DBBACKUP [[ "$INCLUDEDATA_" == "yes" ]] && echo -e "backup datadir... " echo -e "backup files..." mkdir -p $DESTDIR_ -tar -cf \$DESTFILE $DATAFILE \$DBBACKUP nextcloud/ --exclude 'nextcloud/data/*/files/*' && \ +tar -cf \$DESTFILE \$DBBACKUP nextcloud/ --exclude 'nextcloud/data/*/files/*' && \ echo -e "backup \$DESTFILE generated" || \ echo -e "error generating backup" rm \$DBBACKUP diff --git a/etc/nextcloudpi-config.d/nc-backup.sh b/etc/nextcloudpi-config.d/nc-backup.sh index 076298fd..e75648b5 100644 --- a/etc/nextcloudpi-config.d/nc-backup.sh +++ b/etc/nextcloudpi-config.d/nc-backup.sh @@ -19,54 +19,52 @@ INCLUDEDATA_=no BACKUPLIMIT_=4 DESCRIPTION="Backup this NC instance to a file" -DESTFILE=$DESTDIR_/nextcloud-bkp_`date +"%Y%m%d"`.tar -DBBACKUP=nextcloud-sqlbkp_`date +"%Y%m%d"`.bak +DESTFILE="$DESTDIR_"/nextcloud-bkp_$( date +"%Y%m%d" ).tar +DBBACKUP=nextcloud-sqlbkp_$( date +"%Y%m%d" ).bak BASEDIR=/var/www configure() { local DATADIR - DATADIR=$( cd $BASEDIR/nextcloud; sudo -u www-data php occ config:system:get datadirectory ) || { + DATADIR=$( cd "$BASEDIR"/nextcloud; sudo -u www-data php occ config:system:get datadirectory ) || { echo -e "Error reading data directory. Is NextCloud running and configured?"; return 1; } - cd $BASEDIR/nextcloud - sudo -u www-data php occ maintenance:mode --on + sudo -u www-data php "$BASEDIR"/nextcloud/occ maintenance:mode --on - cd $BASEDIR + cd "$BASEDIR" || return 1 echo -e "backup database..." - mysqldump -u root --single-transaction nextcloud > $DBBACKUP + mysqldump -u root --single-transaction nextcloud > "$DBBACKUP" [[ "$INCLUDEDATA_" == "yes" ]] && echo -e "backup datadir... " echo -e "backup files..." - mkdir -p $DESTDIR_ - tar -cf $DESTFILE $DATAFILE $DBBACKUP nextcloud/ \ + mkdir -p "$DESTDIR_" + tar -cf "$DESTFILE" "$DBBACKUP" nextcloud/ \ --exclude "nextcloud/data/*/files/*" \ --exclude "nextcloud/data/.opcache" \ --exclude "nextcloud/data/{access,error,nextcloud}.log" \ && \ echo -e "backup $DESTFILE generated" || \ echo -e "error generating backup" - rm $DBBACKUP + rm "$DBBACKUP" [[ "$INCLUDEDATA_" == "yes" ]] && { - tar -rf $DESTFILE -C $DATADIR/.. $( basename $DATADIR ) || \ + tar -rf "$DESTFILE" -C "$DATADIR"/.. "$( basename "$DATADIR" )" || \ echo -e "error generating data backup" } # delete older backups [[ $BACKUPLIMIT_ != 0 ]] && { - local NUMBKPS=$( ls $DESTDIR_/nextcloud-bkp_* | wc -l ) + local NUMBKPS=$( ls "$DESTDIR_"/nextcloud-bkp_* | wc -l ) [[ $NUMBKPS > $BACKUPLIMIT_ ]] && \ - ls -t $DESTDIR_/nextcloud-bkp_* | tail -$(( NUMBKPS - $BACKUPLIMIT_ )) | while read f; do + ls -t $DESTDIR_/nextcloud-bkp_* | tail -$(( NUMBKPS - BACKUPLIMIT_ )) | while read -r f; do echo -e "clean up old backup $f" - rm $f + rm "$f" done } - cd $BASEDIR/nextcloud - sudo -u www-data php occ maintenance:mode --off + sudo -u www-data php "$BASEDIR"/nextcloud/occ maintenance:mode --off } install() { :; } diff --git a/etc/nextcloudpi-config.d/nc-database.sh b/etc/nextcloudpi-config.d/nc-database.sh index 4b5d6c7c..b1651f13 100644 --- a/etc/nextcloudpi-config.d/nc-database.sh +++ b/etc/nextcloudpi-config.d/nc-database.sh @@ -35,8 +35,8 @@ or the database will fail. configure() { - local SRCDIR=$( grep datadir /etc/mysql/mariadb.conf.d/50-server.cnf | cut -d= -f2 ) - [ -d $SRCDIR ] || { echo -e "database directory $SRCDIR not found"; return 1; } + local SRCDIR=$( grep datadir /etc/mysql/mariadb.conf.d/50-server.cnf | awk -F "= " '{ print $2 }' ) + [ -d "$SRCDIR" ] || { echo -e "database directory $SRCDIR not found"; return 1; } [ -d "$DBDIR_" ] && { [[ $( find "$DBDIR_" -maxdepth 0 -empty | wc -l ) == 0 ]] && { @@ -49,11 +49,11 @@ configure() local BASEDIR=$( dirname "$DBDIR_" ) mkdir -p "$BASEDIR" - grep -q ext <( stat -fc%T $BASEDIR ) || { echo -e "Only ext filesystems can hold the database"; return 1; } + grep -q ext <( stat -fc%T "$BASEDIR" ) || { echo -e "Only ext filesystems can hold the database"; return 1; } - sudo -u mysql test -x $BASEDIR || { echo -e "ERROR: the user mysql does not have access permissions over $BASEDIR"; return 1; } + sudo -u mysql test -x "$BASEDIR" || { echo -e "ERROR: the user mysql does not have access permissions over $BASEDIR"; return 1; } - [[ $( stat -fc%d / ) == $( stat -fc%d $BASEDIR ) ]] && \ + [[ $( stat -fc%d / ) == $( stat -fc%d "$BASEDIR" ) ]] && \ echo -e "INFO: moving database to another place in the same SD card\nIf you want to use an external mount, make sure it is properly set up" cd /var/www/nextcloud @@ -61,7 +61,7 @@ configure() echo "moving database to $DBDIR_..." service mysql stop - mv $SRCDIR "$DBDIR_" && \ + mv "$SRCDIR" "$DBDIR_" && \ sed -i "s|^datadir.*|datadir = $DBDIR_|" /etc/mysql/mariadb.conf.d/50-server.cnf service mysql start diff --git a/etc/nextcloudpi-config.d/nc-datadir.sh b/etc/nextcloudpi-config.d/nc-datadir.sh index 460b3e06..111698df 100644 --- a/etc/nextcloudpi-config.d/nc-datadir.sh +++ b/etc/nextcloudpi-config.d/nc-datadir.sh @@ -35,7 +35,7 @@ configure() echo -e "Error reading data directory. Is NextCloud running and configured?"; return 1; } - [ -d $SRCDIR ] || { echo -e "data directory $SRCDIR not found"; return 1; } + [ -d "$SRCDIR" ] || { echo -e "data directory $SRCDIR not found"; return 1; } [ -d $DATADIR_ ] && { [[ $( find "$DATADIR_" -maxdepth 0 -empty | wc -l ) == 0 ]] && { @@ -48,11 +48,11 @@ configure() local BASEDIR=$( dirname "$DATADIR_" ) mkdir -p "$BASEDIR" - grep -q ext <( stat -fc%T $BASEDIR ) || { echo -e "Only ext filesystems can hold the data directory"; return 1; } + grep -q ext <( stat -fc%T "$BASEDIR" ) || { echo -e "Only ext filesystems can hold the data directory"; return 1; } - sudo -u www-data test -x $BASEDIR || { echo -e "ERROR: the user www-data does not have access permissions over $BASEDIR"; return 1; } + sudo -u www-data test -x "$BASEDIR" || { echo -e "ERROR: the user www-data does not have access permissions over $BASEDIR"; return 1; } - [[ $( stat -fc%d / ) == $( stat -fc%d $BASEDIR ) ]] && \ + [[ $( stat -fc%d / ) == $( stat -fc%d "$BASEDIR" ) ]] && \ echo -e "INFO: moving data dir to another place in the same SD card\nIf you want to use an external mount, make sure it is properly set up" ## COPY @@ -71,7 +71,7 @@ configure() sed -i "s|^opcache.file_cache=.*|opcache.file_cache=$DATADIR_/.opcache|" /etc/php/7.0/mods-available/opcache.ini # datadir - sudo -u www-data php occ config:system:set datadirectory --value=$DATADIR_ + sudo -u www-data php occ config:system:set datadirectory --value="$DATADIR_" sudo -u www-data php occ maintenance:mode --off } diff --git a/etc/nextcloudpi-config.d/nc-format-USB.sh b/etc/nextcloudpi-config.d/nc-format-USB.sh index 259f6fbd..8b952d69 100644 --- a/etc/nextcloudpi-config.d/nc-format-USB.sh +++ b/etc/nextcloudpi-config.d/nc-format-USB.sh @@ -59,9 +59,9 @@ configure() local NAME=( $( lsblk -l -n | grep -v mmcblk | grep disk | awk '{ print $1 }' ) ) [[ ${#NAME[@]} != 1 ]] && { echo "unexpected error"; return 1; } - wipefs -a -f /dev/$NAME || return 1 - printf 'o\nn\np\n1\n\n\nw\n' | sudo fdisk /dev/$NAME || return 1 - mkfs.ext4 -F /dev/${NAME}1 -L "$LABEL_" + wipefs -a -f /dev/"$NAME" || return 1 + printf 'o\nn\np\n1\n\n\nw\n' | sudo fdisk /dev/"$NAME" || return 1 + mkfs.ext4 -F /dev/"${NAME}1" -L "$LABEL_" # trigger automount rules if active test -f /etc/udev/rules.d/50-automount.rules || return 0 diff --git a/etc/nextcloudpi-config.d/nc-forward-ports.sh b/etc/nextcloudpi-config.d/nc-forward-ports.sh index c16631b5..f8342a1f 100644 --- a/etc/nextcloudpi-config.d/nc-forward-ports.sh +++ b/etc/nextcloudpi-config.d/nc-forward-ports.sh @@ -41,10 +41,10 @@ configure() { local IFACE=$( ip r | grep "default via" | awk '{ print $5 }' ) local IP=$( ip a | grep "global $IFACE" | grep -oP '\d{1,3}(.\d{1,3}){3}' | head -1 ) - upnpc -d $HTTPSPORT_ TCP - upnpc -d $HTTPPORT_ TCP - upnpc -a $IP 443 $HTTPSPORT_ TCP - upnpc -a $IP 80 $HTTPPORT_ TCP + upnpc -d "$HTTPSPORT_" TCP + upnpc -d "$HTTPPORT_" TCP + upnpc -a "$IP" 443 "$HTTPSPORT_" TCP + upnpc -a "$IP" 80 "$HTTPPORT_" TCP } cleanup() diff --git a/etc/nextcloudpi-config.d/nc-nextcloud.sh b/etc/nextcloudpi-config.d/nc-nextcloud.sh index 84013b5f..9d0072a7 100644 --- a/etc/nextcloudpi-config.d/nc-nextcloud.sh +++ b/etc/nextcloudpi-config.d/nc-nextcloud.sh @@ -64,7 +64,7 @@ configure() # workaround to emulate DROP USER IF EXISTS ..;) local DBPASSWD=$( grep password /root/.my.cnf | cut -d= -f2 ) - mysql -u root -p$DBPASSWD <<EOF + mysql -u root -p"$DBPASSWD" <<EOF DROP DATABASE IF EXISTS nextcloud; CREATE DATABASE nextcloud CHARACTER SET utf8mb4 diff --git a/etc/nextcloudpi-config.d/nc-notify-updates.sh b/etc/nextcloudpi-config.d/nc-notify-updates.sh index ffcd3f9a..4c9b73b5 100644 --- a/etc/nextcloudpi-config.d/nc-notify-updates.sh +++ b/etc/nextcloudpi-config.d/nc-notify-updates.sh @@ -25,7 +25,7 @@ install() local URL=$( curl -s https://api.github.com/repos/nextcloud/admin_notifications/releases | \ grep browser_download_url | head -1 | cut -d '"' -f 4 ) cd /var/www/nextcloud/apps - wget $URL -O admin_notifications.tar.gz + wget "$URL" -O admin_notifications.tar.gz tar -xf admin_notifications.tar.gz rm *.tar.gz chown -R www-data:www-data * diff --git a/etc/nextcloudpi-config.d/nc-swapfile.sh b/etc/nextcloudpi-config.d/nc-swapfile.sh index 3a890ca8..5c794381 100644 --- a/etc/nextcloudpi-config.d/nc-swapfile.sh +++ b/etc/nextcloudpi-config.d/nc-swapfile.sh @@ -24,7 +24,7 @@ configure() [[ "$ORIG" == "$SWAPFILE_" ]] && return test -d "$SWAPFILE_" && { echo "$SWAPFILE_ is a directory. Abort"; return 1; } - [[ $( stat -fc%d / ) == $( stat -fc%d $( dirname $SWAPFILE_ ) ) ]] && \ + [[ $( stat -fc%d / ) == $( stat -fc%d $( dirname "$SWAPFILE_" ) ) ]] && \ echo -e "INFO: moving swapfile to another place in the same SD card\nIf you want to use an external mount, make sure it is properly set up" sed -i "s|#\?CONF_SWAPFILE=.*|CONF_SWAPFILE=$SWAPFILE_|" /etc/dphys-swapfile diff --git a/etc/nextcloudpi-config.d/no-ip.sh b/etc/nextcloudpi-config.d/no-ip.sh index 118aeeb8..928e139b 100644 --- a/etc/nextcloudpi-config.d/no-ip.sh +++ b/etc/nextcloudpi-config.d/no-ip.sh @@ -36,7 +36,7 @@ install() mkdir /tmp/noip && cd /tmp/noip wget http://www.no-ip.com/client/linux/noip-duc-linux.tar.gz tar vzxf noip-duc-linux.tar.gz - cd -; cd $OLDPWD/noip-2* + cd -; cd "$OLDPWD"/noip-2* make cp noip2 /usr/local/bin/ @@ -70,12 +70,12 @@ configure() ping -W 2 -w 1 -q github.com &>/dev/null || { echo "No internet connectivity"; return 1; } - /usr/local/bin/noip2 -C -c /usr/local/etc/no-ip2.conf -U $TIME_ -u $USER_ -p $PASS_ || return 1 + /usr/local/bin/noip2 -C -c /usr/local/etc/no-ip2.conf -U "$TIME_" -u "$USER_" -p "$PASS_" || return 1 update-rc.d noip2 enable service noip2 restart cd /var/www/nextcloud - sudo -u www-data php occ config:system:set trusted_domains 3 --value=$DOMAIN_ - sudo -u www-data php occ config:system:set overwrite.cli.url --value=https://$DOMAIN_ + sudo -u www-data php occ config:system:set trusted_domains 3 --value="$DOMAIN_" + sudo -u www-data php occ config:system:set overwrite.cli.url --value=https://"$DOMAIN_" } cleanup() diff --git a/installer.sh b/installer.sh index 027d4a16..5d53c8f7 100755 --- a/installer.sh +++ b/installer.sh @@ -37,15 +37,15 @@ IMGFILE=$3 # Third argument is the image file to start from ( empty source etc/library.sh # initializes $IMGNAME -test -f $IMGNAME && { echo "INFO: $IMGNAME already exists. Skip generation ... "; exit 0; } +test -f "$IMGNAME" && { echo "INFO: $IMGNAME already exists. Skip generation ... "; exit 0; } -config $INSTALL_SCRIPT || exit 1 # Initializes $INSTALLATION_CODE +config "$INSTALL_SCRIPT" || exit 1 # Initializes $INSTALLATION_CODE if [[ "$IMGFILE" != "" ]]; then - launch_install_qemu "$IMGFILE" $IP || { sudo killall qemu-system-arm; exit 1; } # initializes $IMGOUT - pack_image "$IMGOUT" "$IMGNAME" + launch_install_qemu "$IMGFILE" "$IP" || { sudo killall qemu-system-arm; exit 1; } # initializes $IMGOUT + pack_image "$IMGOUT" "$IMGNAME" else - launch_installation_online $IP + launch_installation_online "$IP" fi diff --git a/launch-build-container.sh b/launch-build-container.sh index 4d3d1472..d3593a00 100755 --- a/launch-build-container.sh +++ b/launch-build-container.sh @@ -15,11 +15,9 @@ IP=$1 # First argument is the QEMU Raspbian IP address source etc/library.sh # initializes $IMGNAME -IMGBASE="raspbian_docker_base.img" +test -f raspbian_docker.img || ./prepare-build-env-docker.sh "$IP" || exit 1 -test -f raspbian_docker.img || ./prepare-build-env-docker.sh $IP || exit 1 - -./installer.sh docker/build-container.sh $IP raspbian_docker.img || exit 1 +./installer.sh docker/build-container.sh "$IP" raspbian_docker.img || exit 1 # License # diff --git a/prepare-build-env-docker.sh b/prepare-build-env-docker.sh index 6d236ce7..6d438f40 100755 --- a/prepare-build-env-docker.sh +++ b/prepare-build-env-docker.sh @@ -16,9 +16,6 @@ # IP=$1 # First argument is the QEMU Raspbian IP address -DOWNLOAD=0 # Download the latest image -EXTRACT=0 # Extract the image from zip, so start from 0 -IMG=raspbian_lite_latest source etc/library.sh # initializes $IMGNAME @@ -28,8 +25,8 @@ export NO_CONFIG=1 # skip interactive configuration download_resize_raspbian_img 3G $IMGBASE || exit 1 -NO_HALT_STEP=1 ./installer.sh prepare.sh $IP $IMGBASE || exit 1 - ./installer.sh docker/docker-env.sh $IP $( ls -1t *.img | head -1 ) || exit 1 +NO_HALT_STEP=1 ./installer.sh prepare.sh "$IP" "$IMGBASE" || exit 1 + ./installer.sh docker/docker-env.sh "$IP" "$( ls -1t *.img | head -1 )" || exit 1 IMGFILE=$( ls -1t *.img | head -1 ) IMGOUT="raspbian_docker.img" @@ -1,4 +1,4 @@ -#!/bin/bish +#!/bin/bash # Prepare a Raspbian image (resize and update) # diff --git a/remote-update.sh b/remote-update.sh index 21b525e2..03def133 100644 --- a/remote-update.sh +++ b/remote-update.sh @@ -26,8 +26,7 @@ cleanup() rm -f /home/pi/.bash_history systemctl disable ssh - cd /var/www/nextcloud - sudo -u www-data php occ config:system:delete trusted_domains 1 + sudo -u www-data php /var/www/nextcloud/occ config:system:delete trusted_domains 1 } @@ -14,30 +14,30 @@ source /usr/local/etc/library.sh # copy all files in bin and etc for file in bin/* etc/*; do - [ -f $file ] || continue; - cp $file /usr/local/$file + [ -f "$file" ] || continue; + cp "$file" /usr/local/"$file" done # install new entries of nextcloudpi-config and update others for file in etc/nextcloudpi-config.d/*; do - [ -f $file ] || continue; # skip dirs - [ -f /usr/local/$file ] || { # new entry - install_script $file # install + [ -f "$file" ] || continue; # skip dirs + [ -f /usr/local/"$file" ] || { # new entry + install_script "$file" # install # configure if active by default - grep -q '^ACTIVE_=yes$' $file && activate_script $file + grep -q '^ACTIVE_=yes$' "$file" && activate_script "$file" } # save current configuration to (possibly) updated script - [ -f /usr/local/$file ] && { - VARS=( $( grep "^[[:alpha:]]\+_=" /usr/local/$file | cut -d= -f1 ) ) - VALS=( $( grep "^[[:alpha:]]\+_=" /usr/local/$file | cut -d= -f2 ) ) - for i in `seq 0 1 ${#VARS[@]} `; do - sed -i "s|^${VARS[$i]}=.*|${VARS[$i]}=${VALS[$i]}|" $file + [ -f /usr/local/"$file" ] && { + VARS=( $( grep "^[[:alpha:]]\+_=" /usr/local/"$file" | cut -d= -f1 ) ) + VALS=( $( grep "^[[:alpha:]]\+_=" /usr/local/"$file" | cut -d= -f2 ) ) + for i in $( seq 0 1 ${#VARS[@]} ); do + sed -i "s|^${VARS[$i]}=.*|${VARS[$i]}=${VALS[$i]}|" "$file" done } - cp $file /usr/local/$file + cp "$file" /usr/local/"$file" done # these files can contain sensitive information, such as passwords @@ -52,7 +52,7 @@ chmod 770 /var/www/ncp-web ## BACKWARD FIXES ( for older images ) # force-fix unattended-upgrades -cd /usr/local/etc/nextcloudpi-config.d/ +cd /usr/local/etc/nextcloudpi-config.d/ || exit 1 activate_script unattended-upgrades.sh # for old image users, save default password @@ -75,7 +75,7 @@ ls -d /dev/USBdrive* &>/dev/null || { exit 0 } -for i in `seq 1 1 8`; do +for i in $( seq 1 1 8 ); do test -e /media/USBdrive$i && continue echo $i exit 0 |