Skip to content

Commit df8a412

Browse files
committed
Add: script: check if the known package manager for a distribution exists before trying to use it; if it is not available, fail.
1 parent d4f3422 commit df8a412

1 file changed

Lines changed: 35 additions & 5 deletions

File tree

install_rack_free.sh

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ distroLabels=("Arch Linux based distribution" "Debian based distribution" "Fedor
2525
# they are filled when a distro is selected.
2626
checkCommand=''
2727
installCommand=''
28+
packageManager=''
2829

2930
# Begin functions block.
3031
function installRack() {
@@ -107,9 +108,26 @@ function installPrereqs() {
107108
echo
108109
}
109110

111+
function checkPackageManager() {
112+
echo
113+
echo "Checking for package manager $packageManager..."
114+
command -v $packageManager &> /dev/null
115+
if [ $? != 0 ]; then
116+
echo
117+
echo "ERROR: package manager $packageManager not found."
118+
echo "Exiting now..."
119+
exit 1
120+
fi
121+
echo "Package manager found."
122+
}
123+
110124
function installArchPrereqs() {
111-
checkCommand="pacman -Q"
112-
installCommand="pacman -S -q --noconfirm"
125+
packageManager="pacman"
126+
127+
checkPackageManager
128+
129+
checkCommand="$packageManager -Q"
130+
installCommand="$packageManager -S -q --noconfirm"
113131

114132
checkAndInstall wget
115133

@@ -127,6 +145,14 @@ function installArchPrereqs() {
127145
}
128146

129147
function installDebianPrereqs() {
148+
packageManager="dpkg"
149+
150+
checkPackageManager
151+
152+
packageManager="apt"
153+
154+
checkPackageManager
155+
130156
checkCommand="dpkg -s"
131157
installCommand="apt -y install"
132158

@@ -146,11 +172,15 @@ function installDebianPrereqs() {
146172
}
147173

148174
function installFedoraPrereqs() {
149-
checkCommand="dnf list installed"
150-
installCommand="dnf install"
175+
packageManager="dnf"
176+
177+
checkPackageManager
178+
179+
checkCommand="$packageManager list installed"
180+
installCommand="$packageManager install"
151181

152182
# Ensure we can list the packages: this system is not at all smart.
153-
$SUDO dnf list --extras &> /dev/null
183+
$SUDO $packageManager list --extras &> /dev/null
154184

155185
checkAndInstall wget2
156186

0 commit comments

Comments
 (0)