58 lines
1.3 KiB
Bash
58 lines
1.3 KiB
Bash
#!/bin/bash -x
|
|
|
|
cd "$(dirname "$0")"
|
|
export LD_LIBRARY_PATH=usr/lib
|
|
|
|
# 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
|
|
|