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" echo "Invalid input, try again"
;;
esac esac
done done
} }
# Imagemagick is needed in case you are not using Papirus Icons. OS_ID=$(source /etc/os-release && echo "${ID}")
# 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. if ! ask_user "Script will use '${_bold}${RED}sudo${RESET}'. Proceed?"; then
check_deps() { echo -e "$LOG Exiting."
declare -A packages=( exit 1
["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]}")
fi fi
done DEPENDENCIES=()
if [ ${#missed_packages[@]} -eq 0 ]; then case "${OS_ID}" in
echo -e "$CHECK All dependencies are installed." "arch")
else DEPENDENCIES=(curl wine winetricks imagemagick)
echo -e "$WARNING Missing dependencies: ${YELLOW}${missed_packages[*]}${RESET}." ;;
return 1 "redos")
fi 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() { 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 # Refer to /etc/os-release for more info
case "$ID" in case "${OS_ID}" in
"arch") "arch")
# To display the list of packages correctly, we need to format the string. if ! ask_user "Script will use '${_bold}${RED}sudo${RESET}'. Proceed?"; then
# Otherwise `read` will not display the whole list of packages and will stop in the middle of the line. echo -e "$LOG Exiting."
missing_packages_str=$(printf "%s " "${missed_packages[@]}") exit 1
# 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. fi
missing_packages_str=${missing_packages_str% } if ! sudo pacman -S "${DEPENDENCIES[@]}"; then
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
echo -e "$ERROR Pacman terminated with an error." echo -e "$ERROR Pacman terminated with an error."
exit 1 exit 1
else
echo -e "$LOG Missing dependencies was installed"
fi 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 exit 1
fi fi
;; ;;
@ -155,6 +143,7 @@ install_deps() {
exit 1 exit 1
;; ;;
esac esac
echo -e "$LOG Missing dependencies was installed"
} }
# MAIN SCRIPT # MAIN SCRIPT
@ -436,9 +425,7 @@ install_launcher() {
} }
main() { main() {
if ! check_deps; then
install_deps install_deps
fi
verify_path "$INSTALL_PATH" verify_path "$INSTALL_PATH"
is_path_exists "$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." echo "Invalid option: -$OPTARG Use -h for help."
exit 1 exit 1
;;
esac esac
done done