Skip to content

Commit 8313e1b

Browse files
committed
add long options parsing to install.sh
1 parent c54d69f commit 8313e1b

File tree

1 file changed

+65
-16
lines changed

1 file changed

+65
-16
lines changed

scripts/install.sh

Lines changed: 65 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,22 @@ config_overridden=false
2222

2323
show_help_and_exit() {
2424
echo 'Supported arguments:'
25-
echo ' -c PATH Provide custom config for toninstaller.sh'
26-
echo ' -t Disable telemetry'
27-
echo ' -i Ignore minimum requirements'
28-
echo ' -d Use pre-packaged dump. Reduces duration of initial synchronization.'
29-
echo ' -a Set MyTonCtrl git repo author'
30-
echo ' -r Set MyTonCtrl git repo'
31-
echo ' -b Set MyTonCtrl git repo branch'
32-
echo ' -g URL TON node git repo URL (default: https://github.com/ton-blockchain/ton.git)'
33-
echo ' -m MODE Install MyTonCtrl with specified mode (validator or liteserver)'
34-
echo ' -n NETWORK Specify the network (mainnet or testnet)'
35-
echo ' -v VERSION Specify the ton node version (commit, branch, or tag)'
36-
echo ' -u USER Specify the user to be used for MyTonCtrl installation'
37-
echo ' -p PATH Provide backup file for MyTonCtrl installation'
38-
echo ' -o Install only MyTonCtrl. Must be used with -p'
39-
echo ' -l Install only TON node'
40-
echo ' -h Show this help'
25+
echo ' -c, --config URL Provide custom network config'
26+
echo ' -t, --telemetry Disable telemetry'
27+
echo ' -i, --ignore-reqs Ignore minimum requirements'
28+
echo ' -d, --dump Use pre-packaged dump. Reduces duration of initial synchronization.'
29+
echo ' -a, --author Set MyTonCtrl git repo author'
30+
echo ' -r, --repo Set MyTonCtrl git repo name'
31+
echo ' -b, --branch Set MyTonCtrl git repo branch'
32+
echo ' -m, --mode MODE Install MyTonCtrl with specified mode (validator or liteserver)'
33+
echo ' -n, --network NETWORK Specify the network (mainnet or testnet)'
34+
echo ' -g, --node-repo URL TON node git repo URL (default: https://github.com/ton-blockchain/ton.git)'
35+
echo ' -v, --node-version VERSION Specify the TON node version (commit, branch, or tag)'
36+
echo ' -u, --user USER Specify the user to be used for MyTonCtrl installation'
37+
echo ' -p, --backup PATH Provide backup file for MyTonCtrl installation'
38+
echo ' -o, --only-mtc Install only MyTonCtrl. Must be used with -p'
39+
echo ' -l, --only-node Install only TON node'
40+
echo ' -h, --help Show this help'
4141
exit
4242
}
4343

@@ -57,6 +57,55 @@ mode=none
5757
cpu_required=16
5858
mem_required=64000000 # 64GB in KB
5959

60+
# transform --long options to short, because getopts only supports short ones
61+
62+
newargv=()
63+
while (($#)); do
64+
case "$1" in
65+
--) # end of options
66+
shift
67+
newargv+=( -- "$@" )
68+
break
69+
;;
70+
71+
# no arg
72+
--dump) newargv+=(-d) ;;
73+
--only-mtc) newargv+=(-o) ;;
74+
--only-node) newargv+=(-l) ;;
75+
--help) newargv+=(-h) ;;
76+
--telemetry) newargv+=(-t) ;;
77+
--ignore-reqs) newargv+=(-i) ;;
78+
79+
# with arg
80+
--config|--author|--repo|--branch|--mode|--network|--node-repo|--backup|--user)
81+
if (($# < 2)); then
82+
echo "Error: option $1 requires value" >&2; exit 2
83+
fi
84+
case "$1" in
85+
--config) newargv+=(-c "$2") ;;
86+
--author) newargv+=(-a "$2") ;;
87+
--repo) newargv+=(-r "$2") ;;
88+
--branch) newargv+=(-b "$2") ;;
89+
--mode) newargv+=(-m "$2") ;;
90+
--network) newargv+=(-n "$2") ;;
91+
--node-repo) newargv+=(-g "$2") ;;
92+
--backup) newargv+=(-p "$2") ;;
93+
--user) newargv+=(-u "$2") ;;
94+
--node-version) newargv+=(-v "$2") ;;
95+
esac
96+
shift ;;
97+
--*)
98+
echo "Error: unknown option '$1'" >&2; exit 2 ;;
99+
*)
100+
newargv+=("$1") ;;
101+
esac
102+
shift
103+
done
104+
105+
#printf ' %q' "${newargv[@]}"
106+
#printf '\n'
107+
set -- "${newargv[@]}"
108+
60109
while getopts ":c:tidola:r:b:m:n:v:u:p:g:h" flag; do
61110
case "${flag}" in
62111
c) config=${OPTARG}; config_overridden=true;;

0 commit comments

Comments
 (0)