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_MAJOR=$(pecho $VERSION_STRING | cut -s -d "." -f 1)
DETECTED_MINOR=$(pecho $VERSION_STRING | cut -s -d "." -f 2) DETECTED_MINOR=$(pecho $VERSION_STRING | cut -s -d "." -f 2)
if [ -z "$DETECTED_MAJOR" ]; then [ -n "$DETECTED_MAJOR" ] || fatal "Cannot extract $PROGRAM_LABEL major version from version string \"$VERSION_STRING\""
fatal "Cannot extract $PROGRAM_LABEL major version from version string \"$VERSION_STRING\""
fi
if [ -z "$DETECTED_MINOR" ]; then [ -n "$DETECTED_MINOR" ] || fatal "Cannot extract $PROGRAM_LABEL minor version from version string \"$VERSION_STRING\""
fatal "Cannot extract $PROGRAM_LABEL minor version from version string \"$VERSION_STRING\""
fi
case "$DETECTED_MAJOR" in case "$DETECTED_MAJOR" in
''|*[!0-9]*) ''|*[!0-9]*)
@ -44,9 +40,8 @@ require_minimal_version() {
fatal "$PROGRAM_LABEL minor version from \"$VERSION_STRING\" is not a number. Detected: \"$DETECTED_MINOR\"" fatal "$PROGRAM_LABEL minor version from \"$VERSION_STRING\" is not a number. Detected: \"$DETECTED_MINOR\""
esac esac
if [ "$DETECTED_MAJOR" -lt "$REQUIRED_MAJOR" ] || ([ "$DETECTED_MAJOR" -eq "$REQUIRED_MAJOR" ] && [ "$DETECTED_MINOR" -lt "$REQUIRED_MINOR" ]); then [ "$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." || fatal "Your $PROGRAM_LABEL version \"$VERSION_STRING\" is too old. $PROGRAM_LABEL $REQUIRED_MAJOR.$REQUIRED_MINOR.x or higher is required."
fi
} }
# Move to the folder where ep-lite is installed # 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 "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" echo "Please type 'Etherpad rocks my socks' or supply the '--root' argument if you still want to start it as root"
read rocks read rocks
if [ ! "$rocks" = "Etherpad rocks my socks" ] [ "$rocks" = "Etherpad rocks my socks" ] || fatal "Your input was incorrect"
then
fatal "Your input was incorrect"
fi
fi fi
# Prepare the environment # Prepare the environment

View file

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