Format with shfmt

shfmt -bn -ci -sr -s -i 4 -w
This commit is contained in:
Henry Wenger-Stickel 2023-06-23 08:54:17 -05:00
parent d0d2599a56
commit b0f7621112
No known key found for this signature in database
GPG Key ID: 4C015E0C611CD080

View File

@ -3,9 +3,18 @@
SPOTX_VERSION="1.2.3.1115-1"
# Dependencies check
command -v perl >/dev/null || { echo -e "\nperl was not found, please install. Exiting...\n" >&2; exit 1; }
command -v unzip >/dev/null || { echo -e "\nunzip was not found, please install. Exiting...\n" >&2; exit 1; }
command -v zip >/dev/null || { echo -e "\nzip was not found, please install. Exiting...\n" >&2; exit 1; }
command -v perl > /dev/null || {
echo -e "\nperl was not found, please install. Exiting...\n" >&2
exit 1
}
command -v unzip > /dev/null || {
echo -e "\nunzip was not found, please install. Exiting...\n" >&2
exit 1
}
command -v zip > /dev/null || {
echo -e "\nzip was not found, please install. Exiting...\n" >&2
exit 1
}
# Script flags
CACHE_FLAG='false'
@ -24,17 +33,19 @@ while getopts 'cefhopP:' flag; do
o) OLD_UI_FLAG='true' ;;
P)
PATH_FLAG="${OPTARG}"
INSTALL_PATH="${PATH_FLAG}" ;;
INSTALL_PATH="${PATH_FLAG}"
;;
p) PREMIUM_FLAG='true' ;;
*)
echo "Error: Flag not supported."
exit ;;
exit
;;
esac
done
# Handle exclude flag(s)
for EXCLUDE_VAL in "${EXCLUDE_FLAG[@]}"; do
if [[ "${EXCLUDE_VAL}" == "leftsidebar" ]]; then EX_LEFTSIDEBAR='true'; fi
if [[ ${EXCLUDE_VAL} == "leftsidebar" ]]; then EX_LEFTSIDEBAR='true'; fi
done
# Perl command
@ -117,32 +128,37 @@ echo -e "SpotX-Linux version: ${SPOTX_VERSION}\n"
# Locate install directory
if [ -z ${INSTALL_PATH+x} ]; then
INSTALL_PATH=$(readlink -e `type -p spotify` 2>/dev/null | rev | cut -d/ -f2- | rev)
if [[ -d "${INSTALL_PATH}" && "${INSTALL_PATH}" != "/usr/bin" ]]; then
INSTALL_PATH=$(readlink -e $(type -p spotify) 2> /dev/null | rev | cut -d/ -f2- | rev)
if [[ -d ${INSTALL_PATH} && ${INSTALL_PATH} != "/usr/bin" ]]; then
echo "Spotify directory found in PATH: ${INSTALL_PATH}"
elif [[ ! -d "${INSTALL_PATH}" ]]; then
elif [[ ! -d ${INSTALL_PATH} ]]; then
echo -e "\nSpotify not found in PATH. Searching for Spotify directory..."
INSTALL_PATH=$(timeout 10 find / -type f -path "*/spotify*Apps/*" -name "xpui.spa" -size -7M -size +3M -print -quit 2> /dev/null | rev | cut -d/ -f3- | rev)
if [[ -d "${INSTALL_PATH}" ]]; then
if [[ -d ${INSTALL_PATH} ]]; then
echo "Spotify directory found: ${INSTALL_PATH}"
elif [[ ! -d "${INSTALL_PATH}" ]]; then
elif [[ ! -d ${INSTALL_PATH} ]]; then
echo -e "Spotify directory not found. Set directory path with -P flag.\nExiting...\n"
exit; fi
elif [[ "${INSTALL_PATH}" == "/usr/bin" ]]; then
exit
fi
elif [[ ${INSTALL_PATH} == "/usr/bin" ]]; then
echo -e "\nSpotify PATH is set to /usr/bin, searching for Spotify directory..."
INSTALL_PATH=$(timeout 10 find / -type f -path "*/spotify*Apps/*" -name "xpui.spa" -size -7M -size +3M -print -quit 2> /dev/null | rev | cut -d/ -f3- | rev)
if [[ -d "${INSTALL_PATH}" && "${INSTALL_PATH}" != "/usr/bin" ]]; then
if [[ -d ${INSTALL_PATH} && ${INSTALL_PATH} != "/usr/bin" ]]; then
echo "Spotify directory found: ${INSTALL_PATH}"
elif [[ "${INSTALL_PATH}" == "/usr/bin" ]] || [[ ! -d "${INSTALL_PATH}" ]]; then
elif [[ ${INSTALL_PATH} == "/usr/bin" ]] || [[ ! -d ${INSTALL_PATH} ]]; then
echo -e "Spotify directory not found. Set directory path with -P flag.\nExiting...\n"
exit; fi; fi
exit
fi
fi
else
if [[ ! -d "${INSTALL_PATH}" ]]; then
if [[ ! -d ${INSTALL_PATH} ]]; then
echo -e "Directory path set by -P was not found.\nExiting...\n"
exit
elif [[ ! -f "${INSTALL_PATH}/Apps/xpui.spa" ]]; then
echo -e "No xpui found in directory provided with -P.\nPlease confirm directory and try again or re-install Spotify.\nExiting...\n"
exit; fi; fi
exit
fi
fi
# Find client version
CLIENT_VERSION=$("${INSTALL_PATH}"/spotify --version | cut -dn -f2- | rev | cut -d. -f2- | rev)
@ -165,15 +181,16 @@ HOME_V2_JS="${XPUI_DIR}/home-v2.js"
VENDOR_XPUI_JS="${XPUI_DIR}/vendor~xpui.js"
# xpui detection
if [[ ! -f "${XPUI_SPA}" ]]; then
if [[ ! -f ${XPUI_SPA} ]]; then
echo -e "\nxpui not found!\nReinstall Spotify then try again.\nExiting...\n"
exit
else
if [[ ! -w "${XPUI_PATH}" ]]; then
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
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."
echo -e "Re-run SpotX using the '-f' flag to force xpui patching.\n"
echo "Skipping xpui patches and continuing SpotX..."
@ -181,9 +198,10 @@ else
else
echo "Creating xpui backup..."
cp "${XPUI_SPA}" "${XPUI_BAK}"
XPUI_SKIP="false"; fi
XPUI_SKIP="false"
fi
else
if [[ -f "${XPUI_BAK}" ]]; then
if [[ -f ${XPUI_BAK} ]]; then
echo "Backup xpui found, restoring original..."
rm "${XPUI_SPA}"
cp "${XPUI_BAK}" "${XPUI_SPA}"
@ -191,10 +209,13 @@ else
else
echo "Creating xpui backup..."
cp "${XPUI_SPA}" "${XPUI_BAK}"
XPUI_SKIP="false"; fi; fi; fi
XPUI_SKIP="false"
fi
fi
fi
# Extract xpui.spa
if [[ "${XPUI_SKIP}" == "false" ]]; then
if [[ ${XPUI_SKIP} == "false" ]]; then
echo "Extracting xpui..."
unzip -qq "${XPUI_SPA}" -d "${XPUI_DIR}"
if grep -Fq "SpotX" "${XPUI_JS}"; then
@ -205,12 +226,14 @@ if [[ "${XPUI_SKIP}" == "false" ]]; then
rm "${XPUI_BAK}" 2> /dev/null
rm -rf "${XPUI_DIR}" 2> /dev/null
else
rm "${XPUI_SPA}"; fi; fi
rm "${XPUI_SPA}"
fi
fi
echo "Applying SpotX patches..."
if [[ "${XPUI_SKIP}" == "false" ]]; then
if [[ "${PREMIUM_FLAG}" == "false" ]]; then
if [[ ${XPUI_SKIP} == "false" ]]; then
if [[ ${PREMIUM_FLAG} == "false" ]]; then
# Remove Empty ad block
echo "Removing ad-related content..."
$PERL "${AD_EMPTY_AD_BLOCK}" "${XPUI_JS}"
@ -242,13 +265,16 @@ if [[ "${XPUI_SKIP}" == "false" ]]; then
$PERL "${DEVICE_PICKER_NEW}" "${XPUI_JS}"
$PERL "${CONNECT_NEW}" "${XPUI_JS}"
elif [[ $(ver "${CLIENT_VERSION}") -gt $(ver "1.1.96.783") ]]; then
$PERL "${CONNECT_NEW}" "${XPUI_JS}"; fi
$PERL "${CONNECT_NEW}" "${XPUI_JS}"
fi
else
echo "Premium subscription setup selected..."; fi; fi
echo "Premium subscription setup selected..."
fi
fi
# Experimental patches
if [[ "${XPUI_SKIP}" == "false" ]]; then
if [[ "${EXPERIMENTAL_FLAG}" == "true" ]]; then
if [[ ${XPUI_SKIP} == "false" ]]; then
if [[ ${EXPERIMENTAL_FLAG} == "true" ]]; then
echo "Adding experimental features..."
if [[ $(ver "${CLIENT_VERSION}") -ge $(ver "1.1.99.871") ]]; then $PERL "${ENABLE_ADD_PLAYLIST}" "${XPUI_JS}"; fi
if [[ $(ver "${CLIENT_VERSION}") -ge $(ver "1.1.99.871") ]]; then $PERL "${ENABLE_BAD_BUNNY}" "${XPUI_JS}"; fi
@ -274,17 +300,20 @@ if [[ "${XPUI_SKIP}" == "false" ]]; then
if [[ $(ver "${CLIENT_VERSION}") -ge $(ver "1.2.0.1165") ]]; then $PERL "${ENABLE_PODCAST_PLAYBACK_SPEED}" "${XPUI_JS}"; fi
if [[ $(ver "${CLIENT_VERSION}") -ge $(ver "1.1.99.871") ]]; then $PERL "${ENABLE_PODCAST_TRIMMING}" "${XPUI_JS}"; fi
if [[ $(ver "${CLIENT_VERSION}") -ge $(ver "1.1.86.857") && $(ver "${CLIENT_VERSION}") -lt $(ver "1.1.94.864") ]]; then $PERL "${ENABLE_SEARCH_BOX}" "${XPUI_JS}"; fi
if [[ $(ver "${CLIENT_VERSION}") -ge $(ver "1.1.85.884") ]]; then $PERL "${ENABLE_SIMILAR_PLAYLIST}" "${XPUI_JS}"; fi; fi; fi
if [[ $(ver "${CLIENT_VERSION}") -ge $(ver "1.1.85.884") ]]; then $PERL "${ENABLE_SIMILAR_PLAYLIST}" "${XPUI_JS}"; fi
fi
fi
# Remove logging
if [[ "${XPUI_SKIP}" == "false" ]]; then
if [[ ${XPUI_SKIP} == "false" ]]; then
echo "Removing logging..."
$PERL "${LOG_1}" "${XPUI_JS}"
$PERL "${LOG_SENTRY}" "${VENDOR_XPUI_JS}"; fi
$PERL "${LOG_SENTRY}" "${VENDOR_XPUI_JS}"
fi
# Handle new home screen UI
if [[ "${XPUI_SKIP}" == "false" ]]; then
if [[ "${OLD_UI_FLAG}" == "true" ]]; then
if [[ ${XPUI_SKIP} == "false" ]]; then
if [[ ${OLD_UI_FLAG} == "true" ]]; then
echo "Skipping new home UI patch..."
elif [[ $(ver "${CLIENT_VERSION}") -gt $(ver "1.1.93.896") && $(ver "${CLIENT_VERSION}") -lt $(ver "1.1.97.956") ]]; then
echo "Enabling new home screen UI..."
@ -303,11 +332,13 @@ if [[ "${XPUI_SKIP}" == "false" ]]; then
if [[ $(ver "${CLIENT_VERSION}") -ge $(ver "1.1.98.683") ]]; then $PERL "${ENABLE_RIGHT_SIDEBAR}" "${XPUI_JS}"; fi
if [[ $(ver "${CLIENT_VERSION}") -ge $(ver "1.2.0.1165") ]]; then $PERL "${ENABLE_RIGHT_SIDEBAR_LYRICS}" "${XPUI_JS}"; fi
else
:; fi; fi
:
fi
fi
# Hide podcasts, episodes and audiobooks on home screen
if [[ "${XPUI_SKIP}" == "false" ]]; then
if [[ "${HIDE_PODCASTS_FLAG}" == "true" ]]; then
if [[ ${XPUI_SKIP} == "false" ]]; then
if [[ ${HIDE_PODCASTS_FLAG} == "true" ]]; then
if [[ $(ver "${CLIENT_VERSION}") -lt $(ver "1.1.93.896") ]]; then
echo "Hiding non-music items on home screen..."
$PERL "${HIDE_PODCASTS}" "${XPUI_JS}"
@ -319,21 +350,30 @@ if [[ "${XPUI_SKIP}" == "false" ]]; then
$PERL "${HIDE_PODCASTS3}" "${HOME_V2_JS}"
elif [[ $(ver "${CLIENT_VERSION}") -ge $(ver "1.1.98.683") ]]; then
echo "Hiding non-music items on home screen..."
$PERL "${HIDE_PODCASTS3}" "${XPUI_JS}"; fi; fi; fi
$PERL "${HIDE_PODCASTS3}" "${XPUI_JS}"
fi
fi
fi
# Delete app cache
if [[ "${CACHE_FLAG}" == "true" ]]; then
if [[ ${CACHE_FLAG} == "true" ]]; then
echo "Clearing app cache..."
rm -rf "$CACHE_PATH"; fi
rm -rf "$CACHE_PATH"
fi
# Rebuild xpui.spa
if [[ "${XPUI_SKIP}" == "false" ]]; then
if [[ ${XPUI_SKIP} == "false" ]]; then
echo "Rebuilding xpui..."
echo -e "\n//# SpotX was here" >> "${XPUI_JS}"; fi
echo -e "\n//# SpotX was here" >> "${XPUI_JS}"
fi
# Zip files inside xpui folder
if [[ "${XPUI_SKIP}" == "false" ]]; then
(cd "${XPUI_DIR}"; zip -qq -r ../xpui.spa .)
rm -rf "${XPUI_DIR}"; fi
if [[ ${XPUI_SKIP} == "false" ]]; then
(
cd "${XPUI_DIR}"
zip -qq -r ../xpui.spa .
)
rm -rf "${XPUI_DIR}"
fi
echo -e "SpotX finished patching!\n"