@@ -47,7 +47,6 @@ main() {
4747 SHORT=i,u,d,h,v,s
4848 LONG=install,upgrade,debug,help,version,silent
4949 OPTS=$( getopt --options $SHORT --longoptions $LONG -- " $@ " )
50-
5150 if [ $? -ne 0 ]; then
5251 usage
5352 exit 0
@@ -90,32 +89,41 @@ main() {
9089 esac
9190 done
9291
92+ # Check dependencies
93+ do_check_dependencies
94+
95+ # Configure tmux
96+ echo -e " set-option -g mouse on\nbind-key -n C-C confirm-before kill-session" > ~/.tmux.conf
97+
9398 if [ " $INSTALL " == " 1" ] || [ " $UPGRADE " == " 1" ]; then
9499 do_install
95100 exit 0
96101 fi
97102
98- do_check_dependencies
99-
100103 # start the rakpios-cli if no options is passed to the script
101104 if [[ $OPTIND -eq 1 ]]; then
105+ # shellcheck source=/dev/null
102106 source " ${DIR_LIB} /rakpios-cli-network-manage"
107+ # shellcheck source=/dev/null
103108 source " ${DIR_LIB} /rakpios-cli-service-deploy"
109+ # shellcheck source=/dev/null
104110 source " ${DIR_LIB} /rakpios-cli-service-list"
105111 do_check_for_update
106112 do_rakpios_cli_menu
107113 fi
108114}
109115
110116do_check_dependencies () {
117+
111118 # check for necessary tools
119+ # docker will be checked separately
112120 need_cmd curl
113121 need_cmd jq
114122 need_cmd unzip
115123 need_cmd whiptail
116124 need_cmd network-manager
117125 need_cmd tmux
118- # docker will be checkd separately
126+
119127}
120128
121129do_install () {
@@ -147,7 +155,7 @@ do_install() {
147155}
148156
149157do_print_install_location (){
150- __msg_debug " The rakpios-cli will be installed in the ${DIR_BIN} , ${DIR_LIB} and ${DIR_CNF} "
158+ __msg_debug " The rakpios-cli will be installed in the ${DIR_BIN} , ${DIR_LIB} and ${DIR_CNF} folders "
151159}
152160
153161do_print_version (){
@@ -181,11 +189,11 @@ do_check_directory() {
181189}
182190
183191do_fresh_install () {
192+
184193 do_check_dependencies
185- # print install location
186194 do_clean_up
187195 do_print_install_location
188- do_check_directory " ${DIR_TMP} " " ${DIR_LIB } " " ${DIR_CNF } " " ${DIR_BIN} "
196+ do_check_directory " ${DIR_TMP} " " ${DIR_CNF } " " ${DIR_BIN } " # "${DIR_LIB}" # DIR_LIB is created below
189197
190198 # clone the rakpios-cli repo and move the files
191199 if [[ $UPGRADE -eq 1 ]]; then
@@ -196,7 +204,7 @@ do_fresh_install() {
196204
197205 if git clone --quiet https://github.com/${org} /${repo} .git " ${DIR_TMP} /" ; then
198206 __msg_debug " Download completed"
199- cp -r " ${DIR_TMP} /lib/* " " ${DIR_LIB} "
207+ cp -r " ${DIR_TMP} /lib" " ${DIR_LIB} " # overwrites folder (that's why we are not creating it before)
200208 cp " ${DIR_TMP} /rakpios-cli" " ${DIR_BIN} /rakpios-cli"
201209 git -C " ${DIR_TMP} " tag -l --sort=v:refname | tail -1 > " ${DIR_CNF} /rakpios-cli.version"
202210 __msg_debug " Tool copy completed"
@@ -274,13 +282,17 @@ do_rakpios_cli_menu(){
274282# function to install command if not installed before
275283need_cmd () {
276284
277- if ! check_cmd " $1 " ; then
278- echo " need '$1 ' (command not found)"
279- apt install $1 -y
280- fi
281- if [[ $1 == " tmux" ]]; then
282- echo -e " set-option -g mouse on\nbind-key -n C-C confirm-before kill-session" > ~/.tmux.conf
285+ local COMMAND=" $1 "
286+
287+ if ! check_cmd " $COMMAND " ; then
288+ read -rp " Missing dependency: '$COMMAND '. Do you want to install it now? [y/N]: " RESPONSE
289+ if [[ " $RESPONSE " != " y" ]]; then
290+ echo " Quitting..."
291+ exit 0
292+ fi
293+ sudo apt install " $COMMAND " -y
283294 fi
295+
284296}
285297
286298# function to check whether command is installed or not
@@ -294,15 +306,6 @@ check_cmd() {
294306
295307}
296308
297- # slient pushd and popd
298- pushd () {
299- command pushd " $@ " > /dev/null
300- }
301-
302- popd () {
303- command popd " $@ " > /dev/null
304- }
305-
306309do_get_version_information () {
307310
308311 REMOTE_VERSION_URL_portainer_json=" https://raw.githubusercontent.com/RAKWireless/portainer-templates/master/portainer_app_template.json"
@@ -320,7 +323,7 @@ do_get_version_information() {
320323 local_version_rakpios_cli=$( cat " ${DIR_CNF} /rakpios-cli.version" )
321324
322325 else
323- __msg_debug " Can not found Portainer and rakpios-cli configuration files."
326+ __msg_debug " Can not found rakpios-cli or stack configuration files."
324327 CONFIG_FILE=1
325328 fi
326329
@@ -330,26 +333,27 @@ do_get_version_information() {
330333do_check_for_update (){
331334
332335 do_get_version_information
333- VERSION_PATTERN=^v[0-99].[0-99]
336+
334337 if [ $CONFIG_FILE == 1 ] ; then
335- whiptail --title " Error" --msgbox " Unable to find Portainer and rakpios-cli configuration files. Try reinstall the tool to fix it." 10 78
338+ whiptail --title " Error" --msgbox " Unable to find rakpios-cli or stack configuration files. Try reinstall the tool to fix it." 10 78
336339 return
337340 fi
341+
342+ # Check versions format
343+ VERSION_PATTERN=" ^v[0-99].[0-99]"
338344 if [[ ! $remote_version_portainer_json =~ $VERSION_PATTERN ]] || [[ ! $local_version_portainer_json =~ $VERSION_PATTERN ]] || [[ ! $remote_version_rakpios_cli =~ $VERSION_PATTERN ]] || [[ ! $local_version_rakpios_cli =~ $VERSION_PATTERN ]]; then
339345 whiptail --title " Error" --msgbox " Updates check failed, please check your network connection, and try again later." 10 78
340346 return
341347 fi
342348
343- # check updates for rakpios-cli and portainer template version
349+ # Check updates for rakpios-cli and portainer template version
344350 if [[ $remote_version_portainer_json > $local_version_portainer_json ]] || [[ $remote_version_rakpios_cli > $local_version_rakpios_cli ]]; then
345- whiptail --title " New Update is available" --msgbox " An update for rakpios-cli is available. Run 'rakpios-cli --upgrade' to upgrade." 8 78
351+ whiptail --title " New Update is available" --msgbox " An update for rakpios-cli is available.\nRun 'rakpios-cli --upgrade' to upgrade." 8 78
346352 __msg_debug " An update is available."
347353 fi
348354
349355}
350356
351-
352357# ##################################################################################################
353358
354-
355359main " $@ " || exit 1
0 commit comments