summaryrefslogtreecommitdiff
path: root/helpers/lh_genrootfs
blob: 5853ed271e3de1ab43197a4548b69269c4572ba4 (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
66
67
68
69
70
71
72
73
74
75
76
#!/bin/sh

# lh_genrootfs.sh <filesystem>

case "${LIVE_FILESYSTEM}" in
	ext2)
		DU_DIM="`du -ks ${LIVE_CHROOT} | cut -f1`"
		REAL_DIM="`expr ${DU_DIM} + ${DU_DIM} / 20`" # Just 5% more to be sure, need something more sophistcated here...

		if [ -z "${LIVE_ENCRYPTION}" ]
		then
			genext2fs --size-in-blocks=${REAL_DIM} --reserved-blocks=0 --root="${LIVE_CHROOT}" "${LIVE_ROOT}"/binary/casper/filesystem.ext2
		else
			echo "Encrypting ${LIVE_ROOT}/binary/casper/filesystem.ext2 with ${LIVE_ENCRYPTION}..."

			while true
			do
				genext2fs --size-in-blocks=${REAL_DIM} --reserved-blocks=0 --root="${LIVE_CHROOT}" | aespipe -e "${LIVE_ENCRYPTION}" -T > "${LIVE_ROOT}"/binary/casper/filesystem.ext2 && break

				echo -n "Something went wrong... Retry? [YES/no] "
				read ANSWER

				if [ 'no' = "${ANSWER}" ]
				then
					unset ANSWER
					break
 				fi
 			done
 		fi
		;;

	plain)
		if [ -n "${LIVE_ENCRYPTION}" ]
		then
			echo "Error: encryption is not supported for filesystem type 'plain'"
			exit 1
		fi

		cd "${LIVE_CHROOT}"
		find . | cpio -pumd "${LIVE_ROOT}"/binary/casper/filesystem.dir
		cd "${OLDPWD}"
		;;

	squashfs)
		if [ -f "${LIVE_ROOT}"/binary/casper/filesystem.squashfs ]
		then
			rm "${LIVE_ROOT}"/binary/casper/filesystem.squashfs
		fi

		if [ "${LIVE_FLAVOUR}" = "minimal" ] || [ "${LIVE_FLAVOUR}" = "mini" ]
		then
			mksquashfs "${LIVE_CHROOT}" "${LIVE_ROOT}"/binary/casper/filesystem.squashfs -e "${LIVE_CHROOT}"/boot/vmlinuz* "${LIVE_CHROOT}"/boot/initrd.img* "${LIVE_CHROOT}"/vmlinuz "${LIVE_CHROOT}"/initrd.img "${LIVE_CHROOT}"/boot/config-* "${LIVE_CHROOT}"/boot/System.map-*
		else
			mksquashfs "${LIVE_CHROOT}" "${LIVE_ROOT}"/binary/casper/filesystem.squashfs
		fi

		if [ -n "$LIVE_ENCRYPTION" ]
		then
			echo "Encrypting ${LIVE_ROOT}/binary/casper/filesystem.squashfs with ${LIVE_ENCRYPTION}..."

			while true
			do
				cat "${LIVE_ROOT}"/binary/casper/filesystem.squashfs | aespipe -e "${LIVE_ENCRYPTION}" -T > "${LIVE_ROOT}"/binary/casper/filesystem.squashfs.encrypted && mv "${LIVE_ROOT}"/binary/casper/filesystem.squashfs.encrypted "${LIVE_ROOT}"/binary/casper/filesystem.squashfs && break

				echo -n "Something went wrong... Retry? [YES/no] "
				read ANSWER

				if [ 'no' = "${ANSWER}" ]
				then
					unset ANSWER
					break
				fi
			done
		fi
		;;
esac