aboutsummaryrefslogtreecommitdiffstats
path: root/export-image/04-finalise/01-run.sh
blob: e05bfbdf29504a2acb6417a82f4eb1f41da314bc (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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/bin/bash -e

if [ -z "${DEPLOY_DIR}" ] ; then
    echo "Error: Empty DEPLOY_DIR"
    exit 1
elif [ "${DEPLOY_DIR}" = "/" ] ; then
    echo "Error: DEPLOY_DIR is root"
    exit 1
fi

DEPLOY_DIR2="${DEPLOY_DIR}/${IMG_FILENAME}"

IMG_FILE="${STAGE_WORK_DIR}/${IMG_FILENAME}${IMG_SUFFIX}.img"
INFO_FILE="${STAGE_WORK_DIR}/${IMG_FILENAME}${IMG_SUFFIX}.info"

IMG_FILE_ROOT_EXT4="${STAGE_WORK_DIR}/${IMG_FILENAME}${IMG_SUFFIX}.root-ext4.img"
IMG_FILE_ROOT_SQFS_GZ="${STAGE_WORK_DIR}/${IMG_FILENAME}${IMG_SUFFIX}.root-sqfs_gz.img"
IMG_FILE_ROOT_SQFS_LZO="${STAGE_WORK_DIR}/${IMG_FILENAME}${IMG_SUFFIX}.root-sqfs_lzo.img"
IMG_FILE_ROOT_SQFS_NONE="${STAGE_WORK_DIR}/${IMG_FILENAME}${IMG_SUFFIX}.root-sqfs_none.img"
INFO_FILE_ROOT="${STAGE_WORK_DIR}/${IMG_FILENAME}${IMG_SUFFIX}.root.info"

on_chroot << EOF
    if [ -x /etc/init.d/fake-hwclock ]; then
        /etc/init.d/fake-hwclock stop
    fi
    if hash hardlink 2>/dev/null; then
        hardlink -t /usr/share/doc
    fi

    if [ "${REDUCED_FOOTPRINT}" = "1" ]; then
        # Keep in sync:
        #  stage0/00-configure-apt/files/01_nodoc 
        #  export-image/04-finalise/01-run.sh 
        find /usr/share/doc -depth -type f ! -name copyright|xargs rm || true
        find /usr/share/doc -empty|xargs rmdir || true
        rm -rf /usr/share/man /usr/share/groff /usr/share/info /usr/share/lintian /usr/share/linda /var/cache/man
        find /usr/share/locale -mindepth 1 -maxdepth 1 ! -name 'en*' ! -name 'da*' ! -name 'de*' ! -name 'es*' ! -name 'fi*' ! -name 'fr*' ! -name 'is*' ! -name 'nb*' ! -name 'ru*' !  -name 'sv*' ! -name 'zh*' |xargs rm -r
    fi
EOF

if [ -d "${ROOTFS_DIR}/home/${FIRST_USER_NAME}/.config" ]; then
	chmod 700 "${ROOTFS_DIR}/home/${FIRST_USER_NAME}/.config"
fi

rm -f "${ROOTFS_DIR}/usr/bin/qemu-arm-static"

if [ "${USE_QEMU}" != "1" ]; then
	if [ -e "${ROOTFS_DIR}/etc/ld.so.preload.disabled" ]; then
		mv "${ROOTFS_DIR}/etc/ld.so.preload.disabled" "${ROOTFS_DIR}/etc/ld.so.preload"
	fi
fi

rm -f "${ROOTFS_DIR}/etc/network/interfaces.dpkg-old"

rm -f "${ROOTFS_DIR}/etc/apt/sources.list~"
rm -f "${ROOTFS_DIR}/etc/apt/trusted.gpg~"

rm -f "${ROOTFS_DIR}/etc/passwd-"
rm -f "${ROOTFS_DIR}/etc/group-"
rm -f "${ROOTFS_DIR}/etc/shadow-"
rm -f "${ROOTFS_DIR}/etc/gshadow-"
rm -f "${ROOTFS_DIR}/etc/subuid-"
rm -f "${ROOTFS_DIR}/etc/subgid-"

rm -f "${ROOTFS_DIR}"/var/cache/debconf/*-old
rm -f "${ROOTFS_DIR}"/var/lib/dpkg/*-old

rm -f "${ROOTFS_DIR}"/usr/share/icons/*/icon-theme.cache

rm -f "${ROOTFS_DIR}/var/lib/dbus/machine-id"

true > "${ROOTFS_DIR}/etc/machine-id"

ln -nsf /proc/mounts "${ROOTFS_DIR}/etc/mtab"

find "${ROOTFS_DIR}/var/log/" -type f -exec cp /dev/null {} \;

rm -f "${ROOTFS_DIR}/root/.vnc/private.key"
rm -f "${ROOTFS_DIR}/etc/vnc/updateid"

print_issue "$(basename "${EXPORT_DIR}")" > "${ROOTFS_DIR}/etc/rpi-issue"
install -m 644 "${ROOTFS_DIR}/etc/rpi-issue" "${ROOTFS_DIR}/boot/issue.txt"

cp "$ROOTFS_DIR/etc/rpi-issue" "$INFO_FILE"

if [ "${ROOTFS_RO}" = "1" ] ; then
    cp "$INFO_FILE" "$INFO_FILE_ROOT"
    echo >> "$INFO_FILE_ROOT"
    echo "+++" >> "$INFO_FILE_ROOT"
    echo >> "$INFO_FILE_ROOT"
    echo "Root Partition `basename $IMG_FILE_ROOT_EXT4`" >> "$INFO_FILE_ROOT"
    echo "Root Partition of `basename $IMG_FILE`" >> "$INFO_FILE_ROOT"
    echo >> "$INFO_FILE_ROOT"
fi

rm -rf "${DEPLOY_DIR2}"
mkdir -p "${DEPLOY_DIR2}"

if [ "${ROOTFS_RO}" = "1" ] ; then
    cp -a "${ROOTFS_DIR}/boot" "${DEPLOY_DIR2}/sdcard${IMG_SUFFIX}"
fi

unload_qimage
make_bootable_image "${STAGE_WORK_DIR}/${IMG_FILENAME}${IMG_SUFFIX}.qcow2" \
    "$IMG_FILE" \
    "$IMG_FILE_ROOT_EXT4" "$INFO_FILE_ROOT"

if [ "${ROOTFS_RO}" = "1" ] ; then
    mount -o ro "$IMG_FILE_ROOT_EXT4" "${ROOTFS_DIR}"
    mksquashfs "${ROOTFS_DIR}" "${IMG_FILE_ROOT_SQFS_GZ}" -comp gzip
    mksquashfs "${ROOTFS_DIR}" "${IMG_FILE_ROOT_SQFS_LZO}" -comp lzo
    mksquashfs "${ROOTFS_DIR}" "${IMG_FILE_ROOT_SQFS_NONE}" -noI -noD -noF -noX
    umount "${ROOTFS_DIR}"
    cp -a "$INFO_FILE_ROOT" "${DEPLOY_DIR2}/sdcard${IMG_SUFFIX}/sys_arm64_000/rootfs.inf"
fi
mv "$INFO_FILE" "$INFO_FILE_ROOT" "$DEPLOY_DIR2/"

if [ "${DEPLOY_ZIP}" == "1" ]; then
	gzip -k "$IMG_FILE"
    mv "$IMG_FILE".gz "$DEPLOY_DIR2/"
    if [ "${ROOTFS_RO}" = "1" ] ; then
        gzip -k "$IMG_FILE_ROOT_EXT4"
        mv "$IMG_FILE_ROOT_EXT4".gz "$DEPLOY_DIR2/"
    fi
fi

mv "$IMG_FILE" "$DEPLOY_DIR2/"

if [ "${ROOTFS_RO}" = "1" ] ; then
    # cp -a "$IMG_FILE_ROOT_EXT4" "${DEPLOY_DIR2}/sdcard${IMG_SUFFIX}/sys_arm64_000/rootfs.img"
    cp -a "$IMG_FILE_ROOT_SQFS_LZO" "${DEPLOY_DIR2}/sdcard${IMG_SUFFIX}/sys_arm64_000/rootfs.img"

    ( cd "${DEPLOY_DIR2}/sdcard${IMG_SUFFIX}"; zip -r0 "../${IMG_FILENAME}${IMG_SUFFIX}.sdcard.zip" . )

    mv "$IMG_FILE_ROOT_EXT4" "$DEPLOY_DIR2/"
    mv "$IMG_FILE_ROOT_SQFS_GZ" "$DEPLOY_DIR2/"
    mv "$IMG_FILE_ROOT_SQFS_LZO" "$DEPLOY_DIR2/"
    mv "$IMG_FILE_ROOT_SQFS_NONE" "$DEPLOY_DIR2/"
fi

rm -f "${STAGE_WORK_DIR}/SHA256SUMS"
( cd "${DEPLOY_DIR2}"; find . -maxdepth 1 -type f -exec sha256sum -b \{\} >> "${STAGE_WORK_DIR}/SHA256SUMS" \; )
mv "${STAGE_WORK_DIR}/SHA256SUMS" "$DEPLOY_DIR2/"