Skip to content

Commit

Permalink
Added a check for .env file at the beginning and new distro working a…
Browse files Browse the repository at this point in the history
…dded to README.md
  • Loading branch information
AngeIo committed Jan 19, 2024
1 parent 7122bb8 commit 6864a86
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 19 additions & 14 deletions steam-backup-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
###
Expand Down Expand Up @@ -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
###

Expand Down

0 comments on commit 6864a86

Please sign in to comment.