Dependencies based on OS id

This commit is contained in:
Katy248 2024-10-28 15:34:54 +03:00
parent 087a0085b7
commit 082221133b

View File

@ -90,63 +90,51 @@ ask_user() {
*)
echo "Invalid input, try again"
;;
esac
done
}
# Imagemagick is needed in case you are not using Papirus Icons.
# One of the functions will load a Photoshop `.webp` icon and convert it to `.png`. The `.png` file will be used in the `.desktop` entry.
check_deps() {
declare -A packages=(
["curl"]="curl"
["wine"]="wine"
["winetricks"]="winetricks"
["magick"]="imagemagick"
)
missed_packages=()
for bin in "${!packages[@]}"; do
if ! command -v "$bin" > /dev/null; then
missed_packages+=("${packages[$bin]}")
OS_ID=$(source /etc/os-release && echo "${ID}")
if ! ask_user "Script will use '${_bold}${RED}sudo${RESET}'. Proceed?"; then
echo -e "$LOG Exiting."
exit 1
fi
done
DEPENDENCIES=()
if [ ${#missed_packages[@]} -eq 0 ]; then
echo -e "$CHECK All dependencies are installed."
else
echo -e "$WARNING Missing dependencies: ${YELLOW}${missed_packages[*]}${RESET}."
return 1
fi
}
case "${OS_ID}" in
"arch")
DEPENDENCIES=(curl wine winetricks imagemagick)
;;
"redos")
winetricks_opensuse="https://ftp.lysator.liu.se/pub/opensuse/distribution/leap/15.6/repo/oss/x86_64/winetricks-20240105-bp156.1.1.x86_64.rpm"
DEPENDENCIES=(curl wine ImageMagick zstd "${winetricks_opensuse}")
;;
*)
echo -e "$ERROR For now only ${BLUE}Arch Linux${RESET} is supported."
exit 1
;;
esac
install_deps() {
if [ ! -f /etc/os-release ]; then
echo -e "$WARNING Cannot find '${YELLOW}/etc/os-release${RESET}'."
exit 1
fi
source /etc/os-release
_bold=$(tput bold)
# Refer to /etc/os-release for more info
case "$ID" in
case "${OS_ID}" in
"arch")
# To display the list of packages correctly, we need to format the string.
# Otherwise `read` will not display the whole list of packages and will stop in the middle of the line.
missing_packages_str=$(printf "%s " "${missed_packages[@]}")
# Here we can do without it, but in that case there will be an annoying space before the period at the end of the package listing.
missing_packages_str=${missing_packages_str% }
if ask_user "Script will execute: '${RED}sudo ${BLUE}pacman -S ${YELLOW}${missing_packages_str}${RESET}'. Proceed?"; then
echo -e "$LOG Installing missing dependencies"
if ! sudo pacman -S "${missed_packages[@]}"; then
if ! ask_user "Script will use '${_bold}${RED}sudo${RESET}'. Proceed?"; then
echo -e "$LOG Exiting."
exit 1
fi
if ! sudo pacman -S "${DEPENDENCIES[@]}"; then
echo -e "$ERROR Pacman terminated with an error."
exit 1
else
echo -e "$LOG Missing dependencies was installed"
fi
else
echo -e "$LOG Exiting."
;;
"redos")
if ! pkexec dnf install "${DEPENDENCIES[@]}" -y --comment "Installed via 'photoshop-linux' script" ;then
echo -e "${ERROR} ${_bold}DNF${RESET} terminated with an error." >&2
exit 1
fi
;;
@ -155,6 +143,7 @@ install_deps() {
exit 1
;;
esac
echo -e "$LOG Missing dependencies was installed"
}
# MAIN SCRIPT
@ -436,9 +425,7 @@ install_launcher() {
}
main() {
if ! check_deps; then
install_deps
fi
verify_path "$INSTALL_PATH"
is_path_exists "$INSTALL_PATH"
@ -477,6 +464,7 @@ while getopts "a:i:h" flag; do
\?)
echo "Invalid option: -$OPTARG Use -h for help."
exit 1
;;
esac
done