forked from unifreq/openwrt_packit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mk_rk3568_photonicat.sh
executable file
·248 lines (219 loc) · 7 KB
/
mk_rk3568_photonicat.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
#!/bin/bash
echo "========================= begin $0 ================="
source make.env
source public_funcs
init_work_env
# 默认是否开启软件FLOWOFFLOAD
SW_FLOWOFFLOAD=0
# 默认是否开启硬件FLOWOFFLOAD
HW_FLOWOFFLOAD=0
# 默认是否开启SFE
SFE_FLOW=1
PLATFORM=rockchip
SOC=rk3568
BOARD=photonicat
SUBVER=$1
# 锁定内核版本: 因 6.1.28 回退了rk3568的sgmii补丁,故光影猫最高只能采用6.1.27内核
KERNEL_VERSION=6.1.27-flippy-83+
# Kernel image sources
###################################################################
KERNEL_TAGS="stable"
KERNEL_BRANCHES="bsp:rk35xx:>=:5.10 mainline:all:>=:6.1"
MODULES_TGZ=${KERNEL_PKG_HOME}/modules-${KERNEL_VERSION}.tar.gz
check_file ${MODULES_TGZ}
BOOT_TGZ=${KERNEL_PKG_HOME}/boot-${KERNEL_VERSION}.tar.gz
check_file ${BOOT_TGZ}
DTBS_TGZ=${KERNEL_PKG_HOME}/dtb-rockchip-${KERNEL_VERSION}.tar.gz
check_file ${DTBS_TGZ}
###################################################################
# Openwrt
OPWRT_ROOTFS_GZ=$(get_openwrt_rootfs_archive ${PWD})
check_file ${OPWRT_ROOTFS_GZ}
echo "Use $OPWRT_ROOTFS_GZ as openwrt rootfs!"
# Target Image
TGT_IMG="${WORK_DIR}/openwrt_${SOC}_${BOARD}_${OPENWRT_VER}_k${KERNEL_VERSION}${SUBVER}.img"
# patches、scripts
####################################################################
CPUSTAT_SCRIPT="${PWD}/files/cpustat"
CPUSTAT_SCRIPT_PY="${PWD}/files/cpustat.py"
INDEX_PATCH_HOME="${PWD}/files/index.html.patches"
GETCPU_SCRIPT="${PWD}/files/getcpu"
KMOD="${PWD}/files/kmod"
KMOD_BLACKLIST="${PWD}/files/rk3568/photonicat/kmod_blacklist"
FIRSTRUN_SCRIPT="${PWD}/files/first_run.sh"
DAEMON_JSON="${PWD}/files/rk3568/daemon.json"
TTYD="${PWD}/files/ttyd"
FLIPPY="${PWD}/files/scripts_deprecated/flippy_cn"
BANNER="${PWD}/files/banner"
# 20200314 add
FMW_HOME="${PWD}/files/firmware"
SMB4_PATCH="${PWD}/files/smb4.11_enable_smb1.patch"
SYSCTL_CUSTOM_CONF="${PWD}/files/99-custom.conf"
# 20200709 add
COREMARK="${PWD}/files/coremark.sh"
# 20201024 add
BAL_ETH_IRQ="${PWD}/files/balethirq.pl"
# 20201026 add
FIX_CPU_FREQ="${PWD}/files/fixcpufreq.pl"
SYSFIXTIME_PATCH="${PWD}/files/sysfixtime.patch"
# 20201128 add
SSL_CNF_PATCH="${PWD}/files/openssl_engine.patch"
# 20201212 add
BAL_CONFIG="${PWD}/files/rk3568/photonicat/balance_irq"
# 20210307 add
SS_LIB="${PWD}/files/ss-glibc/lib-glibc.tar.xz"
SS_BIN="${PWD}/files/ss-glibc/armv8.2a_crypto/ss-bin-glibc.tar.xz"
JQ="${PWD}/files/jq"
# 20210330 add
DOCKERD_PATCH="${PWD}/files/dockerd.patch"
# 20200416 add
FIRMWARE_TXZ="${PWD}/files/firmware_armbian.tar.xz"
BOOTFILES_HOME="${PWD}/files/bootfiles/rockchip/rk3568/photonicat"
GET_RANDOM_MAC="${PWD}/files/get_random_mac.sh"
BOOTLOADER_IMG="${PWD}/files/rk3568/photonicat/bootloader.bin"
# 20210618 add
DOCKER_README="${PWD}/files/DockerReadme.pdf"
# 20210704 add
SYSINFO_SCRIPT="${PWD}/files/30-sysinfo.sh"
FORCE_REBOOT="${PWD}/files/rk3568/reboot"
# 20210923 add
OPENWRT_KERNEL="${PWD}/files/openwrt-kernel"
OPENWRT_BACKUP="${PWD}/files/openwrt-backup"
OPENWRT_UPDATE="${PWD}/files/openwrt-update-rockchip"
# 20211214 add
P7ZIP="${PWD}/files/7z"
# 20211217 add
DDBR="${PWD}/files/openwrt-ddbr"
# 20220225 add
SSH_CIPHERS="aes256-gcm@openssh.com,aes128-gcm@openssh.com,aes256-ctr,aes192-ctr,aes128-ctr,chacha20-poly1305@openssh.com"
SSHD_CIPHERS="aes256-gcm@openssh.com,aes128-gcm@openssh.com,aes256-ctr,aes192-ctr,aes128-ctr"
# 20220927 add
BOARD_HOME="${PWD}/files/rk3568/photonicat/board.d"
# 20221001 add
MODULES_HOME="${PWD}/files/rk3568/modules.d"
# 20221123 add
BOARD_MODULES_HOME="${PWD}/files/rk3568/photonicat/modules.d"
# 20221013 add
WIRELESS_CONFIG="${PWD}/files/rk3568/photonicat/wireless"
# 20230418 add
PCAT_MANAGER_WEB_HOME="${PWD}/files/rk3568/photonicat/pcat-manager-web"
UHTTPD_PORT="8080"
UHTTPD_PORT_S="8443"
# 20230420 add
PCAT_MANAGER_CONF="${PWD}/files/rk3568/photonicat/pcat-manager.conf"
PCAT_MANAGER_WEB_REQUIRES="
python3-flask.control
python3-flask-httpauth.control
python3-flask-login.control
python3-flask-seasurf.control
python3-flask-session.control
python3-flask-socketio.control
python3-passlib.control
python3-pyserial.control
python3-requests.control
python3-sqlite3.control
python3-xml.control
"
####################################################################
check_depends
SKIP_MB=16
BOOT_MB=256
ROOTFS_MB=960
SIZE=$((SKIP_MB + BOOT_MB + ROOTFS_MB + 1))
create_image "$TGT_IMG" "$SIZE"
create_partition "$TGT_DEV" "gpt" "$SKIP_MB" "$BOOT_MB" "ext4" "0" "-1" "btrfs"
make_filesystem "$TGT_DEV" "B" "ext4" "EMMC_BOOT" "R" "btrfs" "EMMC_ROOTFS1"
mount_fs "${TGT_DEV}p1" "${TGT_BOOT}" "ext4"
mount_fs "${TGT_DEV}p2" "${TGT_ROOT}" "btrfs" "compress=zstd:${ZSTD_LEVEL}"
echo "创建 /etc 子卷 ..."
btrfs subvolume create $TGT_ROOT/etc
extract_rootfs_files
extract_rockchip_boot_files
echo "修改引导分区相关配置 ... "
cd $TGT_BOOT
sed -e '/rootdev=/d' -i armbianEnv.txt
sed -e '/rootfstype=/d' -i armbianEnv.txt
sed -e '/rootflags=/d' -i armbianEnv.txt
cat >> armbianEnv.txt <<EOF
rootdev=UUID=${ROOTFS_UUID}
rootfstype=btrfs
rootflags=compress=zstd:${ZSTD_LEVEL}
EOF
echo "armbianEnv.txt -->"
echo "==============================================================================="
cat armbianEnv.txt
echo "==============================================================================="
echo
echo "修改根文件系统相关配置 ... "
cd $TGT_ROOT
copy_supplement_files
extract_glibc_programs
adjust_docker_config
adjust_openssl_config
adjust_qbittorrent_config
adjust_getty_config
adjust_samba_config
adjust_nfs_config "mmcblk0p4"
adjust_openssh_config
adjust_openclash_config
use_xrayplug_replace_v2rayplug
create_fstab_config
adjust_turboacc_config
adjust_ntfs_config
adjust_mosdns_config
patch_admin_status_index_html
function check_opkg_requires() {
local ok="ok"
while :;do
local control=$1
shift
if [ -n "$control" ];then
if [ ! -f "./usr/lib/opkg/info/$control" ];then
if [ "$ok" == "ok" ];then
ok="The following packages do not exist:"
fi
ok="$ok $control"
fi
else
break
fi
done
echo $ok
}
if [ -n "${PCAT_MANAGER_CONF}" ] && [ -f "${PCAT_MANAGER_CONF}" ];then
cp -v "${PCAT_MANAGER_CONF}" ./etc/pcat-manager.conf
fi
ret=$(check_opkg_requires ${PCAT_MANAGER_WEB_REQUIRES})
if [ "$ret" == "ok" ];then
echo "为光影猫添加个性化主页 ... "
if [ -d "${PCAT_MANAGER_WEB_HOME}" ];then
echo "copy pcat-manager-web files ... "
cp -a ${PCAT_MANAGER_WEB_HOME}/* .
fi
if [ -n "$UHTTPD_PORT" ];then
echo "change http port from 80 to ${UHTTPD_PORT}"
sed -e "s/:80/:${UHTTPD_PORT}/g" -i etc/config/uhttpd
fi
if [ -n "$UHTTPD_PORT_S" ];then
echo "change https port from 443 to ${UHTTPD_PORT_S}"
sed -e "s/:443/:${UHTTPD_PORT_S}/g" -i etc/config/uhttpd
fi
echo "个性化主页配置完成"
echo
else
echo "未满足前置条件,采用默认主页, 原因:"
echo $ret
echo
fi
adjust_kernel_env
copy_uboot_to_fs
write_release_info
write_banner
config_first_run
create_snapshot "etc-000"
write_uboot_to_disk
clean_work_env
mv ${TGT_IMG} ${OUTPUT_DIR} && sync
echo "镜像已生成! 存放在 ${OUTPUT_DIR} 下面!"
echo "========================== end $0 ================================"
echo