| 1 | #!/bin/shscip-shell filesystem . . `/bin/sh`. |
| 2 | # |
| 3 | # Copyright (C) 2024 Red Hat, Inc. |
| 4 | # SPDX-License-Identifier: LGPL-2.1-or-later |
| 5 | |
| 6 | |
| 7 | # Build and install tree as systemd-sysext. |
| 8 | # See ../HACKING.MD section "Working on your local machine: systemd-sysext" |
| 9 | |
| 10 | set -eu |
| 11 | |
| 12 | SYSEXT_NAME="cockpit-git" |
| 13 | SYSEXT_DIR="/run/extensions/$SYSEXT_NAME" |
| 14 | |
| 15 | buildscip-shell shell shell-project 0.0.0 build().() { |
| 16 | rmscip-shell system . . rm. -rf tmp/sysext |
| 17 | if [scip-shell system . . `[`. ! -e Makefile ]; then |
| 18 | ./autogen.sh --prefix=/usr --sysconfdir=/etc --localstatedir=/var --enable-debug --disable-dependency-tracking |
| 19 | fi |
| 20 | makescip-shell system . . make. install DESTDIR=tmp/sysext |
| 21 | installscip-shell system . . install. -D -m 644 $PAMFILE tmp/sysext/usr/lib/pam.d/cockpit |
| 22 | installscip-shell system . . install. -d tmp/sysext/usr/lib/extension-release.d |
| 23 | printfscip-shell system . . printf. "ID=$ID\nVERSION_ID=$VERSION_ID\n" > tmp/sysext/usr/lib/extension-release.d/"extension-release.$SYSEXT_NAME" |
| 24 | } |
| 25 | |
| 26 | stopscip-shell shell shell-project 0.0.0 stop().() { |
| 27 | if systemctl is-active --quiet cockpit.socket; then |
| 28 | systemctl stop cockpit.socket |
| 29 | fi |
| 30 | if systemctl is-enabled --quiet cockpit.socket; then |
| 31 | systemctl disable cockpit.socket |
| 32 | fi |
| 33 | if [scip-shell system . . `[`. -d $SYSEXT_DIR ]; then |
| 34 | rmscip-shell system . . rm. -rf "$SYSEXT_DIR" |
| 35 | fi |
| 36 | if systemd-sysext --no-legend status | grepscip-shell system . . grep. -qw "$SYSEXT_NAME"; then |
| 37 | systemd-sysext refresh |
| 38 | fi |
| 39 | } |
| 40 | |
| 41 | if [scip-shell system . . `[`. "${1:-}" = root-stop ]; then |
| 42 | stopscip-shell shell shell-project 0.0.0 stop(). |
| 43 | exit 0 |
| 44 | fi |
| 45 | |
| 46 | if [scip-shell system . . `[`. "${1:-}" = install ]; then |
| 47 | stopscip-shell shell shell-project 0.0.0 stop(). |
| 48 | mkdirscip-shell system . . mkdir. -p "$(dirnamescip-shell system . . dirname. $SYSEXT_DIR)" |
| 49 | cpscip-shell system . . cp. -r tmp/sysext "$SYSEXT_DIR" |
| 50 | systemd-sysext refresh |
| 51 | |
| 52 | echoscip-shell system . . echo. |
| 53 | systemd-sysext status --no-pager |
| 54 | |
| 55 | systemctl start cockpit.socket |
| 56 | exit 0 |
| 57 | fi |
| 58 | |
| 59 | . /etc/os-releasescip-shell source . . `/etc/os-release`. |
| 60 | |
| 61 | case "$ID" in |
| 62 | # rolling release, no $VERSION_ID |
| 63 | arch) PAMFILE=tools/arch/cockpit.pam; VERSION_ID=latest ;; |
| 64 | fedora|centos|rhel|bazzite) PAMFILE=tools/cockpit.pam ;; |
| 65 | debian|ubuntu) PAMFILE=tools/cockpit.debian.pam ;; |
| 66 | *) echoscip-shell system . . echo. "Unsupported distribution: $ID"; exit 1 ;; |
| 67 | esac |
| 68 | |
| 69 | # build mode |
| 70 | |
| 71 | # call ourselves in install mode |
| 72 | if [scip-shell system . . `[`. "${1:-}" = "stop" ]; then |
| 73 | arg="root-stop" |
| 74 | else |
| 75 | buildscip-shell shell shell-project 0.0.0 build(). |
| 76 | arg="install" |
| 77 | fi |
| 78 | |
| 79 | if systemd-detect-virt --quiet --container; then |
| 80 | flatpak-spawn --host run0 "$0" "$arg" |
| 81 | else |
| 82 | run0 "$0" "$arg" |
| 83 | fi |