-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmkrootfs.sh
executable file
·145 lines (129 loc) · 2.83 KB
/
mkrootfs.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
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
#!/bin/bash
set -e
# BOARD=${BOARD:-lpi4a} # lpi4a, ahead
BOOT_SIZE=500M
BOOT_IMG=""
ROOT_SIZE=5G
ROOT_IMG=""
CHROOT_TARGET=rootfs
LOOP_DEVICE="/dev/loop100"
EFI_MOUNTPOINT=""
BOOT_MOUNTPOINT=""
ROOT_MOUNTPOINT=""
EMMC_ROOT_UUID="80a5a8e9-c744-491a-93c1-4f4194fd690a"
SDCARD_ROOT_UUID="80a5a8e9-c744-491a-93c1-4f4194fd690b"
TIMESTAMP=$(date +%Y%m%d-%H%M%S)
source $(pwd)/scripts/boards_list.sh
source $(pwd)/scripts/packages_list.sh
source $(pwd)/scripts/make_rootfs.sh
source $(pwd)/scripts/make_bootable.sh
source $(pwd)/scripts/after_mkrootfs.sh
source $(pwd)/scripts/create_sdcard.sh
make_imagefile()
{
if [ -f revyos-release ]; then
echo "Found revyos-release, using timestamp in this file."
. ./revyos-release
TIMESTAMP=${BUILD_ID}
fi
BOOT_IMG="boot-$BOARD-$TIMESTAMP.ext4"
truncate -s "$BOOT_SIZE" "$BOOT_IMG"
ROOT_IMG="root-$BOARD-$TIMESTAMP.ext4"
truncate -s "$ROOT_SIZE" "$ROOT_IMG"
# Format partitions
mkfs.ext4 -F "$BOOT_IMG"
mkfs.ext4 -F "$ROOT_IMG"
}
pre_mkrootfs()
{
# Mount loop device
mkdir "$CHROOT_TARGET"
mount "$ROOT_IMG" "$CHROOT_TARGET"
}
unmount_image()
{
echo "Finished and cleaning..."
if mount | grep "$CHROOT_TARGET" > /dev/null; then
umount -l "$CHROOT_TARGET"
fi
if [ "$(ls -A $CHROOT_TARGET)" ]; then
echo "folder not empty! umount may fail!"
exit 2
else
echo "Deleting chroot temp folder..."
if [ -d "$CHROOT_TARGET" ]; then
rmdir -v "$CHROOT_TARGET"
fi
echo "Done."
fi
}
cleanup_env()
{
echo "Cleanup temp files..."
# remove temp file here
echo "Done."
}
calculate_md5()
{
echo "Calculate MD5 for outputs..."
if [ ! -z $IMAGE_FILE ] && [ -f $IMAGE_FILE ]; then
echo "$(md5sum $IMAGE_FILE)"
fi
if [ ! -z $BOOT_IMG ] && [ -f $BOOT_IMG ]; then
echo "$(md5sum $BOOT_IMG)"
fi
if [ ! -z $ROOT_IMG ] && [ -f $ROOT_IMG ]; then
echo "$(md5sum $ROOT_IMG)"
fi
}
main()
{
if [ ! -z "${CREATE_TARBALL}" ]; then
make_rootfs_tarball ${CREATE_TARBALL}
exit 0
fi
check_board_vaild
# install_depends
make_imagefile
pre_mkrootfs
make_rootfs
# make_kernel
make_bootable
after_mkrootfs
create_sdcard
exit
}
# Check root privileges:
if (( $EUID != 0 )); then
echo "Please run as root"
exit 1
fi
trap return 2 INT
trap clean_on_exit EXIT
clean_on_exit()
{
if [ $? -eq 0 ]; then
unmount_image
cleanup_env
echo "Build succeed."
calculate_md5
else
echo "Interrupted exit $?."
unmount_image
cleanup_env
if [ ! -z $IMAGE_FILE ] && [ -f $IMAGE_FILE ]; then
echo "delete image $IMAGE_FILE ..."
rm -v "$IMAGE_FILE"
fi
if [ ! -z $BOOT_IMG ] && [ -f $BOOT_IMG ]; then
echo "delete image $BOOT_IMG ..."
rm -v "$BOOT_IMG"
fi
if [ ! -z $ROOT_IMG ] && [ -f $ROOT_IMG ]; then
echo "delete image $ROOT_IMG ..."
rm -v "$ROOT_IMG"
fi
echo "Build failed."
fi
}
main