Skip to content

Commit 3c7c3a0

Browse files
committed
Improve code robustness and readability
1 parent d4ae192 commit 3c7c3a0

File tree

5 files changed

+69
-56
lines changed

5 files changed

+69
-56
lines changed

build-armbian/armbian-files/common-files/usr/sbin/armbian-apt

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -159,36 +159,36 @@ select_mirror_site() {
159159
echo -e "${INFO} Your selected source ID is: [ ${source_id} ]"
160160

161161
case "${source_id}" in
162-
0)
163-
# Restore the default source
164-
if [[ -f "${armbian_source_backup_file}" ]]; then
165-
cp -f "${armbian_source_backup_file}" "${armbian_source_file}"
166-
echo -e "${SUCCESS} Restore the default source successfully." && exit 0
167-
else
168-
error_msg "The default source file does not exist."
169-
fi
170-
;;
171-
1) MIRROR_URL="mirrors.tuna.tsinghua.edu.cn" ;;
172-
2) MIRROR_URL="mirrors.bfsu.edu.cn" ;;
173-
3) MIRROR_URL="mirrors.aliyun.com" ;;
174-
4) MIRROR_URL="mirrors.xtom.hk" ;;
175-
5) MIRROR_URL="opensource.nchc.org.tw" ;;
176-
6) MIRROR_URL="mirrors.ocf.berkeley.edu" ;;
177-
7) MIRROR_URL="mirrors.xtom.com" ;;
178-
8) MIRROR_URL="mirrors.mit.edu" ;;
179-
9) MIRROR_URL="mirror.csclub.uwaterloo.ca" ;;
180-
10) MIRROR_URL="muug.ca/mirror" ;;
181-
11) MIRROR_URL="mirror.kumi.systems" ;;
182-
12) MIRROR_URL="mirrors.xtom.nl" ;;
183-
13) MIRROR_URL="mirrors.xtom.de" ;;
184-
14) MIRROR_URL="mirror.yandex.ru" ;;
185-
15) MIRROR_URL="in.mirror.coganng.com" ;;
186-
16) MIRROR_URL="mirrors.xtom.ee" ;;
187-
17) MIRROR_URL="mirrors.xtom.au" ;;
188-
18) MIRROR_URL="mirror.yuki.net.uk" ;;
189-
19) MIRROR_URL="mirror.sg.gs" ;;
190-
20) MIRROR_URL="mirrors.xtom.jp" ;;
191-
*) error_msg "The source ID is not detected." ;;
162+
0)
163+
# Restore the default source
164+
if [[ -f "${armbian_source_backup_file}" ]]; then
165+
cp -f "${armbian_source_backup_file}" "${armbian_source_file}"
166+
echo -e "${SUCCESS} Restore the default source successfully." && exit 0
167+
else
168+
error_msg "The default source file does not exist."
169+
fi
170+
;;
171+
1) MIRROR_URL="mirrors.tuna.tsinghua.edu.cn" ;;
172+
2) MIRROR_URL="mirrors.bfsu.edu.cn" ;;
173+
3) MIRROR_URL="mirrors.aliyun.com" ;;
174+
4) MIRROR_URL="mirrors.xtom.hk" ;;
175+
5) MIRROR_URL="opensource.nchc.org.tw" ;;
176+
6) MIRROR_URL="mirrors.ocf.berkeley.edu" ;;
177+
7) MIRROR_URL="mirrors.xtom.com" ;;
178+
8) MIRROR_URL="mirrors.mit.edu" ;;
179+
9) MIRROR_URL="mirror.csclub.uwaterloo.ca" ;;
180+
10) MIRROR_URL="muug.ca/mirror" ;;
181+
11) MIRROR_URL="mirror.kumi.systems" ;;
182+
12) MIRROR_URL="mirrors.xtom.nl" ;;
183+
13) MIRROR_URL="mirrors.xtom.de" ;;
184+
14) MIRROR_URL="mirror.yandex.ru" ;;
185+
15) MIRROR_URL="in.mirror.coganng.com" ;;
186+
16) MIRROR_URL="mirrors.xtom.ee" ;;
187+
17) MIRROR_URL="mirrors.xtom.au" ;;
188+
18) MIRROR_URL="mirror.yuki.net.uk" ;;
189+
19) MIRROR_URL="mirror.sg.gs" ;;
190+
20) MIRROR_URL="mirrors.xtom.jp" ;;
191+
*) error_msg "The source ID is not detected." ;;
192192
esac
193193

194194
# Change the source list

build-armbian/armbian-files/common-files/usr/sbin/armbian-docker

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ echo -e "${INFO} Welcome to the docker management tool."
194194

195195
# Execute script assist functions
196196
case "${1}" in
197-
update) docker_update ;;
198-
remove) docker_remove ;;
199-
*) docker_install ;;
197+
update) docker_update ;;
198+
remove) docker_remove ;;
199+
*) docker_install ;;
200200
esac

build-armbian/armbian-files/common-files/usr/sbin/armbian-kernel

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,11 @@ remaining_space="$(df -Tk ${make_path} | grep '/dev/' | awk '{print $5}' | echo
136136

137137
# Execute script assist functions
138138
case "${1}" in
139-
-u | --update) update_script ;;
140-
-c | --clean) clean_tmp ;;
141-
-h | --help) help_info ;;
142-
*)
143-
[[ -f "${compile_script}" ]] || error_msg "Please run [ armbian-kernel -u ] to update scripts."
144-
cd ${make_path} && sudo ${compile_script} "${@}"
145-
;;
139+
-u | --update) update_script ;;
140+
-c | --clean) clean_tmp ;;
141+
-h | --help) help_info ;;
142+
*)
143+
[[ -f "${compile_script}" ]] || error_msg "Please run [ armbian-kernel -u ] to update scripts."
144+
cd ${make_path} && sudo ${compile_script} "${@}"
145+
;;
146146
esac

build-armbian/armbian-files/common-files/usr/sbin/armbian-update

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -164,55 +164,62 @@ init_var() {
164164
[[ -z "${PLATFORM}" ]] && error_msg "[ PLATFORM ] is missing, stop updating the kernel."
165165

166166
# If it is followed by [ : ], it means that the option requires a parameter value
167-
get_all_ver="$(getopt "r:u:k:b:m:" "${@}")"
167+
local options="r:u:k:b:m:"
168+
parsed_args=$(getopt -o "${options}" -- "${@}")
169+
[[ ${?} -ne 0 ]] && error_msg "Parameter parsing failed."
170+
eval set -- "${parsed_args}"
168171

169-
while [[ -n "${1}" ]]; do
172+
while true; do
170173
case "${1}" in
171174
-r | --kernelRepository)
172175
if [[ -n "${2}" ]]; then
173176
KERNEL_REPO="${2}"
174-
shift
177+
shift 2
175178
else
176179
error_msg "Invalid -r parameter [ ${2} ]!"
177180
fi
178181
;;
179182
-u | --kernel_Usage)
180183
if [[ -n "${2}" ]]; then
181184
kernel_usage="${2}"
182-
shift
185+
shift 2
183186
else
184187
error_msg "Invalid -u parameter [ ${2} ]!"
185188
fi
186189
;;
187190
-k | --Kernel)
188191
if [[ -n "${2}" ]]; then
189192
inputs_kernel="${2}"
190-
shift
193+
shift 2
191194
else
192195
error_msg "Invalid -k parameter [ ${2} ]!"
193196
fi
194197
;;
195198
-b | --Backup_kenlel)
196199
if [[ -n "${2}" ]]; then
197200
[[ "${2}" == "no" ]] && KERNEL_BACKUP="no" || KERNEL_BACKUP="yes"
198-
shift
201+
shift 2
199202
else
200203
error_msg "Invalid -b parameter [ ${2} ]!"
201204
fi
202205
;;
203206
-m | --Mainline_u-boot)
204207
if [[ -n "${2}" ]]; then
205208
[[ "${2}" == "yes" ]] && auto_mainline_uboot="yes" || auto_mainline_uboot="no"
206-
shift
209+
shift 2
207210
else
208211
error_msg "Invalid -m parameter [ ${2} ]!"
209212
fi
210213
;;
214+
--)
215+
shift
216+
break
217+
;;
211218
*)
212-
error_msg "Invalid option [ ${1} ]!"
219+
[[ -n "${1}" ]] && error_msg "Invalid option [ ${1} ]!"
220+
break
213221
;;
214222
esac
215-
shift
216223
done
217224

218225
# Query the current version

build-armbian/armbian-files/common-files/usr/share/ophub/armbian-software/software-command.sh

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -179,15 +179,17 @@ docker_remove() {
179179
# Initialize variables
180180
init_var() {
181181
# If it is followed by [ : ], it means that the option requires a parameter value
182-
get_all_ver="$(getopt "s:m:" "${@}")"
182+
local options="s:m:"
183+
parsed_args=$(getopt -o "${options}" -- "${@}")
184+
[[ ${?} -ne 0 ]] && error_msg "Parameter parsing failed."
185+
eval set -- "${parsed_args}"
183186

184-
# Check the input parameters
185-
while [[ -n "${1}" ]]; do
187+
while true; do
186188
case "${1}" in
187189
-s | --SoftwareID)
188190
if [[ -n "${2}" ]]; then
189191
software_id="${2}"
190-
shift
192+
shift 2
191193
else
192194
error_msg "Invalid -s parameter [ ${2} ]!"
193195
fi
@@ -199,16 +201,20 @@ init_var() {
199201
else
200202
error_msg "Invalid -m parameter [ ${2} ]!"
201203
fi
202-
shift
204+
shift 2
203205
else
204206
error_msg "Invalid -m parameter [ ${2} ]!"
205207
fi
206208
;;
209+
--)
210+
shift
211+
break
212+
;;
207213
*)
208-
error_msg "Invalid option [ ${1} ]!"
214+
[[ -n "${1}" ]] && error_msg "Invalid option [ ${1} ]!"
215+
break
209216
;;
210217
esac
211-
shift
212218
done
213219

214220
# Get related variables

0 commit comments

Comments
 (0)