Skip to content

Commit 139372c

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

20 files changed

+289
-27
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: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
set -Eeuo pipefail
33
IFS=$'\n\t'
44

5-
declare -gx PM=''
5+
declare -gx PM
6+
declare -gx PREFERRED_PACKAGE_MANAGER
67

78
declare -argx PM_PACKAGE_MANAGERS=(
89
apk
@@ -25,6 +26,28 @@ declare -Argx PM_PACKAGE_MANAGER_COMMAND=(
2526
["port"]="port"
2627
)
2728

29+
declare -Argx PM_NICENAME=(
30+
["apk"]="apk"
31+
["nala"]="Nala"
32+
["apt"]="Apt"
33+
["dnf"]="dnf"
34+
["pacman"]="pacman"
35+
["yum"]="yum"
36+
["brew"]="Homebrew"
37+
["port"]="MacPorts"
38+
)
39+
40+
declare -Argx PM_DESCRIPTION=(
41+
["apk"]="Alpine Package Keeper (Alpine Linux)"
42+
["nala"]="Nala alternative to Apt (Debian, Ubuntu)"
43+
["apt"]="Advanced Package Tool (Debian, Ubuntu)"
44+
["dnf"]="Dandified YUM (Fedora, CentOS)"
45+
["yum"]="Yellowdog Updater, Modified (Fedora, CentOS)"
46+
["pacman"]="Package Manager (Arch Linux)"
47+
["brew"]="Homebrew (macOS)"
48+
["port"]="MacPorts (macOS)"
49+
)
50+
2851
declare -argx PM__COMMAND_DEPS=(
2952
"column"
3053
"curl"
@@ -78,12 +101,21 @@ declare -Argx PM_PORT_DEP_PACKAGE=(
78101
)
79102

80103
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
104+
PM=""
105+
if [[ -n ${PREFERRED_PACKAGE_MANAGER-} ]]; then
106+
if [[ -n $(command -v "${PM_PACKAGE_MANAGER_COMMAND["${PREFERRED_PACKAGE_MANAGER}"]}") ]]; then
107+
PM="${PREFERRED_PACKAGE_MANAGER}"
85108
fi
86-
done
109+
fi
110+
if [[ -z ${PM-} ]]; then
111+
for pmname in "${PM_PACKAGE_MANAGERS[@]}"; do
112+
if [[ -n $(command -v "${PM_PACKAGE_MANAGER_COMMAND["${pmname}"]}") ]]; then
113+
PM="${pmname}"
114+
break
115+
fi
116+
done
117+
fi
118+
87119
if [[ -v PM_${PM^^}_COMMAND_DEPS ]]; then
88120
declare -ngx PM_COMMAND_DEPS="PM_${PM^^}_COMMAND_DEPS"
89121
else

.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_package_manager.sh

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
declare -gx PM_PREFERRED_PACKAGE_MANAGER="${PackageManager}"
32+
33+
if [[ -n ${PackageManager} ]] && ! run_script 'package_manager_exists' "${PackageManager}"; then
34+
warn "Package manager '${PackageManager}' not found."
35+
fi
36+
fi
37+
38+
pm_find_package_manager
39+
40+
}
41+
42+
test_config_package_manager() {
43+
warn "CI does not test config_package_manager."
44+
}

.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="Choose 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"]}Set package manager"
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
;;

.scripts/menu_options_display.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ menu_options_display() {
99

1010
local Title="Display Options"
1111

12-
run_script 'apply_theme' &> /dev/null
12+
run_script 'config_theme' &> /dev/null
1313

1414
local DrawLineOption="Draw Lines"
1515
local ShowBordersOption="Show Borders"
@@ -74,7 +74,7 @@ menu_options_display() {
7474
run_script 'config_set' "${OptionVariable["${Option}"]}" ON
7575
done
7676
fi
77-
run_script 'apply_theme' &> /dev/null
77+
run_script 'config_theme' &> /dev/null
7878
fi
7979
;;
8080
CANCEL | ESC)
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#!/usr/bin/env bash
2+
set -Eeuo pipefail
3+
IFS=$'\n\t'
4+
5+
menu_options_package_manager() {
6+
if [[ ${CI-} == true ]]; then
7+
return
8+
fi
9+
10+
local Title="Choose Package Manager"
11+
12+
local PM_AutoDetect_Tag="<Autodetect>"
13+
local PM_Autodetect_Item="Automatically detect the package manager to use"
14+
run_script 'config_package_manager' &> /dev/null
15+
16+
local CurrentPackageManager
17+
CurrentPackageManager="$(run_script 'config_get' PackageManager)"
18+
19+
local -a PackageManagerList
20+
readarray -t PackageManagerList < <(run_script 'package_manager_list')
21+
dialog_message "${Title}" "$(printf '%s\n' "${PackageManagerList[@]}")"
22+
#local -a DetectedPackageManagers
23+
#readarray -t DetectedPackageManagers < <(run_script 'package_manager_existing_list')
24+
25+
local LastChoice
26+
27+
local -a PM_Tag
28+
local -A PM_PackageManager PM_Item
29+
PM_Tag=("${PM_AutoDetect_Tag}")
30+
PM_PackageManager["${PM_AutoDetect_Tag}"]=''
31+
PM_Item["${PM_AutoDetect_Tag}"]="${PM_Autodetect_Item}"
32+
for PackageManager in "${PackageManagerList[@]}"; do
33+
local Tag
34+
Tag="$(run_script 'package_manager_nicename' "${PackageManager}")"
35+
PM_Tag+=("${Tag}")
36+
PM_PackageManager["${Tag}"]="${PackageManager}"
37+
PM_Item["${Tag}"]="$(run_script 'package_manager_description' "${PackageManager}")"
38+
if [[ ${PackageManager} == "${CurrentPackageManager}" ]]; then
39+
LastChoice="${Tag}"
40+
fi
41+
done
42+
43+
while true; do
44+
local -a Opts=()
45+
for Tag in "${PM_Tag[@]-}"; do
46+
if [[ ${PM_PackageManager["${Tag}"]} == "${CurrentPackageManager}" ]]; then
47+
Opts+=("${Tag}" "${DC["ListApp"]-}${PM_Item["${Tag}"]}" ON)
48+
else
49+
Opts+=("${Tag}" "${DC["ListApp"]-}${PM_Item["${Tag}"]}" OFF)
50+
fi
51+
done
52+
local -a ChoiceDialog=(
53+
--output-fd 1
54+
--title "${DC["Title"]-}${Title}"
55+
--ok-label "Select"
56+
--cancel-label "Back"
57+
--radiolist "Select the package manager to use." 0 0 0
58+
"${Opts[@]}"
59+
)
60+
local Choice
61+
local -i DialogButtonPressed=0
62+
Choice=$(_dialog_ --default-item "${LastChoice}" "${ChoiceDialog[@]}") || DialogButtonPressed=$?
63+
LastChoice=${Choice}
64+
case ${DIALOG_BUTTONS[DialogButtonPressed]-} in
65+
OK)
66+
if [[ ${Choice} != "${CurrentPackageManager}" ]]; then
67+
CurrentPackageManager="${Choice}"
68+
run_script 'config_package_manager' "${CurrentPackageManager}"
69+
fi
70+
;;
71+
CANCEL | ESC)
72+
return
73+
;;
74+
*)
75+
if [[ -n ${DIALOG_BUTTONS[DialogButtonPressed]-} ]]; then
76+
fatal "Unexpected dialog button '${DIALOG_BUTTONS[DialogButtonPressed]}' pressed in menu_options_package_manager."
77+
else
78+
fatal "Unexpected dialog button value '${DialogButtonPressed}' pressed in menu_options_package_manager."
79+
fi
80+
;;
81+
esac
82+
done
83+
}
84+
85+
test_menu_options_package_manager() {
86+
warn "CI does not test menu_options_package_manager."
87+
}

0 commit comments

Comments
 (0)