#!/bin/bash

DISCORD_PATH="/opt/discord"
RUNTIME_DIR="/run/user/$(id -u)"

bwrap \
  --ro-bind /usr /usr \
  --ro-bind /lib /lib \
  --ro-bind /lib64 /lib64 \
  --ro-bind "$DISCORD_PATH" "$DISCORD_PATH" \
  --bind ~/.config/discord ~/.config/discord \
  --bind ~/Descargas ~/Descargas \
  --dev /dev \
  --dev-bind /dev/dri /dev/dri \
  --proc /proc \
  --tmpfs /tmp \
  --unshare-all \
  --share-net \
  --ro-bind /etc/resolv.conf /etc/resolv.conf \
  --ro-bind /etc/hosts /etc/hosts \
  --bind "$RUNTIME_DIR/pulse" "$RUNTIME_DIR/pulse" \
  --bind /tmp/.X11-unix /tmp/.X11-unix \
  --setenv HOME "$HOME" \
  --setenv XDG_RUNTIME_DIR "$RUNTIME_DIR" \
  --setenv DBUS_SESSION_BUS_ADDRESS "$DBUS_SESSION_BUS_ADDRESS" \
  --setenv PULSE_SERVER "unix:$RUNTIME_DIR/pulse/native" \
  --setenv DISPLAY "$DISPLAY" \
  --unsetenv WAYLAND_DISPLAY \
  "$DISCORD_PATH/Discord"

