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

@ -54,7 +54,7 @@ on_interrupt() {
if [ -d "$INSTALL_PATH" ]; then if [ -d "$INSTALL_PATH" ]; then
if ask_user "Do you want to ${RED}delete${RESET} a newly created folder?"; then if ask_user "Do you want to ${RED}delete${RESET} a newly created folder?"; then
if rm -rfv "${INSTALL_PATH:?}" 2>> ./install_log.log; then if rm -rfv "${INSTALL_PATH:?}" 2>>./install_log.log; then
exit 0 exit 0
else else
echo -e "$ERORR The last command ended with an error." echo -e "$ERORR The last command ended with an error."
@ -81,72 +81,60 @@ ask_user() {
read -r -p "$(echo -e "${WARNING} $* (yes/no): ")" answer read -r -p "$(echo -e "${WARNING} $* (yes/no): ")" answer
case "$answer" in case "$answer" in
[yY]|[yY][eE][sS]) [yY] | [yY][eE][sS])
return 0 return 0
;; ;;
[nN]|[nN][oO]) [nN] | [nN][oO])
return 1 return 1
;; ;;
*) *)
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
@ -168,7 +157,7 @@ is_path_exists() {
echo -e "$WARNING The specified path '${YELLOW}${1}${RESET}' already exists." echo -e "$WARNING The specified path '${YELLOW}${1}${RESET}' already exists."
if ask_user "Do you want to ${RED}delete${RESET} previous installation?"; then if ask_user "Do you want to ${RED}delete${RESET} previous installation?"; then
if rm -rfv "${1:?}" 2>> ./install_log.log; then if rm -rfv "${1:?}" 2>>./install_log.log; then
echo -e "$LOG Deleted old installation." echo -e "$LOG Deleted old installation."
else else
echo -e "$ERROR Something went wrong." echo -e "$ERROR Something went wrong."
@ -186,11 +175,11 @@ setup_wine() {
local vc_libraries=("vcrun2003" "vcrun2005" "vcrun2010" "vcrun2012" "vcrun2013" "vcrun2022") local vc_libraries=("vcrun2003" "vcrun2005" "vcrun2010" "vcrun2012" "vcrun2013" "vcrun2022")
echo -e "$LOG Setting up wine prefix." echo -e "$LOG Setting up wine prefix."
winecfg /v win10 2> /dev/null winecfg /v win10 2>/dev/null
echo -e "$LOG Downloading and installing core components for wine prefix. This could take some time." echo -e "$LOG Downloading and installing core components for wine prefix. This could take some time."
if ! winetricks --unattended corefonts win10 vkd3d dxvk2030 msxml3 msxml6 gdiplus &> ./install_log.log; then if ! winetricks --unattended corefonts win10 vkd3d dxvk2030 msxml3 msxml6 gdiplus &>./install_log.log; then
echo -e "$ERORR Winetricks terminated with an error." echo -e "$ERORR Winetricks terminated with an error."
echo -e "$ERROR Please open an issue by mentioning the contents of ${YELLOW}./install_log.log${RESET}." echo -e "$ERROR Please open an issue by mentioning the contents of ${YELLOW}./install_log.log${RESET}."
exit 1 exit 1
@ -200,10 +189,10 @@ setup_wine() {
echo "---------------------------------------------------------------------" echo "---------------------------------------------------------------------"
echo " Downloading Visual C++ Libraries " echo " Downloading Visual C++ Libraries "
echo "---------------------------------------------------------------------" echo "---------------------------------------------------------------------"
} >> ./install_log.log # Thanks to Katy248 for the idea. } >>./install_log.log # Thanks to Katy248 for the idea.
echo -e "$LOG Downloading and installing Visual C++ libraries." echo -e "$LOG Downloading and installing Visual C++ libraries."
if ! winetricks --unattended "${vc_libraries[@]}" &>> ./install_log.log; then if ! winetricks --unattended "${vc_libraries[@]}" &>>./install_log.log; then
echo -e "$ERROR Winetricks terminated with an error. Please, refer to ${YELLOW}install_log.log${RESET} for more info." echo -e "$ERROR Winetricks terminated with an error. Please, refer to ${YELLOW}install_log.log${RESET} for more info."
echo -e "$ERROR If you can't solve the issue yourself, please, open an issue on the GitHub." echo -e "$ERROR If you can't solve the issue yourself, please, open an issue on the GitHub."
exit 1 exit 1
@ -224,7 +213,7 @@ download_photoshop() {
if [[ "$CHECKSUM" != "$local_checksum" ]]; then if [[ "$CHECKSUM" != "$local_checksum" ]]; then
echo -e "$LOG Checksums don't match!" echo -e "$LOG Checksums don't match!"
echo -e "$LOG Deleting corrupted archive." echo -e "$LOG Deleting corrupted archive."
rm -v "${archive_name:?}" &>> ./install_log.log rm -v "${archive_name:?}" &>>./install_log.log
fi fi
return 0 return 0
@ -302,7 +291,7 @@ install_photoshop() {
local filename="Photoshop.tar.xz" local filename="Photoshop.tar.xz"
echo -e "$LOG Extracting Photoshop." echo -e "$LOG Extracting Photoshop."
if ! tar xvf "$filename" &>> ./install_log.log; then if ! tar xvf "$filename" &>>./install_log.log; then
echo -e "$ERORR An error occurred while unpacking the archive." echo -e "$ERORR An error occurred while unpacking the archive."
exit 1 exit 1
# TODO: # TODO:
@ -343,7 +332,7 @@ install_photoshop() {
fi fi
echo -e "$LOG Extracting Photoshop." echo -e "$LOG Extracting Photoshop."
if ! tar xvf "$LOCAL_ARCHIVE" &>> ./install_log.log; then if ! tar xvf "$LOCAL_ARCHIVE" &>>./install_log.log; then
echo -e "$ERROR An error occurred while unpacking the archive." echo -e "$ERROR An error occurred while unpacking the archive."
exit 1 exit 1
# TODO: # TODO:
@ -366,11 +355,11 @@ install_photoshop() {
install_icon() { install_icon() {
# Papirus Icon Theme already has a Photoshop icon in it. # Papirus Icon Theme already has a Photoshop icon in it.
# The script will check if you have Papirus installed and use its icon. If Papirus is not installed, the script will download the icon from the Internet and use it. # The script will check if you have Papirus installed and use its icon. If Papirus is not installed, the script will download the icon from the Internet and use it.
if find /usr/share/icons -name "Papirus*" &> /dev/null; then if find /usr/share/icons -name "Papirus*" &>/dev/null; then
ICON="photoshop" ICON="photoshop"
else else
if [ -d "$XDG_DATA_HOME/icons" ]; then if [ -d "$XDG_DATA_HOME/icons" ]; then
if find "$XDG_DATA_HOME/icons" -name "Papirus*" &> /dev/null; then if find "$XDG_DATA_HOME/icons" -name "Papirus*" &>/dev/null; then
ICON="photoshop" ICON="photoshop"
fi fi
else else
@ -380,7 +369,7 @@ install_icon() {
if [ -z "$ICON" ]; then if [ -z "$ICON" ]; then
local icon_url="https://cdn3d.iconscout.com/3d/premium/thumb/adobe-photoshop-file-3d-icon-download-in-png-blend-fbx-gltf-formats--logo-format-graphic-design-pack-development-icons-9831950.png" local icon_url="https://cdn3d.iconscout.com/3d/premium/thumb/adobe-photoshop-file-3d-icon-download-in-png-blend-fbx-gltf-formats--logo-format-graphic-design-pack-development-icons-9831950.png"
if ! curl "$icon_url" -o "icon.webp" &>> ./install_log.log; then if ! curl "$icon_url" -o "icon.webp" &>>./install_log.log; then
echo -e "$ERROR Failed to download icon. Please refer ${YELLOW}install_log.log${RESET} for info." echo -e "$ERROR Failed to download icon. Please refer ${YELLOW}install_log.log${RESET} for info."
exit 1 exit 1
fi fi
@ -403,15 +392,15 @@ install_desktop_entry() {
echo -e "$LOG Genarating application menu item." echo -e "$LOG Genarating application menu item."
echo "[Desktop Entry]" > "$path" echo "[Desktop Entry]" >"$path"
echo "Name=Adobe Photoshop CC 2021" >> "$path" echo "Name=Adobe Photoshop CC 2021" >>"$path"
echo "Exec=bash -c "$HOME/.local/bin/photoshop/photoshop.sh %F"" >> "$path" echo "Exec=bash -c "$HOME/.local/bin/photoshop/photoshop.sh %F"" >>"$path"
echo "Type=Application" >> "$path" echo "Type=Application" >>"$path"
echo "Comment=The industry-standard photo editing software (Wine" >> "$path" echo "Comment=The industry-standard photo editing software (Wine" >>"$path"
echo "Categories=Graphics" >> "$path" echo "Categories=Graphics" >>"$path"
echo "Icon=$ICON" >> "$path" echo "Icon=$ICON" >>"$path"
echo "MimeType=image/psd;image/x-psd;image/png;image/jpg;image/jpeg;image/webp;image/heif;image/raw" >> "$path" echo "MimeType=image/psd;image/x-psd;image/png;image/jpg;image/jpeg;image/webp;image/heif;image/raw" >>"$path"
echo "StartupWMClass=photoshop.exe" >> "$path" echo "StartupWMClass=photoshop.exe" >>"$path"
} }
install_launcher() { install_launcher() {
@ -430,15 +419,13 @@ install_launcher() {
echo "" echo ""
echo "echo -e \"All logs are saved in \$LOG_FILE\"" echo "echo -e \"All logs are saved in \$LOG_FILE\""
echo "wine64 \"\$PHOTOSHOP\" \"\$@\" &> \"\$LOG_FILE\" " echo "wine64 \"\$PHOTOSHOP\" \"\$@\" &> \"\$LOG_FILE\" "
} > "$LAUNCHER" } >"$LAUNCHER"
chmod +x "$LAUNCHER" chmod +x "$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