Skip to content

Commit ee93e09

Browse files
committed
Add a package manager config option
1 parent 89f07d4 commit ee93e09

32 files changed

+472
-90
lines changed

.includes/cmdline.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -766,10 +766,10 @@ run_command() {
766766
fi
767767
notice "${NoticeText}"
768768
if use_dialog_box; then
769-
run_script 'apply_theme' "${ThemeName}" && run_script 'menu_dialog_example' "" "${CURRENT_COMMANDLINE}"
769+
run_script 'config_theme' "${ThemeName}" && run_script 'menu_dialog_example' "" "${CURRENT_COMMANDLINE}"
770770
result=$?
771771
else
772-
run_script 'apply_theme' "${ThemeName}"
772+
run_script 'config_theme' "${ThemeName}"
773773
result=$?
774774
fi
775775
;;

.includes/dialog_functions.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ dialog_pipe() {
133133
local SubTitle=${2:-}
134134
local TimeOut=${3:-0}
135135
if [[ -z ${DC["_defined_"]-} ]]; then
136-
run_script 'apply_theme'
136+
run_script 'config_theme'
137137
fi
138138
Title="$(strip_ansi_colors "${Title}")"
139139
SubTitle="$(strip_ansi_colors "${SubTitle}")"
@@ -153,7 +153,7 @@ run_script_dialog() {
153153
shift 4
154154
if use_dialog_box; then
155155
if [[ -z ${DC["_defined_"]-} ]]; then
156-
run_script 'apply_theme'
156+
run_script 'config_theme'
157157
fi
158158
# Using the GUI, pipe output to a dialog box
159159
coproc {
@@ -197,7 +197,7 @@ dialog_info() {
197197
Title="$(strip_ansi_colors "${Title}")"
198198
Message="$(strip_ansi_colors "${Message}")"
199199
if [[ -z ${DC["_defined_"]-} ]]; then
200-
run_script 'apply_theme'
200+
run_script 'config_theme'
201201
fi
202202
_dialog_ \
203203
--title "${Title}" \
@@ -212,7 +212,7 @@ dialog_message() {
212212
Title="$(strip_ansi_colors "${Title}")"
213213
Message="$(strip_ansi_colors "${Message}")"
214214
if [[ -z ${DC["_defined_"]-} ]]; then
215-
run_script 'apply_theme'
215+
run_script 'config_theme'
216216
fi
217217
_dialog_ \
218218
--title "${Title}" \
@@ -226,7 +226,7 @@ dialog_error() {
226226
local Message=${2:-}
227227
local TimeOut=${3:-0}
228228
if [[ -z ${DC["_defined_"]-} ]]; then
229-
run_script 'apply_theme'
229+
run_script 'config_theme'
230230
fi
231231
dialog_message "${DC["TitleError"]-}${Title}" "${Message}" "${TimeOut}"
232232
}
@@ -235,7 +235,7 @@ dialog_warning() {
235235
local Message=${2:-}
236236
local TimeOut=${3:-0}
237237
if [[ -z ${DC["_defined_"]-} ]]; then
238-
run_script 'apply_theme'
238+
run_script 'config_theme'
239239
fi
240240
dialog_message "${DC["TitleWarning"]-}${Title}" "${Message}" "${TimeOut}"
241241
}
@@ -244,7 +244,7 @@ dialog_success() {
244244
local Message=${2:-}
245245
local TimeOut=${3:-0}
246246
if [[ -z ${DC["_defined_"]-} ]]; then
247-
run_script 'apply_theme'
247+
run_script 'config_theme'
248248
fi
249249
dialog_message "${DC["TitleSuccess"]-}${Title}" "${Message}" "${TimeOut}"
250250
}

.includes/pm_variables.sh

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
set -Eeuo pipefail
33
IFS=$'\n\t'
44

5-
declare -gx PM=''
6-
75
declare -argx PM_PACKAGE_MANAGERS=(
86
apk
97
nala
@@ -25,6 +23,28 @@ declare -Argx PM_PACKAGE_MANAGER_COMMAND=(
2523
["port"]="port"
2624
)
2725

26+
declare -Argx PM_NICENAME=(
27+
["apk"]="APK"
28+
["nala"]="Nala"
29+
["apt"]="APT"
30+
["dnf"]="DNF"
31+
["pacman"]="Pacman"
32+
["yum"]="YUM"
33+
["brew"]="Homebrew"
34+
["port"]="MacPorts"
35+
)
36+
37+
declare -Argx PM_DESCRIPTION=(
38+
["apk"]="Alpine Package Keeper (Alpine Linux)"
39+
["nala"]="Nala alternative to Apt (Debian, Ubuntu)"
40+
["apt"]="Advanced Package Tool (Debian, Ubuntu)"
41+
["dnf"]="Dandified YUM (Fedora, CentOS)"
42+
["yum"]="Yellowdog Updater, Modified (Fedora, CentOS)"
43+
["pacman"]="Package Manager (Arch Linux)"
44+
["brew"]="Homebrew (macOS)"
45+
["port"]="MacPorts (macOS)"
46+
)
47+
2848
declare -argx PM__COMMAND_DEPS=(
2949
"column"
3050
"curl"
@@ -77,30 +97,6 @@ declare -Argx PM_PORT_DEP_PACKAGE=(
7797
["ip"]="iproute2mac"
7898
)
7999

80-
pm_find_package_manager() {
81-
for pmname in "${PM_PACKAGE_MANAGERS[@]}"; do
82-
if [[ -n $(command -v "${PM_PACKAGE_MANAGER_COMMAND["${pmname}"]}") ]]; then
83-
PM="${pmname}"
84-
break
85-
fi
86-
done
87-
if [[ -v PM_${PM^^}_COMMAND_DEPS ]]; then
88-
declare -ngx PM_COMMAND_DEPS="PM_${PM^^}_COMMAND_DEPS"
89-
else
90-
declare -ngx PM_COMMAND_DEPS="PM__COMMAND_DEPS"
91-
fi
92-
if [[ -v PM_${PM^^}_DEP_PACKAGE ]]; then
93-
declare -ngx PM_DEP_PACKAGE="PM_${PM^^}_DEP_PACKAGE"
94-
else
95-
declare -ngx PM_DEP_PACKAGE="PM__DEP_PACKAGE"
96-
fi
97-
if [[ -v PM_${PM^^}_PACKAGE_BLACKLIST ]]; then
98-
declare -ngx PM_PACKAGE_BLACKLIST="PM_${PM^^}_PACKAGE_BLACKLIST"
99-
else
100-
declare -ngx PM_PACKAGE_BLACKLIST="PM__PACKAGE_BLACKLIST"
101-
fi
102-
}
103-
104100
pm_check_dependency() {
105101
local Dep=${1}
106102
case "${Dep}" in
@@ -195,5 +191,3 @@ pm_check_dependencies() {
195191
fi
196192
return 0
197193
}
198-
199-
pm_find_package_manager

.scripts/apply_config.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ apply_config() {
66
if [[ ! -f ${APPLICATION_INI_FILE} ]]; then
77
run_script 'config_create'
88
fi
9-
run_script 'apply_theme'
9+
run_script 'config_theme'
10+
run_script 'config_package_manager'
1011
sort -o "${APPLICATION_INI_FILE}" "${APPLICATION_INI_FILE}"
1112
}
1213

.scripts/config_create.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ IFS=$'\n\t'
44

55
config_create() {
66
if [[ ! -f ${APPLICATION_INI_FILE} ]]; then
7+
unset 'PM'
78
local OldIniFile="${SCRIPTPATH}/menu.ini"
89
if [[ -f ${OldIniFile} ]]; then
910
# Migrate from the old menu.ini file

.scripts/config_package_manager.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env bash
2+
set -Eeuo pipefail
3+
IFS=$'\n\t'
4+
5+
config_package_manager() {
6+
local PackageManager
7+
if [[ $# -gt 0 ]]; then
8+
PackageManager=${1}
9+
fi
10+
11+
if [[ ! -f ${APPLICATION_INI_FILE} ]]; then
12+
run_script 'config_create'
13+
fi
14+
15+
if ! run_script 'env_var_exists' PackageManager "${APPLICATION_INI_FILE}"; then
16+
local DefaultIniFile="${DEFAULTS_FOLDER}/${APPLICATION_INI_NAME}"
17+
local DefaultPackageManager
18+
DefaultPackageManager="$(run_script 'config_get' PackageManager "${DefaultIniFile}")"
19+
notice \
20+
"Setting config option in ${C["File"]}${APPLICATION_INI_FILE}${NC}:" \
21+
" ${C["Var"]}PackageManager='${DefaultPackageManager}'${NC}"
22+
run_script 'config_set' PackageManager "${DefaultPackageManager}"
23+
fi
24+
25+
if [[ -n ${PackageManager+x} ]]; then
26+
if [[ -n ${PackageManager} ]] && ! run_script 'package_manager_is_valid' "${PackageManager}"; then
27+
error "Unknown package manager '${PackageManager}'."
28+
return 1
29+
fi
30+
run_script 'config_set' PackageManager "${PackageManager}"
31+
32+
if [[ -n ${PackageManager} ]] && ! run_script 'package_manager_exists' "${PackageManager}"; then
33+
warn "Package manager '${PackageManager}' not found."
34+
fi
35+
fi
36+
37+
}
38+
39+
test_config_package_manager() {
40+
warn "CI does not test config_package_manager."
41+
}

.scripts/config_set.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ config_set() {
1212
local NEW_VAL=${2-}
1313
local VAR_FILE=${3-$APPLICATION_INI_FILE}
1414

15+
if [[ ${VAR_FILE} == "${APPLICATION_INI_FILE}" && ${SET_VAR} == PackageManager ]]; then
16+
unset 'PM'
17+
fi
18+
1519
# https://unix.stackexchange.com/questions/422165/escape-double-quotes-in-variable/422170#422170
1620
NEW_VAL="$(printf "%s\n" "${NEW_VAL-}" | ${SED} -e "s/'/'\"'\"'/g" -e "1s/^/'/" -e "\$s/\$/'/")"
1721

@@ -20,7 +24,10 @@ config_set() {
2024
touchfile "${VAR_FILE}"
2125
fi
2226
${SED} -i "/^\s*${SET_VAR}\s*=/d" "${VAR_FILE}" || true
23-
echo "${SET_VAR}=${NEW_VAL}" >> "${VAR_FILE}" || fatal "Failed to set ${C["Var"]}${SET_VAR}=${NEW_VAL}${NC}\nFailing command: ${C["FailingCommand"]} \"echo ${SET_VAR}=${NEW_VAL}\" >> \"${VAR_FILE}\""
27+
echo "${SET_VAR}=${NEW_VAL}" >> "${VAR_FILE}" ||
28+
fatal \
29+
"Failed to set ${C["Var"]}${SET_VAR}=${NEW_VAL}${NC}\n" \
30+
"Failing command: ${C["FailingCommand"]} \"echo ${SET_VAR}=${NEW_VAL}\" >> \"${VAR_FILE}\""
2431
}
2532

2633
test_config_set() {

.scripts/apply_theme.sh renamed to .scripts/config_theme.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
set -Eeuo pipefail
33
IFS=$'\n\t'
44

5-
apply_theme() {
5+
config_theme() {
66
local ThemeName=${1-}
77

88
local DefaultThemes=(
@@ -161,6 +161,6 @@ apply_theme() {
161161
run_script 'config_set' Theme "${ThemeName}"
162162
}
163163

164-
test_apply_theme() {
165-
warn "CI does not test apply_theme."
164+
test_config_theme() {
165+
warn "CI does not test config_theme."
166166
}

.scripts/menu_heading.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ menu_heading() {
159159
}
160160

161161
test_menu_heading() {
162-
run_script 'apply_theme'
162+
run_script 'config_theme'
163163
notice WATCHTOWER:
164164
run_script 'menu_heading' WATCHTOWER
165165
notice "WATCHTOWER WATCHTOWER__ENABLED:"

.scripts/menu_options.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ menu_options() {
1010
local Title="Options"
1111
local Option_Theme="Choose Theme"
1212
local Option_Display="Display Options"
13+
local Option_Package_Manager="Package Manager"
1314
local Opts=(
1415
"${Option_Theme}" "${DC["ListDefault"]}Choose a theme for ${APPLICATION_NAME}"
1516
"${Option_Display}" "${DC["ListDefault"]}Set display options"
17+
"${Option_Package_Manager}" "${DC["ListDefault"]}Choose the package manager to use"
1618
)
1719

1820
local LastChoice=""
@@ -38,6 +40,9 @@ menu_options() {
3840
"${Option_Display}")
3941
run_script 'menu_options_display' || true
4042
;;
43+
"${Option_Package_Manager}")
44+
run_script 'menu_options_package_manager' || true
45+
;;
4146
*)
4247
error "Invalid Option"
4348
;;

0 commit comments

Comments
 (0)