-
Notifications
You must be signed in to change notification settings - Fork 3
/
steam-backup-setup.sh
executable file
·146 lines (132 loc) · 5.43 KB
/
steam-backup-setup.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/usr/bin/env bash
set -e
# Get current timestamp
TIMEEPOCH=$(date +'%F_%H.%M.%S')
# Get current script's directory
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
fi
cp $STEAM_BKUPER_DIR/{my-steam-backup.sh,git-sync,init-steam-backup-vars.sh} $BIN_DIR
chmod -R 755 $BIN_DIR
if [ ! -d "$STEAM_SAVES_DIR" ]; then
git clone $STEAM_SAVES_REPO $STEAM_SAVES_DIR
fi
cd $STEAM_SAVES_DIR
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
if [[ "$STEAM_LOPTS" != "$STEAM_LAST_LOPTS" ]]; then
###
# Find the smallest directory number in Steam local files
# Check if the path exists
if [ ! -d "$STEAM_PATH" ]; then
echo "Error: The specified path does not exist."
exit 1
fi
# If STEAM_ACCOUNTID is empty or undefined
if [ ! -n "$STEAM_ACCOUNTID" ]; then
# Change to the specified path
cd "$STEAM_PATH" || exit
# Find all directories in the path
directories=($(find . -maxdepth 1 -type d -not -name '.' -exec basename {} \;))
# Check if any directories were found
if [ ${#directories[@]} -eq 0 ]; then
echo "Error: No directories found in the specified path."
exit 1
fi
# Initialize variables for the smallest number and corresponding directory
smallest_number=""
smallest_dir=""
# Loop through each directory
for dir in "${directories[@]}"; do
# Remove leading zeros from the directory name
dir_number=$(echo "$dir" | sed 's/^0*//')
# Check if the current directory is a number
if [[ "$dir_number" =~ ^[0-9]+$ ]]; then
# If the smallest_number is empty or the current number is smaller
if [ -z "$smallest_number" ] || [ "$dir_number" -lt "$smallest_number" ]; then
smallest_number="$dir_number"
smallest_dir="$dir"
fi
fi
done
# Check if a directory with a number was found
if [ -z "$smallest_dir" ]; then
echo "Error: No directory with a numeric name found."
exit 1
fi
# DEBUG
# echo "Smallest directory: $smallest_dir"
STEAM_ACCOUNTID="$smallest_dir"
fi
###
###
# Asking the user to close Steam before continuing
process_name="steam"
# Use pgrep to check if the process is running
if pgrep -x "$process_name" > /dev/null; then
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 "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
###
###
# Edit the localconfig.vdf file to add the command to each of your games' launch options
LCVDFO="$HOME/.steam/steam/userdata/$STEAM_ACCOUNTID/config/localconfig.vdf"
LCVDF="$LCVDFO.bak.$TIMEEPOCH"
LOPTS="\\\t\t\t\t\t\t\"LaunchOptions\" \"$STEAM_LOPTS\""
if [ ! -f $LCVDF ]; then
# DEBUG
# echo "$LCVDF doesn't exist - copying the original"
if [ ! -f $LCVDFO ]; then
echo "$LCVDFO doesn't exist as well - giving up"
exit 1
else
cp $LCVDFO $LCVDF
fi
fi
sed -i '/LaunchOptions/d' $LCVDFO
sed -i '/"Playtime"/i '"$LOPTS"'' $LCVDFO
echo "Successfully applied your Launch Options to your Steam library!"
echo ""
echo "If you want to restore the previous version of your localconfig.vdf, type the following commands:"
echo "cp $LCVDFO $LCVDFO.bak"
echo "cp $LCVDF $LCVDFO"
echo ""
###
###
# Define STEAM_LAST_LOPTS variable in $STEAM_BKUPER_DIR/.env
# 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
###
else
echo "Launch Options are already added to your Steam library!"
fi
else
echo "Launch Options' automatic setup is disabled!"
fi