-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbg3version
executable file
·108 lines (90 loc) · 2.24 KB
/
bg3version
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
#!/usr/bin/env bash
die() {
echo "${1}"
exit 1
}
activate() {
local version="${1:-current}"
check "${BG3_INSTALL_DIR}" "bg3.${version}"
echo "Removing current game folder …"
sudo btrfs sub del "${BG3_INSTALL_DIR}"
echo "Creating snapshot of \"bg3.${version}\" …"
sudo btrfs sub snap "bg3.${version}" "${BG3_INSTALL_DIR}"
}
check() {
local dir
for dir in "$@"; do
if ! [ -d "${dir}" ] || [ $(stat --format=%i "${dir}") -ne 256 ] || [ $(stat -f --format=%T "${dir}") != "btrfs" ]; then
die "Folder \"${dir}\" is not a BTRFS snapshot, aborting …"
fi
done
}
create() {
check "${BG3_INSTALL_DIR}"
local version="${1}"
if [ -z "${version}" ]; then
die "No VERSION given, aborting …"
fi
echo "Creating snapshot \"bg3.${version}\" …"
sudo btrfs sub snap "${BG3_INSTALL_DIR}" "bg3.${version}"
}
delete() {
local version=$1
if [ -z "${version}" ]; then
die "No VERSION given, aborting …"
fi
check "bg3.${version}"
echo "Removing snapshot \"bg3.${version}\" …"
sudo btrfs sub del "bg3.${version}"
}
list() {
ls | tr " " "\n" | grep "bg3."
}
usage() {
cat <<EOF
Usage: $(basename $0) [OPTION] VERSION
Options:
--activate Use this snapshot as the game folder.
--create, snap Create a new VERSION snapshot.
--delete Delete the snapshot for VERSION.
--help Print this text.
--list Instead of changing to VERSION, list all available versions.
--version Switch to VERSION.
Empty argument list is equivalent to "--list". A single argument is equivalent to
"--activate <argument>".
EOF
}
source "$(dirname $(realpath $0))/util/folders.sh"
CONFIG_FILE="${CONFIG_FILE:-${XDG_CONFIG_HOME:-$HOME/.config}/bg3-mod-profiles/config}"
if [ -f "${CONFIG_FILE}" ]; then
while read line; do declare "$line"; done <"${CONFIG_FILE}"
fi
if [ -z "${BG3_INSTALL_DIR}" ]; then
_library="$(getBg3Library)"
[ $? -eq 1 ] && echo "Steam library folder for Baldur’s Gate 3 not found! Exiting …" && exit 1
BG3_INSTALL_DIR="${_library}/steamapps/common/Baldurs Gate 3"
fi
cd "$(dirname "${BG3_INSTALL_DIR}")"
case $1 in
--create | --snap)
create "$2"
;;
--delete)
delete "$2"
;;
--help)
usage
;;
--list)
list
;;
--version)
activate "$2"
;;
"")
list
;;
*)
activate "$1"
;;
esac