diff --git a/linux/packaging/appimage/AppRun b/linux/packaging/appimage/AppRun index 66bc43fb..21ea9ed0 100644 --- a/linux/packaging/appimage/AppRun +++ b/linux/packaging/appimage/AppRun @@ -2,8 +2,56 @@ cd "$(dirname "$0")" export LD_LIBRARY_PATH=usr/lib -if [ "$1" == "HiddifyService" ];then - exec ./$@ -else - exec ./hiddify $@ + +# Usage info +show_help() { +cat << EOF +Usage: ${0##*/} [-s | -v | -h ] ... +start Hiddify or HiddifyService, when no parameter is given, Hiddify is executed. + -h display this help and exit + -s start|stop start/stop HiddifyService. + -v show version +EOF +} +show_version() { + printf "Hiddify version " + jq .version <./data/flutter_assets/version.json +} +# Initialize variables: +service=0 #declare -i service +OPTIND=1 + +# Resetting OPTIND is necessary if getopts was used previously in the script. +# It is a good idea to make OPTIND local if you process options in a function. + +# if no arg is provided, execute hiddify app +[[ $# == 0 ]] && exec hiddify + +# processing arguments +while getopts s:vh opt; do + case $opt in + h) + show_help + exit 0 + ;; + v) show_version + exit 0 + ;; + s) action="$OPTARG" + ((service++)) + ;; + *) + show_help >&2 + exit 1 + ;; + esac +done +shift "$((OPTIND-1))" # Discard the options and sentinel -- + +# argument -s is given, do HiddfyService +if [[ "$service" == 1 ]]; then + if [[ "$action" =~ start|stop ]]; then + exec ./HiddifyService "$action" + fi fi +