|
| 1 | +#!/bin/bash |
| 2 | +# This file is part of dracut. |
| 3 | +# SPDX-License-Identifier: GPL-2.0-or-later |
| 4 | + |
| 5 | +# Prerequisite check(s) for module. |
| 6 | +check() { |
| 7 | + |
| 8 | + # If the binary(s) requirements are not fulfilled the module can't be installed. |
| 9 | + require_binaries \ |
| 10 | + portablectl \ |
| 11 | + "$systemdutildir"/systemd-portabled \ |
| 12 | + || return 1 |
| 13 | + |
| 14 | + # Return 255 to only include the module, if another module requires it. |
| 15 | + return 255 |
| 16 | + |
| 17 | +} |
| 18 | + |
| 19 | +# Module dependency requirements. |
| 20 | +depends() { |
| 21 | + |
| 22 | + # This module has external dependency on other module(s). |
| 23 | + echo dbus |
| 24 | + # Return 0 to include the dependent module(s) in the initramfs. |
| 25 | + return 0 |
| 26 | + |
| 27 | +} |
| 28 | + |
| 29 | +# Install kernel module(s). |
| 30 | +installkernel() { |
| 31 | + instmods loop squashfs |
| 32 | +} |
| 33 | + |
| 34 | +# Install the required file(s) and directories for the module in the initramfs. |
| 35 | +install() { |
| 36 | + |
| 37 | + # It's intended to work only with raw binary disk images contained in |
| 38 | + # regular files, but not with directory trees. |
| 39 | + local _nonraw |
| 40 | + _nonraw=$(portablectl --no-pager --no-legend list | grep -v " raw " | cut -d ' ' -f1 | tr '\n' ' ') |
| 41 | + if [ -n "$_nonraw" ]; then |
| 42 | + dwarn "systemd-portabled: this module only installs raw disk images in the initramfs; skipping: $_nonraw" |
| 43 | + fi |
| 44 | + |
| 45 | + inst_multiple -o \ |
| 46 | + "/var/lib/portables/*.raw" \ |
| 47 | + "/usr/lib/portables/*.raw" \ |
| 48 | + "$tmpfilesdir/portables.conf" \ |
| 49 | + "$dbussystem"/org.freedesktop.portable1.conf \ |
| 50 | + "$dbussystemservices"/org.freedesktop.portable1.service \ |
| 51 | + "$systemdutildir"/systemd-portabled \ |
| 52 | + "$systemdutildir/portable/profile/default/*.conf" \ |
| 53 | + "$systemdutildir/portable/profile/nonetwork/*.conf" \ |
| 54 | + "$systemdutildir/portable/profile/strict/*.conf" \ |
| 55 | + "$systemdutildir/portable/profile/trusted/*.conf" \ |
| 56 | + "$systemdsystemunitdir"/systemd-portabled.service \ |
| 57 | + "$systemdsystemunitdir/systemd-portabled.service.d/*.conf" \ |
| 58 | + "$systemdsystemunitdir"/dbus-org.freedesktop.portable1.service \ |
| 59 | + portablectl |
| 60 | + |
| 61 | + # The existence of this file is required |
| 62 | + touch "$initdir"/etc/resolv.conf |
| 63 | + |
| 64 | + # Enable systemd type unit(s) |
| 65 | + $SYSTEMCTL -q --root "$initdir" add-wants initrd.target systemd-portabled.service |
| 66 | + $SYSTEMCTL -q --root "$initdir" enable systemd-portabled.service |
| 67 | + |
| 68 | + # Install the hosts local user configurations if enabled. |
| 69 | + if [[ $hostonly ]]; then |
| 70 | + inst_multiple -H -o \ |
| 71 | + "/etc/portables/*.raw" \ |
| 72 | + "$systemdutilconfdir/system.attached/*" \ |
| 73 | + "$systemdutilconfdir/system.attached/*/*" \ |
| 74 | + "$systemdutilconfdir/portable/profile/default/*.conf" \ |
| 75 | + "$systemdutilconfdir/portable/profile/nonetwork/*.conf" \ |
| 76 | + "$systemdutilconfdir/portable/profile/strict/*.conf" \ |
| 77 | + "$systemdutilconfdir/portable/profile/trusted/*.conf" \ |
| 78 | + "$systemdsystemconfdir"/systemd-portabled.service \ |
| 79 | + "$systemdsystemconfdir/systemd-portabled.service.d/*.conf" |
| 80 | + fi |
| 81 | + |
| 82 | +} |
0 commit comments