Error handling and shellcheck additions

- Handle `logname: no login name` error for `$USER`
- Double quote variables and add curly brackets when concatenated (e.g., directories)
- Replace tilde with `$logged_in_home` var
- Capture return codes from wget command directly (404 throws custom exit code 8)
- Fix code block indentions
- Move SC2155 to .shellcheckrc
- Add  SC2164 to exclude `cd` errors
- Breakout SC exclusions to multiple lines to toggle them more easily
- Remove duplicate SC entries
This commit is contained in:
pythoninthegrass 2023-09-01 00:04:17 -05:00
parent aa667f1cb8
commit 23eae27fe0
2 changed files with 38 additions and 26 deletions

View File

@ -1 +1,15 @@
disable=SC2153,SC2155,SC2046,SC1073,SC1078,SC1079,SC2016,SC1091,SC2034,SC2086,SC2153,SC2155,SC2236,SC2317,SC3037,SC3045,SC2046
disable=SC1073
disable=SC1078
disable=SC1079
disable=SC1091
disable=SC2016
disable=SC2034
disable=SC2046
disable=SC2086
disable=SC2153
disable=SC2155
disable=SC2164
disable=SC2236
disable=SC2317
disable=SC3037
disable=SC3045

View File

@ -1,14 +1,12 @@
#!/usr/bin/env bash
# shellcheck disable=SC2155
set -x # activate debugging (execution shown)
set -o pipefail # capture error from pipes
# set -eu # exit immediately, undefined vars are errors
# ENVIRONMENT VARIABLES
# $USER
logged_in_user=$(logname)
[[ -n $(logname >/dev/null 2>&1) ]] && logged_in_user=$(logname) || logged_in_user=$(whoami)
# $UID
# logged_in_uid=$(id -u "${logged_in_user}")
@ -21,7 +19,7 @@ logged_in_home=$(eval echo "~${logged_in_user}")
download_dir="${logged_in_home}/Downloads/NonSteamLaunchersInstallation"
# Create a log file in the same directory as the desktop file/.sh file
exec >> ${logged_in_home}/Downloads/NonSteamLaunchers-install.log 2>&1
exec >> "${logged_in_home}/Downloads/NonSteamLaunchers-install.log" 2>&1
# Version number (major.minor)
version=v2.99
@ -1335,66 +1333,65 @@ echo "0"
echo "# Detecting, Updating and Installing GE-Proton"
# check to make sure compatabilitytools.d exists and makes it if it doesnt
if [ ! -d "${logged_in_home}/.steam/root/compatibilitytools.d" ]; then
if [ ! -d "${logged_in_home}/.steam/root/compatibilitytools.d" ]; then
mkdir -p "${logged_in_home}/.steam/root/compatibilitytools.d"
fi
# Create NonSteamLaunchersInstallation subfolder in Downloads folder
mkdir -p ${logged_in_home}/Downloads/NonSteamLaunchersInstallation
mkdir -p "${logged_in_home}/Downloads/NonSteamLaunchersInstallation"
# Set the path to the Proton directory
proton_dir=$(find ~/.steam/root/compatibilitytools.d -maxdepth 1 -type d -name "GE-Proton*" | sort -V | tail -n1)
proton_dir=$(find "${logged_in_home}/.steam/root/compatibilitytools.d" -maxdepth 1 -type d -name "GE-Proton*" | sort -V | tail -n1)
# Set the URLs to download GE-Proton from
ge_proton_url1=https://github.com/GloriousEggroll/proton-ge-custom/releases/latest/download/GE-Proton.tar.gz
ge_proton_url2=https://github.com/GloriousEggroll/proton-ge-custom/releases/download/GE-Proton8-13/GE-Proton8-13.tar.gz
ge_proton_url1="https://github.com/GloriousEggroll/proton-ge-custom/releases/latest/download/GE-Proton.tar.gz"
ge_proton_url2="https://github.com/GloriousEggroll/proton-ge-custom/releases/download/GE-Proton8-13/GE-Proton8-13.tar.gz"
# Check if GE-Proton is installed
if [ -z "$proton_dir" ]; then
# Download GE-Proton using the first URL
echo "Downloading GE-Proton using the first URL"
wget $ge_proton_url1 -O ${logged_in_home}/Downloads/NonSteamLaunchersInstallation/GE-Proton.tar.gz
ret_code=$(wget "$ge_proton_url1" -O "${logged_in_home}/Downloads/NonSteamLaunchersInstallation/GE-Proton.tar.gz"; echo $?)
# Check if the download succeeded
if [ $? -ne 0 ]; then
if [ "$ret_code" -ne 0 ]; then
# Download GE-Proton using the second URL
echo "Downloading GE-Proton using the second URL"
wget $ge_proton_url2 -O ${logged_in_home}/Downloads/NonSteamLaunchersInstallation/GE-Proton.tar.gz
ret_code=$(wget "$ge_proton_url2" -O "${logged_in_home}/Downloads/NonSteamLaunchersInstallation/GE-Proton.tar.gz"; echo $?)
fi
# Check if either download succeeded
if [ $? -eq 0 ]; then
if [ "$ret_code" -eq 0 ]; then
# Install GE-Proton
echo "Installing GE-Proton"
tar -xvf ${logged_in_home}/Downloads/NonSteamLaunchersInstallation/GE-Proton.tar.gz -C ~/.steam/root/compatibilitytools.d/
proton_dir=$(find ~/.steam/root/compatibilitytools.d -maxdepth 1 -type d -name "GE-Proton*" | sort -V | tail -n1)
tar -xvf "${logged_in_home}/Downloads/NonSteamLaunchersInstallation/GE-Proton.tar.gz" -C "${logged_in_home}/.steam/root/compatibilitytools.d"
proton_dir=$(find "${logged_in_home}/.steam/root/compatibilitytools.d" -maxdepth 1 -type d -name "GE-Proton*" | sort -V | tail -n1)
else
# Handle download failure
echo "Failed to download GE-Proton"
fi
else
# Check if installed version is the latest version
installed_version=$(basename $proton_dir | sed 's/GE-Proton-//')
# Check if installed version is the latest version
installed_version=$(basename $proton_dir | sed 's/GE-Proton-//')
latest_version=$(curl -s https://api.github.com/repos/GloriousEggroll/proton-ge-custom/releases/latest | grep tag_name | cut -d '"' -f 4)
if [ "$installed_version" != "$latest_version" ]; then
# Download GE-Proton using the first URL
echo "Downloading GE-Proton using the first URL"
wget $ge_proton_url1 -O ${logged_in_home}/Downloads/NonSteamLaunchersInstallation/GE-Proton.tar.gz
ret_code=$(wget "$ge_proton_url1" -O "${logged_in_home}/Downloads/NonSteamLaunchersInstallation/GE-Proton.tar.gz"; echo $?)
# Check if the download succeeded
if [ $? -ne 0 ]; then
if [ "$ret_code" -ne 0 ]; then
# Download GE-Proton using the second URL
echo "Downloading GE-Proton using the second URL"
wget $ge_proton_url2 -O ${logged_in_home}/Downloads/NonSteamLaunchersInstallation/GE-Proton.tar.gz
ret_code=$(wget "$ge_proton_url2" -O "${logged_in_home}/Downloads/NonSteamLaunchersInstallation/GE-Proton.tar.gz"; echo $?)
fi
# Check if either download succeeded
if [ $? -eq 0 ]; then
if [ "$ret_code" -eq 0 ]; then
# Install GE-Proton
echo "Installing GE-Proton"
tar -xvf ${logged_in_home}/Downloads/NonSteamLaunchersInstallation/GE-Proton.tar.gz -C ~/.steam/root/compatibilitytools.d/
proton_dir=$(find ~/.steam/root/compatibilitytools.d -maxdepth 1 -type d -name "GE-Proton*" | sort -V | tail -n1)
tar -xvf "${logged_in_home}/Downloads/NonSteamLaunchersInstallation/GE-Proton.tar.gz" -C "${logged_in_home}/.steam/root/compatibilitytools.d"
proton_dir=$(find "${logged_in_home}/.steam/root/compatibilitytools.d" -maxdepth 1 -type d -name "GE-Proton*" | sort -V | tail -n1)
else
# Handle download failure
echo "Failed to download GE-Proton"
@ -2661,8 +2658,9 @@ if [[ -f "${steam_dir}/config/config.vdf" ]]; then
# Initialize the most_recent variable
most_recent=0
# TODO: `find` would likely be safer than globbing
# Loop through all the userdata folders
for USERDATA_FOLDER in ~/.steam/root/userdata/*; do
for USERDATA_FOLDER in "${logged_in_home}"/.steam/root/userdata/*; do
# Check if the current userdata folder is not the "0" or "anonymous" folder
if [[ "$USERDATA_FOLDER" != *"/0" ]] && [[ "$USERDATA_FOLDER" != *"/anonymous" ]]; then
# Get the access time of the current userdata folder