#!/bin/sh## Copyright (C) 2024 Red Hat, Inc.# SPDX-License-Identifier: LGPL-2.1-or-later# Build and install tree as systemd-sysext.# See ../HACKING.MD section "Working on your local machine: systemd-sysext"set -euSYSEXT_NAME="cockpit-git"SYSEXT_DIR="/run/extensions/$SYSEXT_NAME"build() {rm -rf tmp/sysextif [ ! -e Makefile ]; then./autogen.sh --prefix=/usr --sysconfdir=/etc --localstatedir=/var --enable-debug --disable-dependency-trackingfimake install DESTDIR=tmp/sysextinstall -D -m 644 $PAMFILE tmp/sysext/usr/lib/pam.d/cockpitinstall -d tmp/sysext/usr/lib/extension-release.dprintf "ID=$ID\nVERSION_ID=$VERSION_ID\n" > tmp/sysext/usr/lib/extension-release.d/"extension-release.$SYSEXT_NAME"}stop() {if systemctl is-active --quiet cockpit.socket; thensystemctl stop cockpit.socketfiif systemctl is-enabled --quiet cockpit.socket; thensystemctl disable cockpit.socketfiif [ -d $SYSEXT_DIR ]; thenrm -rf "$SYSEXT_DIR"fiif systemd-sysext --no-legend status | grep -qw "$SYSEXT_NAME"; thensystemd-sysext refreshfi}if [ "${1:-}" = root-stop ]; thenstopexit 0fiif [ "${1:-}" = install ]; thenstopmkdir -p "$(dirname $SYSEXT_DIR)"cp -r tmp/sysext "$SYSEXT_DIR"systemd-sysext refreshechosystemd-sysext status --no-pagersystemctl start cockpit.socketexit 0fi. /etc/os-releasecase "$ID" in# rolling release, no $VERSION_IDarch) PAMFILE=tools/arch/cockpit.pam; VERSION_ID=latest ;;fedora|centos|rhel|bazzite) PAMFILE=tools/cockpit.pam ;;debian|ubuntu) PAMFILE=tools/cockpit.debian.pam ;;*) echo "Unsupported distribution: $ID"; exit 1 ;;esac# build mode# call ourselves in install modeif [ "${1:-}" = "stop" ]; thenarg="root-stop"elsebuildarg="install"fiif systemd-detect-virt --quiet --container; thenflatpak-spawn --host run0 "$0" "$arg"elserun0 "$0" "$arg"fi