···
+
# Run an executable in a Bubblewrap sandbox set up for Ren'Py games. The saves
+
# directory will be in '$XDG_CONFIG_DIR/renpy' or '$HOME/.config/renpy' instead
+
# of the normal '$HOME/.renpy'.
+
# Set script title for error messages.
+
SCRIPT_TITLE="Run in Bubblewrap (Ren'Py)"
+
# Notify the user of an error and exit.
+
# Make sure enough arguments were given.
+
if [ "$#" -ne 2 ]; then
+
printf "Error: notify_and_exit() called with '%i' arguments\n" "$#"
+
# Either print to stdout or send a notification.
+
if [ "$TERM" = "dumb" ]; then
+
notify-send --urgency=normal --icon=error "$SCRIPT_TITLE" "$error_msg"
+
printf "%s: %s\n" "$SCRIPT_TITLE" "$error_msg"
+
# Exit with the error code.
+
# Only one command can be run.
+
[ "$#" -ne 1 ] && notify_and_exit "Only one command can be run with this script" 1
+
# Make sure Bubblewrap is installed.
+
if ! command -v bwrap > /dev/null 2>&1; then
+
notify_and_exit "Could not find executable \`bwrap\`" 1
+
# Set the Ren'Py saves directory.
+
if [ ! -z "$\{XDG_CONFIG_HOME+x\}" ]; then
+
RENPY_SAVE_DIR="$XDG_CONFIG_HOME/renpy"
+
RENPY_SAVE_DIR="$HOME/.config/renpy"
+
# Create the Ren'Py saves directory if it doesn't exist.
+
[ ! -d "$RENPY_SAVE_DIR" ] && mkdir -p "$RENPY_SAVE_DIR"
+
# Get the full path of the file.
+
executable=$(realpath "$1")
+
# Get the directory the file is contained in so it can be mounted int the
+
executable_dir=$(dirname "$executable")
+
# Make sure the file is executable.
+
[ ! -x "$executable" ] && notify_and_exit "File \`$executable\` is not executable" 1
+
# Run the specified command in Bubblewrap. Unshare all namespaces, and bind the
+
# working directory and Ren'Py saves directory.
+
--unsetenv RENPY_PATH_TO_SAVES \
+
--dev-bind "/dev/dri" "/dev/dri" \
+
--bind "$XDG_CONFIG_HOME/MangoHud" "$XDG_CONFIG_HOME/MangoHud" \
+
--bind "$executable_dir" "$executable_dir" \
+
--bind "$RENPY_SAVE_DIR" "$HOME/.renpy" \