Skip to content

Instantly share code, notes, and snippets.

@elmarco
Created February 6, 2022 21:33
Show Gist options
  • Save elmarco/0178036a288d0859567a5a4f88409237 to your computer and use it in GitHub Desktop.
Save elmarco/0178036a288d0859567a5a4f88409237 to your computer and use it in GitHub Desktop.
#!/bin/sh
if [ -z "$XDG_CONFIG_HOME" ]; then
XDG_CONFIG_HOME="$HOME/.config"
fi
if [ -z "$XDG_DATA_HOME" ]; then
XDG_DATA_HOME="$HOME/.local/share"
fi
MSYS2_ETC="$XDG_CONFIG_HOME/msys2/etc"
MSYS2_ROOT="$XDG_DATA_HOME/msys2"
mkdir -p "$MSYS2_ROOT/"{mingw32,mingw64,ucrt64,var/cache/pacman,var/lib/pacman,run}
FEDORA_MINGW32_SYSROOT="/usr/i686-w64-mingw32/sys-root/mingw"
FEDORA_MINGW64_SYSROOT="/usr/x86_64-w64-mingw32/sys-root/mingw"
AS_ROOT="--uid 0 --gid 0"
CMD="$@"
if [ -z "$CMD" ]; then
CMD="$SHELL"
fi
export MSYS2=1
bwrap \
--unshare-user \
--share-net \
$AS_ROOT \
--bind "$MSYS2_ROOT" / \
--ro-bind /usr /usr \
--ro-bind /etc /etc \
--ro-bind /run/systemd /run/systemd \
--bind "$HOME" "$HOME" \
--proc /proc \
--dev /dev \
--ro-bind "$MSYS2_ROOT/mingw32" "$FEDORA_MINGW32_SYSROOT" \
--ro-bind "$MSYS2_ROOT/mingw64" "$FEDORA_MINGW64_SYSROOT" \
--ro-bind "$MSYS2_ETC/pacman.conf" /etc/pacman.conf \
--ro-bind "$MSYS2_ETC/pacman.d" /etc/pacman.d \
--ro-bind "$MSYS2_ROOT" "$MSYS2_ROOT" \
"$CMD"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment