Debian Codegraph @

debian/cryptsetup-nuke-password.postinst

raw
1 #!/bin/sh
2
3 set -e
4
5 . /usr/share/debconf/confmodule
6
7 password_hash_path="/etc/cryptsetup-nuke-password/password_hash"
8
9 get_nuke_password() {
10 db_get cryptsetup-nuke-password/password || true
11 local NUKE_PASS="$RET"
12 db_get cryptsetup-nuke-password/password-again || true
13 local NUKE_PASS_CONFIRMATION="$RET"
14
15 if [ "$NUKE_PASS" != "$NUKE_PASS_CONFIRMATION" ]; then
16 return
17 fi
18
19 echo -n "$NUKE_PASS"
20 }
21
22 log() {
23 if [ -n "$DEBCONF_RECONFIGURE" ]; then
24 echo "$1"
25 fi
26 }
27
28 store_password_hash() {
29 local password=$(get_nuke_password)
30
31 if [ -z "$password" ]; then
32 if [ -e "$password_hash_path" ]; then
33 log "INFO: Keeping current nuke password."
34 else
35 log "INFO: No nuke password found in debconf's database, nothing to configure."
36 log "INFO: Try 'dpkg-reconfigure cryptsetup-nuke-password' to set a nuke password."
37 fi
38 return
39 fi
40
41 echo "INFO: Storing the nuke password's crypted hash in $password_hash_path"
42 mkdir -p $(dirname $password_hash_path)
43 :> $password_hash_path
44 chmod 600 $password_hash_path
45 echo "$password" | /usr/lib/cryptsetup-nuke-password/crypt --generate >$password_hash_path
46
47 # Drop the password from the debconf database for extra safety
48 db_reset cryptsetup-nuke-password/password || true
49 db_reset cryptsetup-nuke-password/password-again || true
50 }
51
52 update_initramfs() {
53 # The usual postinst run already triggers it due to the "triggers"
54 # file generated by dh_installinitramfs. But there's no harm in
55 # triggering twice and we want to make sure it also gets triggered
56 # when the postinst is run by dpkg-reconfigure.
57 dpkg-trigger --no-await update-initramfs
58 }
59
60 configure_nuke_password() {
61 if test "$(dpkg-divert --truename /lib/cryptsetup/askpass)" != /lib/cryptsetup/askpass; then
62 dpkg-divert --no-rename --package cryptsetup-nuke-password \
63 --divert /lib/cryptsetup/askpass.cryptsetup.usr-is-merged \
64 --remove /lib/cryptsetup/askpass
65 fi
66
67 db_get cryptsetup-nuke-password/already-configured || true
68 what="$RET"
69
70 case "$what" in
71 keep)
72 # Nothing to do, move on
73 if [ -e "$password_hash_path" ]; then
74 log "INFO: Keeping current nuke password."
75 fi
76 ;;
77 remove)
78 if [ -e "$password_hash_path" ]; then
79 echo "INFO: Removing current nuke password."
80 rm -f "$password_hash_path"
81 fi
82 update_initramfs
83 ;;
84 overwrite)
85 store_password_hash
86 update_initramfs
87 ;;
88 *)
89 echo "WARNING: unexpected value in debconf's cryptsetup-nuke-password/already-configured: '$what'" >&2
90 ;;
91 esac
92
93 # Reset to default value for next time we reconfigure
94 db_reset cryptsetup-nuke-password/already-configured || true
95 }
96
97 case "$1" in
98 configure)
99 configure_nuke_password
100 ;;
101 esac
102
103 #DEBHELPER#