summaryrefslogtreecommitdiff
path: root/package/cryptinit/src/cryptinitsc
blob: c29e231eeb94ec56c790b39f4c16ea1afad29925 (plain)
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
#!/bin/sh

load_modules() {
	(sed "s,^[^#][^[:space:]]*,insmod /lib/modules/$(uname -r)/&.ko," $* | sh 2>&- || :)
}

echo -n "Kernel currently running: "
uname -rsmo
echo -n "Kernel parameters: "; cat /proc/cmdline
for word in $(cat /proc/cmdline) ; do
    case $word in
         [a-z]*=*)
             eval "export $word"
             ;;
    esac
done

echo 0 > /proc/sys/kernel/printk

load_modules /etc/modules
for f in /etc/modules.d/*; do
	[[ -e $f ]] && load_modules /etc/modules.d/*
	break
done

mount /dev/sda1 /boot
mkdir -p /var/run/openct
openct-control init
pcscd -f >/dev/null &
sleep 2

fail=0
count=0
while true; do
	pkcs15-crypt --decipher --input /boot/key  --pkcs1 --raw >/tmp/skey
	cryptsetup -d /tmp/skey --batch-mode luksOpen $swap swapcrypt
	if [ $? = 0 ];then
		break
	fi
	if [ $count = 2 ];then
		echo "You are not allowed"
		sleep 3
		fail=1
		break
	fi
	count=$(($count+1))
done

if [ $fail -eq 1 ];then
	echo "Poweroff."
	p
fi

echo "Try to resume from hibernation"
echo "254:0" > /sys/power/resume

cryptsetup -d /tmp/skey --batch-mode luksOpen $root rootcrypt
swapon /dev/mapper/swapcrypt
mount /dev/mapper/rootcrypt /mnt
pkill pcscd
rm /tmp/skey
umount /proc
umount /sys
umount /dev/pts
umount /tmp