-
Notifications
You must be signed in to change notification settings - Fork 48
/
build-armbian.sh
executable file
·96 lines (80 loc) · 2.76 KB
/
build-armbian.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
#!/bin/bash
# requirements: sudo jq sfdisk u-boot-tools
[ "$EUID" != "0" ] && echo "please run as root" && exit 1
mount_point="/mnt/tmp"
tmpdir="tmp"
output="output"
origin="Rock64"
target="beikeyun"
func_umount() {
umount $mount_point
}
func_mount() {
local img=$1
[ ! -f "$img" ] && echo "img file not found!" && return 1
mkdir -p $mount_point
start=$(sfdisk -J $img | jq .partitiontable.partitions[0].start)
offset=$((start * 512))
mount -o loop,offset=$offset $1 $mount_point
}
func_modify() {
local dtb=$1
[ ! -f "$dtb" ] && echo "dtb file not found!" && return 1
# patch /boot
echo "patch /boot"
cp -f $dtb $mount_point/boot/
sed -i '/^verbosity/cverbosity=7' $mount_point/boot/armbianEnv.txt
if [ -z "`grep fdtfile $mount_point/boot/armbianEnv.txt`" ]; then
echo "fdtfile=$(basename $dtb)" >> $mount_point/boot/armbianEnv.txt
fi
sed -i 's#${prefix}dtb/${fdtfile}#${prefix}/${fdtfile}#' $mount_point/boot/boot.cmd
mkimage -C none -T script -d $mount_point/boot/boot.cmd $mount_point/boot/boot.scr
# patch rootfs
echo "patch rootfs"
sed -i 's#http://ports.ubuntu.com#https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports#' $mount_point/etc/apt/sources.list
sed -i 's#http://httpredir.debian.org#https://mirrors.tuna.tsinghua.edu.cn#' $mount_point/etc/apt/sources.list
sed -i 's#http://security.debian.org#https://mirrors.tuna.tsinghua.edu.cn/debian-security#' $mount_point/etc/apt/sources.list
sed -i 's#http://apt.armbian.com#https://mirrors.tuna.tsinghua.edu.cn/armbian#' $mount_point/etc/apt/sources.list.d/armbian.list
sed -i 's/ENABLED=true/#ENABLED=true/' $mount_point/etc/default/armbian-zram-config
sed -i 's/ENABLED=true/#ENABLED=true/' $mount_point/etc/default/armbian-ramlog
rm -f $mount_point/etc/systemd/system/getty.target.wants/serial-getty\@ttyS2.service
ln -sf /usr/share/zoneinfo/Asia/Shanghai $mount_point/etc/localtime
sync
}
func_release() {
local dlpkg=$1
[ ! -f "$dlpkg" ] && echo "dlpkg not found!" && return 1
rm -rf ${tmpdir}
echo "Extract 7zpkg and checksum..."
7z x -y -o${tmpdir} $dlpkg >/dev/null && cd ${tmpdir} && sha256sum -c sha256sum.sha && cd - > /dev/null || exit 1
local dtb=$2
imgfile="$(ls ${tmpdir}/*.img)"
echo "origin image file: $imgfile"
echo "dtb file: $dtb"
func_mount $imgfile && func_modify $dtb && func_umount
imgname_new=`basename $imgfile | sed "s/${origin}/${target}/"`
echo "new image file: $imgname_new"
mv $imgfile ${output}/${imgname_new}
if [ -n "$TRAVIS_TAG" ]; then
xz -f -T0 -v ${output}/${imgname_new}
fi
rm -rf ${tmpdir}
}
case "$1" in
umount)
func_umount
;;
mount)
func_mount "$2"
;;
modify)
func_mount "$2" && func_modify "$3" && func_umount
;;
release)
func_release "$2" "$3"
;;
*)
echo "Usage: $0 { mount | umount [img] | modify [img] [dtb] | release [7zpkg] [dtb] }"
exit 1
;;
esac