Debian Codegraph @

examples/state-scripts/retain-ssh-keys/Download_Leave_01

raw symbols SCIP
1 #!/bin/sh
2 #
3 # Retain ssh server keys from the current root
4 #
5
6 echo "$(cat /etc/mender/artifact_info): Running $(basename "$0")" >&2
7
8 if [ ! -x /sbin/fw_printenv ]; then
9 exit 1
10 fi
11
12 current=$(/sbin/fw_printenv mender_boot_part | awk -F = '{ print $2 }')
13
14 if [ $current = "2" ]; then
15 newroot=/dev/mmcblk0p3
16 elif [ $current = "3" ]; then
17 newroot=/dev/mmcblk0p2
18 else
19 echo "Unexpected current root: $current" >&2
20 exit 1
21 fi
22
23 mount $newroot /mnt
24
25 if [ $? -ne 0 ]; then
26 echo "Failed to mount $newroot" >&2
27 exit 1
28 fi
29
30 sleep 2
31
32 if [ -d /mnt/etc/ssh ]; then
33 keys=$(ls -l /mnt/etc/ssh/*key* 2>/dev/null | wc -l)
34
35 if [ $keys -eq 0 ]; then
36 cp /etc/ssh/*key* /mnt/etc/ssh
37 else
38 echo "Found ssh keys in new root, skipping copy" >&2
39 fi
40 else
41 echo "Failed to find a /etc/ssh on newroot partition" >&2
42 exit 1
43 fi
44
45 umount $newroot