Skip to content

Instantly share code, notes, and snippets.

@parke
Last active June 16, 2021 19:21
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save parke/ec6fbba80878a43cfd63106ce5cf1ed0 to your computer and use it in GitHub Desktop.
flatpak.sh is a demo that shows how to install and run Flatpak packages inside of an Alpine Linux guest userland inside Lxroot.
#! /bin/dash
# version 20210616
# flatpak.sh is a demo that shows how to install and run Flatpak
# packages inside of an Alpine Linux guest userland inside Lxroot.
set -o errexit
demo=/tmp/flatpak-demo # demo workspace
nr="$demo"/newroot # demo newroot
trace () { echo "+ $@" ; "$@" ; } # --------------------- trace
main () { # ------------------------------------------------------ main
# make $demo directory
if [ -d "$demo" ]
then echo "found $demo"
else trace mkdir -p "$demo" ; fi
trace cd "$demo"
# download lxroot source code
if [ -d lxroot ]
then echo 'found lxroot'
else trace git clone https://github.com/parke/lxroot.git ; fi
trace cd lxroot
# build bin/lxroot
if [ -f bin/lxroot ]
then echo 'found bin/lxroot'
else trace make build ; fi
# download and extract Alpine Linux
if [ -d "$nr" ]
then echo "found $nr"
else trace bash demo.sh demo1_extract "$demo" "$nr" ; fi
# install resolv.conf
if [ -f "$nr"/etc/resolv.conf ]
then echo "found $nr/etc/resolv.conf"
else trace cp -n /etc/resolv.conf "$nr"/etc/ ; fi
# mkdir $HOME inside $nr
if [ -d "$nr/$HOME" ]
then echo "found $nr/$HOME"
else trace mkdir -p "$nr/$HOME" ; fi
# mkdir /tmp/.X11-unit inside $nr
if [ -d "$nr/tmp/.X11-unix" ]
then echo "found $nr/tmp/.X11-unix"
else trace mkdir -p "$nr/tmp/.X11-unix" ; fi
# lxroot options explained:
# -n allow network access
# -r simulate root user
# -w grant non-root users write access to all of newroot
# -x bind mount /tmp/.X11-unix and set $DISPLAY
# as (simulated) root, install Flatpak inside $nr
if [ -f "$nr"/usr/bin/flatpak ]
then echo "found $nr/usr/bin/flatpak"
else trace bin/lxroot -nr "$nr" apk update
trace bin/lxroot -nr "$nr" apk add flatpak || true ; fi
# as non-root, flatpak remote-add
echo ; echo '--------'
trace bin/lxroot -nw "$nr" \
flatpak --user remote-add --if-not-exists flathub \
https://dl.flathub.org/repo/flathub.flatpakrepo
# as non-root, install GnuCash
echo ; echo '--------'
trace bin/lxroot -nw "$nr" \
flatpak --user install flathub org.gnucash.GnuCash
# as non-root, run GnuCash
echo ; echo '--------'
trace bin/lxroot -wx "$nr" \
flatpak --user run org.gnucash.GnuCash
exit ; }
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment