#!/usr/bin/env sh confd="/etc/opt/simplex" logd="/var/opt/simplex/" # Check if server has been initialized if [ ! -f "$confd/smp-server.ini" ]; then # If not, determine ip or domain case "$ADDR" in '') printf "Please specify \$ADDR environment variable.\n"; exit 1 ;; *[a-zA-Z]*) case "$ADDR" in *:*) set -- --ip "$ADDR" ;; *) set -- -n "$ADDR" ;; esac ;; *) set -- --ip "$ADDR" ;; esac # Optionally, set password case "$PASS" in '') set -- "$@" --no-password ;; *) set -- "$@" --password "$PASS" ;; esac # And init certificates and configs smp-server init -y -l "$@" fi # Backup store log just in case _file="${logd}/smp-server-store.log" if [ -f "${_file}" ]; then _backup_extension="$(date --universal '+%FT%T%:z')" cp -v -p "${_file}" "${_file}.${_backup_extension:-date-failed}" unset -v _backup_extension fi unset -v _file # Finally, run smp-sever. Notice that "exec" here is important: # smp-server replaces our helper script, so that it can catch INT signal exec smp-server start +RTS -N -RTS