Skip to content

Instantly share code, notes, and snippets.

@xperia64
Last active January 13, 2024 21:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xperia64/9c2f9a5318df5cd61899b7c4111111ad to your computer and use it in GitHub Desktop.
Save xperia64/9c2f9a5318df5cd61899b7c4111111ad to your computer and use it in GitHub Desktop.
Bootstrapping a chroot on the Steam Deck
#!/bin/bash
# Largely adapted from https://www.reddit.com/r/SteamDeck/comments/xgslv9/howto_installing_pacman_packages_in_userspace/
if [ -z "$1" ] || [ -z "$2" ]; then
echo "Usage: $0 <chrootdir> <command>"
echo ""
echo "Possible commands:"
echo " init - initialize an empty directory as a chroot"
echo " pacman [args] - use the host pacman to manage packages within the chroot"
echo " chroot - calls arch-chroot on the chroot"
echo " venv - runs an interactive host shell using the chroot's binaries and libraries"
echo " run <command> - runs the given command on the host using the chroot's binaries and libaries"
exit 1
fi
if [ "$EUID" -ne 0 ] && [ "$2" != "venv" ] && [ "$2" != "run" ]; then
echo "Please run as root"
exit 2
fi
USERROOT="$1"
if [ ! -d "$USERROOT" ]; then
echo "Root dir doesn't exist"
exit 3
fi
PACMAN_CONF="$USERROOT/etc/pacman.conf"
GPGDIR="$USERROOT/etc/pacman.d/gnupg"
DBPATH="$USERROOT/usr/lib/holo/pacmandb"
CACHEDIR="$USERROOT/var/cache/pacman/pkg"
mkdir -p "$USERROOT/etc"
mkdir -p "$GPGDIR"
mkdir -p "$USERROOT/usr/lib/holo/pacmandb"
mkdir -p "$USERROOT/var/lib/pacman"
mkdir -p "$CACHEDIR"
if [ "$2" == "init" ]; then
cp /etc/pacman.conf "$USERROOT/etc/pacman.conf"
sed -i 's/^CheckSpace/#CheckSpace/g' "$USERROOT/etc/pacman.conf"
cp /etc/pacman.d/mirrorlist "$USERROOT/etc/pacman.d"
pacman-key --gpgdir "$GPGDIR" --conf "$PACMAN_CONF" --init
pacman-key --gpgdir "$GPGDIR" --conf "$PACMAN_CONF" --populate
elif [ "$2" == "pacman" ]; then
shift 2
pacman -r "$USERROOT" --gpgdir "$GPGDIR" --dbpath "$DBPATH" --cachedir "$CACHEDIR" "$@"
elif [ "$2" == "chroot" ]; then
arch-chroot "$USERROOT"
elif [ "$2" == "venv" ]; then
export PATH=$PATH:"$USERROOT/usr/bin"
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:"$USERROOT/lib":"$USERROOT/lib32"
echo "Entering venv..."
exec bash -i
elif [ "$2" == "run" ]; then
shift 2
export PATH=$PATH:"$USERROOT/usr/bin"
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:"$USERROOT/lib":"$USERROOT/lib32"
cmd="$1"
shift
"$cmd" "$@"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment