96 lines
4.5 KiB
Bash
Executable File
96 lines
4.5 KiB
Bash
Executable File
#!/bin/bash
|
|
# R3 Pro II — patch v2.2 真机部署脚本(bind-mount 免刷机)
|
|
#
|
|
# 用法:
|
|
# ./deploy_device.sh <设备IP> [ssh 私钥]
|
|
#
|
|
# 安全规矩(强制):
|
|
# - 杀 hiby_player: 杀 hiby_player.sh 父 shell → 杀 hiby_player → 确认零残留 → 手动拉起一个
|
|
# - 每步记录: ps 实例数 / brightness / bind 列表
|
|
# - busybox 无 pkill/killall; 绝不用 killall(会触发 hiby_player.sh 的 reboot 看门狗)
|
|
set -e
|
|
|
|
IP="${1:?usage: deploy_device.sh <IP> [key]}"
|
|
KEY="${2:-$HOME/Project/R3ProII/ssh_keys/<device_key>}"
|
|
ROOT="$HOME/Project/R3ProII/patch_v2"
|
|
|
|
ssh_cmd() {
|
|
ssh -i "$KEY" -o StrictHostKeyChecking=no -o ConnectTimeout=8 root@"$IP" "$@"
|
|
}
|
|
|
|
echo "==> 连接 $IP ..."
|
|
ssh_cmd "echo OK" || { echo "SSH 失败"; exit 1; }
|
|
|
|
echo "==> 轮前状态"
|
|
ssh_cmd 'echo "instances=$(ps | grep hiby_player | grep -v grep | grep -v sh | wc -l) brightness=$(cat /sys/class/backlight/backlight_pwm0/brightness) binds=$(mount | grep -c overlay)"'
|
|
|
|
echo "==> 推送文件"
|
|
scp -i "$KEY" -o StrictHostKeyChecking=no "$ROOT/hiby_player_patched_v2" root@$IP:/data/hiby_player_patched_v2
|
|
scp -i "$KEY" -o StrictHostKeyChecking=no "$ROOT/meow_watchdog/meow_watchdog" root@$IP:/usr/data/meow_watchdog
|
|
scp -i "$KEY" -o StrictHostKeyChecking=no "$ROOT/apps_assets/apps/os.meow.hello/hello" root@$IP:/data/hello.bin
|
|
scp -i "$KEY" -o StrictHostKeyChecking=no "$ROOT/apps_assets/apps/os.meow.hello/app.json" root@$IP:/data/hello_app.json
|
|
|
|
echo "==> 设备侧组装"
|
|
ssh_cmd '
|
|
set -e
|
|
if ! grep -q "sd_0" /proc/mounts; then
|
|
echo "!! TF 卡未挂载"; mount /dev/mmcblk0p1 /usr/data/mnt/sd_0 2>/dev/null || echo "!! 挂载失败"
|
|
fi
|
|
mkdir -p /usr/data/mnt/sd_0/MeowAPPs/os.meow.hello /data/overlay
|
|
cp -f /data/hello.bin /usr/data/mnt/sd_0/MeowAPPs/os.meow.hello/hello
|
|
cp -f /data/hello_app.json /usr/data/mnt/sd_0/MeowAPPs/os.meow.hello/app.json
|
|
chmod 755 /usr/data/mnt/sd_0/MeowAPPs/os.meow.hello/hello
|
|
chmod 755 /usr/data/meow_watchdog
|
|
ls /usr/data/mnt/sd_0/MeowAPPs/os.meow.hello/
|
|
rm -rf /data/overlay/theme1 /data/overlay/str_zh /data/overlay/str_en
|
|
cp -a /usr/resource/layout/theme1 /data/overlay/theme1
|
|
cp -a /usr/resource/str/simplified_chinese /data/overlay/str_zh
|
|
cp -a /usr/resource/str/english /data/overlay/str_en
|
|
echo "overlay ready"
|
|
'
|
|
|
|
echo "==> 推送资源文件"
|
|
cat > /tmp/deploy_batch.sftp << EOF
|
|
put $ROOT/apps_assets/layout/theme1/hiby_apps_main.view /data/overlay/theme1/hiby_apps_main.view
|
|
put $ROOT/apps_assets/str/simplified_chinese/apps.ini /data/overlay/str_zh/apps.ini
|
|
put $ROOT/apps_assets/str/english/apps.ini /data/overlay/str_en/apps.ini
|
|
EOF
|
|
sftp -i "$KEY" -o StrictHostKeyChecking=no -b /tmp/deploy_batch.sftp root@$IP
|
|
|
|
echo "==> 单实例重启 + bind-mount(先杀进程再 umount,顺序关键)"
|
|
ssh_cmd '
|
|
set -e
|
|
# 1) 杀 hiby_player.sh 父 shell(防 reboot 看门狗)
|
|
for pid in $(ps | grep "hiby_player.sh" | grep -v grep | awk "{print \$1}"); do kill $pid 2>/dev/null || true; done
|
|
sleep 1
|
|
# 2) 杀 hiby_player(先杀干净,文件挂载点才能 umount)
|
|
for pid in $(ps | grep hiby_player | grep -v grep | grep -v "hiby_player.sh" | awk "{print \$1}"); do kill $pid 2>/dev/null || true; done
|
|
sleep 2
|
|
echo "remaining=$(ps | grep hiby_player | grep -v grep | wc -l)"
|
|
# 3) umount 旧 bind
|
|
umount /usr/bin/hiby_player 2>/dev/null || true
|
|
umount /usr/bin/meow_watchdog 2>/dev/null || true
|
|
umount /usr/resource/layout/theme1 2>/dev/null || true
|
|
umount /usr/resource/str/simplified_chinese 2>/dev/null || true
|
|
umount /usr/resource/str/english 2>/dev/null || true
|
|
# 4) 组装 + bind
|
|
cp -f /data/hiby_player_patched_v2 /data/overlay/hiby_player
|
|
chmod 755 /data/overlay/hiby_player
|
|
mount --bind /data/overlay/hiby_player /usr/bin/hiby_player
|
|
# 看门狗: cave 内 exec 路径为 /usr/bin/meow_watchdog(与固件一致), 测试期
|
|
# /usr/bin 只读, 把可写卷上的 /usr/data/meow_watchdog bind 过去
|
|
mount --bind /usr/data/meow_watchdog /usr/bin/meow_watchdog 2>/dev/null || true
|
|
mount --bind /data/overlay/theme1 /usr/resource/layout/theme1
|
|
mount --bind /data/overlay/str_zh /usr/resource/str/simplified_chinese
|
|
mount --bind /data/overlay/str_en /usr/resource/str/english
|
|
echo "md5: $(md5sum /usr/bin/hiby_player | cut -d" " -f1)"
|
|
ls /usr/resource/layout/theme1/hiby_apps_main.view >/dev/null && echo "view ok"
|
|
ls /usr/resource/str/english/apps.ini >/dev/null && echo "ini ok"
|
|
# 5) 拉起一个
|
|
nohup /usr/bin/hiby_player > /tmp/hiby_player.log 2>&1 &
|
|
sleep 4
|
|
echo "instances=$(ps | grep hiby_player | grep -v grep | grep -v sh | wc -l)"
|
|
ps | grep hiby_player | grep -v grep | grep -v sh
|
|
'
|
|
echo "==> 部署完成"
|