forked from gcwnow/imager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_data_image.sh
executable file
·53 lines (46 loc) · 1.31 KB
/
create_data_image.sh
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
#!/bin/bash
# Currently everything runs as root, but that is going to change.
USER_UID=0
USER_GID=0
source ./su_command.sh
TOTAL_SIZE=0
echo "Gathering applications..."
APPS=
for app in apps/*
do
if test -f $app
then
APPS="${APPS} $app"
SIZE=$(stat -Lc %s ${app})
TOTAL_SIZE=$((${TOTAL_SIZE} + ${SIZE}))
echo "app: ${app} - $((${SIZE} / 1024)) kB"
elif [ $app != "apps/*" ]
then
echo "skipping non-regular file: $app"
fi
done
echo "Total data size: ${TOTAL_SIZE} bytes"
echo
# Pick a partition size that is large enough to contain all files but not much
# larger so the image stays small.
IMAGE_SIZE=$((8 + ${TOTAL_SIZE} / (920*1024)))
echo "Creating data partition of ${IMAGE_SIZE} MB..."
mkdir -p images
dd if=/dev/zero of=images/data.bin bs=1M count=${IMAGE_SIZE}
MKE2FS_CONFIG=mke2fs.conf /sbin/mke2fs -t od-data -F images/data.bin
echo
echo "Populating data partition..."
echo "(this step needs superuser privileges)"
mkdir mnt
${SU_CMD} "
mount images/data.bin mnt -o loop &&
install -m 755 -o ${USER_UID} -g ${USER_GID} -d mnt/apps/ &&
if [ \"${APPS}\" != \"\" ]
then
install -m 644 -o ${USER_UID} -g ${USER_GID} -t mnt/apps/ ${APPS}
fi &&
install -m 755 -o 0 -g 0 -d mnt/local/etc/init.d &&
install -m 755 -o 0 -g 0 resize_data_part.target-sh mnt/local/etc/init.d/S00resize &&
umount mnt
"
rmdir mnt