Skip to content

Commit 24ff1ad

Browse files
authored
Add package manager selection options (#2283)
1 parent 79f4ab5 commit 24ff1ad

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+731
-96
lines changed

.defaults/dockstarter.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
Borders='yes'
22
LineCharacters='yes'
3+
PackageManager=''
34
Scrollbar='yes'
45
Shadow='yes'
56
Theme='DockSTARTer'

.includes/cmdline.sh

Lines changed: 77 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ parse_arguments() {
5353
;;
5454

5555
# --command
56+
--config-pm-auto) ;&
57+
--config-pm-list | --config-pm-table) ;&
58+
--config-pm-existing-list | --config-pm-existing-table) ;&
5659
-e | --env) ;&
5760
-i | --install) ;&
5861
-l | --list) ;&
@@ -99,6 +102,19 @@ parse_arguments() {
99102
break
100103
;;
101104

105+
--config-pm)
106+
if [[ -z ${!OPTIND-} || ${!OPTIND} == "-"* ]]; then
107+
cmdline_error \
108+
"${OPTION}" \
109+
"Command %c requires a package manager name." \
110+
"${ParsedArgs[@]}" "${CurrentFlags[@]}" "${CurrentCommand[@]}" "${OPTION}"
111+
exit 1
112+
fi
113+
CurrentCommand+=("${OPTION}" "${!OPTIND}")
114+
OPTIND+=1
115+
break
116+
;;
117+
102118
-M | --menu)
103119
CurrentCommand=("${OPTION}")
104120
if [[ -n ${!OPTIND-} && ${!OPTIND} != "-"* ]]; then
@@ -364,6 +380,12 @@ run_command() {
364380
["--add"]="appvars_create"
365381
["-c"]="docker_compose"
366382
["--compose"]="docker_compose"
383+
["--config-pm"]="config_package_manager"
384+
["--config-pm-auto"]="config_package_manager"
385+
["--config-pm-list"]="package_manager_list"
386+
["--config-pm-table"]="package_manager_table"
387+
["--config-pm-existing-list"]="package_manager_existing_list"
388+
["--config-pm-existing-table"]="package_manager_existing_table"
367389
["-e"]="appvars_create_all"
368390
["--env"]="appvars_create_all"
369391
["--env-appvars"]="appvars_list"
@@ -441,6 +463,12 @@ run_command() {
441463
["-a"]=1
442464
["--add"]=1
443465
["-e"]=1
466+
["--config-pm"]=1
467+
["--config-pm-auto"]=1
468+
["--config-pm-list"]=1
469+
["--config-pm-table"]=1
470+
["--config-pm-existing-list"]=1
471+
["--config-pm-existing-table"]=1
444472
["--env"]=1
445473
["--list"]=1
446474
["-r"]=1
@@ -452,6 +480,12 @@ run_command() {
452480
CommandTitle+=(
453481
["-a"]="Add Application"
454482
["--add"]="Add Application"
483+
["--config-pm"]="Select package manager"
484+
["--config-pm-auto"]="Select package manager"
485+
["--config-pm-list"]="List known package managers"
486+
["--config-pm-table"]="List known package managers"
487+
["--config-pm-existing-list"]="List existing package managers"
488+
["--config-pm-existing-table"]="List existing package managers"
455489
["-e"]="${DC["TitleSuccess"]-}Creating environment variables for added apps"
456490
["--env"]="${DC["TitleSuccess"]-}Creating environment variables for added apps"
457491
["--env-appvars"]="Variables for Application"
@@ -674,6 +708,9 @@ run_command() {
674708
;;
675709
-a | --add) ;&
676710
-c | --compose) ;&
711+
--config-pm) ;&
712+
--config-pm-list | --config-pm-table) ;&
713+
--config-pm-existing-list | --config-pm-existing-table) ;&
677714
-e | --env) ;&
678715
-i | --install) ;&
679716
--list) ;&
@@ -725,6 +762,44 @@ run_command() {
725762
fi
726763
;;
727764

765+
--config-pm-auto)
766+
if [[ -z ${Script} ]]; then
767+
fatal \
768+
"No script is defined for command '${C["UserCommand"]-}${Command}${NC-}'.\n" \
769+
"Please let the dev know."
770+
fi
771+
if [[ -n ${EnvCreate-} ]]; then
772+
run_script 'env_create'
773+
fi
774+
if [[ -n ${EnvBackup-} ]]; then
775+
run_script 'env_backup'
776+
fi
777+
if [[ ${RequireDialog-} ]]; then
778+
if [[ -z ${DIALOG-} ]]; then
779+
fatal \
780+
"The GUI requires the '${C["Program"]-}dialog${NC-}' command to be installed.\n" \
781+
"'${C["Program"]-}dialog${NC-}' command not found. Run '${C["UserCommand"]-}${APPLICATION_COMMAND} -i${NC-}' to install all dependencies.\n" \
782+
"\n" \
783+
"Unable to start GUI without the '${C["Program"]-}dialog${NC-}' command.\n"
784+
fi
785+
declare -gx PROMPT="GUI"
786+
run_script "${Script}" ""
787+
result=$?
788+
else
789+
if [[ ${UseDialog} ]]; then
790+
run_script_dialog "${Title}" "${SubTitle}" "" \
791+
"${Script}" ""
792+
result=$?
793+
else
794+
run_script "${Script}" ""
795+
result=$?
796+
fi
797+
fi
798+
if [[ -n ${EnvUpdate-} ]]; then
799+
run_script 'env_update'
800+
fi
801+
;;
802+
728803
--menu-config-app)
729804
if [[ -z ${Script} ]]; then
730805
fatal \
@@ -766,10 +841,10 @@ run_command() {
766841
fi
767842
notice "${NoticeText}"
768843
if use_dialog_box; then
769-
run_script 'apply_theme' "${ThemeName}" && run_script 'menu_dialog_example' "" "${CURRENT_COMMANDLINE}"
844+
run_script 'config_theme' "${ThemeName}" && run_script 'menu_dialog_example' "" "${CURRENT_COMMANDLINE}"
770845
result=$?
771846
else
772-
run_script 'apply_theme' "${ThemeName}"
847+
run_script 'config_theme' "${ThemeName}"
773848
result=$?
774849
fi
775850
;;

.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: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@
22
set -Eeuo pipefail
33
IFS=$'\n\t'
44

5-
declare -gx PM=''
6-
75
declare -argx PM_PACKAGE_MANAGERS=(
8-
apk
96
nala
107
apt
11-
dnf
8+
apk
129
pacman
10+
dnf
1311
yum
1412
brew
13+
none
1514
)
1615

1716
declare -Argx PM_PACKAGE_MANAGER_COMMAND=(
@@ -23,6 +22,31 @@ declare -Argx PM_PACKAGE_MANAGER_COMMAND=(
2322
["yum"]="yum"
2423
["brew"]="brew"
2524
["port"]="port"
25+
["none"]="bash"
26+
)
27+
28+
declare -Argx PM_NICENAME=(
29+
["apk"]="APK"
30+
["nala"]="Nala"
31+
["apt"]="APT"
32+
["dnf"]="DNF"
33+
["pacman"]="Pacman"
34+
["yum"]="YUM"
35+
["brew"]="Homebrew"
36+
["port"]="MacPorts"
37+
["none"]="None"
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+
["none"]="No package manager"
2650
)
2751

2852
declare -argx PM__COMMAND_DEPS=(
@@ -70,37 +94,25 @@ declare -argx PM_PORT_COMMAND_DEPS=(
7094
"ip"
7195
)
7296

97+
declare -argx PM_NONE_COMMAND_DEPS=(
98+
"column"
99+
"curl"
100+
"dialog"
101+
"gfind"
102+
"git"
103+
"ggrep"
104+
"gsed"
105+
"gstat"
106+
"ip"
107+
)
108+
73109
declare -Argx PM_PORT_DEP_PACKAGE=(
74110
["dialog"]="dialog"
75111
["find"]="findutils"
76112
["gsed"]="gnu-sed"
77113
["ip"]="iproute2mac"
78114
)
79115

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-
104116
pm_check_dependency() {
105117
local Dep=${1}
106118
case "${Dep}" in
@@ -195,5 +207,3 @@ pm_check_dependencies() {
195207
fi
196208
return 0
197209
}
198-
199-
pm_find_package_manager

.includes/usage.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,34 @@ ${C["UsageCommand"]-}-c --compose${NC-} < ${C["UsageOption"]-}pull${NC-} | ${C["
106106
The '${C["UsageOption"]-}update${NC-}' command is the same as a '${C["UsageOption"]-}pull${NC-}' followed by an '${C["UsageOption"]-}up${NC-}'
107107
${C["UsageCommand"]-}-c --compose${NC-} < ${C["UsageOption"]-}generate${NC-} | ${C["UsageOption"]-}merge${NC-} >${NC-}
108108
Generates the '${C["UsageFile"]-}docker-compose.yml${NC-} file
109+
EOF
110+
;;&
111+
--config-pm-list | "")
112+
Found=1
113+
cat << EOF
114+
${C["UsageCommand"]-}--config-pm-list${NC-}
115+
Lists the compatible package managers
116+
EOF
117+
;;&
118+
--config-pm-table | "")
119+
Found=1
120+
cat << EOF
121+
${C["UsageCommand"]-}--config-pm-table${NC-}
122+
Lists the compatible package managers in a table format
123+
EOF
124+
;;&
125+
--config-pm-existing-list | "")
126+
Found=1
127+
cat << EOF
128+
${C["UsageCommand"]-}--config-pm-existing-list${NC-}
129+
Lists the existing package managers
130+
EOF
131+
;;&
132+
--config-pm-existing-table | "")
133+
Found=1
134+
cat << EOF
135+
${C["UsageCommand"]-}--config-pm-existing-table${NC-}
136+
Lists the existing package managers in a table format
109137
EOF
110138
;;&
111139
-e | --env | "")

.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

0 commit comments

Comments
 (0)