@@ -1,118 +1,118 | |||||
1 | #!/bin/sh |
|
1 | #!/bin/sh | |
2 | # Setup fstab and initramfs |
|
2 | # Setup fstab and initramfs | |
3 | # |
|
3 | # | |
4 |
|
4 | |||
5 | # Load utility functions |
|
5 | # Load utility functions | |
6 | . ./functions.sh |
|
6 | . ./functions.sh | |
7 |
|
7 | |||
8 | # Install and setup fstab |
|
8 | # Install and setup fstab | |
9 | install_readonly files/mount/fstab "${ETC_DIR}/fstab" |
|
9 | install_readonly files/mount/fstab "${ETC_DIR}/fstab" | |
10 |
|
10 | |||
11 | # Add usb/sda disk root partition to fstab |
|
11 | # Add usb/sda disk root partition to fstab | |
12 | if [ "$ENABLE_SPLITFS" = true ] && [ "$ENABLE_CRYPTFS" = false ] ; then |
|
12 | if [ "$ENABLE_SPLITFS" = true ] && [ "$ENABLE_CRYPTFS" = false ] ; then | |
13 | sed -i "s/mmcblk0p2/sda1/" "${ETC_DIR}/fstab" |
|
13 | sed -i "s/mmcblk0p2/sda1/" "${ETC_DIR}/fstab" | |
14 | fi |
|
14 | fi | |
15 |
|
15 | |||
16 | if [ "$ENABLE_USBBOOT" = true ] ; then |
|
16 | if [ "$ENABLE_USBBOOT" = true ] ; then | |
17 | sed -i "s/mmcblk0p1/sda1/" "${ETC_DIR}/fstab" |
|
17 | sed -i "s/mmcblk0p1/sda1/" "${ETC_DIR}/fstab" | |
18 | sed -i "s/mmcblk0p2/sda2/" "${ETC_DIR}/fstab" |
|
18 | sed -i "s/mmcblk0p2/sda2/" "${ETC_DIR}/fstab" | |
19 | fi |
|
19 | fi | |
20 |
|
20 | |||
21 | # Generate initramfs file |
|
21 | # Generate initramfs file | |
22 | if [ "$ENABLE_INITRAMFS" = true ] ; then |
|
22 | if [ "$ENABLE_INITRAMFS" = true ] ; then | |
23 | if [ "$ENABLE_CRYPTFS" = true ] ; then |
|
23 | if [ "$ENABLE_CRYPTFS" = true ] ; then | |
24 | if [ "$ENABLE_USBBOOT" = true ] ; then |
|
24 | if [ "$ENABLE_USBBOOT" = true ] ; then | |
25 | # Add usb/sda2 disk to crypttab |
|
25 | # Add usb/sda2 disk to crypttab | |
26 | sed -i "s/mmcblk0p2/sda2/" "${ETC_DIR}/crypttab" |
|
26 | sed -i "s/mmcblk0p2/sda2/" "${ETC_DIR}/crypttab" | |
27 | fi |
|
27 | fi | |
28 |
|
28 | |||
29 | # Include initramfs scripts to auto expand encrypted root partition |
|
29 | # Include initramfs scripts to auto expand encrypted root partition | |
30 | if [ "$EXPANDROOT" = true ] ; then |
|
30 | if [ "$EXPANDROOT" = true ] ; then | |
31 | install_exec files/initramfs/expand_encrypted_rootfs "${ETC_DIR}/initramfs-tools/scripts/init-premount/expand_encrypted_rootfs" |
|
31 | install_exec files/initramfs/expand_encrypted_rootfs "${ETC_DIR}/initramfs-tools/scripts/init-premount/expand_encrypted_rootfs" | |
32 | install_exec files/initramfs/expand-premount "${ETC_DIR}/initramfs-tools/scripts/local-premount/expand-premount" |
|
32 | install_exec files/initramfs/expand-premount "${ETC_DIR}/initramfs-tools/scripts/local-premount/expand-premount" | |
33 | install_exec files/initramfs/expand-tools "${ETC_DIR}/initramfs-tools/hooks/expand-tools" |
|
33 | install_exec files/initramfs/expand-tools "${ETC_DIR}/initramfs-tools/hooks/expand-tools" | |
34 | fi |
|
34 | fi | |
35 |
|
35 | |||
36 | # Replace fstab root partition with encrypted partition mapping |
|
36 | # Replace fstab root partition with encrypted partition mapping | |
37 | sed -i "s/mmcblk0p2/mapper\/${CRYPTFS_MAPPING}/" "${ETC_DIR}/fstab" |
|
37 | sed -i "s/mmcblk0p2/mapper\/${CRYPTFS_MAPPING}/" "${ETC_DIR}/fstab" | |
38 |
|
38 | |||
39 | # Add encrypted partition to crypttab and fstab |
|
39 | # Add encrypted partition to crypttab and fstab | |
40 | install_readonly files/mount/crypttab "${ETC_DIR}/crypttab" |
|
40 | install_readonly files/mount/crypttab "${ETC_DIR}/crypttab" | |
41 | echo "${CRYPTFS_MAPPING} /dev/mmcblk0p2 none luks,initramfs" >> "${ETC_DIR}/crypttab" |
|
41 | echo "${CRYPTFS_MAPPING} /dev/mmcblk0p2 none luks,initramfs" >> "${ETC_DIR}/crypttab" | |
42 |
|
42 | |||
43 | # Add encrypted root partition to fstab and crypttab |
|
43 | # Add encrypted root partition to fstab and crypttab | |
44 | if [ "$ENABLE_SPLITFS" = true ] ; then |
|
44 | if [ "$ENABLE_SPLITFS" = true ] ; then | |
45 | # Add usb/sda1 disk to crypttab |
|
45 | # Add usb/sda1 disk to crypttab | |
46 | sed -i "s/mmcblk0p2/sda1/" "${ETC_DIR}/crypttab" |
|
46 | sed -i "s/mmcblk0p2/sda1/" "${ETC_DIR}/crypttab" | |
47 | fi |
|
47 | fi | |
48 |
|
48 | |||
49 | if [ "$CRYPTFS_DROPBEAR" = true ]; then |
|
49 | if [ "$CRYPTFS_DROPBEAR" = true ]; then | |
50 | if [ "$ENABLE_DHCP" = false ] ; then |
|
50 | if [ "$ENABLE_DHCP" = false ] ; then | |
51 | # Get cdir from NET_ADDRESS e.g. 24 |
|
51 | # Get cdir from NET_ADDRESS e.g. 24 | |
52 | cdir=$(printf "%s" "${NET_ADDRESS}" | cut -d '/' -f2) |
|
52 | cdir=$(printf "%s" "${NET_ADDRESS}" | cut -d '/' -f2) | |
53 |
|
53 | |||
54 | # Convert cdir ro netmask e.g. 24 to 255.255.255.0 |
|
54 | # Convert cdir ro netmask e.g. 24 to 255.255.255.0 | |
55 | NET_MASK=$(cdr2mask "$cdir") |
|
55 | NET_MASK=$(cdr2mask "$cdir") | |
56 |
|
56 | |||
57 | # Write static ip settings to "${ETC_DIR}"/initramfs-tools/initramfs.conf |
|
57 | # Write static ip settings to "${ETC_DIR}"/initramfs-tools/initramfs.conf | |
58 | sed -i "\$aIP=${NET_ADDRESS}::${NET_GATEWAY}:${NET_MASK}:${HOSTNAME}:" "${ETC_DIR}"/initramfs-tools/initramfs.conf |
|
58 | sed -i "\$a\nIP=${NET_ADDRESS}::${NET_GATEWAY}:${NET_MASK}:${HOSTNAME}:" "${ETC_DIR}"/initramfs-tools/initramfs.conf | |
59 |
|
59 | |||
60 | #Regenerate initramfs |
|
60 | #Regenerate initramfs | |
61 | chroot_exec mkinitramfs -o "/boot/firmware/initramfs-${KERNEL_VERSION}" "${KERNEL_VERSION}" |
|
61 | #chroot_exec mkinitramfs -o "/boot/firmware/initramfs-${KERNEL_VERSION}" "${KERNEL_VERSION}" | |
62 | fi |
|
62 | fi | |
63 |
|
63 | |||
64 | if [ -n "$CRYPTFS_DROPBEAR_PUBKEY" ] && [ -f "$CRYPTFS_DROPBEAR_PUBKEY" ] ; then |
|
64 | if [ -n "$CRYPTFS_DROPBEAR_PUBKEY" ] && [ -f "$CRYPTFS_DROPBEAR_PUBKEY" ] ; then | |
65 | install_readonly "${CRYPTFS_DROPBEAR_PUBKEY}" "${ETC_DIR}"/dropbear-initramfs/id_rsa.pub |
|
65 | install_readonly "${CRYPTFS_DROPBEAR_PUBKEY}" "${ETC_DIR}"/dropbear-initramfs/id_rsa.pub | |
66 | cat "${ETC_DIR}"/dropbear-initramfs/id_rsa.pub >> "${ETC_DIR}"/dropbear-initramfs/authorized_keys |
|
66 | cat "${ETC_DIR}"/dropbear-initramfs/id_rsa.pub >> "${ETC_DIR}"/dropbear-initramfs/authorized_keys | |
67 | else |
|
67 | else | |
68 | # Create key |
|
68 | # Create key | |
69 | chroot_exec /usr/bin/dropbearkey -t rsa -f /etc/dropbear-initramfs/id_rsa.dropbear |
|
69 | chroot_exec /usr/bin/dropbearkey -t rsa -f /etc/dropbear-initramfs/id_rsa.dropbear | |
70 |
|
70 | |||
71 | # Convert dropbear key to openssh key |
|
71 | # Convert dropbear key to openssh key | |
72 | chroot_exec /usr/lib/dropbear/dropbearconvert dropbear openssh /etc/dropbear-initramfs/id_rsa.dropbear /etc/dropbear-initramfs/id_rsa |
|
72 | chroot_exec /usr/lib/dropbear/dropbearconvert dropbear openssh /etc/dropbear-initramfs/id_rsa.dropbear /etc/dropbear-initramfs/id_rsa | |
73 |
|
73 | |||
74 | # Get Public Key Part |
|
74 | # Get Public Key Part | |
75 | chroot_exec /usr/bin/dropbearkey -y -f /etc/dropbear-initramfs/id_rsa.dropbear | chroot_exec tee /etc/dropbear-initramfs/id_rsa.pub |
|
75 | chroot_exec /usr/bin/dropbearkey -y -f /etc/dropbear-initramfs/id_rsa.dropbear | chroot_exec tee /etc/dropbear-initramfs/id_rsa.pub | |
76 |
|
76 | |||
77 | # Delete unwanted lines |
|
77 | # Delete unwanted lines | |
78 | sed -i '/Public/d' "${ETC_DIR}"/dropbear-initramfs/id_rsa.pub |
|
78 | sed -i '/Public/d' "${ETC_DIR}"/dropbear-initramfs/id_rsa.pub | |
79 | sed -i '/Fingerprint/d' "${ETC_DIR}"/dropbear-initramfs/id_rsa.pub |
|
79 | sed -i '/Fingerprint/d' "${ETC_DIR}"/dropbear-initramfs/id_rsa.pub | |
80 |
|
80 | |||
81 | # Trust the new key |
|
81 | # Trust the new key | |
82 | cat "${ETC_DIR}"/dropbear-initramfs/id_rsa.pub > "${ETC_DIR}"/dropbear-initramfs/authorized_keys |
|
82 | cat "${ETC_DIR}"/dropbear-initramfs/id_rsa.pub > "${ETC_DIR}"/dropbear-initramfs/authorized_keys | |
83 |
|
83 | |||
84 | # Save Keys - convert with putty from rsa/openssh to puttkey |
|
84 | # Save Keys - convert with putty from rsa/openssh to puttkey | |
85 | cp -f "${ETC_DIR}"/dropbear-initramfs/id_rsa "${BASEDIR}"/dropbear_initramfs_key.rsa |
|
85 | cp -f "${ETC_DIR}"/dropbear-initramfs/id_rsa "${BASEDIR}"/dropbear_initramfs_key.rsa | |
86 |
|
86 | |||
87 | # Get unlock script |
|
87 | # Get unlock script | |
88 | install_exec files/initramfs/crypt_unlock.sh "${ETC_DIR}"/initramfs-tools/hooks/crypt_unlock.sh |
|
88 | install_exec files/initramfs/crypt_unlock.sh "${ETC_DIR}"/initramfs-tools/hooks/crypt_unlock.sh | |
89 |
|
89 | |||
90 | # Enable Dropbear inside initramfs |
|
90 | # Enable Dropbear inside initramfs | |
91 | printf "#\n# DROPBEAR: [ y | n ]\n#\n\nDROPBEAR=y\n" >> "${ETC_DIR}/initramfs-tools/initramfs.conf" |
|
91 | printf "#\n# DROPBEAR: [ y | n ]\n#\n\nDROPBEAR=y\n" >> "${ETC_DIR}/initramfs-tools/initramfs.conf" | |
92 |
|
92 | |||
93 | # Enable Dropbear inside initramfs |
|
93 | # Enable Dropbear inside initramfs | |
94 | sed -i "54 i sleep 5" "${R}"/usr/share/initramfs-tools/scripts/init-premount/dropbear |
|
94 | sed -i "54 i sleep 5" "${R}"/usr/share/initramfs-tools/scripts/init-premount/dropbear | |
95 | fi |
|
95 | fi | |
96 | # CRYPTFSDROPBEAR=false |
|
96 | # CRYPTFSDROPBEAR=false | |
97 | else |
|
97 | else | |
98 | # Disable SSHD inside initramfs |
|
98 | # Disable SSHD inside initramfs | |
99 | printf "#\n# DROPBEAR: [ y | n ]\n#\n\nDROPBEAR=n\n" >> "${ETC_DIR}/initramfs-tools/initramfs.conf" |
|
99 | printf "#\n# DROPBEAR: [ y | n ]\n#\n\nDROPBEAR=n\n" >> "${ETC_DIR}/initramfs-tools/initramfs.conf" | |
100 | fi |
|
100 | fi | |
101 |
|
101 | |||
102 | # Add cryptsetup modules to initramfs |
|
102 | # Add cryptsetup modules to initramfs | |
103 | printf "#\n# CRYPTSETUP: [ y | n ]\n#\n\nCRYPTSETUP=y\n" >> "${ETC_DIR}/initramfs-tools/conf-hook" |
|
103 | printf "#\n# CRYPTSETUP: [ y | n ]\n#\n\nCRYPTSETUP=y\n" >> "${ETC_DIR}/initramfs-tools/conf-hook" | |
104 |
|
104 | |||
105 | # Dummy mapping required by mkinitramfs |
|
105 | # Dummy mapping required by mkinitramfs | |
106 | echo "0 1 crypt $(echo "${CRYPTFS_CIPHER}" | cut -d ':' -f 1) ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff 0 7:0 4096" | chroot_exec dmsetup create "${CRYPTFS_MAPPING}" |
|
106 | echo "0 1 crypt $(echo "${CRYPTFS_CIPHER}" | cut -d ':' -f 1) ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff 0 7:0 4096" | chroot_exec dmsetup create "${CRYPTFS_MAPPING}" | |
107 |
|
107 | |||
108 | # Generate initramfs with encrypted root partition support |
|
108 | # Generate initramfs with encrypted root partition support | |
109 | chroot_exec mkinitramfs -o "/boot/firmware/initramfs-${KERNEL_VERSION}" "${KERNEL_VERSION}" |
|
109 | chroot_exec mkinitramfs -o "/boot/firmware/initramfs-${KERNEL_VERSION}" "${KERNEL_VERSION}" | |
110 |
|
110 | |||
111 | # Remove dummy mapping |
|
111 | # Remove dummy mapping | |
112 | chroot_exec cryptsetup close "${CRYPTFS_MAPPING}" |
|
112 | chroot_exec cryptsetup close "${CRYPTFS_MAPPING}" | |
113 | # CRYPTFS=false |
|
113 | # CRYPTFS=false | |
114 | else |
|
114 | else | |
115 | # Generate initramfs without encrypted root partition support |
|
115 | # Generate initramfs without encrypted root partition support | |
116 | chroot_exec mkinitramfs -o "/boot/firmware/initramfs-${KERNEL_VERSION}" "${KERNEL_VERSION}" |
|
116 | chroot_exec mkinitramfs -o "/boot/firmware/initramfs-${KERNEL_VERSION}" "${KERNEL_VERSION}" | |
117 | fi |
|
117 | fi | |
118 | fi |
|
118 | fi |
General Comments 0
Vous devez vous connecter pour laisser un commentaire.
Se connecter maintenant