-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-linux.sh
More file actions
executable file
·357 lines (300 loc) · 10 KB
/
setup-linux.sh
File metadata and controls
executable file
·357 lines (300 loc) · 10 KB
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
#!/usr/bin/env bash
set -euo pipefail
APP_ID="1462040"
REPO_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
DEFAULT_ENGINE_INI_SOURCE="$REPO_DIR/Engine.ini"
ENGINE_INI_SOURCE="$DEFAULT_ENGINE_INI_SOURCE"
HOOK_DLL_SOURCE="$REPO_DIR/FFVIIHook/xinput1_3.dll"
LUMA_ZIP_SOURCE="$REPO_DIR/Luma-Final_Fantasy_VII_Remake-1974-2-6-1770058756.zip"
STEAM_INSTALL="auto"
STEAM_ROOT=""
CUSTOM_STEAM_ROOT=""
INSTALL_PACKAGES=1
INSTALL_PROTON_DEPS=1
INSTALL_HOOK=1
INSTALL_LUMA=1
INSTALL_CONFIG=1
USE_MANGOHUD=1
GPU_MODE="auto"
DRY_RUN=0
log() {
printf '[setup-linux] %s\n' "$*"
}
fail() {
printf '[setup-linux] Error: %s\n' "$*" >&2
exit 1
}
ensure_not_root() {
if [[ "${EUID:-$(id -u)}" -eq 0 ]]; then
fail "Do not run this script with sudo. Run it as your normal user; the script will call sudo itself only when installing Ubuntu packages."
fi
}
usage() {
cat <<'EOF'
Usage: ./setup-linux.sh [options]
Automates the Linux steps from this repo's README:
- selects the Steam layout or auto-detects it
- installs protontricks, gamemode, and mangohud on Ubuntu when missing
- installs Proton runtime dependencies for FF7 Remake
- copies the selected .ini file into the game's Proton prefix as Engine.ini
- installs FFVIIHook's xinput1_3.dll
- extracts the bundled Luma archive into the game's Win64 folder
- prints the Steam launch options to paste into Steam
Options:
--engine-ini PATH Use a custom source .ini file. Destination stays Engine.ini.
(Optional; Luma works without it.)
--steam-install TYPE Choose Steam layout: auto, deb, flatpak, or custom.
--custom-steam-root Steam root for --steam-install custom. Must contain steamapps.
--luma-only Skip FFVIIHook installation and use Luma-only launch options.
--skip-packages Do not install Ubuntu packages.
--skip-protontricks Do not run protontricks.
--skip-config Do not deploy Engine.ini (optional performance setting).
--skip-luma Do not extract the bundled Luma archive.
--skip-mangohud Do not include mangohud in the suggested launch options.
--gpu MODE Launch option GPU mode: auto, nvidia, or generic.
--dry-run Print actions without making changes.
--help Show this help text.
EOF
}
run_cmd() {
if [[ "$DRY_RUN" -eq 1 ]]; then
log "DRY RUN: $*"
return 0
fi
log "Running: $*"
"$@"
}
detect_steam_root() {
local candidates=(
"$HOME/.local/share/Steam"
"$HOME/.steam/debian-installation"
"$HOME/.var/app/com.valvesoftware.Steam/.local/share/Steam"
)
local candidate
for candidate in "${candidates[@]}"; do
if [[ -d "$candidate/steamapps" ]]; then
printf '%s\n' "$candidate"
return 0
fi
done
return 1
}
resolve_steam_root() {
case "$STEAM_INSTALL" in
auto)
detect_steam_root || return 1
;;
deb)
if [[ -d "$HOME/.local/share/Steam/steamapps" ]]; then
printf '%s\n' "$HOME/.local/share/Steam"
return 0
fi
if [[ -d "$HOME/.steam/debian-installation/steamapps" ]]; then
printf '%s\n' "$HOME/.steam/debian-installation"
return 0
fi
return 1
;;
flatpak)
if [[ -d "$HOME/.var/app/com.valvesoftware.Steam/.local/share/Steam/steamapps" ]]; then
printf '%s\n' "$HOME/.var/app/com.valvesoftware.Steam/.local/share/Steam"
return 0
fi
return 1
;;
custom)
[[ -n "$CUSTOM_STEAM_ROOT" ]] || fail "--custom-steam-root is required when --steam-install custom is used"
printf '%s\n' "$CUSTOM_STEAM_ROOT"
;;
*)
return 1
;;
esac
}
ensure_command() {
local command_name="$1"
command -v "$command_name" >/dev/null 2>&1 || fail "Required command not found: $command_name"
}
install_ubuntu_packages() {
local packages=()
command -v apt >/dev/null 2>&1 || {
log "Skipping package installation because apt is not available."
return 0
}
command -v protontricks >/dev/null 2>&1 || packages+=(protontricks)
command -v gamemoderun >/dev/null 2>&1 || packages+=(gamemode)
if [[ "$USE_MANGOHUD" -eq 1 ]]; then
command -v mangohud >/dev/null 2>&1 || packages+=(mangohud)
fi
if [[ "${#packages[@]}" -eq 0 ]]; then
log "All requested Ubuntu packages are already installed."
return 0
fi
if [[ "$DRY_RUN" -eq 1 ]]; then
log "DRY RUN: sudo apt update"
log "DRY RUN: sudo add-apt-repository -y universe"
log "DRY RUN: sudo apt install -y ${packages[*]}"
return 0
fi
log "Installing Ubuntu packages: ${packages[*]}"
sudo apt update
if printf '%s\n' "${packages[@]}" | grep -qx 'protontricks'; then
if ! apt-cache show protontricks >/dev/null 2>&1; then
log "Enabling the universe repository because protontricks is not currently available."
sudo add-apt-repository -y universe
sudo apt update
fi
fi
sudo apt install -y "${packages[@]}"
}
build_launch_options() {
local dll_override
local launch_options
local resolved_gpu_mode="$GPU_MODE"
if [[ "$INSTALL_HOOK" -eq 1 ]]; then
dll_override='WINEDLLOVERRIDES="xinput1_3=n,b;dxgi=n,b"'
else
dll_override='WINEDLLOVERRIDES="dxgi=n,b"'
fi
if [[ "$resolved_gpu_mode" == "auto" ]]; then
if command -v nvidia-smi >/dev/null 2>&1; then
resolved_gpu_mode="nvidia"
else
resolved_gpu_mode="generic"
fi
fi
launch_options="$dll_override"
if [[ "$resolved_gpu_mode" == "nvidia" ]]; then
launch_options="__NV_PRIME_RENDER_OFFLOAD=1 __GLX_VENDOR_LIBRARY_NAME=nvidia $launch_options"
fi
if command -v gamemoderun >/dev/null 2>&1; then
launch_options="$launch_options gamemoderun"
fi
if [[ "$USE_MANGOHUD" -eq 1 ]] && command -v mangohud >/dev/null 2>&1; then
launch_options="$launch_options mangohud"
fi
launch_options="$launch_options %command% -dx11"
printf '%s\n' "$launch_options"
}
while [[ "$#" -gt 0 ]]; do
case "$1" in
--engine-ini)
[[ "$#" -ge 2 ]] || fail "--engine-ini requires a path"
ENGINE_INI_SOURCE="$2"
shift 2
;;
--steam-install)
[[ "$#" -ge 2 ]] || fail "--steam-install requires a value"
STEAM_INSTALL="$2"
shift 2
;;
--custom-steam-root)
[[ "$#" -ge 2 ]] || fail "--custom-steam-root requires a path"
CUSTOM_STEAM_ROOT="$2"
shift 2
;;
--luma-only)
INSTALL_HOOK=0
shift
;;
--skip-packages)
INSTALL_PACKAGES=0
shift
;;
--skip-protontricks)
INSTALL_PROTON_DEPS=0
shift
;;
--skip-config)
INSTALL_CONFIG=0
shift
;;
--skip-luma)
INSTALL_LUMA=0
shift
;;
--skip-mangohud)
USE_MANGOHUD=0
shift
;;
--gpu)
[[ "$#" -ge 2 ]] || fail "--gpu requires a value"
GPU_MODE="$2"
shift 2
;;
--dry-run)
DRY_RUN=1
shift
;;
--help)
usage
exit 0
;;
*)
fail "Unknown argument: $1"
;;
esac
done
case "$GPU_MODE" in
auto|nvidia|generic)
;;
*)
fail "--gpu must be one of: auto, nvidia, generic"
;;
esac
case "$STEAM_INSTALL" in
auto|deb|flatpak|custom)
;;
*)
fail "--steam-install must be one of: auto, deb, flatpak, custom"
;;
esac
ensure_not_root
if [[ "$INSTALL_CONFIG" -eq 1 ]]; then
[[ -f "$ENGINE_INI_SOURCE" ]] || fail "Engine.ini not found at $ENGINE_INI_SOURCE"
fi
if [[ "$INSTALL_HOOK" -eq 1 ]]; then
[[ -f "$HOOK_DLL_SOURCE" ]] || fail "FFVIIHook DLL not found at $HOOK_DLL_SOURCE"
fi
if [[ "$INSTALL_LUMA" -eq 1 ]]; then
[[ -f "$LUMA_ZIP_SOURCE" ]] || fail "Luma zip not found at $LUMA_ZIP_SOURCE"
ensure_command unzip
fi
STEAM_ROOT="$(resolve_steam_root || true)"
[[ -n "$STEAM_ROOT" ]] || fail "Could not resolve a Steam root for --steam-install $STEAM_INSTALL"
LIBRARY_ROOT="$STEAM_ROOT/steamapps"
[[ -d "$LIBRARY_ROOT" ]] || fail "Steam library root not found: $LIBRARY_ROOT"
GAME_WIN64_DIR="$LIBRARY_ROOT/common/FINAL FANTASY VII REMAKE/End/Binaries/Win64"
COMPATDATA_ROOT="$LIBRARY_ROOT/compatdata/$APP_ID"
CONFIG_DIR="$COMPATDATA_ROOT/pfx/drive_c/users/steamuser/Documents/My Games/FINAL FANTASY VII REMAKE/Saved/Config/WindowsNoEditor"
[[ -d "$GAME_WIN64_DIR" ]] || fail "Game Win64 directory not found: $GAME_WIN64_DIR"
if [[ ! -d "$COMPATDATA_ROOT" ]]; then
fail "Compatdata directory not found: $COMPATDATA_ROOT. Launch the game once through Steam first."
fi
if [[ "$INSTALL_PACKAGES" -eq 1 ]]; then
install_ubuntu_packages
fi
if [[ "$INSTALL_CONFIG" -eq 1 ]]; then
run_cmd mkdir -p "$CONFIG_DIR"
run_cmd cp "$ENGINE_INI_SOURCE" "$CONFIG_DIR/Engine.ini"
fi
if [[ "$INSTALL_HOOK" -eq 1 ]]; then
run_cmd cp "$HOOK_DLL_SOURCE" "$GAME_WIN64_DIR/xinput1_3.dll"
fi
if [[ "$INSTALL_LUMA" -eq 1 ]]; then
run_cmd unzip -oq "$LUMA_ZIP_SOURCE" -d "$GAME_WIN64_DIR"
fi
if [[ "$INSTALL_PROTON_DEPS" -eq 1 ]]; then
ensure_command protontricks
if [[ "$DRY_RUN" -eq 1 ]]; then
log "DRY RUN: STEAM_DIR=$STEAM_ROOT protontricks $APP_ID msvcrt40 vcrun2022"
else
log "Installing Proton runtime components into app $APP_ID"
STEAM_DIR="$STEAM_ROOT" protontricks "$APP_ID" msvcrt40 vcrun2022
fi
fi
LAUNCH_OPTIONS="$(build_launch_options)"
log "Setup complete."
log "Game directory: $GAME_WIN64_DIR"
log "Config directory: $CONFIG_DIR"
printf '\nSteam launch options:\n%s\n' "$LAUNCH_OPTIONS"