-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathasgard-run
More file actions
executable file
·89 lines (79 loc) · 3.32 KB
/
asgard-run
File metadata and controls
executable file
·89 lines (79 loc) · 3.32 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
#!/usr/bin/env bash
set -e
GAME_NAME=$1
ROOT_DIR="$(cd "$(dirname "$0")" && pwd)"
GAMES_DIR="$ROOT_DIR/games"
# Defaults (can be overridden by per-game asgard.cfg)
GAMESCOPE_WIDTH=${GAMESCOPE_WIDTH:-1280}
GAMESCOPE_HEIGHT=${GAMESCOPE_HEIGHT:-1024}
USE_GAMESCOPE=${USE_GAMESCOPE:-1}
USE_PADSP=${USE_PADSP:-1}
SOFTWARE_GL=${SOFTWARE_GL:-1}
MESA_YEAR=${MESA_YEAR:-}
SAVE_DIRS=() # Array of "host_dir:container_dir" pairs
LAUNCH_CMD="" # Custom launch command (default: ./<game> or ./<game>.sh)
PRE_LAUNCH="" # Commands to run inside the container before launching the game
USE_STRACE=${USE_STRACE:-1} # Workaround for games with init race conditions
GAMESCOPE_ARGS="" # Extra gamescope arguments
HOST_WRAPPER="" # Command to wrap the docker run (e.g. "pasuspender --" to free /dev/dsp)
EXTRA_ENV="" # Extra environment variable to pass into container (KEY=VALUE)
# Source per-game config if it exists
if [[ -f "$ROOT_DIR/config/$GAME_NAME.cfg" ]]; then
source "$ROOT_DIR/config/$GAME_NAME.cfg"
fi
DOCKER_EXTRA_ARGS=()
if [[ "$SOFTWARE_GL" == "1" ]]; then
DOCKER_EXTRA_ARGS+=(-e LIBGL_ALWAYS_SOFTWARE=1)
fi
if [[ -n "$MESA_YEAR" ]]; then
DOCKER_EXTRA_ARGS+=(-e "MESA_EXTENSION_MAX_YEAR=$MESA_YEAR")
fi
for save_dir in "${SAVE_DIRS[@]}"; do
host_dir="${save_dir%%:*}"
container_dir="${save_dir#*:}"
mkdir -p "$host_dir"
DOCKER_EXTRA_ARGS+=(-v "$host_dir:$container_dir:rw")
done
# Pass /dev/dsp if available (OSS emulation via snd-pcm-oss kernel module)
# Note: --privileged exposes all /dev/dsp* devices; use SDL_PATH_DSP env var to select one
if [[ -e /dev/dsp ]]; then
DOCKER_EXTRA_ARGS+=(--device /dev/dsp)
fi
if [[ -n "$EXTRA_ENV" ]]; then
DOCKER_EXTRA_ARGS+=(-e "$EXTRA_ENV")
fi
xhost +local:docker > /dev/null 2>&1
GAMESCOPE_CMD=""
if [[ "$USE_GAMESCOPE" == "1" ]]; then
GAMESCOPE_CMD="gamescope -w $GAMESCOPE_WIDTH -h $GAMESCOPE_HEIGHT $GAMESCOPE_ARGS --"
fi
uid=$(id -u)
$GAMESCOPE_CMD $HOST_WRAPPER docker run \
--rm \
-e DISPLAY=$DISPLAY \
--privileged \
--network host \
--device /dev/snd \
--device /dev/dri \
--group-add=audio \
-v /etc/machine-id:/etc/machine-id \
-v /var/lib/dbus:/var/lib/dbus \
-e PULSE_SERVER=unix:${XDG_RUNTIME_DIR}/pulse/native \
-v ${XDG_RUNTIME_DIR}/pulse/native:${XDG_RUNTIME_DIR}/pulse/native \
-v ${HOME}/.config/pulse/cookie:/home/loki/.config/pulse/cookie:ro \
--group-add $(getent group audio | cut -d: -f3) \
-v "${HOME}/.Xauthority:/home/loki/.Xauthority:rw" \
-v "${HOME}/.loki:/home/loki/.loki:rw" \
-v "/tmp/.X11-unix:/tmp/.X11-unix:rw" \
-v "${XDG_RUNTIME_DIR}:/run/loki/$uid:rw" \
-v "/media/cdrom:/cdrom" \
--env=DISPLAY \
--env=XDG_RUNTIME_DIR=/run/user/$uid \
"${DOCKER_EXTRA_ARGS[@]}" \
-e GAME_NAME="$GAME_NAME" \
-e LAUNCH_CMD="$LAUNCH_CMD" \
-e PRE_LAUNCH="$PRE_LAUNCH" \
-e USE_STRACE="$USE_STRACE" \
-e USE_PADSP="$USE_PADSP" \
$GAME_NAME \
bash -c 'cd /home/loki/game && export LD_LIBRARY_PATH=./lib:$LD_LIBRARY_PATH && [ -n "$PRE_LAUNCH" ] && eval "$PRE_LAUNCH"; STRACE="" && [ "$USE_STRACE" = "1" ] && STRACE="strace -e trace=none -o /dev/null -f"; PADSP="" && [ "$USE_PADSP" = "1" ] && PADSP="padsp"; if [ -n "$LAUNCH_CMD" ]; then $STRACE $PADSP $LAUNCH_CMD; elif [ -e "${GAME_NAME}.sh" ]; then $STRACE $PADSP ./${GAME_NAME}.sh; else $STRACE $PADSP ./${GAME_NAME}; fi'