1010
1111BIN_DIR=/usr/bin
1212SYSTEMD_DIR=/etc/systemd/system
13- VERSION=
13+ VERSION=" latest "
1414SYSTEM_NAME=coroot-node-agent
1515SYSTEMD_SERVICE=${SYSTEM_NAME} .service
1616UNINSTALL_SH=${BIN_DIR} /${SYSTEM_NAME} -uninstall.sh
@@ -26,9 +26,17 @@ info()
2626fatal ()
2727{
2828 echo ' [ERROR] ' " $@ " >&2
29+ show_help
2930 exit 1
3031}
3132
33+ show_help () {
34+ echo " Usage: $0 [options]"
35+ echo " Options:"
36+ echo " -h, --help Show this help message and exit"
37+ echo " -v v1.22.2, --version v1.22.2 Specify the version to install (default: latest)"
38+ }
39+
3240verify_system () {
3341 if [ -x /bin/systemctl ] || type systemctl > /dev/null 2>&1 ; then
3442 return
@@ -84,20 +92,24 @@ setup_tmp() {
8492}
8593
8694get_release_version () {
87- info " Finding the latest release"
88- latest_release_url=${GITHUB_URL} /latest
89- case $DOWNLOADER in
90- curl)
91- VERSION=$( curl -w ' %{url_effective}' -L -s -S ${latest_release_url} -o /dev/null | sed -e ' s|.*/||' )
92- ;;
93- wget)
94- VERSION=$( wget -SqO /dev/null ${latest_release_url} 2>&1 | grep -i Location | sed -e ' s|.*/||' )
95- ;;
96- * )
97- fatal " Incorrect downloader executable '$DOWNLOADER '"
98- ;;
99- esac
100- info " The latest release is ${VERSION} "
95+ if [ " $VERSION " = " latest" ]; then
96+ info " Finding the latest release"
97+ latest_release_url=${GITHUB_URL} /latest
98+ case $DOWNLOADER in
99+ curl)
100+ VERSION=$( curl -w ' %{url_effective}' -L -s -S ${latest_release_url} -o /dev/null | sed -e ' s|.*/||' )
101+ ;;
102+ wget)
103+ VERSION=$( wget -SqO /dev/null ${latest_release_url} 2>&1 | grep -i Location | sed -e ' s|.*/||' )
104+ ;;
105+ * )
106+ fatal " Incorrect downloader executable '$DOWNLOADER '"
107+ ;;
108+ esac
109+ info " The latest release is ${VERSION} "
110+ else
111+ info " Using specified version ${VERSION} "
112+ fi
101113}
102114
103115download_binary () {
@@ -136,7 +148,6 @@ download() {
136148 setup_binary
137149}
138150
139-
140151create_uninstall () {
141152 info " Creating uninstall script ${UNINSTALL_SH} "
142153 $SUDO tee ${UNINSTALL_SH} > /dev/null << EOF
@@ -229,7 +240,6 @@ systemd_start() {
229240 $SUDO systemctl restart ${SYSTEM_NAME}
230241}
231242
232-
233243service_enable_and_start () {
234244 systemd_enable
235245
@@ -244,6 +254,22 @@ service_enable_and_start() {
244254 return 0
245255}
246256
257+ while [ $# -gt 0 ]; do
258+ case " $1 " in
259+ -h|--help)
260+ show_help
261+ exit 0
262+ ;;
263+ -v|--version)
264+ VERSION=" $2 "
265+ shift 2
266+ ;;
267+ * )
268+ fatal " Unknown option: $1 "
269+ ;;
270+ esac
271+ done
272+
247273{
248274 verify_system
249275 download
0 commit comments