mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-23 08:56:17 -04:00
bin: Create and use new logging functions
These write errors to stderr and avoid unintentional backslash escape processing in their arguments.
This commit is contained in:
parent
a87a9bb63b
commit
5462d2109c
4 changed files with 49 additions and 54 deletions
|
@ -1,5 +1,9 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
|
pecho() { printf %s\\n "$*"; }
|
||||||
|
log() { pecho "$@"; }
|
||||||
|
error() { log "ERROR: $@" >&2; }
|
||||||
|
fatal() { error "$@"; exit 1; }
|
||||||
is_cmd() { command -v "$@" >/dev/null 2>&1; }
|
is_cmd() { command -v "$@" >/dev/null 2>&1; }
|
||||||
|
|
||||||
# Move to the folder where ep-lite is installed
|
# Move to the folder where ep-lite is installed
|
||||||
|
@ -11,27 +15,18 @@ if [ -d "../bin" ]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Is wget installed?
|
# Is wget installed?
|
||||||
is_cmd wget || {
|
is_cmd wget || fatal "Please install wget"
|
||||||
echo "Please install wget" >&2
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
# Is zip installed?
|
# Is zip installed?
|
||||||
is_cmd zip || {
|
is_cmd zip || fatal "Please install zip"
|
||||||
echo "Please install zip" >&2
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
# Is zip installed?
|
# Is zip installed?
|
||||||
is_cmd unzip || {
|
is_cmd unzip || fatal "Please install unzip"
|
||||||
echo "Please install unzip" >&2
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
START_FOLDER=$(pwd);
|
START_FOLDER=$(pwd);
|
||||||
TMP_FOLDER=$(mktemp -d)
|
TMP_FOLDER=$(mktemp -d)
|
||||||
|
|
||||||
echo "create a clean environment in $TMP_FOLDER..."
|
log "create a clean environment in $TMP_FOLDER..."
|
||||||
cp -ar . $TMP_FOLDER
|
cp -ar . $TMP_FOLDER
|
||||||
cd $TMP_FOLDER
|
cd $TMP_FOLDER
|
||||||
rm -rf node_modules
|
rm -rf node_modules
|
||||||
|
@ -41,33 +36,33 @@ rm -f etherpad-lite-win.zip
|
||||||
# making the windows package smaller
|
# making the windows package smaller
|
||||||
export NODE_ENV=production
|
export NODE_ENV=production
|
||||||
|
|
||||||
echo "do a normal unix install first..."
|
log "do a normal unix install first..."
|
||||||
bin/installDeps.sh || exit 1
|
bin/installDeps.sh || exit 1
|
||||||
|
|
||||||
echo "copy the windows settings template..."
|
log "copy the windows settings template..."
|
||||||
cp settings.json.template settings.json
|
cp settings.json.template settings.json
|
||||||
|
|
||||||
echo "resolve symbolic links..."
|
log "resolve symbolic links..."
|
||||||
cp -rL node_modules node_modules_resolved
|
cp -rL node_modules node_modules_resolved
|
||||||
rm -rf node_modules
|
rm -rf node_modules
|
||||||
mv node_modules_resolved node_modules
|
mv node_modules_resolved node_modules
|
||||||
|
|
||||||
echo "download windows node..."
|
log "download windows node..."
|
||||||
cd bin
|
cd bin
|
||||||
wget "https://nodejs.org/dist/latest-erbium/win-x86/node.exe" -O ../node.exe
|
wget "https://nodejs.org/dist/latest-erbium/win-x86/node.exe" -O ../node.exe
|
||||||
|
|
||||||
echo "remove git history to reduce folder size"
|
log "remove git history to reduce folder size"
|
||||||
rm -rf .git/objects
|
rm -rf .git/objects
|
||||||
|
|
||||||
echo "remove windows jsdom-nocontextify/test folder"
|
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/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/nodemailer/node_modules/mailcomposer/node_modules/mimelib/node_modules/encoding/node_modules/iconv-lite/encodings/tables
|
||||||
|
|
||||||
echo "create the zip..."
|
log "create the zip..."
|
||||||
cd $TMP_FOLDER
|
cd $TMP_FOLDER
|
||||||
zip -9 -r $START_FOLDER/etherpad-lite-win.zip ./*
|
zip -9 -r $START_FOLDER/etherpad-lite-win.zip ./*
|
||||||
|
|
||||||
echo "clean up..."
|
log "clean up..."
|
||||||
rm -rf $TMP_FOLDER
|
rm -rf $TMP_FOLDER
|
||||||
|
|
||||||
echo "Finished. You can find the zip in the Etherpad root folder, it's called etherpad-lite-win.zip"
|
log "Finished. You can find the zip in the Etherpad root folder, it's called etherpad-lite-win.zip"
|
||||||
|
|
|
@ -8,6 +8,10 @@ REQUIRED_NODE_MINOR=13
|
||||||
REQUIRED_NPM_MAJOR=5
|
REQUIRED_NPM_MAJOR=5
|
||||||
REQUIRED_NPM_MINOR=5
|
REQUIRED_NPM_MINOR=5
|
||||||
|
|
||||||
|
pecho() { printf %s\\n "$*"; }
|
||||||
|
log() { pecho "$@"; }
|
||||||
|
error() { log "ERROR: $@" >&2; }
|
||||||
|
fatal() { error "$@"; exit 1; }
|
||||||
is_cmd() { command -v "$@" >/dev/null 2>&1; }
|
is_cmd() { command -v "$@" >/dev/null 2>&1; }
|
||||||
|
|
||||||
require_minimal_version() {
|
require_minimal_version() {
|
||||||
|
@ -18,35 +22,30 @@ require_minimal_version() {
|
||||||
|
|
||||||
# Flag -s (--only-delimited on GNU cut) ensures no string is returned
|
# Flag -s (--only-delimited on GNU cut) ensures no string is returned
|
||||||
# when there is no match
|
# when there is no match
|
||||||
DETECTED_MAJOR=$(echo $VERSION_STRING | cut -s -d "." -f 1)
|
DETECTED_MAJOR=$(pecho $VERSION_STRING | cut -s -d "." -f 1)
|
||||||
DETECTED_MINOR=$(echo $VERSION_STRING | cut -s -d "." -f 2)
|
DETECTED_MINOR=$(pecho $VERSION_STRING | cut -s -d "." -f 2)
|
||||||
|
|
||||||
if [ -z "$DETECTED_MAJOR" ]; then
|
if [ -z "$DETECTED_MAJOR" ]; then
|
||||||
printf 'Cannot extract %s major version from version string "%s"\n' "$PROGRAM_LABEL" "$VERSION_STRING" >&2
|
fatal "Cannot extract $PROGRAM_LABEL major version from version string \"$VERSION_STRING\""
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$DETECTED_MINOR" ]; then
|
if [ -z "$DETECTED_MINOR" ]; then
|
||||||
printf 'Cannot extract %s minor version from version string "%s"\n' "$PROGRAM_LABEL" "$VERSION_STRING" >&2
|
fatal "Cannot extract $PROGRAM_LABEL minor version from version string \"$VERSION_STRING\""
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
case "$DETECTED_MAJOR" in
|
case "$DETECTED_MAJOR" in
|
||||||
''|*[!0-9]*)
|
''|*[!0-9]*)
|
||||||
printf '%s major version from "%s" is not a number. Detected: "%s"\n' "$PROGRAM_LABEL" "$VERSION_STRING" "$DETECTED_MAJOR" >&2
|
fatal "$PROGRAM_LABEL major version from \"$VERSION_STRING\" is not a number. Detected: \"$DETECTED_MAJOR\""
|
||||||
exit 1
|
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
case "$DETECTED_MINOR" in
|
case "$DETECTED_MINOR" in
|
||||||
''|*[!0-9]*)
|
''|*[!0-9]*)
|
||||||
printf '%s minor version from "%s" is not a number. Detected: "%s"\n' "$PROGRAM_LABEL" "$VERSION_STRING" "$DETECTED_MINOR" >&2
|
fatal "$PROGRAM_LABEL minor version from \"$VERSION_STRING\" is not a number. Detected: \"$DETECTED_MINOR\""
|
||||||
exit 1
|
|
||||||
esac
|
esac
|
||||||
|
|
||||||
if [ "$DETECTED_MAJOR" -lt "$REQUIRED_MAJOR" ] || ([ "$DETECTED_MAJOR" -eq "$REQUIRED_MAJOR" ] && [ "$DETECTED_MINOR" -lt "$REQUIRED_MINOR" ]); then
|
if [ "$DETECTED_MAJOR" -lt "$REQUIRED_MAJOR" ] || ([ "$DETECTED_MAJOR" -eq "$REQUIRED_MAJOR" ] && [ "$DETECTED_MINOR" -lt "$REQUIRED_MINOR" ]); then
|
||||||
printf 'Your %s version "%s" is too old. %s %d.%d.x or higher is required.\n' "$PROGRAM_LABEL" "$VERSION_STRING" "$PROGRAM_LABEL" "$REQUIRED_MAJOR" "$REQUIRED_MINOR" >&2
|
fatal "Your $PROGRAM_LABEL version \"$VERSION_STRING\" is too old. $PROGRAM_LABEL $REQUIRED_MAJOR.$REQUIRED_MINOR.x or higher is required."
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,16 +59,10 @@ fi
|
||||||
|
|
||||||
# Is node installed?
|
# Is node installed?
|
||||||
# Not checking io.js, default installation creates a symbolic link to node
|
# Not checking io.js, default installation creates a symbolic link to node
|
||||||
is_cmd node || {
|
is_cmd node || fatal "Please install node.js ( https://nodejs.org )"
|
||||||
echo "Please install node.js ( https://nodejs.org )" >&2
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
# Is npm installed?
|
# Is npm installed?
|
||||||
is_cmd npm || {
|
is_cmd npm || fatal "Please install npm ( https://npmjs.org )"
|
||||||
echo "Please install npm ( https://npmjs.org )" >&2
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
# Check npm version
|
# Check npm version
|
||||||
NPM_VERSION_STRING=$(npm --version)
|
NPM_VERSION_STRING=$(npm --version)
|
||||||
|
@ -92,11 +85,11 @@ done
|
||||||
|
|
||||||
# Does a $settings exist? if not copy the template
|
# Does a $settings exist? if not copy the template
|
||||||
if [ ! -f $settings ]; then
|
if [ ! -f $settings ]; then
|
||||||
echo "Copy the settings template to $settings..."
|
log "Copy the settings template to $settings..."
|
||||||
cp settings.json.template $settings || exit 1
|
cp settings.json.template $settings || exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Ensure that all dependencies are up to date... If this is the first time you have run Etherpad please be patient."
|
log "Ensure that all dependencies are up to date... If this is the first time you have run Etherpad please be patient."
|
||||||
(
|
(
|
||||||
mkdir -p node_modules
|
mkdir -p node_modules
|
||||||
cd node_modules
|
cd node_modules
|
||||||
|
@ -109,7 +102,7 @@ echo "Ensure that all dependencies are up to date... If this is the first time
|
||||||
}
|
}
|
||||||
|
|
||||||
# Remove all minified data to force node creating it new
|
# Remove all minified data to force node creating it new
|
||||||
echo "Clearing minified cache..."
|
log "Clearing minified cache..."
|
||||||
rm -f var/minified*
|
rm -f var/minified*
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
|
10
bin/run.sh
10
bin/run.sh
|
@ -1,5 +1,10 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
|
pecho() { printf %s\\n "$*"; }
|
||||||
|
log() { pecho "$@"; }
|
||||||
|
error() { log "ERROR: $@" >&2; }
|
||||||
|
fatal() { error "$@"; exit 1; }
|
||||||
|
|
||||||
# Move to the folder where ep-lite is installed
|
# Move to the folder where ep-lite is installed
|
||||||
cd $(dirname $0)
|
cd $(dirname $0)
|
||||||
|
|
||||||
|
@ -23,8 +28,7 @@ if [ "$(id -u)" -eq 0 ] && [ $ignoreRoot -eq 0 ]; then
|
||||||
read rocks
|
read rocks
|
||||||
if [ ! "$rocks" = "Etherpad rocks my socks" ]
|
if [ ! "$rocks" = "Etherpad rocks my socks" ]
|
||||||
then
|
then
|
||||||
echo "Your input was incorrect"
|
fatal "Your input was incorrect"
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -32,7 +36,7 @@ fi
|
||||||
bin/installDeps.sh "$@" || exit 1
|
bin/installDeps.sh "$@" || exit 1
|
||||||
|
|
||||||
# Move to the node folder and start
|
# Move to the node folder and start
|
||||||
echo "Started Etherpad..."
|
log "Starting Etherpad..."
|
||||||
|
|
||||||
SCRIPTPATH=$(pwd -P)
|
SCRIPTPATH=$(pwd -P)
|
||||||
exec node "$SCRIPTPATH/node_modules/ep_etherpad-lite/node/server.js" "$@"
|
exec node "$SCRIPTPATH/node_modules/ep_etherpad-lite/node/server.js" "$@"
|
||||||
|
|
|
@ -16,6 +16,11 @@ TIME_BETWEEN_EMAILS=600 # 10 minutes
|
||||||
|
|
||||||
# DON'T EDIT AFTER THIS LINE
|
# DON'T EDIT AFTER THIS LINE
|
||||||
|
|
||||||
|
pecho() { printf %s\\n "$*"; }
|
||||||
|
log() { pecho "$@"; }
|
||||||
|
error() { log "ERROR: $@" >&2; }
|
||||||
|
fatal() { error "$@"; exit 1; }
|
||||||
|
|
||||||
LAST_EMAIL_SEND=0
|
LAST_EMAIL_SEND=0
|
||||||
LOG="$1"
|
LOG="$1"
|
||||||
|
|
||||||
|
@ -29,8 +34,7 @@ fi
|
||||||
|
|
||||||
# Check if a logfile parameter is set
|
# Check if a logfile parameter is set
|
||||||
if [ -z "${LOG}" ]; then
|
if [ -z "${LOG}" ]; then
|
||||||
echo "Set a logfile as the first parameter"
|
fatal "Set a logfile as the first parameter"
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
shift
|
shift
|
||||||
|
@ -38,13 +42,12 @@ while [ 1 ]
|
||||||
do
|
do
|
||||||
# Try to touch the file if it doesn't exist
|
# Try to touch the file if it doesn't exist
|
||||||
if [ ! -f ${LOG} ]; then
|
if [ ! -f ${LOG} ]; then
|
||||||
touch ${LOG} || ( echo "Logfile '${LOG}' is not writeable" && exit 1 )
|
touch ${LOG} || fatal "Logfile '${LOG}' is not writeable"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check if the file is writeable
|
# Check if the file is writeable
|
||||||
if [ ! -w ${LOG} ]; then
|
if [ ! -w ${LOG} ]; then
|
||||||
echo "Logfile '${LOG}' is not writeable"
|
fatal "Logfile '${LOG}' is not writeable"
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Start the application
|
# Start the application
|
||||||
|
@ -62,7 +65,7 @@ do
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "RESTART!" >>${LOG}
|
pecho "RESTART!" >>${LOG}
|
||||||
|
|
||||||
# Sleep 10 seconds before restart
|
# Sleep 10 seconds before restart
|
||||||
sleep 10
|
sleep 10
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue