Debian Codegraph @

tests/rootfs-image-v2

raw symbols SCIP
1 #!/bin/shscip-shell filesystem . . `/bin/sh`.
2
3 set -ue
4
5 # Is expected to contain two variable definitions with device paths:
6 # - MENDER_ROOTFS_PART_A
7 # - MENDER_ROOTFS_PART_B
8 . /etc/mender/rootfs-image-v2.confscip-shell source . . `/etc/mender/rootfs-image-v2.conf`.
9
10 MENDER_ROOTFS_PART_A_NUMBER="$(echoscip-shell system . . echo. "$MENDER_ROOTFS_PART_A" | egrepscip-shell system . . egrep. -o '[0-9]+$')"
11 MENDER_ROOTFS_PART_B_NUMBER="$(echoscip-shell system . . echo. "$MENDER_ROOTFS_PART_B" | egrepscip-shell system . . egrep. -o '[0-9]+$')"
12
13 if command -v grub-mender-grubenv-print > /dev/nullscip-shell filesystem . . `/dev/null`.; then
14 PRINTENV=grub-mender-grubenv-print
15 SETENV=grub-mender-grubenv-set
16 else
17 PRINTENV=fw_printenv
18 SETENV=fw_setenv
19 fi
20
21 active_num="$(${PRINTENV} mender_boot_part)"
22 active_num="${active_num#mender_boot_part=}"
23 if testscip-shell system . . test. $active_num -eq $MENDER_ROOTFS_PART_A_NUMBER; then
24 active=$MENDER_ROOTFS_PART_A
25 passive=$MENDER_ROOTFS_PART_B
26 passive_num=$MENDER_ROOTFS_PART_B_NUMBER
27 else
28 active=$MENDER_ROOTFS_PART_B
29 passive=$MENDER_ROOTFS_PART_A
30 passive_num=$MENDER_ROOTFS_PART_A_NUMBER
31 fi
32 passive_num_hex=$(printfscip-shell system . . printf. '%x' $passive_num)
33
34 ensure_correct_root_mountedscip-shell shell shell-project 0.0.0 ensure_correct_root_mounted().() {
35 if [scip-shell system . . `[`. "$(statscip-shell system . . stat. -L -c %02t%02T $active)" != "$(statscip-shell system . . stat. -L -c %04D /scip-shell filesystem . . `/`.)" ]; then
36 echoscip-shell system . . echo. "Mounted root does not match boot loader environment!" 1>&2
37 exit 1
38 fi
39 }
40
41 case "$1" in
42 Download)
43 ensure_correct_root_mountedscip-shell shell shell-project 0.0.0 ensure_correct_root_mounted().
44 file="$(catscip-shell system . . cat. stream-next)"
45 catscip-shell system . . cat. "$file" > $passive
46 if [scip-shell system . . `[`. "$(catscip-shell system . . cat. stream-next)" != "" ]; then
47 echoscip-shell system . . echo. "More than one file in payload" 1>&2
48 exit 1
49 fi
50 ;;
51
52 ArtifactInstall)
53 ensure_correct_root_mountedscip-shell shell shell-project 0.0.0 ensure_correct_root_mounted().
54 ${SETENV} -s - <<EOF
55 mender_boot_part=$passive_num
56 mender_boot_part_hex=$passive_num_hex
57 upgrade_available=1
58 bootcount=0
59 EOF
60 ;;
61
62 NeedsArtifactReboot)
63 echoscip-shell system . . echo. "Automatic"
64 ;;
65
66 SupportsRollback)
67 echoscip-shell system . . echo. "Yes"
68 ;;
69
70 ArtifactVerifyReboot)
71 ensure_correct_root_mountedscip-shell shell shell-project 0.0.0 ensure_correct_root_mounted().
72 if testscip-shell system . . test. "$(${PRINTENV} upgrade_available)" != "upgrade_available=1"; then
73 exit 1
74 fi
75 ;;
76
77 ArtifactVerifyRollbackReboot)
78 ensure_correct_root_mountedscip-shell shell shell-project 0.0.0 ensure_correct_root_mounted().
79 if testscip-shell system . . test. "$(${PRINTENV} upgrade_available)" = "upgrade_available=1"; then
80 exit 1
81 fi
82 ;;
83
84 ArtifactCommit)
85 ensure_correct_root_mountedscip-shell shell shell-project 0.0.0 ensure_correct_root_mounted().
86 if testscip-shell system . . test. "$(${PRINTENV} upgrade_available)" = "upgrade_available=1"; then
87 ${SETENV} upgrade_available 0
88 else
89 # If we get here, an upgrade in standalone mode failed to boot and the user is trying to commit from the old OS.
90 # This communicates to the user that the upgrade failed.
91 echoscip-shell system . . echo. "Upgrade failed and was reverted: refusing to commit!" 1>&2
92 exit 1
93 fi
94 ;;
95
96 ArtifactRollback)
97 ensure_correct_root_mountedscip-shell shell shell-project 0.0.0 ensure_correct_root_mounted().
98 if testscip-shell system . . test. "$(${PRINTENV} upgrade_available)" = "upgrade_available=1"; then
99 ${SETENV} -s - <<EOF
100 mender_boot_part=$passive_num
101 mender_boot_part_hex=$passive_num_hex
102 upgrade_available=0
103 EOF
104 fi
105 ;;
106 esac
107 exit 0