From 3ff46a558d5b38c23c57eb0cd262ee3d0ded8bc5 Mon Sep 17 00:00:00 2001 From: jetfir3 <95306468+jetfir3@users.noreply.github.com> Date: Mon, 24 Oct 2022 13:07:23 -0400 Subject: [PATCH] Add path flag support - add `-P` flag to manually set Spotify path - add support for enabling write permissions in Spotify directory if write permissions are not found (thanks to @dabiathenord for the heads up) - update readme for path flag and to note that Snap installs are not supported --- README.md | 2 ++ install.sh | 62 +++++++++++++++++++++++++++++------------------------- 2 files changed, 35 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index ad5acac..828a98a 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ ### Installation/Update: +NOTE: SpotX does not support the Spotify client from Snap - Close Spotify completely. - Run The following command in Terminal: @@ -37,6 +38,7 @@ bash <(curl -sSL https://raw.githubusercontent.com/SpotX-CLI/SpotX-Linux/main/in `-c` Clear app cache -- use if UI-related patches aren't working `-e` Experimental features -- enables experimental features `-f` Force patch -- forces re-patching if backup detected +`-P` Path directory -- manually set Spotify directory if not found in PATH `-p` Premium subscription setup -- use if premium subscriber Use any combination of flags. diff --git a/install.sh b/install.sh index d87aa35..85aff56 100644 --- a/install.sh +++ b/install.sh @@ -5,9 +5,32 @@ command -v perl >/dev/null || { echo -e "\nperl was not found, exiting...\n" >&2 command -v unzip >/dev/null || { echo -e "\nunzip was not found, exiting...\n" >&2; exit 1; } command -v zip >/dev/null || { echo -e "\nzip was not found, exiting...\n" >&2; exit 1; } -# Inital paths and filenames +# Script flags +CACHE_FLAG='false' +EXPERIMENTAL_FLAG='false' +FORCE_FLAG='false' +PATH_FLAG='' +PREMIUM_FLAG='false' + +while getopts 'cefP:p' flag; do + case "${flag}" in + c) CACHE_FLAG='true' ;; + e) EXPERIMENTAL_FLAG='true' ;; + f) FORCE_FLAG='true' ;; + P) + PATH_FLAG="${OPTARG}" + INSTALL_PATH="${PATH_FLAG}" ;; + p) PREMIUM_FLAG='true' ;; + *) + echo "Error: ${flag} not supported." + exit ;; + esac +done + +# path vars +if [ -z ${INSTALL_PATH+x} ]; then + INSTALL_PATH=$(readlink -e `type -p spotify` 2>/dev/null | rev | cut -d/ -f2- | rev); fi CACHE_PATH="${HOME}/.cache/spotify/" -INSTALL_PATH=$(readlink -e `type -p spotify` | rev | cut -d/ -f2- | rev) XPUI_PATH="${INSTALL_PATH}/Apps" XPUI_DIR="${XPUI_PATH}/xpui" XPUI_BAK="${XPUI_PATH}/xpui.bak" @@ -17,33 +40,6 @@ XPUI_CSS="${XPUI_DIR}/xpui.css" HOME_V2_JS="${XPUI_DIR}/home-v2.js" VENDOR_XPUI_JS="${XPUI_DIR}/vendor~xpui.js" -# Detect client in PATH -if [[ ! -d "${INSTALL_PATH}" ]]; then - echo -e "\nSpotify not found in PATH. Exiting...\n" - exit; fi - -# Script flags -CACHE_FLAG='false' -EXPERIMENTAL_FLAG='false' -FORCE_FLAG='false' -PREMIUM_FLAG='false' - -while getopts 'cefp' flag; do - case "${flag}" in - c) - CACHE_FLAG='true' ;; - e) - EXPERIMENTAL_FLAG='true' ;; - f) - FORCE_FLAG='true' ;; - p) - PREMIUM_FLAG='true' ;; - *) - echo "Error: Flag not supported." - exit ;; - esac -done - # Perl command PERL="perl -pi -w -e" @@ -98,11 +94,19 @@ echo "SpotX-Linux by @SpotX-CLI" echo "**************************" echo +# Detect client in PATH +if [[ ! -d "${INSTALL_PATH}" ]]; then + echo -e "\nSpotify path not found.\nSet directory path with -P flag.\nExiting...\n" + exit; fi + # xpui detection if [[ ! -f "${XPUI_SPA}" ]]; then echo - e "\nxpui not found!\nReinstall Spotify then try again.\nExiting...\n" exit else + if [[ ! -w "${XPUI_PATH}" ]]; then + echo -e "\nSpotX does not have write permission in Spotify directory.\nRequesting sudo permission...\n" + sudo chmod a+wr "${INSTALL_PATH}" && sudo chmod a+wr -R "${XPUI_PATH}"; fi if [[ "${FORCE_FLAG}" == "false" ]]; then if [[ -f "${XPUI_BAK}" ]]; then echo "SpotX backup found, SpotX has already been used on this install."