Install dependencies only if needed

This commit is contained in:
Howard Wu 2022-09-05 13:41:13 +08:00
parent 70bb0fdb8f
commit 89bf502389

View File

@ -34,6 +34,70 @@ abort() {
exit 1 exit 1
} }
echo "Checking and ensuring dependencies"
check_dependencies() {
command -v whiptail >/dev/null 2>&1 || NEED_INSTALL+=("whiptail")
command -v seinfo >/dev/null 2>&1 || NEED_INSTALL+=("setools")
command -v lzip >/dev/null 2>&1 || NEED_INSTALL+=("lzip")
command -v wine64 >/dev/null 2>&1 || NEED_INSTALL+=("wine")
command -v winetricks >/dev/null 2>&1 || NEED_INSTALL+=("winetricks")
command -v patchelf >/dev/null 2>&1 || NEED_INSTALL+=("patchelf")
command -v resize2fs >/dev/null 2>&1 || NEED_INSTALL+=("e2fsprogs")
command -v pip >/dev/null 2>&1 || NEED_INSTALL+=("python3-pip")
command -v aria2c >/dev/null 2>&1 || NEED_INSTALL+=("aria2")
}
check_dependencies
declare -A os_pm_install;
# os_pm_install["/etc/redhat-release"]=yum
# os_pm_install["/etc/arch-release"]=pacman
# os_pm_install["/etc/gentoo-release"]=emerge
# os_pm_install["/etc/SuSE-release"]=zypp
os_pm_install["/etc/debian_version"]=apt-get
# os_pm_install["/etc/alpine-release"]=apk
declare -A PM_UPDATE_MAP;
PM_UPDATE_MAP["yum"]="check-update"
PM_UPDATE_MAP["pacman"]="-Syu --noconfirm"
PM_UPDATE_MAP["emerge"]="-auDN @world"
PM_UPDATE_MAP["zypp"]="update -y"
PM_UPDATE_MAP["apt-get"]="update"
PM_UPDATE_MAP["apk"]="update"
declare -A PM_INSTALL_MAP;
PM_INSTALL_MAP["yum"]="install -y"
PM_INSTALL_MAP["pacman"]="-S --noconfirm --needed"
PM_INSTALL_MAP["emerge"]="-a"
PM_INSTALL_MAP["zypp"]="install -y"
PM_INSTALL_MAP["apt-get"]="install -y"
PM_INSTALL_MAP["apk"]="add"
check_package_manager() {
for f in "${!os_pm_install[@]}"; do
if [[ -f $f ]]; then
PM="${os_pm_install[$f]}"
readarray -td ' ' UPDATE_OPTION <<<"${PM_UPDATE_MAP[$PM]} "; unset 'UPDATE_OPTION[-1]';
readarray -td ' ' INSTALL_OPTION <<<"${PM_INSTALL_MAP[$PM]} "; unset 'INSTALL_OPTION[-1]';
break
fi
done
}
check_package_manager
if [ -n "${NEED_INSTALL[*]}" ]; then
if [ -z "$PM" ]; then
echo "Unable to determine package manager: unknown distribution"
exit 1
else
if ! sudo "$PM" "${UPDATE_OPTION[@]}" && sudo "$PM" "${INSTALL_OPTION[@]}" "${NEED_INSTALL[@]}"; then abort; fi
fi
fi
pip list --disable-pip-version-check | grep -E "^requests " >/dev/null 2>&1 || python3 -m pip install requests
winetricks list-installed | grep -E "^msxml6" >/dev/null 2>&1 || {
cp -r ../wine/.cache/* ~/.cache
winetricks -q msxml6 || abort
}
function Radiolist { function Radiolist {
declare -A o="$1" declare -A o="$1"
shift shift
@ -48,12 +112,6 @@ function YesNoBox {
whiptail --title "${o[title]}" --yesno "${o[text]}" 0 0 whiptail --title "${o[title]}" --yesno "${o[text]}" 0 0
} }
echo "Dependencies"
sudo apt update && sudo apt -y install setools lzip wine winetricks patchelf whiptail e2fsprogs python3-pip aria2
python3 -m pip install requests
cp -r ../wine/.cache/* ~/.cache
winetricks msxml6 || abort
ARCH=$( ARCH=$(
Radiolist '([title]="Build arch" Radiolist '([title]="Build arch"
[default]="x64")' \ [default]="x64")' \