Skip to content

Commit e313fed

Browse files
committed
Clean up
1 parent 7cc6ca6 commit e313fed

File tree

4 files changed

+38
-52
lines changed

4 files changed

+38
-52
lines changed

lib/rakpios-cli-network-manage

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -284,11 +284,4 @@ do_network_main_menu()
284284
esac
285285
fi
286286

287-
}
288-
289-
# if [ $(id -u) -ne 0 ]; then
290-
# printf "Script must be run as root. Try 'sudo ./whiptail_network_config'\n"
291-
# exit 1
292-
# fi
293-
294-
# do_main_menu
287+
}

lib/rakpios-cli-service-deploy

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ do_choose_service_env() {
7878
service_env_array=()
7979

8080
IFS=$'\n' keys=($(sort -n <<<"${!service_env[@]}"))
81+
unset IFS
8182
for k in "${keys[@]}"
8283
do
8384
value=${service_env[$k]}
@@ -398,13 +399,4 @@ do_print_post_up_info() {
398399

399400
do_container() {
400401
do_select_service
401-
}
402-
403-
# if [ $(id -u) -ne 0 ]; then
404-
# printf "Script must be run as root. Try 'sudo ./portainer-json-parser'\n"
405-
# exit 1
406-
# fi
407-
408-
#do_container
409-
410-
402+
}

lib/rakpios-cli-service-list

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ do_command() {
5656
docker stop "$CONTAINER_NAME" > /dev/null
5757
else
5858
docker compose -p "$CONTAINER_NAME" stop
59-
6059
fi
6160
if [ $? -eq 0 ]; then
6261
# __msg_debug "docker compose stop ran successfully"
@@ -138,6 +137,4 @@ do_service_menu() {
138137

139138

140139
fi
141-
}
142-
143-
# do_service_menu
140+
}

rakpios-cli

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -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

110116
do_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

121129
do_install() {
@@ -147,7 +155,7 @@ do_install() {
147155
}
148156

149157
do_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

153161
do_print_version(){
@@ -181,11 +189,11 @@ do_check_directory() {
181189
}
182190

183191
do_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
275283
need_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-
306309
do_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() {
330333
do_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-
355359
main "$@" || exit 1

0 commit comments

Comments
 (0)