sector-f-linux

Sector F Linux
git clone https://git.sectorflabs.com/sector-f-linux.git
Log | Files | Refs | README | LICENSE

vm-try.sh (2514B)


      1 #!/usr/bin/env bash
      2 # Tries the greeter in the test VM (linux/vm), under cage as greetd runs it, on the mock backend:
      3 # the real compositor, the image's own Mesa and a real keyboard, which a desktop-less shell
      4 # does not have. The VM must be up (`make run` in the repository root).
      5 #
      6 #   greeter/vm-try.sh build            build it in the Fedora builder (links what the image has)
      7 #   greeter/vm-try.sh install          put the binary in the VM (a writable /usr until it reboots)
      8 #   greeter/vm-try.sh show login       run it there: login or setup, with a demo state if given
      9 #   greeter/vm-try.sh show setup filled    (GREETER_ENV='PATINA_SKIN=...' adds environment)
     10 #   greeter/vm-try.sh type 'Alice\tpw\n'   type into it (\t Tab, \n Enter)
     11 #   greeter/vm-try.sh shot [file.png]  the VM's screen (default linux/out/screen.png)
     12 #   greeter/vm-try.sh restore          greetd back on gtkgreet, which survives a reboot
     13 set -euo pipefail
     14 here=$(cd "$(dirname "$0")" && pwd)
     15 repo=$(cd "$here/.." && pwd)
     16 vm="$repo/linux/vm/vm.sh"
     17 
     18 greetd() {  # greetd's session command, restarted
     19   $vm ssh "cat > /etc/greetd/config.toml <<CFG
     20 [terminal]
     21 vt = 1
     22 
     23 [default_session]
     24 command = \"$1\"
     25 user = \"greetd\"
     26 CFG
     27 systemctl stop greetd 2>/dev/null; systemctl reset-failed greetd; systemctl start greetd; sleep 10"
     28 }
     29 
     30 case "${1:-}" in
     31   build)
     32     docker run --rm --user "$(id -u):$(id -g)" -e CARGO_HOME=/cargo -e HOME=/tmp \
     33       -v patina-os-cargo:/cargo -v "$repo:/repo" -w /repo/greeter patina-os-desktop-builder \
     34       cargo build --release --target-dir /repo/greeter/target-fedora
     35     ;;
     36   install)
     37     $vm ssh 'touch /usr/.w 2>/dev/null && rm -f /usr/.w || bootc usroverlay >/dev/null 2>&1; systemctl stop greetd 2>/dev/null; sleep 1
     38              cat > /usr/libexec/patina-greeter && chmod 755 /usr/libexec/patina-greeter && restorecon /usr/libexec/patina-greeter' \
     39       < "$here/target-fedora/release/patina-greeter"
     40     ;;
     41   show)
     42     greetd "env ${2:+PATINA_GREETER_MOCK=$2} PATINA_GREETER_DEMO=${3:-} ${GREETER_ENV:-} cage -s -- /usr/libexec/patina-greeter"
     43     ;;
     44   type)
     45     python3 "$here/vm-keys.py" "${2:?what to type}"
     46     ;;
     47   shot)
     48     # QEMU writes the file itself, relative to its own directory: so the path is made absolute.
     49     out=${2:-$repo/linux/out/screen.png}
     50     $vm screenshot "$(cd "$(dirname "$out")" && pwd)/$(basename "$out")"
     51     ;;
     52   restore)
     53     greetd "cage -s -- gtkgreet -c 'patina-session --session'"
     54     ;;
     55   *)
     56     sed -n '2,13p' "$0" | sed 's/^# \{0,1\}//'
     57     exit 2
     58     ;;
     59 esac