forked from unifreq/openwrt_packit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mk_openwrt_dockerimg.sh
executable file
·121 lines (102 loc) · 4.54 KB
/
mk_openwrt_dockerimg.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
#!/bin/bash
# 用法:
# 本机必须安装并运行docker服务
# 把编译好的 openwrt-armvirt-64-default-rootfs.tar.gz 放到 ./src2/,或./, 再运行本脚本
#
# 脚本可以代入2个参数: [img_name] [tag]
# 例如:./mk_openwrt_dockerimg.sh myname/openwrt-aarch64 latest
# 如果不填命令行参数的话,默认镜像名称是 unifreq/openwrt-aarch64:latest
#
# build成功后,用 docker images可以看到生成的镜像
# 并且会打包成本地镜像: ${OUTDIR}/docker-img-openwrt-aarch64-${TAG}.gz (可以用docker loader 命令导入)
IMG_NAME=unifreq/openwrt-aarch64
TAG=latest
if [ ! -z "$1" ];then
IMG_NAME=$1
if [ ! -z "$2" ];then
TAG=$2
fi
fi
WORKDIR=${PWD}
if [ -f ${WORKDIR}/src2/openwrt-armvirt-64-default-rootfs.tar.gz ];then
SRC_IMG=${WORKDIR}/src2/openwrt-armvirt-64-default-rootfs.tar.gz
else
SRC_IMG=${WORKDIR}/openwrt-armvirt-64-default-rootfs.tar.gz
fi
if [ ! -f ${SRC_IMG} ];then
echo "Source image is not exists: ${SRC_IMG}"
exit 1
fi
TMPDIR=${PWD}/openwrt_docker_rootfs
OUTDIR=${PWD}/output
[ -d "$OUTDIR" ] || mkdir -p ${OUTDIR}
[ -d "$TMPDIR" ] && rm -rf "$TMPDIR"
mkdir -p "$TMPDIR" && gzip -dc ${SRC_IMG} | ( cd "$TMPDIR" && tar xf - && rm -rf ./lib/firmware/* && rm -rf ./lib/modules/*)
[ -x $TMPDIR/bin/bash ] && \
cp -f files/docker/30-sysinfo.sh $TMPDIR/etc/profile.d/ && \
sed -e "s/\/bin\/ash/\/bin\/bash/" -i $TMPDIR/etc/passwd && \
sed -e "s/\/bin\/ash/\/bin\/bash/" -i $TMPDIR/usr/libexec/login.sh
[ -f files/banner ] && \
cp -f files/banner $TMPDIR/etc/ && \
echo "The docker aarch64 special edition" >> $TMPDIR/etc/banner && \
echo "" >> $TMPDIR/etc/banner
cat >> $TMPDIR/etc/sysupgrade.conf <<EOF
/etc/ssh/ssh_host_ed25519_key
/etc/ssh/ssh_host_ed25519_key.pub
/etc/ssh/ssh_host_rsa_key
/etc/ssh/ssh_host_rsa_key.pub
/root/.ssh/
EOF
cp -f files/docker/rc.local "$TMPDIR/etc/" && \
cp -f files/99-custom.conf "$TMPDIR/etc/sysctl.d/" && \
cp -f files/cpustat "$TMPDIR/usr/bin/" && chmod 755 "$TMPDIR/usr/bin/cpustat" && \
cp -f files/getcpu "$TMPDIR/bin/" && chmod 755 "$TMPDIR/bin/getcpu" && \
cp -f files/coremark.sh "$TMPDIR/etc/" && chmod 755 "$TMPDIR/etc/coremark.sh"
cp -f files/kmod "$TMPDIR/sbin/" && \
(
cd $TMPDIR/sbin && \
chmod 755 kmod && \
rm insmod lsmod modinfo modprobe rmmod && \
ln -s kmod insmod && \
ln -s kmod lsmod && \
ln -s kmod modinfo && \
ln -s kmod modprobe && \
ln -s kmod rmmod
)
for p in `echo files/index.html.patches/*.patch`;do
cat $p | (cd "$TMPDIR/" && patch -p1 && find . -name '*.orig' -exec rm {} \; && find . -name '*.rej' -exec rm {} \;)
done
cat files/docker/init.d_turboacc.patch | (cd "$TMPDIR/" && patch -p1 )
if ! cat files/docker/cbi_turboacc_new.patch | (cd "$TMPDIR/" && patch -p1 );then
cat files/docker/cbi_turboacc.patch | (cd "$TMPDIR/" && patch -p1 )
( find "$TMPDIR" -name '*.rej' -exec rm {} \;
find "$TMPDIR" -name '*.orig' -exec rm {} \;
)
fi
sed -e "s/hw_flow '1'/hw_flow '0'/" -i $TMPDIR/etc/config/turboacc
sed -e "s/sfe_flow '1'/sfe_flow '0'/" -i $TMPDIR/etc/config/turboacc
rm -f "$TMPDIR/etc/bench.log" && \
echo "17 3 * * * /etc/coremark.sh" >> "$TMPDIR/etc/crontabs/root"
[ -f ${TMPDIR}/etc/config/qbittorrent ] && sed -e 's/\/opt/\/etc/' -i "${TMPDIR}/etc/config/qbittorrent"
[ -f ${TMPDIR}/etc/ssh/sshd_config ] && sed -e "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/" -i "${TMPDIR}/etc/ssh/sshd_config"
[ -f ${TMPDIR}/etc/samba/smb.conf.template ] && cat patches/smb4.11_enable_smb1.patch | (cd "$TMPDIR" && [ -f etc/samba/smb.conf.template ] && patch -p1)
sss=$(date +%s) && \
ddd=$((sss/86400)) && \
sed -e "s/:0:0:99999:7:::/:${ddd}:0:99999:7:::/" -i "${TMPDIR}/etc/shadow" && \
sed -e "s/root::/root:\$1\$0yUsq67p\$RC5cEtaQpM6KHQfhUSIAl\.:/" -i "${TMPDIR}/etc/shadow"
(cd "$TMPDIR" && tar cf ../openwrt-armvirt-64-default-rootfs-patched.tar .) && \
if [ `uname -i` == "aarch64" ];then
# native platform build
rm -f DockerImg-OpenwrtArm64-${TAG}.gz && \
docker build -t ${IMG_NAME}:${TAG} . && \
rm -f openwrt-armvirt-64-default-rootfs-patched.tar && \
rm -rf "$TMPDIR" && \
docker save ${IMG_NAME}:${TAG} | pigz -9 > $OUTDIR/docker-img-openwrt-aarch64-${TAG}.gz
else
# cross platform build
rm -f DockerImg-OpenwrtArm64-${TAG}.gz && \
DOCKER_BUILDKIT=1 docker build --platform=linux/arm64 -t ${IMG_NAME}:${TAG} . && \
rm -f openwrt-armvirt-64-default-rootfs-patched.tar && \
rm -rf "$TMPDIR" && \
docker save ${IMG_NAME}:${TAG} | pigz -9 > $OUTDIR/docker-img-openwrt-aarch64-${TAG}.gz
fi