aboutsummaryrefslogtreecommitdiffstats
path: root/export-image/04-finalise/01-run.sh
blob: 18e097ddbef126283e3f738fc230ed9e2a3ce64b (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
145
146
#!/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="${STAGE_WORK_DIR}/${IMG_FILENAME}${IMG_SUFFIX}.root.img"
INFO_FILE_ROOT="${STAGE_WORK_DIR}/${IMG_FILENAME}${IMG_SUFFIX}.root.info"
#IMG_FILE_BOOT="${STAGE_WORK_DIR}/${IMG_FILENAME}${IMG_SUFFIX}.boot.img"
#INFO_FILE_BOOT="${STAGE_WORK_DIR}/${IMG_FILENAME}${IMG_SUFFIX}.boot.info"
#IMG_FILE_DATA="${STAGE_WORK_DIR}/${IMG_FILENAME}${IMG_SUFFIX}.data.img"
#INFO_FILE_DATA="${STAGE_WORK_DIR}/${IMG_FILENAME}${IMG_SUFFIX}.data.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

    # 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 'de*' !  -name 'se*' ! -name 'fr*' |xargs rm -r
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"

cp "$INFO_FILE" "$INFO_FILE_ROOT"
#cp "$INFO_FILE" "$INFO_FILE_BOOT"
#cp "$INFO_FILE" "$INFO_FILE_DATA"

echo >> "$INFO_FILE_ROOT"
echo "+++" >> "$INFO_FILE_ROOT"
echo >> "$INFO_FILE_ROOT"
echo "Root Partition `basename $IMG_FILE_ROOT`" >> "$INFO_FILE_ROOT"
echo "Root Partition of `basename $IMG_FILE`" >> "$INFO_FILE_ROOT"
echo >> "$INFO_FILE_ROOT"

#echo >> "$INFO_FILE_BOOT"
#echo "+++" >> "$INFO_FILE_BOOT"
#echo >> "$INFO_FILE_BOOT"
#echo "Boot Partition `basename $IMG_FILE_BOOT`" >> "$INFO_FILE_BOOT"
#echo "Boot Partition of `basename $IMG_FILE`" >> "$INFO_FILE_BOOT"
#echo >> "$INFO_FILE_BOOT"

#echo >> "$INFO_FILE_DATA"
#echo "+++" >> "$INFO_FILE_DATA"
#echo >> "$INFO_FILE_DATA"
#echo "Data Partition `basename $IMG_FILE_DATA`" >> "$INFO_FILE_DATA"
#echo "Data Partition of `basename $IMG_FILE`" >> "$INFO_FILE_DATA"
#echo >> "$INFO_FILE_DATA"

rm -rf "${DEPLOY_DIR2}"
mkdir -p "${DEPLOY_DIR2}"
cp -a "${ROOTFS_DIR}/boot" "${DEPLOY_DIR2}/sdcard"
mkdir -p "${DEPLOY_DIR2}/sdcard/sys_arm64_000"

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

#    "$IMG_FILE_BOOT" "$INFO_FILE_BOOT" \
#    "$IMG_FILE_DATA" "$INFO_FILE_DATA"


cp -a "$INFO_FILE_ROOT" "${DEPLOY_DIR2}/sdcard/sys_arm64_000/rootfs.inf"
mv "$INFO_FILE" "$INFO_FILE_ROOT" "$DEPLOY_DIR2/"
#mv "$INFO_FILE" "$INFO_FILE_ROOT" "$INFO_FILE_BOOT" "$INFO_FILE_DATA" "$DEPLOY_DIR2/"

if [ "${DEPLOY_ZIP}" == "1" ]; then
	gzip -k "$IMG_FILE"
	gzip -k "$IMG_FILE_ROOT"
	#gzip -k "$IMG_FILE_BOOT"
	#gzip -k "$IMG_FILE_DATA"
    mv "$IMG_FILE".gz      "$DEPLOY_DIR2/"
    mv "$IMG_FILE_ROOT".gz "$DEPLOY_DIR2/"
    #mv "$IMG_FILE_BOOT".gz "$DEPLOY_DIR2/"
    #mv "$IMG_FILE_DATA".gz "$DEPLOY_DIR2/"
fi

mv "$IMG_FILE"      "$DEPLOY_DIR2/"

cp -a "$IMG_FILE_ROOT" "${DEPLOY_DIR2}/sdcard/sys_arm64_000/rootfs.img"
mv "$IMG_FILE_ROOT" "$DEPLOY_DIR2/"

#mv "$IMG_FILE_BOOT" "$DEPLOY_DIR2/"
#mv "$IMG_FILE_DATA" "$DEPLOY_DIR2/"