#!/bin/sh -eu# This is the install script for cockpit-ws when run in a privileged container# We expect that cockpit-bridge and related stuff is already in the host.## The host file system must be mounted at /hostIMAGE=${1:-}cd /PATH="/bin:/sbin"if [ ! -d /host/etc -o ! -d /host/proc -o ! -d /host/run ]; thenecho "cockpit-run: host file system is not mounted at /host" >&2exit 1fiif [ -f /host/usr/libexec/cockpit-ws ]; thenecho "cockpit-ws must not be installed in the host" >&2exit 1fiset -x# Copy the cockpit pam file into the host, since the PAM stack is gonna run# on the host with host PAM modules, and the host files, such as /etc/shadow# However we must ensure that it doesn't have selinux stuff ... because well,# containers and SELinux don't mix (yet?)sed -e '/pam_selinux/d' -e '/pam_sepermit/d' /etc/pam.d/cockpit > /host/etc/pam.d/cockpit# Make sure that we have required directories in the hostmkdir -p /host/etc/cockpit/ws-certs.d /host/etc/cockpit/machines.dchmod 755 /host/etc/cockpit/ws-certs.d /host/etc/cockpit/machines.dchown root:root /host/etc/cockpit/ws-certs.d /host/etc/cockpit/machines.d# For sharing ssh's known hosts with containermkdir -p /etc/ssh# For podman, generate a systemd unit for starting on bootif [ "${container:-}" = oci -o "${container:-}" = podman ] && [ -n "$IMAGE" ] && [ ! -e /host/etc/systemd/system/cockpit.service ]; thenmkdir -p /host/etc/systemd/system/cat << EOF > /host/etc/systemd/system/cockpit.service[Unit]Description=$IMAGE podman container[Service]Type=oneshotExecStartPre=-/usr/bin/podman rm -f cockpit-wsExecStart=/usr/bin/podman container runlabel --name cockpit-ws RUN $IMAGEExecStop=/usr/bin/podman rm -f cockpit-wsRemainAfterExit=yesKillMode=none[Install]WantedBy=multi-user.targetEOFfi# Ensure we have certificates/bin/mount --bind /host/etc/cockpit /etc/cockpit/usr/libexec/cockpit-certificate-ensure