2020-11-13 03:18:11 +08:00
|
|
|
#!/bin/bash
|
|
|
|
|
2022-09-21 00:42:15 +08:00
|
|
|
function operating_system() {
|
2020-11-13 03:18:11 +08:00
|
|
|
grep -E '^(VERSION_)?ID=' /etc/os-release | \
|
|
|
|
sort | cut -d '=' -f 2- | sed 's/"//g' | paste -s -d '-'
|
|
|
|
}
|
|
|
|
|
2022-09-21 00:42:15 +08:00
|
|
|
function check_operating_system() {
|
2022-07-13 23:48:01 +08:00
|
|
|
if [ "$(operating_system)" != "$1" ]; then
|
|
|
|
echo "Not the right operating system!"
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
echo "The right operating system."
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2022-09-21 00:42:15 +08:00
|
|
|
function architecture() {
|
2022-04-07 21:23:18 +08:00
|
|
|
uname -m
|
|
|
|
}
|
|
|
|
|
2022-07-13 23:48:01 +08:00
|
|
|
check_architecture() {
|
2023-03-02 01:44:56 +08:00
|
|
|
local ARCH=$(architecture)
|
2022-09-21 00:42:15 +08:00
|
|
|
for arch in "$@"; do
|
2023-03-02 01:44:56 +08:00
|
|
|
if [ "${ARCH}" = "$arch" ]; then
|
2022-09-21 00:42:15 +08:00
|
|
|
echo "The right architecture!"
|
2022-10-06 21:55:23 +08:00
|
|
|
return 0
|
2022-09-21 00:42:15 +08:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
echo "Not the right architecture!"
|
2023-03-02 01:44:56 +08:00
|
|
|
echo "Expected: $@"
|
|
|
|
echo "Actual: ${ARCH}"
|
2022-09-21 00:42:15 +08:00
|
|
|
exit 1
|
2022-07-13 23:48:01 +08:00
|
|
|
}
|
|
|
|
|
2022-09-21 00:42:15 +08:00
|
|
|
function check_all_yum() {
|
2020-11-13 03:18:11 +08:00
|
|
|
local missing=""
|
|
|
|
for pkg in $1; do
|
|
|
|
if ! yum list installed "$pkg" >/dev/null 2>/dev/null; then
|
|
|
|
missing="$pkg $missing"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
if [ "$missing" != "" ]; then
|
|
|
|
echo "MISSING PACKAGES: $missing"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2022-09-21 00:42:15 +08:00
|
|
|
function check_all_dpkg() {
|
2020-11-13 03:18:11 +08:00
|
|
|
local missing=""
|
|
|
|
for pkg in $1; do
|
|
|
|
if ! dpkg -s "$pkg" >/dev/null 2>/dev/null; then
|
|
|
|
missing="$pkg $missing"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
if [ "$missing" != "" ]; then
|
|
|
|
echo "MISSING PACKAGES: $missing"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2022-09-21 00:42:15 +08:00
|
|
|
function check_all_dnf() {
|
2020-11-13 03:18:11 +08:00
|
|
|
local missing=""
|
|
|
|
for pkg in $1; do
|
|
|
|
if ! dnf list installed "$pkg" >/dev/null 2>/dev/null; then
|
|
|
|
missing="$pkg $missing"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
if [ "$missing" != "" ]; then
|
|
|
|
echo "MISSING PACKAGES: $missing"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
2022-09-21 00:42:15 +08:00
|
|
|
|
|
|
|
function install_all_apt() {
|
2021-01-15 16:26:15 +08:00
|
|
|
for pkg in $1; do
|
|
|
|
apt install -y "$pkg"
|
|
|
|
done
|
|
|
|
}
|