Skip to content

Commit d4d7885

Browse files
committed
Update package_manager_init.sh
1 parent 5b4fb72 commit d4d7885

File tree

1 file changed

+31
-28
lines changed

1 file changed

+31
-28
lines changed

.scripts/package_manager_init.sh

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ package_manager_init() {
1010
run_script 'config_package_manager'
1111

1212
declare -lgx PM
13-
13+
1414
local PreferredPackageManager
1515
PreferredPackageManager="$(run_script 'config_get' PackageManager)"
1616
if [[ -n ${PreferredPackageManager} ]]; then
@@ -20,40 +20,43 @@ package_manager_init() {
2020
warn "Selected package manager '${C["UserCommand"]}${PreferredPackageManager}${NC}' not found."
2121
fi
2222
fi
23-
if [[ -n ${PM} ]]; then
23+
if [[ -z ${PM} ]]; then
2424
notice "Automatically detecting package managers."
2525
for pmname in "${PM_PACKAGE_MANAGERS[@]}"; do
2626
if [[ -n $(command -v "${PM_PACKAGE_MANAGER_COMMAND["${pmname}"]}") ]]; then
2727
PM="${pmname}"
2828
break
2929
fi
3030
done
31-
if [[ -z ${PM-} ]]; then
32-
#shellcheck disable=SC2124 #Assigning an array to a string! Assign as array, or use * instead of @ to concatenate.
33-
local pmlist="${PM_PACKAGE_MANAGERS[@]}"
34-
pmlist="${pmlist// /${NC}\', \'${C["UserCommand"]}}"
35-
pmlist="${NC}'${C["UserCommand"]}${pmlist}${NC}'"
36-
fatal \
37-
"Unable to detect a compatible package manager. Compatible packages managers are:\n" \
38-
" ${pmlist}"
39-
fi
40-
notice "Using detected package manager '${C["UserCommand"]}${PM}${NC}'."
41-
42-
if [[ -v PM_${PM^^}_COMMAND_DEPS ]]; then
43-
declare -ngx PM_COMMAND_DEPS="PM_${PM^^}_COMMAND_DEPS"
44-
else
45-
declare -ngx PM_COMMAND_DEPS="PM__COMMAND_DEPS"
46-
fi
47-
if [[ -v PM_${PM^^}_DEP_PACKAGE ]]; then
48-
declare -ngx PM_DEP_PACKAGE="PM_${PM^^}_DEP_PACKAGE"
49-
else
50-
declare -ngx PM_DEP_PACKAGE="PM__DEP_PACKAGE"
51-
fi
52-
if [[ -v PM_${PM^^}_PACKAGE_BLACKLIST ]]; then
53-
declare -ngx PM_PACKAGE_BLACKLIST="PM_${PM^^}_PACKAGE_BLACKLIST"
54-
else
55-
declare -ngx PM_PACKAGE_BLACKLIST="PM__PACKAGE_BLACKLIST"
56-
fi
31+
fi
32+
33+
if [[ -z ${PM-} ]]; then
34+
#shellcheck disable=SC2124 #Assigning an array to a string! Assign as array, or use * instead of @ to concatenate.
35+
local pmlist="${PM_PACKAGE_MANAGERS[@]}"
36+
pmlist="${pmlist// /${NC}\', \'${C["UserCommand"]}}"
37+
pmlist="${NC}'${C["UserCommand"]}${pmlist}${NC}'"
38+
fatal \
39+
"Unable to detect a compatible package manager. Compatible packages managers are:\n" \
40+
" ${pmlist}"
41+
fi
42+
notice "Using detected package manager '${C["UserCommand"]}${PM}${NC}'."
43+
44+
# Set the global variables to use for the selected package manager
45+
if [[ -v PM_${PM^^}_COMMAND_DEPS ]]; then
46+
declare -ngx PM_COMMAND_DEPS="PM_${PM^^}_COMMAND_DEPS"
47+
else
48+
declare -ngx PM_COMMAND_DEPS="PM__COMMAND_DEPS"
49+
fi
50+
if [[ -v PM_${PM^^}_DEP_PACKAGE ]]; then
51+
declare -ngx PM_DEP_PACKAGE="PM_${PM^^}_DEP_PACKAGE"
52+
else
53+
declare -ngx PM_DEP_PACKAGE="PM__DEP_PACKAGE"
54+
fi
55+
if [[ -v PM_${PM^^}_PACKAGE_BLACKLIST ]]; then
56+
declare -ngx PM_PACKAGE_BLACKLIST="PM_${PM^^}_PACKAGE_BLACKLIST"
57+
else
58+
declare -ngx PM_PACKAGE_BLACKLIST="PM__PACKAGE_BLACKLIST"
59+
fi
5760
}
5861

5962
test_package_manager_init() {

0 commit comments

Comments
 (0)