add AppRun parameters - provided a help menu
This commit is contained in:
@@ -1,9 +1,57 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash -x
|
||||||
|
|
||||||
cd "$(dirname "$0")"
|
cd "$(dirname "$0")"
|
||||||
export LD_LIBRARY_PATH=usr/lib
|
export LD_LIBRARY_PATH=usr/lib
|
||||||
if [ "$1" == "HiddifyService" ];then
|
|
||||||
exec ./$@
|
# Usage info
|
||||||
else
|
show_help() {
|
||||||
exec ./hiddify $@
|
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
|
fi
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user