-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved build script for Debian, Arch, and RedHat based Linux distri…
…butions.
- Loading branch information
1 parent
ce01ed1
commit f38e098
Showing
2 changed files
with
163 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
#!/bin/bash | ||
|
||
find_package_manager() | ||
{ | ||
declare -A osInfo; | ||
osInfo[/etc/alpine-release]=apk | ||
osInfo[/etc/arch-release]=pacman | ||
osInfo[/etc/debian_version]=apt-get | ||
osInfo[/etc/gentoo-release]=emerge | ||
osInfo[/etc/redhat-release]=yum | ||
osInfo[/etc/SuSE-release]=zypp | ||
|
||
for F in ${!osInfo[@]}; do | ||
if [[ -f $F ]]; then | ||
echo ${osInfo[$F]} | ||
return 0 | ||
fi | ||
done | ||
|
||
return 1 # Could not identify package manager | ||
} | ||
|
||
list_missing_packages_generic() | ||
{ | ||
ARGS=("$@") | ||
CHECK_CMD="${ARGS[0]}" | ||
REQUEST=("${ARGS[@]:1}") | ||
MISSING="" | ||
|
||
for PKG in ${REQUEST[@]}; do | ||
eval $CHECK_CMD "$PKG" &> /dev/null | ||
if [ $? -ne 0 ]; then | ||
if [ ! -z "$MISSING" ]; then | ||
MISSING="$MISSING $PKG" | ||
else | ||
MISSING="$PKG" | ||
fi | ||
fi | ||
done | ||
|
||
if [ ! -z "$MISSING" ]; then | ||
echo "$MISSING" | ||
fi | ||
} | ||
|
||
list_missing_packages_arch() | ||
{ | ||
list_missing_packages_generic "pacman -Qi" $@ | ||
} | ||
|
||
list_missing_packages_debian() | ||
{ | ||
list_missing_packages_generic "dpkg -s" $@ | ||
} | ||
|
||
list_missing_packages_redhat() | ||
{ | ||
list_missing_packages_generic "yum list installed" $@ | ||
} | ||
|
||
report_missing_packages() | ||
{ | ||
CMD=$1 | ||
MISSING=$2 | ||
if [ ! -z "$MISSING" ]; then | ||
echo "missing packages! enter the following command to install them:" | ||
echo "$CMD $MISSING" | ||
exit 1 | ||
fi | ||
} | ||
|
||
PKG_MGR=$(find_package_manager) | ||
|
||
if [ $PKG_MGR = "pacman" ]; then | ||
MISSING=$( list_missing_packages_arch \ | ||
git cmake libx11 libxrandr libgl ) | ||
report_missing_packages "sudo pacman -S" "$MISSING" | ||
elif [ $PKG_MGR = "apt-get" ]; then | ||
MISSING=$( list_missing_packages_debian \ | ||
git cmake libx11-dev libxrandr-dev mesa-common-dev libglu1-mesa-dev freeglut3-dev ) | ||
report_missing_packages "sudo apt-get install" "$MISSING" | ||
elif [ $PKG_MGR = "yum" ]; then | ||
MISSING=$( list_missing_packages_redhat \ | ||
git cmake libx11-devel libXrandr-devel mesa-libGL-devel ) | ||
report_missing_packages "sudo yum install" "$MISSING" | ||
else | ||
echo error: could not identify Linux distribution | ||
exit 1 | ||
fi | ||
|
||
|