-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbg3switch
executable file
·160 lines (144 loc) · 4.32 KB
/
bg3switch
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/usr/bin/env bash
create() {
if [ -d "profiles/${1}" ]; then
echo "Baldur’s Gate 3 folder for \"${1}\" already exists."
exit 1
else
mkdir "profiles/${1}"
switch "${1}"
fi
}
link() {
if [ -z ${1} ]; then
_dir="current"
else
_dir="profiles/${1}"
fi
# sym link the “Mods” folder
if [ ! -L "Baldur's Gate 3/Mods" ]; then
echo "Non-link \"Mods\" folder detected! Setting up symbolic link …"
if [ -d "Baldur's Gate 3/Mods/" ]; then
mv "Baldur's Gate 3/Mods/" "${_dir}"
fi
ln -s "../current/Mods" "Baldur's Gate 3/Mods"
fi
if [ ! -d "${_dir}/Mods" ]; then
echo "Creating \"Mods\" folder …"
mkdir -p "${_dir}/Mods"
fi
# sym link the modsettings file
mkdir -p "${_dir}/PlayerProfiles/Public/"
if [ ! -L "Baldur's Gate 3/PlayerProfiles/Public/modsettings.lsx" ]; then
echo "Non-link \"modsettings.lsx\" detected! Setting up symbolic link …"
if [ -f "${_dir}/PlayerProfiles/Public/modsettings.lsx" ]; then
mv "Baldur's Gate 3/PlayerProfiles/Public/modsettings.lsx" "${_dir}/PlayerProfiles/Public/"
fi
ln -s "../../../current/PlayerProfiles/Public/modsettings.lsx" "Baldur's Gate 3/PlayerProfiles/Public/"
fi
if [ ! -f "${_dir}/PlayerProfiles/Public/modsettings.lsx" ]; then
echo "Creating empty modsettings file …"
touch "${_dir}/PlayerProfiles/Public/modsettings.lsx"
fi
# sym link the “ScriptExtender” folder
if [ ! -L "Baldur's Gate 3/Script Extender" ]; then
echo "Non-link \"Script Extender\" folder detected! Setting up symbolic link …"
if [ -d "Baldur's Gate 3/Script Extender/" ]; then
mv "Baldur's Gate 3/Script Extender/" "${_dir}"
fi
ln -s "../current/Script Extender" "Baldur's Gate 3/Script Extender"
fi
if [ ! -d "${_dir}/Script Extender" ]; then
echo "Creating \"Script Extender\" folder …"
mkdir -p "${_dir}/Script Extender"
fi
# create override folders for loose files mods
if [ ! -d "${_dir}/override" ]; then
echo "Creating \"override\" folder …"
mkdir "${_dir}/override"
fi
if [ ! -d "${_dir}/modular-override" ]; then
echo "Creating \"modular-override\" folder …"
mkdir "${_dir}/modular-override"
fi
}
list() {
if [ -d "profiles" ]; then
echo -e "Mod Profiles:"
ls profiles | tr " " "\n"
else
echo "No profile folder present. Try \"$(basename $0) --create PROFILE\"."
fi
current=$(readlink -- current)
if [ -z $current ]; then
echo -e "\nNo link to current profile found. Try \"$(basename $0) --create PROFILE\"."
else
echo -e "\nCurrent Profile:\n${current##*/}"
fi
}
switch() {
if [ -z "${1}" ]; then
echo "No profile name given!"
exit 1
fi
if [ -d "profiles/${1}" ]; then
link "${1}"
ln -nsf "./profiles/${1}" current
else
echo "No Baldur’s Gate 3 folder for \"${1}\" found. Try \"$(basename $0) --help\""
exit 1
fi
}
usage() {
cat <<EOF
Usage: $(basename $0) [OPTION] PROFILE
Options:
--create,--add,--new Creates a new mod profile under PROFILE. If this is your first,
your current mods will be moved to the profile and the necessary
symbolic links set up automatically.
--help,-h Prints this help.
--link Checks if the necessary folders are sym linked. If not, creates
them. Will link to \`current\` unless a PROFILE is given.
--open,--cd Opens a new shell in the "%AppData%/Local/Larian Studios" folder.
--switch Switch to PROFILE.
Empty argument list is equivalent to "--list". A single argument is equivalent to
"--switch <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_DATA_DIR" ]; then
_library="$(getBg3Library)"
[ $? -eq 1 ] && echo "Steam library folder for Baldur’s Gate 3 not found! Exiting …" && exit 1
BG3_DATA_DIR="${_library}/steamapps/compatdata/1086940/pfx/drive_c/users/steamuser/AppData/Local/Larian Studios/Baldur's Gate 3/"
fi
cd "$(dirname "${BG3_DATA_DIR}")"
case "$1" in
--create | --add | --new)
create "$2"
;;
--help | -h)
usage
exit 1
;;
--link)
link "$2"
;;
--list | --ls)
list
;;
--open | --cd)
$SHELL
;;
--switch)
switch "$2"
;;
"")
list
;;
*)
switch "$1"
;;
esac