From 57237b856874ef58aea41cd05b9c201a90e0e7fc Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Thu, 14 May 2020 17:40:16 -0400 Subject: [PATCH] bin: Quote expansions that are subject to field splitting --- bin/buildForWindows.sh | 16 ++++++++-------- bin/debugRun.sh | 2 +- bin/installDeps.sh | 10 +++++----- bin/run.sh | 4 ++-- bin/safeRun.sh | 14 +++++++------- 5 files changed, 23 insertions(+), 23 deletions(-) diff --git a/bin/buildForWindows.sh b/bin/buildForWindows.sh index 229e4ea2f..7636fecea 100755 --- a/bin/buildForWindows.sh +++ b/bin/buildForWindows.sh @@ -7,7 +7,7 @@ fatal() { error "$@"; exit 1; } is_cmd() { command -v "$@" >/dev/null 2>&1; } # Move to the folder where ep-lite is installed -cd $(dirname $0) +cd "$(dirname "$0")" # Was this script started in the bin folder? if yes move out if [ -d "../bin" ]; then @@ -27,8 +27,8 @@ START_FOLDER=$(pwd); TMP_FOLDER=$(mktemp -d) log "create a clean environment in $TMP_FOLDER..." -cp -ar . $TMP_FOLDER -cd $TMP_FOLDER +cp -ar . "$TMP_FOLDER" +cd "$TMP_FOLDER" rm -rf node_modules rm -f etherpad-lite-win.zip @@ -55,14 +55,14 @@ log "remove git history to reduce folder size" rm -rf .git/objects log "remove windows jsdom-nocontextify/test folder" -rm -rf $TMP_FOLDER/src/node_modules/wd/node_modules/request/node_modules/form-data/node_modules/combined-stream/test -rm -rf $TMP_FOLDER/src/node_modules/nodemailer/node_modules/mailcomposer/node_modules/mimelib/node_modules/encoding/node_modules/iconv-lite/encodings/tables +rm -rf "$TMP_FOLDER"/src/node_modules/wd/node_modules/request/node_modules/form-data/node_modules/combined-stream/test +rm -rf "$TMP_FOLDER"/src/node_modules/nodemailer/node_modules/mailcomposer/node_modules/mimelib/node_modules/encoding/node_modules/iconv-lite/encodings/tables log "create the zip..." -cd $TMP_FOLDER -zip -9 -r $START_FOLDER/etherpad-lite-win.zip ./* +cd "$TMP_FOLDER" +zip -9 -r "$START_FOLDER"/etherpad-lite-win.zip ./* log "clean up..." -rm -rf $TMP_FOLDER +rm -rf "$TMP_FOLDER" log "Finished. You can find the zip in the Etherpad root folder, it's called etherpad-lite-win.zip" diff --git a/bin/debugRun.sh b/bin/debugRun.sh index 75995e838..abb27c40b 100755 --- a/bin/debugRun.sh +++ b/bin/debugRun.sh @@ -1,7 +1,7 @@ #!/bin/sh # Move to the folder where ep-lite is installed -cd $(dirname $0) +cd "$(dirname "$0")" # Was this script started in the bin folder? if yes move out if [ -d "../bin" ]; then diff --git a/bin/installDeps.sh b/bin/installDeps.sh index af8912114..b7105531e 100755 --- a/bin/installDeps.sh +++ b/bin/installDeps.sh @@ -22,8 +22,8 @@ require_minimal_version() { # Flag -s (--only-delimited on GNU cut) ensures no string is returned # when there is no match - DETECTED_MAJOR=$(pecho $VERSION_STRING | cut -s -d "." -f 1) - DETECTED_MINOR=$(pecho $VERSION_STRING | cut -s -d "." -f 2) + DETECTED_MAJOR=$(pecho "$VERSION_STRING" | cut -s -d "." -f 1) + DETECTED_MINOR=$(pecho "$VERSION_STRING" | cut -s -d "." -f 2) [ -n "$DETECTED_MAJOR" ] || fatal "Cannot extract $PROGRAM_LABEL major version from version string \"$VERSION_STRING\"" @@ -45,7 +45,7 @@ require_minimal_version() { } # Move to the folder where ep-lite is installed -cd $(dirname $0) +cd "$(dirname "$0")" # Was this script started in the bin folder? if yes move out if [ -d "../bin" ]; then @@ -79,9 +79,9 @@ for arg in "$@"; do done # Does a $settings exist? if not copy the template -if [ ! -f $settings ]; then +if [ ! -f "$settings" ]; then log "Copy the settings template to $settings..." - cp settings.json.template $settings || exit 1 + cp settings.json.template "$settings" || exit 1 fi log "Ensure that all dependencies are up to date... If this is the first time you have run Etherpad please be patient." diff --git a/bin/run.sh b/bin/run.sh index cab223fb4..e2fe8cb23 100755 --- a/bin/run.sh +++ b/bin/run.sh @@ -6,7 +6,7 @@ error() { log "ERROR: $@" >&2; } fatal() { error "$@"; exit 1; } # Move to the folder where ep-lite is installed -cd $(dirname $0) +cd "$(dirname "$0")" # Was this script started in the bin folder? if yes move out if [ -d "../bin" ]; then @@ -22,7 +22,7 @@ do done # Stop the script if it's started as root -if [ "$(id -u)" -eq 0 ] && [ $ignoreRoot -eq 0 ]; then +if [ "$(id -u)" -eq 0 ] && [ "$ignoreRoot" -eq 0 ]; then echo "You shouldn't start Etherpad as root!" echo "Please type 'Etherpad rocks my socks' or supply the '--root' argument if you still want to start it as root" read rocks diff --git a/bin/safeRun.sh b/bin/safeRun.sh index 149f95d22..2eba74d4c 100755 --- a/bin/safeRun.sh +++ b/bin/safeRun.sh @@ -25,7 +25,7 @@ LAST_EMAIL_SEND=0 LOG="$1" # Move to the folder where ep-lite is installed -cd $(dirname $0) +cd "$(dirname "$0")" # Was this script started in the bin folder? if yes move out if [ -d "../bin" ]; then @@ -39,21 +39,21 @@ shift while [ 1 ] do # Try to touch the file if it doesn't exist - [ -f ${LOG} ] || touch ${LOG} || fatal "Logfile '${LOG}' is not writeable" + [ -f "${LOG}" ] || touch "${LOG}" || fatal "Logfile '${LOG}' is not writeable" # Check if the file is writeable - [ -w ${LOG} ] || fatal "Logfile '${LOG}' is not writeable" + [ -w "${LOG}" ] || fatal "Logfile '${LOG}' is not writeable" # Start the application - bin/run.sh $@ >>${LOG} 2>>${LOG} + bin/run.sh "$@" >>${LOG} 2>>${LOG} # Send email - if [ $ERROR_HANDLING = 1 ]; then + if [ "$ERROR_HANDLING" = 1 ]; then TIME_NOW=$(date +%s) TIME_SINCE_LAST_SEND=$(($TIME_NOW - $LAST_EMAIL_SEND)) - if [ $TIME_SINCE_LAST_SEND -gt $TIME_BETWEEN_EMAILS ]; then - printf "Server was restarted at: $(date)\nThe last 50 lines of the log before the error happens:\n $(tail -n 50 ${LOG})" | mail -s "Pad Server was restarted" $EMAIL_ADDRESS + if [ "$TIME_SINCE_LAST_SEND" -gt "$TIME_BETWEEN_EMAILS" ]; then + printf "Server was restarted at: $(date)\nThe last 50 lines of the log before the error happens:\n $(tail -n 50 "${LOG}")" | mail -s "Pad Server was restarted" "$EMAIL_ADDRESS" LAST_EMAIL_SEND=$TIME_NOW fi