From 23c702366e34296cc4c7a64126d6360516603618 Mon Sep 17 00:00:00 2001 From: teasiu Date: Mon, 13 Apr 2026 04:12:43 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=87=E7=BA=A7=E8=84=9A=E6=9C=AC=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E8=87=AA=E5=8A=A8=E6=89=A9=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- static/mv100_upgrade.sh | 75 +++++++++++++++++++++++++--------- static/mv200_upgrade.sh | 90 ++++++++++++++++++++++++++++------------- static/mv300_upgrade.sh | 84 ++++++++++++++++++++++++++------------ 3 files changed, 176 insertions(+), 73 deletions(-) diff --git a/static/mv100_upgrade.sh b/static/mv100_upgrade.sh index 348faaf..127aee5 100755 --- a/static/mv100_upgrade.sh +++ b/static/mv100_upgrade.sh @@ -1,7 +1,5 @@ #!/bin/bash - dlfile="mv100-99.flash.gz" - echo " +---------------------------------------------------------------------- | 海纳思系统hi3798mv100升级系统专用脚本温馨提示: @@ -19,47 +17,86 @@ read -p "继续执行?[y/n]: " result temp_file=$(mktemp) curl -sSL https://hi.ecoo.top/mirror-utils.sh > $temp_file if [ ! -f /etc/public-download.sh ] || [ "$(cat $temp_file|md5sum|awk '{print $1}')" != "$(cat /etc/public-download.sh|md5sum|awk '{print $1}')" ]; then - cp $temp_file /etc/public-download.sh + cp $temp_file /etc/public-download.sh fi rm -f $temp_file source /etc/public-download.sh -if [ $(whoami) != "root" ];then - _exit 1 "请使用root权限切换用户!" +if [ $(whoami) != "root" ]; then + _exit 1 "请使用root权限切换用户!" fi model=$(cpuid) platform=hi3798mv100 - -if [ "$(echo ${model})" != "$platform" ];then - _exit 1 "本升级程序仅支持${platform}机型!" +if [ "$(echo ${model})" != "$platform" ]; then + _exit 1 "本升级程序仅支持${platform}机型!" fi promode=$(uname -r|cut -c 13-) -if [ $promode = 16010066 ];then - _exit 1 "专业版用户请使用vipupgrade命令进行升级!" +if [ $promode = 16010066 ]; then + _exit 1 "专业版用户请使用vipupgrade命令进行升级!" fi -space_left=$(df -hT|grep /dev/root|awk '{print $4}') -if [ "$(expr $(echo ${space_left%%G}) \> 1)" != 1 ];then - _exit 1 "请确保剩余空间大于1G!" +# --------------------------------------------------------------- +# 检测 /tmp 剩余空间,不足 400M 时尝试扩容或清理 +# --------------------------------------------------------------- +printStr yellow "检测 /tmp 可用空间..." +TMP_AVAIL=$(df -T | grep '/tmp' | awk '{print int($5)}') # 单位:KB + +if [ "${TMP_AVAIL}" -lt 409600 ]; then # 409600 KB = 400M + printStr yellow "/tmp 剩余空间不足 400M(当前 ${TMP_AVAIL} KB),尝试 remount 扩容..." + + mount -o remount,size=500M /tmp 2>/dev/null + if [ $? -eq 0 ]; then + printStr green "/tmp 已扩容至 500M" + else + printStr yellow "remount 失败,尝试清理 /tmp 旧文件..." + # 删除超过 1 天的普通文件 + find /tmp -type f -mtime +1 -delete 2>/dev/null + # 删除同名残留包(防止上次下载中断) + rm -f /tmp/${dlfile} + + # 清理后再次尝试扩容 + mount -o remount,size=400M /tmp 2>/dev/null + if [ $? -eq 0 ]; then + printStr green "清理后 remount 成功,/tmp 已扩容至 400M" + else + # 最后兜底:检查清理后实际剩余空间是否已满足要求 + TMP_AVAIL=$(df -T | grep '/tmp' | awk '{print int($5)}') + if [ "${TMP_AVAIL}" -lt 409600 ]; then + _exit 1 "/tmp 空间不足且无法扩容(当前 ${TMP_AVAIL} KB),请手动清理后重试!" + else + printStr green "清理后 /tmp 剩余空间已满足要求(${TMP_AVAIL} KB)" + fi + fi + fi +else + printStr green "/tmp 剩余空间充足(${TMP_AVAIL} KB),继续..." fi +# --------------------------------------------------------------- printStr yellow "检测并选定下载节点..." get_mirror_url printStr yellow "下载刷机包..." -dl_get update/system/${dlfile} /${dlfile} +dl_get update/system/${dlfile} /tmp/${dlfile} + printStr yellow "校验刷机包..." echo "${NODE_URL}/update/system/${dlfile}.md5sum" -[ "$(get_md5 -c ${NODE_URL}/update/system/${dlfile}.md5sum ${dlfile})" != "$(get_md5 -l /${dlfile})" ] && _exit 1 "文件校验失败,请重试" +[ "$(get_md5 -c ${NODE_URL}/update/system/${dlfile}.md5sum ${dlfile})" != "$(get_md5 -l /tmp/${dlfile})" ] && \ + _exit 1 "文件校验失败,请重试" printStr green "下载完成!" printStr yellow "刷机中,请勿断电..." -gunzip -c /${dlfile} | dd of=/dev/mmcblk0 bs=1024 seek=1024 status=progress conv=sync +gunzip -c /tmp/${dlfile} | dd of=/dev/mmcblk0 bs=1024 seek=1024 status=progress conv=sync -[[ $? == 0 ]] && printStr yellow " +if [[ $? == 0 ]]; then + rm -f /tmp/${dlfile} # 刷机成功后清理临时文件 + printStr yellow " ============================================================== 恭喜刷机已完成,系统重启中,待初始化5-8分钟结束后即可登录。 -==============================================================" && reboot || \ - _exit 1 "刷机失败" +==============================================================" + reboot +else + _exit 1 "刷机失败" +fi diff --git a/static/mv200_upgrade.sh b/static/mv200_upgrade.sh index d849939..36afc4e 100755 --- a/static/mv200_upgrade.sh +++ b/static/mv200_upgrade.sh @@ -1,12 +1,11 @@ #!/bin/bash - if [ -f /sys/firmware/devicetree/base/my_board_info/custom_id ];then custom_id=$(tr -d '\0' < /sys/firmware/devicetree/base/my_board_info/custom_id) if [ "${custom_id}" = "n2ns1" ];then dlfile="n2-99.flash.gz" fi else - dlfile="mv200-99.flash.gz" + dlfile="mv200-99.flash.gz" fi echo " @@ -26,55 +25,90 @@ read -p "继续执行?[y/n]: " result temp_file=$(mktemp) curl -sSL https://hi.ecoo.top/mirror-utils.sh > $temp_file if [ ! -f /etc/public-download.sh ] || [ "$(cat $temp_file|md5sum|awk '{print $1}')" != "$(cat /etc/public-download.sh|md5sum|awk '{print $1}')" ]; then - cp $temp_file /etc/public-download.sh + cp $temp_file /etc/public-download.sh fi rm -f $temp_file source /etc/public-download.sh model=$(cpuid) platform=hi3798mv200 - -if [ "$(echo ${model})" != "$platform" ];then - _exit 1 "本升级程序仅支持${platform}机型!" +if [ "$(echo ${model})" != "$platform" ]; then + _exit 1 "本升级程序仅支持${platform}机型!" fi -if [ $(whoami) != "root" ];then - _exit 1 "请使用root权限切换系统命令!" +if [ $(whoami) != "root" ]; then + _exit 1 "请使用root权限切换系统命令!" fi is64bit=$(getconf LONG_BIT) -if [ "${is64bit}" != '64' ];then - _exit 1 "抱歉, 当前系统切换版本不支持32位系统, 请使用64位系统!"; +if [ "${is64bit}" != '64' ]; then + _exit 1 "抱歉, 当前系统切换版本不支持32位系统, 请使用64位系统!" fi -promode=$(uname -r|cut -c 13-) -if [ $promode = 26010066 ];then - _exit 1 "专业版用户请使用vipupgrade命令进行升级!" -fi -#nasversion=`cat /etc/nasversion` -#if [ $nasversion = "20230101" ];then -# _exit 1 "已经是20230101最新版,无需升级系统!" -#fi -space_left=$(df -hT|grep /dev/root|awk '{print $4}') -if [ "$(expr $(echo ${space_left%%G}) \> 1)" != 1 ];then - _exit 1 "请确保剩余空间大于1G!" +promode=$(uname -r|cut -c 13-) +if [ $promode = 26010066 ]; then + _exit 1 "专业版用户请使用vipupgrade命令进行升级!" fi +# --------------------------------------------------------------- +# 检测 /tmp 剩余空间,不足 400M 时尝试扩容或清理 +# --------------------------------------------------------------- +printStr yellow "检测 /tmp 可用空间..." +TMP_AVAIL=$(df -T | grep '/tmp' | awk '{print int($5)}') # 单位:KB + +if [ "${TMP_AVAIL}" -lt 409600 ]; then # 409600 KB = 400M + printStr yellow "/tmp 剩余空间不足 400M(当前 ${TMP_AVAIL} KB),尝试 remount 扩容..." + + mount -o remount,size=500M /tmp 2>/dev/null + if [ $? -eq 0 ]; then + printStr green "/tmp 已扩容至 500M" + else + printStr yellow "remount 失败,尝试清理 /tmp 旧文件..." + # 删除超过 1 天的普通文件 + find /tmp -type f -mtime +1 -delete 2>/dev/null + # 删除同名残留包(防止上次下载中断) + rm -f /tmp/${dlfile} + + # 清理后再次尝试扩容 + mount -o remount,size=400M /tmp 2>/dev/null + if [ $? -eq 0 ]; then + printStr green "清理后 remount 成功,/tmp 已扩容至 400M" + else + # 最后兜底:检查清理后实际剩余空间是否已满足要求 + TMP_AVAIL=$(df -T | grep '/tmp' | awk '{print int($5)}') + if [ "${TMP_AVAIL}" -lt 409600 ]; then + _exit 1 "/tmp 空间不足且无法扩容(当前 ${TMP_AVAIL} KB),请手动清理后重试!" + else + printStr green "清理后 /tmp 剩余空间已满足要求(${TMP_AVAIL} KB)" + fi + fi + fi +else + printStr green "/tmp 剩余空间充足(${TMP_AVAIL} KB),继续..." +fi +# --------------------------------------------------------------- + printStr yellow "检测并选定下载节点..." get_mirror_url printStr yellow "下载刷机包..." -dl_get update/system/${dlfile} /${dlfile} +dl_get update/system/${dlfile} /tmp/${dlfile} + printStr yellow "校验刷机包..." -[ "$(get_md5 -c ${NODE_URL}/update/system/${dlfile}.md5sum ${dlfile})" != "$(get_md5 -l /${dlfile})" ] && _exit 1 "文件校验失败,请重试" +[ "$(get_md5 -c ${NODE_URL}/update/system/${dlfile}.md5sum ${dlfile})" != "$(get_md5 -l /tmp/${dlfile})" ] && \ + _exit 1 "文件校验失败,请重试" printStr green "下载完成!" printStr yellow "刷机中,请勿断电..." -gunzip -c /${dlfile} | dd of=/dev/mmcblk0 bs=1024 seek=1024 status=progress conv=sync +gunzip -c /tmp/${dlfile} | dd of=/dev/mmcblk0 bs=1024 seek=1024 status=progress conv=sync -[[ $? == 0 ]] && printStr yellow " +if [[ $? == 0 ]]; then + rm -f /tmp/${dlfile} # 刷机成功后清理临时文件 + printStr yellow " ============================================================== 刷机已完成,请手工关闭电源并再次开启,等待初始化5-8分钟即可。 -==============================================================" && reboot || \ - _exit 1 "刷机失败" - +==============================================================" + reboot +else + _exit 1 "刷机失败" +fi diff --git a/static/mv300_upgrade.sh b/static/mv300_upgrade.sh index 469c448..6c1a098 100755 --- a/static/mv300_upgrade.sh +++ b/static/mv300_upgrade.sh @@ -1,7 +1,5 @@ #!/bin/bash - dlfile="mv300-99.flash.gz" # 文件路径 - echo " +---------------------------------------------------------------------- | 海纳思系统hi3798mv300升级系统专用脚本温馨提示: @@ -19,56 +17,90 @@ read -p "继续执行?[y/n]: " result temp_file=$(mktemp) curl -sSL https://hi.ecoo.top/mirror-utils.sh > $temp_file if [ ! -f /etc/public-download.sh ] || [ "$(cat $temp_file|md5sum|awk '{print $1}')" != "$(cat /etc/public-download.sh|md5sum|awk '{print $1}')" ]; then - cp $temp_file /etc/public-download.sh + cp $temp_file /etc/public-download.sh fi rm -f $temp_file source /etc/public-download.sh model=$(cpuid) platform=hi3798mv300 - -if [ "$(echo ${model})" != "$platform" ];then - _exit 1 "本升级程序仅支持${platform}机型!" +if [ "$(echo ${model})" != "$platform" ]; then + _exit 1 "本升级程序仅支持${platform}机型!" fi -if [ $(whoami) != "root" ];then - _exit 1 "请使用root权限切换系统命令!" +if [ $(whoami) != "root" ]; then + _exit 1 "请使用root权限切换系统命令!" fi is64bit=$(getconf LONG_BIT) -if [ "${is64bit}" != '64' ];then - _exit 1 "抱歉, 当前系统切换版本不支持32位系统, 请使用64位系统!"; +if [ "${is64bit}" != '64' ]; then + _exit 1 "抱歉, 当前系统切换版本不支持32位系统, 请使用64位系统!" fi promode=$(uname -r|cut -c 13-) -if [ $promode = 36010066 ];then - _exit 1 "专业版用户请使用vipupgrade命令进行升级!" +if [ $promode = 36010066 ]; then + _exit 1 "专业版用户请使用vipupgrade命令进行升级!" fi -#nasversion=`cat /etc/nasversion` -#if [ $nasversion = "20230101" ];then -# _exit 1 "已经是20230101最新版,无需升级系统!" -#fi -space_left=$(df -hT|grep /dev/root|awk '{print $4}') -if [ "$(expr $(echo ${space_left%%G}) \> 1)" != 1 ];then - _exit 1 "请确保剩余空间大于1G!" +# --------------------------------------------------------------- +# 检测 /tmp 剩余空间,不足 500M 时尝试扩容或清理 +# --------------------------------------------------------------- +printStr yellow "检测 /tmp 可用空间..." +TMP_AVAIL=$(df -T | grep '/tmp' | awk '{print int($5)}') # 单位:KB + +if [ "${TMP_AVAIL}" -lt 512000 ]; then # 512000 KB ≈ 500M + printStr yellow "/tmp 剩余空间不足 500M(当前 ${TMP_AVAIL} KB),尝试 remount 扩容..." + + mount -o remount,size=500M /tmp 2>/dev/null + if [ $? -eq 0 ]; then + printStr green "/tmp 已扩容至 500M" + else + printStr yellow "remount 失败,尝试清理 /tmp 旧文件..." + # 删除超过 1 天的普通文件 + find /tmp -type f -mtime +1 -delete 2>/dev/null + # 删除同名残留包(防止上次下载中断) + rm -f /tmp/${dlfile} + + # 清理后再次尝试扩容 + mount -o remount,size=450M /tmp 2>/dev/null + if [ $? -eq 0 ]; then + printStr green "清理后 remount 成功,/tmp 已扩容至 450M" + else + # 最后再检查一次实际剩余空间,也许清理后已经够用 + TMP_AVAIL=$(df -T | grep '/tmp' | awk '{print int($5)}') + if [ "${TMP_AVAIL}" -lt 498000 ]; then + _exit 1 "/tmp 空间不足且无法扩容(当前 ${TMP_AVAIL} KB),请手动清理后重试!" + else + printStr green "清理后 /tmp 剩余空间已满足要求(${TMP_AVAIL} KB)" + fi + fi + fi +else + printStr green "/tmp 剩余空间充足(${TMP_AVAIL} KB),继续..." fi +# --------------------------------------------------------------- printStr yellow "检测并选定下载节点..." get_mirror_url - printStr yellow "下载刷机包..." -dl_get update/system/${dlfile} /${dlfile} +dl_get update/system/${dlfile} /tmp/${dlfile} + printStr yellow "校验刷机包..." -[ "$(get_md5 -c ${NODE_URL}/update/system/${dlfile}.md5sum ${dlfile})" != "$(get_md5 -l /${dlfile})" ] && _exit 1 "文件校验失败,请重试" +[ "$(get_md5 -c ${NODE_URL}/update/system/${dlfile}.md5sum ${dlfile})" != "$(get_md5 -l /tmp/${dlfile})" ] && \ + _exit 1 "文件校验失败,请重试" printStr green "下载完成!" printStr yellow "刷机中,请勿断电..." -gunzip -c /${dlfile} | dd of=/dev/mmcblk0 bs=1024 seek=1024 status=progress conv=sync +gunzip -c /tmp/${dlfile} | dd of=/dev/mmcblk0 bs=1024 seek=1024 status=progress conv=sync -[[ $? == 0 ]] && printStr yellow " +if [[ $? == 0 ]]; then + rm -f /tmp/${dlfile} # 刷机成功后清理临时文件 + printStr yellow " ============================================================== 刷机已完成,请手工关闭电源并再次开启,等待初始化5-8分钟即可。 -==============================================================" && reboot || \ - _exit 1 "刷机失败" +==============================================================" + reboot +else + _exit 1 "刷机失败" +fi