Added separate desktop file

This commit is contained in:
Katy248 2024-10-16 12:14:23 +03:00
parent ef30a7c461
commit 425a05ce46
2 changed files with 160 additions and 151 deletions

View File

@ -17,14 +17,14 @@
XDG_DATA_HOME="$HOME/.local/share" XDG_DATA_HOME="$HOME/.local/share"
# LOGGING SYSTEM # LOGGING SYSTEM
# ##################################################################### # #####################################################################
# #
BLUE="\e[1;34m" # Blue BLUE="\e[1;34m" # Blue
RED="\e[1;31m" # Red RED="\e[1;31m" # Red
YELLOW="\e[1;33m" # Yellow YELLOW="\e[1;33m" # Yellow
GREEN="\e[1;32m" # Green GREEN="\e[1;32m" # Green
RESET="\e[0m" # Reset colors RESET="\e[0m" # Reset colors
LOG="${BLUE}[LOG]${RESET}" LOG="${BLUE}[LOG]${RESET}"
WARNING="${YELLOW}[WARNING]${RESET}" WARNING="${YELLOW}[WARNING]${RESET}"
@ -33,7 +33,7 @@ SUCCES="${GREEN}[SUCCES]${RESET}"
CHECK="${GREEN}[CHECK]${RESET}" CHECK="${GREEN}[CHECK]${RESET}"
# CHECKS & OTHER FUNCTIONS # CHECKS & OTHER FUNCTIONS
# ################################################################### # ###################################################################
# #
# Photoshop URL # Photoshop URL
@ -58,19 +58,20 @@ on_interrupt() {
read -p "$(echo -e "$YELLOW")[WARNING]$(echo -e "$RESET") Do you want to $(echo -e "$RED")delete$(echo -e "$RESET") the just created wine prefix? (yes/no): " answer read -p "$(echo -e "$YELLOW")[WARNING]$(echo -e "$RESET") Do you want to $(echo -e "$RED")delete$(echo -e "$RESET") the just created wine prefix? (yes/no): " answer
case "$answer" in case "$answer" in
[Yy]es|y) [Yy]es | y)
if rm -rf "${INSTALL_PATH:?}"; then if rm -rf "${INSTALL_PATH:?}"; then
exit 0
else
echo -e "$ERORR The last command ended with an error."
exit 1
fi
;;
[Nn]o|n)
exit 0 exit 0
;; else
*) echo -e "$ERORR The last command ended with an error."
echo -e "$WARNING Invalid input!" exit 1
fi
;;
[Nn]o | n)
exit 0
;;
*)
echo -e "$WARNING Invalid input!"
;;
esac esac
done done
else else
@ -90,97 +91,105 @@ print_error() {
command ... command ...
} }
print_warn() {
local message=$1
echo "${WARNING} ${message}" >&2
}
# Not used yet # Not used yet
ask_user() { ask_user() {
local message=$1
echo -e "${WARNING} ${message}"
while true; do while true; do
read -p "$(echo -e "${WARNING} "$@" (yes/no) : ")" answer read -p "([Y]es/[N]o): " answer
case "$answer" in case "$answer" in
[Yy]es|[Yy]) [Yy]es | [Yy])
return 0 return 0
;; ;;
[Nn]o|[Nn]) [Nn]o | [Nn])
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. # 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. # 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() { check_deps() {
declare -A packages=( declare -A packages=(
["curl"]="curl" ["curl"]="curl"
["wine"]="wine" ["wine"]="wine"
["winetricks"]="winetricks" ["winetricks"]="winetricks"
["magick"]="imagemagick" ["magick"]="imagemagick"
) )
missed_packages=() missed_packages=()
for bin in "${!packages[@]}"; do for bin in "${!packages[@]}"; do
if ! command -v "$bin" > /dev/null; then if ! command -v "$bin" >/dev/null; then
missed_packages+=("${packages[$bin]}") missed_packages+=("${packages[$bin]}")
fi fi
done done
if [ ${#missed_packages[@]} -eq 0 ]; then if [ ${#missed_packages[@]} -eq 0 ]; then
echo -e "$CHECK All dependencies are installed." echo -e "$CHECK All dependencies are installed."
else else
echo -e "$WARNING Missing dependencies: ${YELLOW}${missed_packages[*]}${RESET}." echo -e "$WARNING Missing dependencies: ${YELLOW}${missed_packages[*]}${RESET}."
return 1 return 1
fi fi
} }
install_deps() { install_deps() {
local os="$(uname -n)" local os="$(uname -n)"
case "$os" in case "$os" in
"archlinux") "archlinux")
# To display the list of packages correctly, we need to format the string. # 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. # 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[@]}") 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. # 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% } missing_packages_str=${missing_packages_str% }
while true; do while true; do
# Yeah yeah, I know it's unreadable. # Yeah yeah, I know it's unreadable.
# But it's beautiful! # But it's beautiful!
read -p "$(echo -e "$YELLOW")[WARNING]$(echo -e "$RESET") Script will execute: '$(echo -e "$RED")sudo$(echo -e "$RED") $(echo -e "$BLUE")pacman -S $(echo -e "$YELLOW")${missing_packages_str}$(echo -e "$RESET")'. Proceed? (yes/no): " answer read -p "$(echo -e "$YELLOW")[WARNING]$(echo -e "$RESET") Script will execute: '$(echo -e "$RED")sudo$(echo -e "$RED") $(echo -e "$BLUE")pacman -S $(echo -e "$YELLOW")${missing_packages_str}$(echo -e "$RESET")'. Proceed? (yes/no): " answer
case "$answer" in case "$answer" in
[Yy]es|y) [Yy]es | y)
echo -e "$LOG Installing missing dependencies" echo -e "$LOG Installing missing dependencies"
if ! sudo pacman -S "${missed_packages[@]}"; then 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
fi fi
echo -e "$LOG Missing dependencies was installed" echo -e "$LOG Missing dependencies was installed"
break break
;; ;;
[Nn]o|n) [Nn]o | n)
echo -e "$LOG Exiting" echo -e "$LOG Exiting"
exit 1 exit 1
;; ;;
*) *)
echo -e "$WARNING Invalid input!" echo -e "$WARNING Invalid input!"
;; ;;
esac esac
done done
;; ;;
*) *)
echo -e "$ERROR For now only ${BLUE}Arch Linux${RESET} is supported." echo -e "$ERROR For now only ${BLUE}Arch Linux${RESET} is supported."
exit 1 exit 1
;; ;;
esac esac
} }
# MAIN SCRIPT # MAIN SCRIPT
# ################################################################### # ###################################################################
# #
is_path_exists() { is_path_exists() {
@ -188,27 +197,27 @@ is_path_exists() {
# BUG # BUG
# echo -e "$WARNING The specified path '$1' already exists." # echo -e "$WARNING The specified path '$1' already exists."
echo -e "$WARNING The specified path already exists." echo -e "$WARNING The specified path already exists."
while true; do while true; do
read -p "$(echo -e "$YELLOW")[WARNING]$(echo -e "$RESET") Do you want to $(echo -e "$RED")delete$(echo -e "$RESET") previous installation? (yes/no): " answer read -p "$(echo -e "$YELLOW")[WARNING]$(echo -e "$RESET") Do you want to $(echo -e "$RED")delete$(echo -e "$RESET") previous installation? (yes/no): " answer
case "$answer" in case "$answer" in
[Yy]es|y) [Yy]es | y)
if rm -rf "${1:?}"; then if rm -rf "${1:?}"; then
echo -e "$LOG Deleted old installation." echo -e "$LOG Deleted old installation."
break break
else else
echo -e "$ERROR Something went wrong." echo -e "$ERROR Something went wrong."
exit 1
fi
;;
[Nn]o|n)
echo -e "$LOG Exiting."
exit 1 exit 1
;; fi
*) ;;
echo -e "$WARNING Invalid input!" [Nn]o | n)
;; echo -e "$LOG Exiting."
exit 1
;;
*)
echo -e "$WARNING Invalid input!"
;;
esac esac
done done
fi fi
@ -219,24 +228,24 @@ 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_NORMAL}[LOG]${LOG_RESET} Executing winetricks. All winetricks logs are saved in ${LOG_WARNING}./winetricks.log${LOG_RESET}." # echo -e "${LOG_NORMAL}[LOG]${LOG_RESET} Executing winetricks. All winetricks logs are saved in ${LOG_WARNING}./winetricks.log${LOG_RESET}."
echo -e "$LOG Executing winetricks." echo -e "$LOG Executing winetricks."
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
fi fi
echo "---------------------------------------------------------------------" >> ./install_log.log echo "---------------------------------------------------------------------" >>./install_log.log
echo " Downloading Visual C++ Libraries " >> ./install_log.log echo " Downloading Visual C++ Libraries " >>./install_log.log
echo "---------------------------------------------------------------------" >> ./install_log.log echo "---------------------------------------------------------------------" >>./install_log.log
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 "${LOG_ERROR}[ERROR]${LOG_RESET} Please open an issue by mentioning the contents of ${LOG_WARNING}./install_log.log${LOG_RESET}." # echo -e "${LOG_ERROR}[ERROR]${LOG_RESET} Please open an issue by mentioning the contents of ${LOG_WARNING}./install_log.log${LOG_RESET}."
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."
@ -258,21 +267,21 @@ 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
fi fi
# echo -e "${LOG_NORMAL}[LOG]${LOG_RESET} Downloading Photoshop (1.1G). Using ${LOG_WARNING}curl${LOG_RESET} as backend. Logs are available in ${LOG_WARNING}./curl.log${LOG_RESET}." # echo -e "${LOG_NORMAL}[LOG]${LOG_RESET} Downloading Photoshop (1.1G). Using ${LOG_WARNING}curl${LOG_RESET} as backend. Logs are available in ${LOG_WARNING}./curl.log${LOG_RESET}."
echo -e "$LOG Downloading Photoshop (1.1G)." echo -e "$LOG Downloading Photoshop (1.1G)."
if ! curl "$PHOTOSHOP_URL" -o "$archive_name" &>> ./install_log.log; then if ! curl "$PHOTOSHOP_URL" -o "$archive_name" &>>./install_log.log; then
# TODO: # TODO:
# separate function to avoid repeating # separate function to avoid repeating
echo -e "$ERROR An error occurred during the download. Please, refer to ${YELLOW}install_log.log${RESET} for more info." echo -e "$ERROR An error occurred during the download. 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
fi fi
echo -e "$LOG Photoshop Downloaded." echo -e "$LOG Photoshop Downloaded."
# TODO: # TODO:
@ -337,10 +346,10 @@ 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:
# A separate function so you don't have to write this code multiple times # A separate function so you don't have to write this code multiple times
# while true; do # while true; do
# read -p "Delete wine prefix?" # read -p "Delete wine prefix?"
@ -377,10 +386,10 @@ 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:
# A separate function so you don't have to write this code multiple times # A separate function so you don't have to write this code multiple times
# while true; do # while true; do
# read -p "Delete wine prefix?" # read -p "Delete wine prefix?"
@ -395,16 +404,16 @@ install_photoshop() {
exit 1 exit 1
fi fi
fi fi
} }
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
@ -414,11 +423,11 @@ 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
magick "icon.webp" "icon.png" magick "icon.webp" "icon.png"
rm "./icon.webp" rm "./icon.webp"
@ -426,26 +435,17 @@ install_icon() {
mv "./icon.png" "$XDG_DATA_HOME/icons/photoshop.png" mv "./icon.png" "$XDG_DATA_HOME/icons/photoshop.png"
ICON="$XDG_DATA_HOME/icons/photoshop.png" ICON="$XDG_DATA_HOME/icons/photoshop.png"
fi fi
echo "Icon=${ICON}" >>./photoshop.desktop
} }
install_desktop_entry() { install_desktop_entry() {
if [ ! -d "$XDG_DATA_HOME/applications" ]; then mkdir "$XDG_DATA_HOME/applications" -p
mkdir "$XDG_DATA_HOME/applications"
fi
local path="$XDG_DATA_HOME/applications/photoshop.desktop" local path="$XDG_DATA_HOME/applications/photoshop.desktop"
echo -e "$LOG Genarating application menu item" echo -e "$LOG Genarating application menu item"
echo "[Desktop Entry]" > "$path" cp ./photoshop.desktop "${path}"
echo "Name=Adobe Photoshop CC 2021" >> "$path"
echo "Exec=bash -c "$HOME/.local/bin/photoshop.sh %F"" >> "$path"
echo "Type=Application" >> "$path"
echo "Comment=The industry-standard photo editing software (Wine" >> "$path"
echo "Categories=Graphics" >> "$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 "StartupWMClass=photoshop.exe" >> "$path"
} }
install_launcher() { install_launcher() {
@ -455,16 +455,16 @@ install_launcher() {
fi fi
echo -e "$LOG Installing launcher." echo -e "$LOG Installing launcher."
{
echo "#!/usr/bin/env bash" > "$LAUNCHER" echo "#!/usr/bin/env bash"
echo " " >> "$LAUNCHER" echo " "
echo "WINEPREFIX=\"$WINEPREFIX\"" >> "$LAUNCHER" echo "WINEPREFIX=\"$WINEPREFIX\""
echo "DXVK_LOG_PATH=\"\$WINEPREFIX/dxvk_cache\"" >> "$LAUNCHER" echo "DXVK_LOG_PATH=\"\$WINEPREFIX/dxvk_cache\""
echo "DXVK_STATE_CACHE_PATH=\"\$WINEPREFIX/dxvk_cache\"" >> "$LAUNCHER" echo "DXVK_STATE_CACHE_PATH=\"\$WINEPREFIX/dxvk_cache\""
echo "PHOTOSHOP=\"\$WINEPREFIX/drive_c/Program Files/Adobe Photoshop 2021/photoshop.exe\"" >> "$LAUNCHER" echo "PHOTOSHOP=\"\$WINEPREFIX/drive_c/Program Files/Adobe Photoshop 2021/photoshop.exe\""
echo " " >> "$LAUNCHER" echo " "
echo "wine64 \"\$PHOTOSHOP\" \"\$@\" " >> "$LAUNCHER" echo "wine64 \"\$PHOTOSHOP\" \"\$@\" "
} >"${LAUNCHER}"
chmod +x "$LAUNCHER" chmod +x "$LAUNCHER"
} }
@ -473,13 +473,13 @@ main() {
install_deps install_deps
fi fi
verify_path "$INSTALL_PATH" verify_path "$INSTALL_PATH"
is_path_exists "$INSTALL_PATH" is_path_exists "$INSTALL_PATH"
setup_wine setup_wine
if [ -z "$LOCAL_ARCHIVE" ]; then if [ -z "$LOCAL_ARCHIVE" ]; then
download_photoshop download_photoshop
install_photoshop install_photoshop
else else
install_photoshop install_photoshop
fi fi
@ -492,25 +492,26 @@ main() {
} }
if [[ $# -eq 0 ]]; then if [[ $# -eq 0 ]]; then
get_help get_help
exit 0 exit 0
fi fi
while getopts "a:i:h" flag; do while getopts "a:i:h" flag; do
case $flag in case $flag in
a) a)
LOCAL_ARCHIVE="$OPTARG" LOCAL_ARCHIVE="$OPTARG"
;; ;;
h) h)
get_help get_help
;; ;;
i) i)
INSTALL_PATH="$OPTARG" INSTALL_PATH="$OPTARG"
;; ;;
\?) \?)
echo "Invalid option: -$OPTARG Use -h for help." echo "Invalid option: -$OPTARG Use -h for help."
exit 1 exit 1
esac ;;
esac
done done
main main

8
photoshop.desktop Normal file
View File

@ -0,0 +1,8 @@
[Desktop Entry]
Name=Photoshop
Type=Application
Terminal=false
Comment=The industry-standard photo editing software (Wine)
Categories=Graphics
MimeType=image/psd;image/x-psd;image/png;image/jpg;image/jpeg;image/webp;image/heif;image/raw
StartupWMClass=photoshop.exe