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