bin: Use assertion-style condition checks

This commit is contained in:
Richard Hansen 2020-05-14 17:36:16 -04:00
parent 5462d2109c
commit a28b7c7595
3 changed files with 8 additions and 22 deletions

View file

@ -25,13 +25,9 @@ require_minimal_version() {
DETECTED_MAJOR=$(pecho $VERSION_STRING | cut -s -d "." -f 1)
DETECTED_MINOR=$(pecho $VERSION_STRING | cut -s -d "." -f 2)
if [ -z "$DETECTED_MAJOR" ]; then
fatal "Cannot extract $PROGRAM_LABEL major version from version string \"$VERSION_STRING\""
fi
[ -n "$DETECTED_MAJOR" ] || fatal "Cannot extract $PROGRAM_LABEL major version from version string \"$VERSION_STRING\""
if [ -z "$DETECTED_MINOR" ]; then
fatal "Cannot extract $PROGRAM_LABEL minor version from version string \"$VERSION_STRING\""
fi
[ -n "$DETECTED_MINOR" ] || fatal "Cannot extract $PROGRAM_LABEL minor version from version string \"$VERSION_STRING\""
case "$DETECTED_MAJOR" in
''|*[!0-9]*)
@ -44,9 +40,8 @@ require_minimal_version() {
fatal "$PROGRAM_LABEL minor version from \"$VERSION_STRING\" is not a number. Detected: \"$DETECTED_MINOR\""
esac
if [ "$DETECTED_MAJOR" -lt "$REQUIRED_MAJOR" ] || ([ "$DETECTED_MAJOR" -eq "$REQUIRED_MAJOR" ] && [ "$DETECTED_MINOR" -lt "$REQUIRED_MINOR" ]); then
fatal "Your $PROGRAM_LABEL version \"$VERSION_STRING\" is too old. $PROGRAM_LABEL $REQUIRED_MAJOR.$REQUIRED_MINOR.x or higher is required."
fi
[ "$DETECTED_MAJOR" -gt "$REQUIRED_MAJOR" ] || ([ "$DETECTED_MAJOR" -eq "$REQUIRED_MAJOR" ] && [ "$DETECTED_MINOR" -ge "$REQUIRED_MINOR" ]) \
|| fatal "Your $PROGRAM_LABEL version \"$VERSION_STRING\" is too old. $PROGRAM_LABEL $REQUIRED_MAJOR.$REQUIRED_MINOR.x or higher is required."
}
# Move to the folder where ep-lite is installed

View file

@ -26,10 +26,7 @@ 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
if [ ! "$rocks" = "Etherpad rocks my socks" ]
then
fatal "Your input was incorrect"
fi
[ "$rocks" = "Etherpad rocks my socks" ] || fatal "Your input was incorrect"
fi
# Prepare the environment

View file

@ -33,22 +33,16 @@ if [ -d "../bin" ]; then
fi
# Check if a logfile parameter is set
if [ -z "${LOG}" ]; then
fatal "Set a logfile as the first parameter"
fi
[ -n "${LOG}" ] || fatal "Set a logfile as the first parameter"
shift
while [ 1 ]
do
# Try to touch the file if it doesn't exist
if [ ! -f ${LOG} ]; then
touch ${LOG} || fatal "Logfile '${LOG}' is not writeable"
fi
[ -f ${LOG} ] || touch ${LOG} || fatal "Logfile '${LOG}' is not writeable"
# Check if the file is writeable
if [ ! -w ${LOG} ]; then
fatal "Logfile '${LOG}' is not writeable"
fi
[ -w ${LOG} ] || fatal "Logfile '${LOG}' is not writeable"
# Start the application
bin/run.sh $@ >>${LOG} 2>>${LOG}