···11+#!/usr/bin/env sh
22+33+# bwrap-preset-renpy
44+#
55+# Run an executable in a Bubblewrap sandbox set up for Ren'Py games. The saves
66+# directory will be in '$XDG_CONFIG_DIR/renpy' or '$HOME/.config/renpy' instead
77+# of the normal '$HOME/.renpy'.
88+99+set -eu
1010+1111+# Set script title for error messages.
1212+SCRIPT_TITLE="Run in Bubblewrap (Ren'Py)"
1313+1414+# Notify the user of an error and exit.
1515+notify_and_exit () {
1616+ # Make sure enough arguments were given.
1717+ if [ "$#" -ne 2 ]; then
1818+ printf "Error: notify_and_exit() called with '%i' arguments\n" "$#"
1919+ exit 127
2020+ fi
2121+2222+ # Name the arguments.
2323+ error_msg="$1"
2424+ exit_code="$2"
2525+2626+ # Either print to stdout or send a notification.
2727+ if [ "$TERM" = "dumb" ]; then
2828+ notify-send --urgency=normal --icon=error "$SCRIPT_TITLE" "$error_msg"
2929+ else
3030+ printf "%s: %s\n" "$SCRIPT_TITLE" "$error_msg"
3131+ fi
3232+3333+ # Exit with the error code.
3434+ exit "$exit_code"
3535+}
3636+3737+# Only one command can be run.
3838+[ "$#" -ne 1 ] && notify_and_exit "Only one command can be run with this script" 1
3939+4040+4141+# Make sure Bubblewrap is installed.
4242+if ! command -v bwrap > /dev/null 2>&1; then
4343+ notify_and_exit "Could not find executable \`bwrap\`" 1
4444+fi
4545+4646+# Set the Ren'Py saves directory.
4747+if [ ! -z "$\{XDG_CONFIG_HOME+x\}" ]; then
4848+ RENPY_SAVE_DIR="$XDG_CONFIG_HOME/renpy"
4949+else
5050+ RENPY_SAVE_DIR="$HOME/.config/renpy"
5151+fi
5252+5353+# Create the Ren'Py saves directory if it doesn't exist.
5454+[ ! -d "$RENPY_SAVE_DIR" ] && mkdir -p "$RENPY_SAVE_DIR"
5555+5656+# Get the full path of the file.
5757+executable=$(realpath "$1")
5858+5959+# Get the directory the file is contained in so it can be mounted int the
6060+# sandbox.
6161+executable_dir=$(dirname "$executable")
6262+6363+# Make sure the file is executable.
6464+[ ! -x "$executable" ] && notify_and_exit "File \`$executable\` is not executable" 1
6565+6666+# Run the specified command in Bubblewrap. Unshare all namespaces, and bind the
6767+# working directory and Ren'Py saves directory.
6868+exec bwrap \
6969+ --unshare-all \
7070+ --die-with-parent \
7171+ --new-session \
7272+ --unsetenv RENPY_PATH_TO_SAVES \
7373+ --ro-bind "/" "/" \
7474+ --dev "/dev" \
7575+ --dev-bind "/dev/dri" "/dev/dri" \
7676+ --proc "/proc" \
7777+ --tmpfs "$HOME" \
7878+ --bind "$XDG_CONFIG_HOME/MangoHud" "$XDG_CONFIG_HOME/MangoHud" \
7979+ --bind "$executable_dir" "$executable_dir" \
8080+ --bind "$RENPY_SAVE_DIR" "$HOME/.renpy" \
8181+ "$executable"
8282+
+1
private_dot_local/private_share/nautilus/private_scripts/symlink_Run in Bubblewrap (Ren'Py)