File: zz-depthcharge-tools

package info (click to toggle)
depthcharge-tools 0.6.2-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 760 kB
  • sloc: python: 6,286; sh: 650; makefile: 12
file content (76 lines) | stat: -rwxr-xr-x 2,134 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/sh

set -e

kversion="$1"
vmlinuz="${2:-/boot/vmlinuz-$kversion}"

set -- $DEB_MAINT_PARAMS
action="$1"
version="$2"

# Disable if our package is not installed.
if ! command -v depthchargectl >/dev/null 2>&1; then
    echo "Not writing depthcharge image, depthchargectl is missing." >&2
    exit 0
fi

# Ignore errors if we're not booted with depthcharge
maybe_error() {
    if grep "cros_secure" /proc/cmdline >/dev/null 2>&1; then
        echo "Failed to write depthcharge image, system may be unbootable." >&2
        exit 1
    else
        echo "Not booted with depthcharge, so ignoring that." >&2
        exit 0
    fi
}

# Disable based on package configuration
enabled="$(
    depthchargectl config \
        --section depthchargectl/write \
        --default False \
        enable-system-hooks
)" || maybe_error
if [ "$enabled" != "True" ]; then
    echo "Not writing depthcharge image, disabled by config." >&2
    exit 0
fi

board="$(depthchargectl config board)" || maybe_error
if [ "$board" = "none" ]; then
    echo "Cannot build depthcharge images when no board is specified." >&2
    maybe_error
fi

# Don't run if update-initramfs is going to generate an initramfs, as
# we will run after that anyway.
if [ -f /etc/kernel/postinst.d/initramfs-tools ] \
    && [ -x /usr/sbin/update-initramfs ] \
    && [ "$INITRD" != 'no' ]
then
    echo "Not writing depthcharge image, already did for initramfs update." >&2
    exit 0
fi

# Run only once at the end.
case "$action" in
    "configure"|"'configure'"|'')
        count="$(depthchargectl list -c)" || maybe_error
        if [ "$count" -gt 1 ]; then
            echo "Running depthchargectl write '$kversion':" >&2
            depthchargectl write "$kversion" >/dev/null \
                || maybe_error

        elif [ "$count" -eq 1 ]; then
            echo "Running depthchargectl write --allow-current '$kversion':" >&2
            depthchargectl write --allow-current "$kversion" >/dev/null \
                || maybe_error

        else
            echo "No usable Chrome OS Kernel partition found." >&2
            maybe_error
        fi
        ;;
esac