-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild-rootfs.sh
executable file
·76 lines (63 loc) · 1.84 KB
/
build-rootfs.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
#!/bin/bash
. config
archivename="${url##*/}"
ext='gz'
filename=`basename ${archivename} .$ext`
if [ -e "${archivename}" ]
then
echo "Already have the image file: $archivename"
else
if [ -e "${filename}" ]
then
echo "$filename exists. Not downloading $url."
else
echo "Retrieving $url .."
wget -q --show-progress --progress=bar:force:noscroll $url
fi
fi
if [ -e "${filename}" ]
then
echo "Already extracted to: $filename"
else
echo "Extracting $filename .."
if [ $ext == "gz" ]; then
gzip -d "${archivename}"
elif [ $ext == "xz" ]; then
xz -d "${archivename}"
fi
fi
declare -i start_sector
start_sector=$(/sbin/fdisk -l ./${filename} | awk -F" " '{ print $3 }' | tail -n1)
(( start_offset = $start_sector * 512 ))
mkdir -p img-mount
(sudo umount img-mount || /bin/true)
if ! (sudo mount -o loop,offset=$start_offset ./${filename} ./img-mount); then
echo "mount failed, trying a different partition"
mkdir -p sys-mount
start_sector=$(/sbin/fdisk -l ./${filename} | awk -F" " '{ print $3 }' | tail -n2 | head -n1)
(( start_offset = $start_sector * 512 ))
if ! (sudo mount -o loop,offset=$start_offset ./${filename} ./sys-mount); then
echo "unable to mount. error."
exit
else
if ! (sudo mount -o loop ./sys-mount/SYSTEM ./img-mount); then
echo "unable to find an image within the image."
exit
else
echo "SYSTEM mounted"
ls img-mount
fi
fi
fi
mkdir -p docker/rootfs
sudo rsync -axHAX --info=progress2 img-mount/ docker/rootfs/
sudo umount ./img-mount
rmdir ./img-mount
sudo umount ./sys-mount
rmdir ./sys-mount
echo $name >.release
echo "$url extracted to docker/rootfs/"
# cleanup
#rm "${filename}"
#rm "${archivename}"
# sudo mount -o loop,offset=16777216 ./LibreELEC-RK3399.arm-9.1-nightly-20190324-5ccaa74-rockpro64.img ./img-mount