From 6864a86f75fda721d4f9c0feacce02acdfb3f62b Mon Sep 17 00:00:00 2001 From: Angelo GERARD Date: Fri, 19 Jan 2024 04:10:44 +0100 Subject: [PATCH] Added a check for .env file at the beginning and new distro working added to README.md --- README.md | 2 +- steam-backup-setup.sh | 33 +++++++++++++++++++-------------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 8140025..464dea9 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ This script has been specially made to ensure that those who use it NEVER EVER l - [x] "Launch Options" are automatically set on all games of your Steam library ## Prerequisites -- Tested on SteamOS 3.5.7 (Arch Linux) but could be working on other distros +- Tested on SteamOS 3.5.7 (Arch Linux) and Ubuntu 22.04.3 but could be working on other distros - Git ## Usage diff --git a/steam-backup-setup.sh b/steam-backup-setup.sh index 824456c..09387ab 100755 --- a/steam-backup-setup.sh +++ b/steam-backup-setup.sh @@ -8,10 +8,17 @@ SCRIPT_DIR=$(dirname `readlink -f $0`) ln -s $SCRIPT_DIR/.env $HOME/steam-bkuper.env &>/dev/null || true source $SCRIPT_DIR/init-steam-backup-vars.sh +# If $STEAM_BKUPER_DIR/.env don't exist, exit +if [ ! -f "$STEAM_BKUPER_DIR/.env" ]; then + echo ".env file not found. Please make sure the file exists in the current directory. Is STEAM_BKUPER_DIR path correct?" + exit 1 +fi + cd $BIN_DIR wget -qc https://github.com/mtkennerly/ludusavi/releases/download/$LUDUSAVI_VER/$LUDUSAVI_FILE -O $LUDUSAVI_FILE unzip -oq $LUDUSAVI_FILE rm $LUDUSAVI_FILE +echo "Installed ludusavi $LUDUSAVI_VER" if [ ! -d "$STEAM_BKUPER_DIR" ]; then git clone $STEAM_BKUPER_REPO $STEAM_BKUPER_DIR @@ -29,6 +36,8 @@ if [ -n "$STEAM_SAVES_REPO2" ]; then git remote add origin-new $STEAM_SAVES_REPO2 &>/dev/null || true fi +echo "Git setup is ready" + # --- Launch Options installation --- if [[ "$STEAM_LOPTS" != "NULL" ]]; then @@ -83,9 +92,9 @@ if [[ "$STEAM_LOPTS" != "NULL" ]]; then process_name="steam" # Use pgrep to check if the process is running if pgrep -x "$process_name" > /dev/null; then - printf "%s " "Looks like Steam is running... please close it before proceeding and press Enter to continue or CTRL+C to exit the current script." && read ans + printf "Looks like Steam is running... please close it before proceeding and press Enter to continue or CTRL+C to exit the current script.\nQuick tip: In .env file, put "NULL" in STEAM_LOPTS to prevent adding Launch Options automatically and skipping this message! " && read ans while pgrep -x "$process_name" > /dev/null; do - printf "%s " "Looks like Steam is STILL running... please close it before proceeding and press Enter to continue or CTRL+C to exit the current script." && read ans + printf "Looks like Steam is STILL running... please close it before proceeding and press Enter to continue or CTRL+C to exit the current script.\nQuick tip: In .env file, put "NULL" in STEAM_LOPTS to prevent adding Launch Options automatically and skipping this message! " && read ans done fi ### @@ -117,19 +126,15 @@ if [[ "$STEAM_LOPTS" != "NULL" ]]; then ### # Define STEAM_LAST_LOPTS variable in $STEAM_BKUPER_DIR/.env - if [ -f "$STEAM_BKUPER_DIR/.env" ]; then - # Check if the line containing STEAM_LAST_LOPTS exists (ignoring comments) - if grep -q "^export STEAM_LAST_LOPTS=" "$STEAM_BKUPER_DIR/.env"; then - # Use sed to replace the value of STEAM_LAST_LOPTS - sed -i --expression "s@^export STEAM_LAST_LOPTS=\"[^\"]*\"@export STEAM_LAST_LOPTS=\"$STEAM_LOPTS\"@" $STEAM_BKUPER_DIR/.env - echo "Successfully updated STEAM_LAST_LOPTS in .env file." - else - # If the line doesn't exist, add it to a new line at the end of the file - echo -e "\nexport STEAM_LAST_LOPTS=\"$STEAM_LOPTS\"" >> $STEAM_BKUPER_DIR/.env - echo "Added STEAM_LAST_LOPTS to .env file." - fi + # Check if the line containing STEAM_LAST_LOPTS exists (ignoring comments) + if grep -q "^export STEAM_LAST_LOPTS=" "$STEAM_BKUPER_DIR/.env"; then + # Use sed to replace the value of STEAM_LAST_LOPTS + sed -i --expression "s@^export STEAM_LAST_LOPTS=\"[^\"]*\"@export STEAM_LAST_LOPTS=\"$STEAM_LOPTS\"@" $STEAM_BKUPER_DIR/.env + echo "Successfully updated STEAM_LAST_LOPTS in .env file." else - echo ".env file not found. Please make sure the file exists in the current directory." + # If the line doesn't exist, add it to a new line at the end of the file + echo -e "\nexport STEAM_LAST_LOPTS=\"$STEAM_LOPTS\"" >> $STEAM_BKUPER_DIR/.env + echo "Added STEAM_LAST_LOPTS to .env file." fi ###