···
5
+
# Run an executable in a Bubblewrap sandbox set up for Ren'Py games. The saves
6
+
# directory will be in '$XDG_CONFIG_DIR/renpy' or '$HOME/.config/renpy' instead
7
+
# of the normal '$HOME/.renpy'.
11
+
# Set script title for error messages.
12
+
SCRIPT_TITLE="Run in Bubblewrap (Ren'Py)"
14
+
# Notify the user of an error and exit.
15
+
notify_and_exit () {
16
+
# Make sure enough arguments were given.
17
+
if [ "$#" -ne 2 ]; then
18
+
printf "Error: notify_and_exit() called with '%i' arguments\n" "$#"
22
+
# Name the arguments.
26
+
# Either print to stdout or send a notification.
27
+
if [ "$TERM" = "dumb" ]; then
28
+
notify-send --urgency=normal --icon=error "$SCRIPT_TITLE" "$error_msg"
30
+
printf "%s: %s\n" "$SCRIPT_TITLE" "$error_msg"
33
+
# Exit with the error code.
37
+
# Only one command can be run.
38
+
[ "$#" -ne 1 ] && notify_and_exit "Only one command can be run with this script" 1
41
+
# Make sure Bubblewrap is installed.
42
+
if ! command -v bwrap > /dev/null 2>&1; then
43
+
notify_and_exit "Could not find executable \`bwrap\`" 1
46
+
# Set the Ren'Py saves directory.
47
+
if [ ! -z "$\{XDG_CONFIG_HOME+x\}" ]; then
48
+
RENPY_SAVE_DIR="$XDG_CONFIG_HOME/renpy"
50
+
RENPY_SAVE_DIR="$HOME/.config/renpy"
53
+
# Create the Ren'Py saves directory if it doesn't exist.
54
+
[ ! -d "$RENPY_SAVE_DIR" ] && mkdir -p "$RENPY_SAVE_DIR"
56
+
# Get the full path of the file.
57
+
executable=$(realpath "$1")
59
+
# Get the directory the file is contained in so it can be mounted int the
61
+
executable_dir=$(dirname "$executable")
63
+
# Make sure the file is executable.
64
+
[ ! -x "$executable" ] && notify_and_exit "File \`$executable\` is not executable" 1
66
+
# Run the specified command in Bubblewrap. Unshare all namespaces, and bind the
67
+
# working directory and Ren'Py saves directory.
72
+
--unsetenv RENPY_PATH_TO_SAVES \
75
+
--dev-bind "/dev/dri" "/dev/dri" \
78
+
--bind "$XDG_CONFIG_HOME/MangoHud" "$XDG_CONFIG_HOME/MangoHud" \
79
+
--bind "$executable_dir" "$executable_dir" \
80
+
--bind "$RENPY_SAVE_DIR" "$HOME/.renpy" \