diff --git a/files/30-sysinfo.sh b/files/30-sysinfo.sh index 8653c7a7c1..cb8b0a5c1e 100755 --- a/files/30-sysinfo.sh +++ b/files/30-sysinfo.sh @@ -19,21 +19,20 @@ for f in $MOTD_DISABLE; do done # don't edit below here -function display() -{ +function display() { # $1=name $2=value $3=red_limit $4=minimal_show_limit $5=unit $6=after $7=acs/desc{ # battery red color is opposite, lower number if [[ "$1" == "Battery" ]]; then - local great="<"; + local great="<" else - local great=">"; + local great=">" fi - if [[ -n "$2" && "$2" > "0" && (( "${2%.*}" -ge "$4" )) ]]; then + if [[ -n "$2" && "$2" > "0" && (("${2%.*}" -ge "$4")) ]]; then printf "%-14s%s" "$1:" if awk "BEGIN{exit ! ($2 $great $3)}"; then - echo -ne "\e[0;91m $2"; + echo -ne "\e[0;91m $2" else - echo -ne "\e[0;92m $2"; + echo -ne "\e[0;92m $2" fi printf "%-1s%s\x1B[0m" "$5" printf "%-11s%s\t" "$6" @@ -41,9 +40,7 @@ function display() fi } # display - -function get_ip_addresses() -{ +function get_ip_addresses() { local ips=() for f in /sys/class/net/*; do local intf=$(basename $f) @@ -59,9 +56,7 @@ function get_ip_addresses() echo "${ips[@]}" } # get_ip_addresses - -function storage_info() -{ +function storage_info() { # storage info RootInfo=$(df -h /) root_usage=$(awk '/\// {print $(NF-1)}' <<<${RootInfo} | sed 's/%//g') @@ -85,15 +80,14 @@ function storage_info() fi } # storage_info -function get_data_storage() -{ - if which lsblk >/dev/null;then - root_name=$(lsblk -l -o NAME,MOUNTPOINT | awk '$2~/^\/$/ {print $1'}) - mmc_name=$(echo $root_name | awk '{print substr($1,1,length($1)-2);}') - if echo $mmc_name | grep mmcblk >/dev/null;then - DATA_STORAGE="/mnt/${mmc_name}p4" +function get_data_storage() { + if which lsblk >/dev/null; then + root_name=$(lsblk -l -o NAME,MOUNTPOINT | awk '$2~/^\/$/ {print $1'}) + mmc_name=$(echo $root_name | awk '{print substr($1,1,length($1)-2);}') + if echo $mmc_name | grep mmcblk >/dev/null; then + DATA_STORAGE="/mnt/${mmc_name}p4" + fi fi - fi } # query various systems and send some stuff to the background for overall faster execution. @@ -101,29 +95,29 @@ function get_data_storage() ip_address=$(get_ip_addresses &) get_data_storage storage_info -critical_load=$(( 1 + $(grep -c processor /proc/cpuinfo) / 2 )) +critical_load=$((1 + $(grep -c processor /proc/cpuinfo) / 2)) # get uptime, logged in users and load in one take -if [ -x /usr/bin/cpustat ];then - time=$(/usr/bin/cpustat -u) - load=$(/usr/bin/cpustat -l) +if [ -x /usr/bin/cpustat ]; then + time=$(/usr/bin/cpustat -u) + load=$(/usr/bin/cpustat -l) else - UptimeString=$(uptime | tr -d ',') - time=$(awk -F" " '{print $3" "$4}' <<<"${UptimeString}") - load="$(awk -F"average: " '{print $2}'<<<"${UptimeString}")" - case ${time} in + UptimeString=$(uptime | tr -d ',') + time=$(awk -F" " '{print $3" "$4}' <<<"${UptimeString}") + load="$(awk -F"average: " '{print $2}' <<<"${UptimeString}")" + case ${time} in 1:*) # 1-2 hours - time=$(awk -F" " '{print $3" 小时"}' <<<"${UptimeString}") + time=$(awk -F" " '{print $3" h"}' <<<"${UptimeString}") ;; *:*) # 2-24 hours - time=$(awk -F" " '{print $3" 小时"}' <<<"${UptimeString}") + time=$(awk -F" " '{print $3" h"}' <<<"${UptimeString}") ;; *day) # days - days=$(awk -F" " '{print $3"天"}' <<<"${UptimeString}") + days=$(awk -F" " '{print $3"d"}' <<<"${UptimeString}") time=$(awk -F" " '{print $5}' <<<"${UptimeString}") - time="$days "$(awk -F":" '{print $1"小时 "$2"分钟"}' <<<"${time}") + time="$days "$(awk -F":" '{print $1"h "$2"m"}' <<<"${time}") ;; - esac + esac fi # memory and swap @@ -135,61 +129,59 @@ swap_usage=$( (awk '/Swap/ { printf("%3.0f", $3/$2*100) }' <<<${swap_info} 2>/de swap_total=$(awk '{print $(2)}' <<<${swap_info}) if grep -q "ipq40xx" "/etc/openwrt_release"; then - cpu_temp="$(sensors | grep -Eo '\+[0-9]+.+C' | sed ':a;N;$!ba;s/\n/ /g;s/+//g')" + cpu_temp="$(sensors | grep -Eo '\+[0-9]+.+C' | sed ':a;N;$!ba;s/\n/ /g;s/+//g')" elif [ -f "/sys/class/thermal/thermal_zone0/temp" ]; then - cpu_temp="$(awk '{ printf("%.1f °C", $0 / 1000) }' /sys/class/thermal/thermal_zone0/temp)" + cpu_temp="$(awk '{ printf("%.1f °C", $0 / 1000) }' /sys/class/thermal/thermal_zone0/temp)" elif [ -f "/sys/class/hwmon/hwmon0/temp1_input" ]; then - cpu_temp="$(awk '{ printf("%.1f °C", $0 / 1000) }' /sys/class/hwmon/hwmon0/temp1_input)" + cpu_temp="$(awk '{ printf("%.1f °C", $0 / 1000) }' /sys/class/hwmon/hwmon0/temp1_input)" else - cpu_temp="50.0 °C" + cpu_temp="50.0 °C" fi -cpu_tempx=`echo $cpu_temp | sed 's/°C//g'` +cpu_tempx=$(echo $cpu_temp | sed 's/°C//g') -if [ -x /usr/bin/cpustat ];then - sys_temp=$(/usr/bin/cpustat -A) +if [ -x /usr/bin/cpustat ]; then + sys_temp=$(/usr/bin/cpustat -A) else - sys_temp=$(cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c) + sys_temp=$(cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c) fi -sys_tempx=`echo $sys_temp | sed 's/ / /g'` +sys_tempx=$(echo $sys_temp | sed 's/ / /g') # display info -machine_model=$(cat /proc/device-tree/model|tr -d "\000") -echo -e "设备信息: \033[93m${machine_model}\033[0m" -printf "CPU 型号: \x1B[93m%s\x1B[0m" "$sys_tempx" +machine_model=$(cat /proc/device-tree/model | tr -d "\000") +echo -e " Device Model: \033[93m${machine_model}\033[0m" +printf " Architecture: \x1B[93m%s\x1B[0m" "$sys_tempx" echo "" -display "系统负载" "${load%% *}" "${critical_load}" "0" "" "${load#* }" -printf "运行时间: \x1B[92m%s\x1B[0m\t\t" "$time" +display " Load Average" "${load%% *}" "${critical_load}" "0" "" "${load#* }" +printf "Uptime: \x1B[92m%s\x1B[0m\t\t" "$time" echo "" -display "环境温度" "$cpu_tempx" "60" "0" "°C" "" -if [ -x /usr/bin/cpustat ];then - cpu_freq=$(/usr/bin/cpustat -F1500) - echo -n "当前频率: $cpu_freq" +display " Ambient Temp" "$cpu_tempx" "60" "0" "" "°C" +if [ -x /usr/bin/cpustat ]; then + cpu_freq=$(/usr/bin/cpustat -F1500) + echo -n "Frequency: $cpu_freq" else - display "当前频率" "$cpu_freq" "1500" "0" " Mhz" "" + display "Frequency" "$cpu_freq" "1500" "0" " Mhz" "" fi echo "" -display "内存已用" "$memory_usage" "70" "0" "%" " of ${memory_total}MB" -printf "IP 地址: \x1B[92m%s\x1B[0m" "$ip_address" -#display "交换内存" "$swap_usage" "10" "0" "%" " of $swap_total""Mb" +display " Memory Usage" "$memory_usage" "70" "0" "%" " of ${memory_total}MB" +printf "IP Address: \x1B[92m%s\x1B[0m" "$ip_address" +#display "Swap Usage" "$swap_usage" "10" "0" "%" " of $swap_total""Mb" echo "" #echo "" # fixed newline -display "启动存储" "$boot_usage" "90" "1" "%" " of $boot_total" -display "系统存储" "$root_usage" "90" "1" "%" " of $root_total" +display " Boot Storage" "$boot_usage" "90" "1" "%" " of $boot_total" +display "SYS Storage" "$root_usage" "90" "1" "%" " of $root_total" echo "" -if [ "$data_usage" != "" ];then - display "数据存储" "$data_usage" "90" "1" "%" " of $data_total" - echo "" +if [ "$data_usage" != "" ]; then + display " Data Storage" "$data_usage" "90" "1" "%" " of $data_total" + echo "" fi -if [ "$media_usage" != "" ];then - display "媒体存储" "$media_usage" "90" "1" "%" " of $media_total" - echo "" +if [ "$media_usage" != "" ]; then + display " Data Storage" "$media_usage" "90" "1" "%" " of $media_total" + echo "" fi echo "" - - diff --git a/files/openwrt-backup b/files/openwrt-backup index 719ea0f96d..6a34cbefb5 100755 --- a/files/openwrt-backup +++ b/files/openwrt-backup @@ -85,7 +85,7 @@ backup() { [ -d "${BACKUP_DIR}" ] || mkdir -p "${BACKUP_DIR}" eval tar czf "${BACKUP_FILE}" "${BACKUP_LIST}" 2>/dev/null sync - if [ -f "${BACKUP_FILE}" ];then + if [ -f "${BACKUP_FILE}" ]; then echo "Has been backed up to [ ${BACKUP_FILE} ], please download and save." exit 0 else @@ -97,24 +97,27 @@ backup() { restore() { # Find the partition where root is located ROOT_PTNAME=$(df / | tail -n1 | awk '{print $1}' | awk -F '/' '{print $3}') - if [ "${ROOT_PTNAME}" == "" ];then + if [ "${ROOT_PTNAME}" == "" ]; then echo "Cannot find the partition corresponding to the root file system!" exit 1 fi # Find the disk where the partition is located, only supports mmcblk?p? sd?? hd?? vd?? and other formats case ${ROOT_PTNAME} in - mmcblk?p[1-4]) EMMC_NAME=$(echo ${ROOT_PTNAME} | awk '{print substr($1, 1, length($1)-2)}') - PARTITION_NAME="p" - LB_PRE="EMMC_" - ;; - [hsv]d[a-z][1-4]) EMMC_NAME=$(echo ${ROOT_PTNAME} | awk '{print substr($1, 1, length($1)-1)}') - PARTITION_NAME="" - LB_PRE="" - ;; - *) echo "Unable to recognize the disk type of ${ROOT_PTNAME}!" - exit 1 - ;; + mmcblk?p[1-4]) + EMMC_NAME=$(echo ${ROOT_PTNAME} | awk '{print substr($1, 1, length($1)-2)}') + PARTITION_NAME="p" + LB_PRE="EMMC_" + ;; + [hsv]d[a-z][1-4]) + EMMC_NAME=$(echo ${ROOT_PTNAME} | awk '{print substr($1, 1, length($1)-1)}') + PARTITION_NAME="" + LB_PRE="" + ;; + *) + echo "Unable to recognize the disk type of ${ROOT_PTNAME}!" + exit 1 + ;; esac [ -d "${BACKUP_DIR}" ] || mkdir -p "${BACKUP_DIR}" @@ -140,26 +143,29 @@ restore() { gen_fstab() { # Find the partition where root is located ROOT_PTNAME=$(df / | tail -n1 | awk '{print $1}' | awk -F '/' '{print $3}') - if [ "${ROOT_PTNAME}" == "" ];then + if [ "${ROOT_PTNAME}" == "" ]; then echo "Cannot find the partition corresponding to the root file system!" exit 1 fi # Find the disk where the partition is located, only supports mmcblk?p? sd?? hd?? vd?? and other formats case ${ROOT_PTNAME} in - mmcblk?p[1-4]) EMMC_NAME=$(echo ${ROOT_PTNAME} | awk '{print substr($1, 1, length($1)-2)}') - PARTITION_NAME="p" - ;; - [hsv]d[a-z][1-4]) EMMC_NAME=$(echo ${ROOT_PTNAME} | awk '{print substr($1, 1, length($1)-1)}') - PARTITION_NAME="" - ;; - *) echo "Unable to recognize the disk type of ${ROOT_PTNAME}!" - exit 1 - ;; + mmcblk?p[1-4]) + EMMC_NAME=$(echo ${ROOT_PTNAME} | awk '{print substr($1, 1, length($1)-2)}') + PARTITION_NAME="p" + ;; + [hsv]d[a-z][1-4]) + EMMC_NAME=$(echo ${ROOT_PTNAME} | awk '{print substr($1, 1, length($1)-1)}') + PARTITION_NAME="" + ;; + *) + echo "Unable to recognize the disk type of ${ROOT_PTNAME}!" + exit 1 + ;; esac ROOT_MSG=$(lsblk -l -o NAME,PATH,MOUNTPOINT,UUID,FSTYPE,LABEL | awk '$3 ~ /^\/$/ {print $0}') - if [ "$ROOT_MSG" == "" ];then + if [ "$ROOT_MSG" == "" ]; then echo "Get rootfs message failed!" exit 1 fi @@ -177,7 +183,7 @@ gen_fstab() { BOOT_FSTYPE=$(echo $BOOT_MSG | awk '{print $3}') BOOT_LABEL=$(echo $BOOT_MSG | awk '{print $4}') - cat > /etc/config/fstab </etc/config/fstab <> /etc/config/fstab + if [ "${ROOT_FSTYPE}" == "btrfs" ]; then + echo " option options 'compress=zstd'" >>/etc/config/fstab fi - cat >> /etc/config/fstab <>/etc/config/fstab <> /etc/config/fstab + + if [ "${BOOT_FSTYPE}" == "vfat" ]; then + echo " option label '${BOOT_LABEL}'" >>/etc/config/fstab else - echo " option uuid '${BOOT_UUID}'" >> /etc/config/fstab + echo " option uuid '${BOOT_UUID}'" >>/etc/config/fstab fi - cat >> /etc/config/fstab <>/etc/config/fstab < /dev/null; then + elif echo "${nname}" | grep -E "\s+" >/dev/null; then echo "The name [${nname}] contains spaces, please re-enter!" continue elif [ "${nname}" == "q" ] || [ "${nname}" == "Q" ]; then @@ -259,14 +265,15 @@ create_snapshot() { fi done - ( cd / - chattr -ia etc/config/fstab - btrfs subvolume snapshot -r /etc "${SNAPSHOT_PRESTR}${snap_name}" - if [[ "$?" -eq "0" ]]; then - echo "The snapshot is created successfully: ${snap_name}" - else - echo "Snapshot creation failed!" - fi + ( + cd / + chattr -ia etc/config/fstab + btrfs subvolume snapshot -r /etc "${SNAPSHOT_PRESTR}${snap_name}" + if [[ "$?" -eq "0" ]]; then + echo "The snapshot is created successfully: ${snap_name}" + else + echo "Snapshot creation failed!" + fi ) read -p "Press [ enter ] to return." q } @@ -279,31 +286,32 @@ restore_snapshot() { btrfs subvolume list -rt / echo "----------------------------------------------------------------" read -p "Please enter the name of the snapshot to be restored (only the part after ${SNAPSHOT_PRESTR} needs to be entered): " snap_name - if btrfs subvolume list -rt / | grep "${SNAPSHOT_PRESTR}${snap_name}" > /dev/null; then + if btrfs subvolume list -rt / | grep "${SNAPSHOT_PRESTR}${snap_name}" >/dev/null; then while :; do echo "Once the snapshot is restored, the current [ /etc ] will be overwritten!" read -p "Are you sure you want to restore the snapshot: [$snap_name]? y/n [n] " yn case $yn in - y|Y) - ( - cd / - chattr -ia etc/config/fstab - mv etc etc.backup - btrfs subvolume snapshot "${SNAPSHOT_PRESTR}${snap_name}" etc - if [[ "$?" -eq "0" ]]; then - btrfs subvolume delete -c etc.backup - echo "Successfully restored, please enter [ reboot ] to restart the openwrt." - else - rm -rf etc - mv etc.backup etc - echo "Recovery failed, [ etc ] has not changed!" - fi - ) - read -p "Press [ enter ] to return." q - break - ;; - *) break - ;; + y | Y) + ( + cd / + chattr -ia etc/config/fstab + mv etc etc.backup + btrfs subvolume snapshot "${SNAPSHOT_PRESTR}${snap_name}" etc + if [[ "$?" -eq "0" ]]; then + btrfs subvolume delete -c etc.backup + echo "Successfully restored, please enter [ reboot ] to restart the openwrt." + else + rm -rf etc + mv etc.backup etc + echo "Recovery failed, [ etc ] has not changed!" + fi + ) + read -p "Press [ enter ] to return." q + break + ;; + *) + break + ;; esac done else @@ -324,23 +332,24 @@ delete_snapshot() { elif [ "${snap_name}" == "" ]; then read -p "Name is empty! Press [ enter ] to return." q else - if btrfs subvolume list -rt / | grep "${SNAPSHOT_PRESTR}${snap_name}" > /dev/null; then + if btrfs subvolume list -rt / | grep "${SNAPSHOT_PRESTR}${snap_name}" >/dev/null; then read -p "Are you sure you want to delete ${snap_name}? y/n [n] " yn case $yn in - y|Y) - ( - cd / - btrfs subvolume delete -c "${SNAPSHOT_PRESTR}${snap_name}" - if [[ "$?" -eq "0" ]]; then - echo "Snapshot [ ${snap_name} ] has been deleted." - else - echo "Snapshot [ ${snap_name} ] failed to delete!" - fi - ) - read -p "Press [ Enter ] to return." q - ;; - *) break - ;; + y | Y) + ( + cd / + btrfs subvolume delete -c "${SNAPSHOT_PRESTR}${snap_name}" + if [[ "$?" -eq "0" ]]; then + echo "Snapshot [ ${snap_name} ] has been deleted." + else + echo "Snapshot [ ${snap_name} ] failed to delete!" + fi + ) + read -p "Press [ Enter ] to return." q + ;; + *) + break + ;; esac else read -p "The name of the snapshot is incorrect, press [ Enter ] to return." q @@ -349,8 +358,8 @@ delete_snapshot() { } migrate_snapshot() { - cur_rootdev=$(lsblk -l -o NAME,MOUNTPOINT |awk '$2~/^\/$/ {print $1}') - if [ "${cur_rootdev}" == "" ];then + cur_rootdev=$(lsblk -l -o NAME,MOUNTPOINT | awk '$2~/^\/$/ {print $1}') + if [ "${cur_rootdev}" == "" ]; then echo "The disk device corresponding to the current rootfs cannot be found!" read -p "Press [ enter ] to return." q return @@ -358,12 +367,17 @@ migrate_snapshot() { dev_pre=$(echo "${cur_rootdev}" | awk '{print substr($1, 1, length($1)-1);}') rootdev_idx=$(echo "${cur_rootdev}" | awk '{print substr($1, length($1),1);}') case $rootdev_idx in - 2) old_rootpath="/mnt/${dev_pre}3";; - 3) old_rootpath="/mnt/${dev_pre}2";; - *) echo "Judge the old version of rootfs path failed!" - read -p "Press [ enter ] to return." q - return - ;; + 2) + old_rootpath="/mnt/${dev_pre}3" + ;; + 3) + old_rootpath="/mnt/${dev_pre}2" + ;; + *) + echo "Judge the old version of rootfs path failed!" + read -p "Press [ enter ] to return." q + return + ;; esac echo "The following are snapshots of etc found from the old version of rootfs, please enter the name of one of them." echo "Tip: Automatically exclude etc-000 and etc-001" @@ -371,21 +385,21 @@ migrate_snapshot() { btrfs subvolume list -rt "${old_rootpath}" | grep -v "${SNAPSHOT_PRESTR}etc-000" | grep -v "${SNAPSHOT_PRESTR}etc-001" echo "-----------------------------------------------------------------------------------" read -p "Please enter the name of the snapshot to be migrated (only the part after $(SNAPSHOT_PRESTR) needs to be entered): " old_snap_name - if [ "${old_snap_name}" == "" ];then + if [ "${old_snap_name}" == "" ]; then read -p "The name is empty, Press [ enter ] to return." q return - elif ! btrfs subvolume list -rt "${old_rootpath}" | awk '{print $4}' | grep "^${SNAPSHOT_PRESTR}${old_snap_name}$" >/dev/null;then + elif ! btrfs subvolume list -rt "${old_rootpath}" | awk '{print $4}' | grep "^${SNAPSHOT_PRESTR}${old_snap_name}$" >/dev/null; then echo "The name was entered incorrectly, and the corresponding snapshot was not found!" read -p "Press [ enter ] to return." q return - elif [ "${old_snap_name}" == "etc-000" ] || [ "${old_snap_name}" == "etc-001" ];then + elif [ "${old_snap_name}" == "etc-000" ] || [ "${old_snap_name}" == "etc-001" ]; then echo "Critical snapshots are not allowed to migrate!" read -p "Press [ enter ] to return." q return fi # Find out if there is a snapshot with the same name under the current rootfs - if btrfs subvolume list -rt / | awk '{print $4}' | grep "^\\${SNAPSHOT_PRESTR}${old_snap_name}$" >/dev/null;then + if btrfs subvolume list -rt / | awk '{print $4}' | grep "^\\${SNAPSHOT_PRESTR}${old_snap_name}$" >/dev/null; then echo "A snapshot with the name [ ${old_snap_name} ] already exists and cannot be migrated! (But you can delete the existing snapshot with the same name and then migrate)" read -p "Press [ enter ] to return." q return @@ -398,11 +412,11 @@ migrate_snapshot() { echo -e "Note: To migrate the snapshot [ ${old_snap_name} ] of [ ${old_rootpath} ] to the current rootfs, it takes about [ ${need_size} ] space," echo -e " Please confirm whether the partition [/dev/${cur_rootdev}] where [/] is located has enough free space (Available)?" read -p "Are you sure to migrate? y/n [n] " yn - if [ "$yn" == "y" ] || [ "$yn" == "Y" ];then + if [ "$yn" == "y" ] || [ "$yn" == "Y" ]; then ( cd / btrfs send ${old_rootpath}/${SNAPSHOT_PRESTR}${old_snap_name} | btrfs receive ${SNAPSHOT_PRESTR} - if [ $? -eq 0 ];then + if [ $? -eq 0 ]; then btrfs property set -ts ${SNAPSHOT_PRESTR}${old_snap_name} ro false cp ${SNAPSHOT_PRESTR}etc-000/config/fstab ${SNAPSHOT_PRESTR}${old_snap_name}/config/ cp ${SNAPSHOT_PRESTR}etc-000/fstab ${SNAPSHOT_PRESTR}${old_snap_name}/ @@ -482,7 +496,7 @@ print_help() { } menu() { - while :;do + while :; do clear cat </tmp/fdisk.script while [ $p -ge 1 ]; do - echo "d" >> /tmp/fdisk.script + echo "d" >>/tmp/fdisk.script if [ $p -gt 1 ]; then - echo "$p" >> /tmp/fdisk.script + echo "$p" >>/tmp/fdisk.script fi - p=$((p-1)) + p=$((p - 1)) done # you can change ROOT size(MB) >= 320 @@ -320,21 +320,21 @@ else BLANK4=0 fi -DST_TOTAL_MB=$((EMMC_SIZE/1024/1024)) +DST_TOTAL_MB=$((EMMC_SIZE / 1024 / 1024)) -start1=$(( BLANK1 * 2048 )) -end1=$(( start1 + (BOOT * 2048) - 1 )) +start1=$((BLANK1 * 2048)) +end1=$((start1 + (BOOT * 2048) - 1)) -start2=$(( (BLANK2 * 2048) + end1 + 1 )) -end2=$(( start2 + (ROOT1 * 2048) -1 )) +start2=$(((BLANK2 * 2048) + end1 + 1)) +end2=$((start2 + (ROOT1 * 2048) - 1)) -start3=$(( (BLANK3 * 2048) + end2 + 1 )) -end3=$(( start3 + (ROOT2 * 2048) -1 )) +start3=$(((BLANK3 * 2048) + end2 + 1)) +end3=$((start3 + (ROOT2 * 2048) - 1)) -start4=$(( (BLANK4 * 2048) + end3 + 1 )) -end4=$(( DST_TOTAL_MB * 2048 -1 )) +start4=$(((BLANK4 * 2048) + end3 + 1)) +end4=$((DST_TOTAL_MB * 2048 - 1)) -cat >> /tmp/fdisk.script <>/tmp/fdisk.script </dev/null +fdisk /dev/${EMMC_NAME} /dev/null if [ $? -ne 0 ]; then echo "The fdisk partition fails, Please try again." dd if=/root/BackupOldBootloader.img of=/dev/${EMMC_NAME} conf=fsync && sync @@ -393,7 +393,7 @@ dd if=/dev/zero of=/dev/${EMMC_NAME} bs=1M count=1 seek=$seek conv=fsync #Mainline U-BOOT detection FLASH_MAINLINE_UBOOT=0 -if [[ -n "${MAINLINE_UBOOT}" && -f "${MAINLINE_UBOOT}" ]]; then +if [[ -n "${MAINLINE_UBOOT}" && -f "${MAINLINE_UBOOT}" ]]; then cat < uEnv.txt <uEnv.txt </dev/null - echo "FDTFILE='${FDTFILE}'" >> etc/flippy-openwrt-release 2>/dev/null + echo "FDTFILE='${FDTFILE}'" >>etc/flippy-openwrt-release 2>/dev/null sed -i '/UBOOT_OVERLOAD/d' etc/flippy-openwrt-release 2>/dev/null - echo "UBOOT_OVERLOAD='${UBOOT_OVERLOAD}'" >> etc/flippy-openwrt-release 2>/dev/null + echo "UBOOT_OVERLOAD='${UBOOT_OVERLOAD}'" >>etc/flippy-openwrt-release 2>/dev/null sed -i '/MAINLINE_UBOOT/d' etc/flippy-openwrt-release 2>/dev/null - echo "MAINLINE_UBOOT='${MAINLINE_UBOOT}'" >> etc/flippy-openwrt-release 2>/dev/null + echo "MAINLINE_UBOOT='${MAINLINE_UBOOT}'" >>etc/flippy-openwrt-release 2>/dev/null sed -i '/ANDROID_UBOOT/d' etc/flippy-openwrt-release 2>/dev/null - echo "ANDROID_UBOOT='${ANDROID_UBOOT}'" >> etc/flippy-openwrt-release 2>/dev/null + echo "ANDROID_UBOOT='${ANDROID_UBOOT}'" >>etc/flippy-openwrt-release 2>/dev/null sed -i '/SOC/d' etc/flippy-openwrt-release 2>/dev/null - echo "SOC='${AMLOGIC_SOC}'" >> etc/flippy-openwrt-release 2>/dev/null + echo "SOC='${AMLOGIC_SOC}'" >>etc/flippy-openwrt-release 2>/dev/null echo "Update complete." sync - - cat > etc/docker/daemon.json <etc/docker/daemon.json </dev/null;then - if find ../../lib/modules -name 'shortcut-fe-cm.ko';then + rm -f S??shortcut-fe + if grep "sfe_flow '1'" ../config/turboacc >/dev/null; then + if find ../../lib/modules -name 'shortcut-fe-cm.ko'; then ln -sf ../init.d/shortcut-fe S99shortcut-fe - fi - fi + fi + fi cd /mnt/${EMMC_NAME}p2/etc - cat > fstab <fstab < fstab <fstab < .snapshots/etc-000" - cd /mnt/${EMMC_NAME}p2 && \ - btrfs subvolume snapshot -r etc .snapshots/etc-000 + cd /mnt/${EMMC_NAME}p2 && + btrfs subvolume snapshot -r etc .snapshots/etc-000 sync cd / @@ -670,22 +672,22 @@ EOF read TARGET_SHARED_FSTYPE fi case $TARGET_SHARED_FSTYPE in - 2 | btrfs) - mkfs.btrfs -f -L EMMC_SHARED -m single /dev/${EMMC_NAME}p4 >/dev/null - mount -t btrfs /dev/${EMMC_NAME}p4 /mnt/${EMMC_NAME}p4 - ;; - 3 | f2fs) - mkfs.f2fs -f -l EMMC_SHARED /dev/${EMMC_NAME}p4 >/dev/null - mount -t f2fs /dev/${EMMC_NAME}p4 /mnt/${EMMC_NAME}p4 - ;; - 4 | xfs) - mkfs.xfs -f -L EMMC_SHARED /dev/${EMMC_NAME}p4 >/dev/null - mount -t xfs /dev/${EMMC_NAME}p4 /mnt/${EMMC_NAME}p4 - ;; - *) - mkfs.ext4 -F -L EMMC_SHARED /dev/${EMMC_NAME}p4 >/dev/null - mount -t ext4 /dev/${EMMC_NAME}p4 /mnt/${EMMC_NAME}p4 - ;; +2 | btrfs) + mkfs.btrfs -f -L EMMC_SHARED -m single /dev/${EMMC_NAME}p4 >/dev/null + mount -t btrfs /dev/${EMMC_NAME}p4 /mnt/${EMMC_NAME}p4 + ;; +3 | f2fs) + mkfs.f2fs -f -l EMMC_SHARED /dev/${EMMC_NAME}p4 >/dev/null + mount -t f2fs /dev/${EMMC_NAME}p4 /mnt/${EMMC_NAME}p4 + ;; +4 | xfs) + mkfs.xfs -f -L EMMC_SHARED /dev/${EMMC_NAME}p4 >/dev/null + mount -t xfs /dev/${EMMC_NAME}p4 /mnt/${EMMC_NAME}p4 + ;; +*) + mkfs.ext4 -F -L EMMC_SHARED /dev/${EMMC_NAME}p4 >/dev/null + mount -t ext4 /dev/${EMMC_NAME}p4 /mnt/${EMMC_NAME}p4 + ;; esac mkdir -p /mnt/${EMMC_NAME}p4/docker /mnt/${EMMC_NAME}p4/AdGuardHome/data sync diff --git a/files/openwrt-kernel b/files/openwrt-kernel index aaed03d76e..9c1c66a0df 100755 --- a/files/openwrt-kernel +++ b/files/openwrt-kernel @@ -52,24 +52,27 @@ fi # Find the partition where root is located ROOT_PTNAME=$(df / | tail -n1 | awk '{print $1}' | awk -F '/' '{print $3}') -if [ "${ROOT_PTNAME}" == "" ];then +if [ "${ROOT_PTNAME}" == "" ]; then echo "Cannot find the partition corresponding to the root file system!" exit 1 fi # Find the disk where the partition is located, only supports mmcblk?p? sd?? hd?? vd?? and other formats case ${ROOT_PTNAME} in - mmcblk?p[1-4]) EMMC_NAME=$(echo ${ROOT_PTNAME} | awk '{print substr($1, 1, length($1)-2)}') - PARTITION_NAME="p" - LB_PRE="EMMC_" - ;; - [hsv]d[a-z][1-4]) EMMC_NAME=$(echo ${ROOT_PTNAME} | awk '{print substr($1, 1, length($1)-1)}') - PARTITION_NAME="" - LB_PRE="" - ;; - *) echo "Unable to recognize the disk type of ${ROOT_PTNAME}!" - exit 1 - ;; +mmcblk?p[1-4]) + EMMC_NAME=$(echo ${ROOT_PTNAME} | awk '{print substr($1, 1, length($1)-2)}') + PARTITION_NAME="p" + LB_PRE="EMMC_" + ;; +[hsv]d[a-z][1-4]) + EMMC_NAME=$(echo ${ROOT_PTNAME} | awk '{print substr($1, 1, length($1)-1)}') + PARTITION_NAME="" + LB_PRE="" + ;; +*) + echo "Unable to recognize the disk type of ${ROOT_PTNAME}!" + exit 1 + ;; esac echo -e "Current device: ${MYDEVICE_NAME} [ ${MYDTB_FILE} ], Use in [ ${EMMC_NAME} ]" @@ -80,18 +83,18 @@ P4_PATH="/mnt/${EMMC_NAME}${PARTITION_NAME}4" # Move kernel related files to the ${P4_PATH} directory mv -f /tmp/upload/* ${P4_PATH}/ 2>/dev/null && sync -if [ $( ls ${P4_PATH}/*.tar.gz -l 2>/dev/null | grep "^-" | wc -l ) -ge 3 ]; then +if [ $(ls ${P4_PATH}/*.tar.gz -l 2>/dev/null | grep "^-" | wc -l) -ge 3 ]; then - if [ $( ls ${P4_PATH}/boot-*.tar.gz -l 2>/dev/null | grep "^-" | wc -l ) -ge 1 ]; then - build_boot=$( ls ${P4_PATH}/boot-*.tar.gz | head -n 1 ) && build_boot=${build_boot##*/} + if [ $(ls ${P4_PATH}/boot-*.tar.gz -l 2>/dev/null | grep "^-" | wc -l) -ge 1 ]; then + build_boot=$(ls ${P4_PATH}/boot-*.tar.gz | head -n 1) && build_boot=${build_boot##*/} echo -e "Update using [ ${build_boot} ] files. Please wait a moment ..." flippy_version=${build_boot/boot-/} && flippy_version=${flippy_version/.tar.gz/} kernel_version=$(echo ${flippy_version} | grep -oE '^[1-9].[0-9]{1,3}.[0-9]+') kernel_vermaj=$(echo ${kernel_version} | grep -oE '^[1-9].[0-9]{1,3}') k510_ver=${kernel_vermaj%%.*} k510_maj=${kernel_vermaj##*.} - if [ ${k510_ver} -eq "5" ]; then - if [ "${k510_maj}" -ge "10" ]; then + if [ ${k510_ver} -eq "5" ]; then + if [ "${k510_maj}" -ge "10" ]; then K510=1 else K510=0 @@ -105,13 +108,13 @@ if [ $( ls ${P4_PATH}/*.tar.gz -l 2>/dev/null | grep "^-" | wc -l ) -ge 3 ]; th die "Have no boot-*.tar.gz file found in the ${P4_PATH} directory." fi - if [[ -f ${P4_PATH}/dtb-${MYDTB_FILE}-${flippy_version}.tar.gz ]]; then + if [[ -f ${P4_PATH}/dtb-${MYDTB_FILE}-${flippy_version}.tar.gz ]]; then build_dtb="dtb-${MYDTB_FILE}-${flippy_version}.tar.gz" else die "Have no dtb-${MYDTB_FILE}-${flippy_version}.tar.gz file." fi - if [ -f ${P4_PATH}/modules-${flippy_version}.tar.gz ]; then + if [ -f ${P4_PATH}/modules-${flippy_version}.tar.gz ]; then build_modules="modules-${flippy_version}.tar.gz" else die "Have no modules-*.tar.gz file found in the ${P4_PATH} directory." @@ -138,8 +141,8 @@ MODULES_OLD=$(ls /lib/modules/ 2>/dev/null) VERSION_OLD=$(echo ${MODULES_OLD} | grep -oE '^[1-9].[0-9]{1,3}' 2>/dev/null) VERSION_ver=${VERSION_OLD%%.*} VERSION_maj=${VERSION_OLD##*.} -if [ ${VERSION_ver} -eq "5" ]; then - if [ "${VERSION_maj}" -ge "10" ]; then +if [ ${VERSION_ver} -eq "5" ]; then + if [ "${VERSION_maj}" -ge "10" ]; then V510=1 else V510=0 @@ -277,21 +280,21 @@ if [[ "${MYDTB_FILE}" == "rockchip" ]]; then ln -sf /boot/dtb-${flippy_version} /boot/dtb fi tar -xzf ${P4_PATH}/${build_dtb} -C /boot/dtb/${MYDTB_FILE} && sync -[ "$( ls /boot/dtb/${MYDTB_FILE} -l 2>/dev/null | grep "^-" | wc -l )" -ge "1" ] || die "/boot/dtb/${MYDTB_FILE} file is missing." +[ "$(ls /boot/dtb/${MYDTB_FILE} -l 2>/dev/null | grep "^-" | wc -l)" -ge "1" ] || die "/boot/dtb/${MYDTB_FILE} file is missing." echo -e "02. Unpack [ ${build_dtb} ] complete." sleep 3 # 03 for /lib/modules/* rm -rf /lib/modules/* 2>/dev/null && sync tar -xzf ${P4_PATH}/${build_modules} -C /lib/modules && sync - cd /lib/modules/${flippy_version}/ - rm -f *.ko 2>/dev/null - find ./ -type f -name '*.ko' -exec ln -s {} ./ \; - sync && sleep 3 - x=$( ls *.ko -l 2>/dev/null | grep "^l" | wc -l ) - if [ "${x}" -eq "0" ]; then - die "Error *.ko Files not found." - fi +cd /lib/modules/${flippy_version}/ +rm -f *.ko 2>/dev/null +find ./ -type f -name '*.ko' -exec ln -s {} ./ \; +sync && sleep 3 +x=$(ls *.ko -l 2>/dev/null | grep "^l" | wc -l) +if [ "${x}" -eq "0" ]; then + die "Error *.ko Files not found." +fi echo -e "03. Unpack [ ${build_modules} ] complete." sleep 3 @@ -299,10 +302,10 @@ rm -rf ${P4_PATH}/dtb-*.tar.gz ${P4_PATH}/boot-*.tar.gz ${P4_PATH}/modules-*.tar sync sed -i '/KERNEL_VERSION/d' /etc/flippy-openwrt-release 2>/dev/null -echo "KERNEL_VERSION='${kernel_version}'" >> /etc/flippy-openwrt-release 2>/dev/null +echo "KERNEL_VERSION='${kernel_version}'" >>/etc/flippy-openwrt-release 2>/dev/null sed -i '/K510/d' /etc/flippy-openwrt-release 2>/dev/null -echo "K510='${K510}'" >> /etc/flippy-openwrt-release 2>/dev/null +echo "K510='${K510}'" >>/etc/flippy-openwrt-release 2>/dev/null sed -i "s/ Kernel.*/ Kernel: ${flippy_version}/g" /etc/banner 2>/dev/null @@ -313,4 +316,3 @@ echo "Successfully updated, automatic restarting..." sleep 3 reboot exit 0 - diff --git a/files/openwrt-update-allwinner b/files/openwrt-update-allwinner index 2320d86107..429080ba1d 100755 --- a/files/openwrt-update-allwinner +++ b/files/openwrt-update-allwinner @@ -33,24 +33,27 @@ fi # Find the partition where root is located ROOT_PTNAME=$(df / | tail -n1 | awk '{print $1}' | awk -F '/' '{print $3}') -if [ "${ROOT_PTNAME}" == "" ];then +if [ "${ROOT_PTNAME}" == "" ]; then echo "Cannot find the partition corresponding to the root file system!" exit 1 fi # Find the disk where the partition is located, only supports mmcblk?p? sd?? hd?? vd?? and other formats case ${ROOT_PTNAME} in - mmcblk?p[1-4]) EMMC_NAME=$(echo ${ROOT_PTNAME} | awk '{print substr($1, 1, length($1)-2)}') - PARTITION_NAME="p" - LB_PRE="EMMC_" - ;; - [hsv]d[a-z][1-4]) EMMC_NAME=$(echo ${ROOT_PTNAME} | awk '{print substr($1, 1, length($1)-1)}') - PARTITION_NAME="" - LB_PRE="" - ;; - *) echo "Unable to recognize the disk type of ${ROOT_PTNAME}!" - exit 1 - ;; +mmcblk?p[1-4]) + EMMC_NAME=$(echo ${ROOT_PTNAME} | awk '{print substr($1, 1, length($1)-2)}') + PARTITION_NAME="p" + LB_PRE="EMMC_" + ;; +[hsv]d[a-z][1-4]) + EMMC_NAME=$(echo ${ROOT_PTNAME} | awk '{print substr($1, 1, length($1)-1)}') + PARTITION_NAME="" + LB_PRE="" + ;; +*) + echo "Unable to recognize the disk type of ${ROOT_PTNAME}!" + exit 1 + ;; esac cd /mnt/${EMMC_NAME}${PARTITION_NAME}4/ @@ -58,30 +61,30 @@ mv -f /tmp/upload/* . 2>/dev/null && sync if [[ "${IMG_NAME}" == *.img ]]; then echo -e "Update using [ ${IMG_NAME} ] file. Please wait a moment ..." -elif [ $( ls *.img -l 2>/dev/null | grep "^-" | wc -l ) -ge 1 ]; then - IMG_NAME=$( ls *.img | head -n 1 ) +elif [ $(ls *.img -l 2>/dev/null | grep "^-" | wc -l) -ge 1 ]; then + IMG_NAME=$(ls *.img | head -n 1) echo -e "Update using [ ${IMG_NAME} ] ] file. Please wait a moment ..." -elif [ $( ls *.img.xz -l 2>/dev/null | grep "^-" | wc -l ) -ge 1 ]; then - xz_file=$( ls *.img.xz | head -n 1 ) +elif [ $(ls *.img.xz -l 2>/dev/null | grep "^-" | wc -l) -ge 1 ]; then + xz_file=$(ls *.img.xz | head -n 1) echo -e "Update using [ ${xz_file} ] file. Please wait a moment ..." xz -d ${xz_file} 2>/dev/null - IMG_NAME=$( ls *.img | head -n 1 ) -elif [ $( ls *.img.gz -l 2>/dev/null | grep "^-" | wc -l ) -ge 1 ]; then - gz_file=$( ls *.img.gz | head -n 1 ) + IMG_NAME=$(ls *.img | head -n 1) +elif [ $(ls *.img.gz -l 2>/dev/null | grep "^-" | wc -l) -ge 1 ]; then + gz_file=$(ls *.img.gz | head -n 1) echo -e "Update using [ ${gz_file} ] file. Please wait a moment ..." gzip -df ${gz_file} 2>/dev/null - IMG_NAME=$( ls *.img | head -n 1 ) -elif [ $( ls *.7z -l 2>/dev/null | grep "^-" | wc -l ) -ge 1 ]; then - gz_file=$( ls *.7z | head -n 1 ) + IMG_NAME=$(ls *.img | head -n 1) +elif [ $(ls *.7z -l 2>/dev/null | grep "^-" | wc -l) -ge 1 ]; then + gz_file=$(ls *.7z | head -n 1) echo -e "Update using [ ${gz_file} ] file. Please wait a moment ..." bsdtar -xmf ${gz_file} 2>/dev/null [ $? -eq 0 ] || 7z x ${gz_file} -aoa -y 2>/dev/null - IMG_NAME=$( ls *.img | head -n 1 ) -elif [ $( ls *.zip -l 2>/dev/null | grep "^-" | wc -l ) -ge 1 ]; then - zip_file=$( ls *.zip | head -n 1 ) + IMG_NAME=$(ls *.img | head -n 1) +elif [ $(ls *.zip -l 2>/dev/null | grep "^-" | wc -l) -ge 1 ]; then + zip_file=$(ls *.zip | head -n 1) echo -e "Update using [ ${zip_file} ] file. Please wait a moment ..." unzip -o ${zip_file} 2>/dev/null - IMG_NAME=$( ls *.img | head -n 1 ) + IMG_NAME=$(ls *.img | head -n 1) else echo -e "Please upload or specify the update openwrt firmware file." echo -e "Upload method: system menu → Amlogic Service → Manually Upload Update" @@ -93,16 +96,16 @@ fi sync # check file -if [ ! -f "${IMG_NAME}" ]; then +if [ ! -f "${IMG_NAME}" ]; then echo "No update file found." exit 1 else echo "Start update from [ ${IMG_NAME} ]" fi -# find boot partition +# find boot partition BOOT_PART_MSG=$(lsblk -l -o NAME,PATH,TYPE,UUID,MOUNTPOINT | awk '$3~/^part$/ && $5 ~ /^\/boot$/ {print $0}') -if [ "${BOOT_PART_MSG}" == "" ];then +if [ "${BOOT_PART_MSG}" == "" ]; then echo "The boot partition is not exists or not mounted, so it cannot be upgraded with this script!" exit 1 fi @@ -117,33 +120,38 @@ else read yn fi case $yn in - n*|N*) BR_FLAG=0;; +n* | N*) + BR_FLAG=0 + ;; esac BOOT_NAME=$(echo $BOOT_PART_MSG | awk '{print $1}') BOOT_PATH=$(echo $BOOT_PART_MSG | awk '{print $2}') BOOT_UUID=$(echo $BOOT_PART_MSG | awk '{print $4}') -# find root partition +# find root partition ROOT_PART_MSG=$(lsblk -l -o NAME,PATH,TYPE,UUID,MOUNTPOINT | awk '$3~/^part$/ && $5 ~ /^\/$/ {print $0}') ROOT_NAME=$(echo $ROOT_PART_MSG | awk '{print $1}') ROOT_PATH=$(echo $ROOT_PART_MSG | awk '{print $2}') ROOT_UUID=$(echo $ROOT_PART_MSG | awk '{print $4}') -case $ROOT_NAME in - ${EMMC_NAME}${PARTITION_NAME}2) NEW_ROOT_NAME="${EMMC_NAME}${PARTITION_NAME}3" - NEW_ROOT_LABEL="${LB_PRE}ROOTFS2" - ;; - ${EMMC_NAME}${PARTITION_NAME}3) NEW_ROOT_NAME="${EMMC_NAME}${PARTITION_NAME}2" - NEW_ROOT_LABEL="${LB_PRE}ROOTFS1" - ;; - *) echo "The root partition location is invalid, so it cannot be upgraded with this script!" - exit 1 - ;; +case $ROOT_NAME in +${EMMC_NAME}${PARTITION_NAME}2) + NEW_ROOT_NAME="${EMMC_NAME}${PARTITION_NAME}3" + NEW_ROOT_LABEL="${LB_PRE}ROOTFS2" + ;; +${EMMC_NAME}${PARTITION_NAME}3) + NEW_ROOT_NAME="${EMMC_NAME}${PARTITION_NAME}2" + NEW_ROOT_LABEL="${LB_PRE}ROOTFS1" + ;; +*) + echo "The root partition location is invalid, so it cannot be upgraded with this script!" + exit 1 + ;; esac # find new root partition NEW_ROOT_PART_MSG=$(lsblk -l -o NAME,PATH,TYPE,UUID,MOUNTPOINT | grep "${NEW_ROOT_NAME}" | awk '$3 ~ /^part$/ && $5 !~ /^\/$/ && $5 !~ /^\/boot$/ {print $0}') -if [ "${NEW_ROOT_PART_MSG}" == "" ];then +if [ "${NEW_ROOT_PART_MSG}" == "" ]; then echo "The new root partition is not exists, so it cannot be upgraded with this script!" exit 1 fi @@ -154,9 +162,9 @@ NEW_ROOT_MP=$(echo $NEW_ROOT_PART_MSG | awk '{print $5}') # losetup losetup -f -P $IMG_NAME -if [ $? -eq 0 ];then +if [ $? -eq 0 ]; then LOOP_DEV=$(losetup | grep "$IMG_NAME" | awk '{print $1}') - if [ "$LOOP_DEV" == "" ];then + if [ "$LOOP_DEV" == "" ]; then echo "loop device not found!" exit 1 fi @@ -166,22 +174,22 @@ else fi WAIT=3 echo -n "The loopdev is $LOOP_DEV, wait ${WAIT} seconds " -while [ $WAIT -ge 1 ];do +while [ $WAIT -ge 1 ]; do echo -n "." sleep 1 - WAIT=$(( WAIT - 1 )) + WAIT=$((WAIT - 1)) done echo # umount loop devices (openwrt will auto mount some partition) MOUNTED_DEVS=$(lsblk -l -o NAME,PATH,MOUNTPOINT | grep "$LOOP_DEV" | awk '$3 !~ /^$/ {print $2}') -for dev in $MOUNTED_DEVS;do - while : ;do +for dev in $MOUNTED_DEVS; do + while :; do echo -n "umount $dev ... " umount -f $dev sleep 1 mnt=$(lsblk -l -o NAME,PATH,MOUNTPOINT | grep "$dev" | awk '$3 !~ /^$/ {print $2}') - if [ "$mnt" == "" ];then + if [ "$mnt" == "" ]; then echo "ok" break else @@ -197,29 +205,29 @@ P2=${WORK_DIR}/root mkdir -p $P1 $P2 echo -n "mount ${LOOP_DEV}p1 -> ${P1} ... " mount -t vfat -o ro ${LOOP_DEV}p1 ${P1} -if [ $? -ne 0 ];then +if [ $? -ne 0 ]; then echo "mount failed" losetup -D exit 1 -else +else echo "ok" -fi +fi echo -n "mount ${LOOP_DEV}p2 -> ${P2} ... " mount -t btrfs -o ro,compress=zstd ${LOOP_DEV}p2 ${P2} -if [ $? -ne 0 ];then +if [ $? -ne 0 ]; then echo "mount failed" umount -f ${P1} losetup -D exit 1 else echo "ok" -fi +fi #format NEW_ROOT echo "umount ${NEW_ROOT_MP}" umount -f "${NEW_ROOT_MP}" -if [ $? -ne 0 ];then +if [ $? -ne 0 ]; then echo "umount failed, please reboot and try again!" umount -f ${P1} umount -f ${P2} @@ -230,7 +238,7 @@ fi echo "format ${NEW_ROOT_PATH}" NEW_ROOT_UUID=$(uuidgen) mkfs.btrfs -f -U ${NEW_ROOT_UUID} -L ${NEW_ROOT_LABEL} ${NEW_ROOT_PATH} -if [ $? -ne 0 ];then +if [ $? -ne 0 ]; then echo "format ${NEW_ROOT_PATH} failed!" umount -f ${P1} umount -f ${P2} @@ -240,7 +248,7 @@ fi echo "mount ${NEW_ROOT_PATH} to ${NEW_ROOT_MP}" mount -t btrfs -o compress=zstd ${NEW_ROOT_PATH} ${NEW_ROOT_MP} -if [ $? -ne 0 ];then +if [ $? -ne 0 ]; then echo "mount ${NEW_ROOT_PATH} to ${NEW_ROOT_MP} failed!" umount -f ${P1} umount -f ${P2} @@ -252,13 +260,13 @@ fi cd ${NEW_ROOT_MP} echo "Start copy data from ${P2} to ${NEW_ROOT_MP} ..." ENTRYS=$(ls) -for entry in $ENTRYS;do - if [ "$entry" == "lost+found" ];then +for entry in $ENTRYS; do + if [ "$entry" == "lost+found" ]; then continue fi echo -n "remove old $entry ... " rm -rf $entry - if [ $? -eq 0 ];then + if [ $? -eq 0 ]; then echo "ok" else echo "failed" @@ -278,7 +286,7 @@ echo COPY_SRC="root etc bin sbin lib opt usr www" echo "copy data ... " -for src in $COPY_SRC;do +for src in $COPY_SRC; do echo -n "copy $src ... " (cd ${P2} && tar cf - $src) | tar xf - sync @@ -289,21 +297,21 @@ SHFS="/mnt/${EMMC_NAME}${PARTITION_NAME}4" echo "Modify config files ... " rm -f "./etc/rc.local.orig" "./etc/first_run.sh" "./etc/part_size" rm -f ./etc/bench.log -if [ -x ./usr/sbin/balethirq.pl ];then - if grep "balethirq.pl" "./etc/rc.local";then +if [ -x ./usr/sbin/balethirq.pl ]; then + if grep "balethirq.pl" "./etc/rc.local"; then echo "balance irq is enabled" else echo "enable balance irq" sed -e "/exit/i\/usr/sbin/balethirq.pl" -i ./etc/rc.local fi fi -cat > ./etc/fstab <./etc/fstab < ./etc/config/fstab <./etc/config/fstab </dev/null;then - if find ../../lib/modules -name 'shortcut-fe-cm.ko';then + if grep "sfe_flow '1'" ../config/turboacc >/dev/null; then + if find ../../lib/modules -name 'shortcut-fe-cm.ko'; then ln -sf ../init.d/shortcut-fe S99shortcut-fe fi fi ) # move /etc/config/balance_irq to /etc/balance_irq -[ -f "./etc/config/balance_irq" ] && mv ./etc/config/balance_irq ./etc/ +[ -f "./etc/config/balance_irq" ] && mv ./etc/config/balance_irq ./etc/ sync echo "create the first etc snapshot -> .snapshots/etc-000" @@ -348,17 +356,17 @@ btrfs subvolume snapshot -r etc .snapshots/etc-000 [ -d ${SHFS}/docker ] || mkdir -p ${SHFS}/docker rm -rf opt/docker && ln -sf ${SHFS}/docker/ opt/docker -if [ -f /mnt/${NEW_ROOT_NAME}/etc/config/AdGuardHome ];then +if [ -f /mnt/${NEW_ROOT_NAME}/etc/config/AdGuardHome ]; then [ -d ${SHFS}/AdGuardHome/data ] || mkdir -p ${SHFS}/AdGuardHome/data - if [ ! -L /usr/bin/AdGuardHome ];then - [ -d /usr/bin/AdGuardHome ] && \ - cp -a /usr/bin/AdGuardHome/* ${SHFS}/AdGuardHome/ + if [ ! -L /usr/bin/AdGuardHome ]; then + [ -d /usr/bin/AdGuardHome ] && + cp -a /usr/bin/AdGuardHome/* ${SHFS}/AdGuardHome/ fi ln -sf ${SHFS}/AdGuardHome /mnt/${NEW_ROOT_NAME}/usr/bin/AdGuardHome fi BOOTLOADER="./lib/u-boot/u-boot-sunxi-with-spl.bin" -if [ -f ${BOOTLOADER} ];then +if [ -f ${BOOTLOADER} ]; then echo "update u-boot ... " # erase from 8kb to 4mb dd if=/dev/zero of=/dev/${EMMC_NAME} bs=1024 seek=8 count=4088 conv=fsync @@ -371,14 +379,14 @@ echo "copy done" echo BACKUP_LIST=$(${P2}/usr/sbin/openwrt-backup -p) -if [ $BR_FLAG -eq 1 ];then +if [ $BR_FLAG -eq 1 ]; then echo -n "Restore your old config files ... " ( cd / eval tar czf ${NEW_ROOT_MP}/.reserved/openwrt_config.tar.gz "${BACKUP_LIST}" 2>/dev/null ) tar xzf ${NEW_ROOT_MP}/.reserved/openwrt_config.tar.gz - [ -f ./etc/config/dockerman ] && sed -e "s/option wan_mode 'false'/option wan_mode 'true'/" -i ./etc/config/dockerman 2>/dev/null + [ -f ./etc/config/dockerman ] && sed -e "s/option wan_mode 'false'/option wan_mode 'true'/" -i ./etc/config/dockerman 2>/dev/null [ -f ./etc/config/dockerd ] && sed -e "s/option wan_mode '0'/option wan_mode '1'/" -i ./etc/config/dockerd 2>/dev/null [ -f ./etc/config/verysync ] && sed -e 's/config setting/config verysync/' -i ./etc/config/verysync @@ -391,26 +399,26 @@ if [ $BR_FLAG -eq 1 ];then fi rm -f ./etc/bench.log -cat >> ./etc/crontabs/root << EOF +cat >>./etc/crontabs/root <> ./etc/passwd - echo "sshd:x:22:sshd" >> ./etc/group - echo "sshd:x:${ddd}:0:99999:7:::" >> ./etc/shadow +if [ $(grep "sshd:x:22:22" ./etc/passwd | wc -l) -eq 0 ]; then + echo "sshd:x:22:22:sshd:/var/run/sshd:/bin/false" >>./etc/passwd + echo "sshd:x:22:sshd" >>./etc/group + echo "sshd:x:${ddd}:0:99999:7:::" >>./etc/shadow fi -if [ $BR_FLAG -eq 1 ];then - if [ -x ./bin/bash ] && [ -f ./etc/profile.d/30-sysinfo.sh ];then +if [ $BR_FLAG -eq 1 ]; then + if [ -x ./bin/bash ] && [ -f ./etc/profile.d/30-sysinfo.sh ]; then sed -e 's/\/bin\/ash/\/bin\/bash/' -i ./etc/passwd fi sync @@ -419,10 +427,10 @@ if [ $BR_FLAG -eq 1 ];then fi sed -e "s/option hw_flow '1'/option hw_flow '0'/" -i ./etc/config/turboacc ( - cd etc/rc.d + cd etc/rc.d rm -f S??shortcut-fe - if grep "sfe_flow '1'" ../config/turboacc >/dev/null;then - if find ../../lib/modules -name 'shortcut-fe-cm.ko';then + if grep "sfe_flow '1'" ../config/turboacc >/dev/null; then + if find ../../lib/modules -name 'shortcut-fe-cm.ko'; then ln -sf ../init.d/shortcut-fe S99shortcut-fe fi fi @@ -432,7 +440,7 @@ eval tar czf .reserved/openwrt_config.tar.gz "${BACKUP_LIST}" 2>/dev/null rm -f ./etc/part_size ./etc/first_run.sh mv ./etc/rc.local ./etc/rc.local.orig -cat > ./etc/rc.local <./etc/rc.local < .snapshots/etc-001" btrfs subvolume snapshot -r etc .snapshots/etc-001 @@ -456,20 +464,20 @@ btrfs subvolume snapshot -r etc .snapshots/etc-001 #chattr +ia ./etc/config/fstab cd ${WORK_DIR} - + echo "Start copy data from ${P1} to /boot ..." cd /boot echo -n "remove old boot files ..." rm -rf * echo "done" -echo -n "copy new boot files ... " -(cd ${P1} && tar cf - . ) | tar xf - +echo -n "copy new boot files ... " +(cd ${P1} && tar cf - .) | tar xf - sync echo "done" echo echo -n "Update boot args ... " -cat > uEnv.txt <uEnv.txt </dev/null;then - ROOT_DISK_TYPE="EMMC" - else - ROOT_DISK_TYPE="SD" - fi - PARTITION_NAME="p" - LB_PRE="${ROOT_DISK_TYPE}_" - ;; - [hsv]d[a-z][1-4]) EMMC_NAME=$(echo ${ROOT_PTNAME} | awk '{print substr($1, 1, length($1)-1)}') - ROOT_DISK_TYPE="USB" - PARTITION_NAME="" - LB_PRE="${ROOT_DISK_TYPE}_" - ;; - *) echo "Unable to recognize the disk type of ${ROOT_PTNAME}!" - exit 1 - ;; +mmcblk?p[1-4]) + EMMC_NAME=$(echo ${ROOT_PTNAME} | awk '{print substr($1, 1, length($1)-2)}') + if lsblk -l -o NAME | grep "${EMMC_NAME}boot0" >/dev/null; then + ROOT_DISK_TYPE="EMMC" + else + ROOT_DISK_TYPE="SD" + fi + PARTITION_NAME="p" + LB_PRE="${ROOT_DISK_TYPE}_" + ;; +[hsv]d[a-z][1-4]) + EMMC_NAME=$(echo ${ROOT_PTNAME} | awk '{print substr($1, 1, length($1)-1)}') + ROOT_DISK_TYPE="USB" + PARTITION_NAME="" + LB_PRE="${ROOT_DISK_TYPE}_" + ;; +*) + echo "Unable to recognize the disk type of ${ROOT_PTNAME}!" + exit 1 + ;; esac DOCKER_ROOT="/mnt/${EMMC_NAME}${PARTITION_NAME}4/docker/" @@ -65,30 +68,30 @@ mv -f /tmp/upload/* . 2>/dev/null && sync if [[ "${IMG_NAME}" == *.img ]]; then echo -e "Update using [ ${IMG_NAME} ] file. Please wait a moment ..." -elif [ $( ls *.img -l 2>/dev/null | grep "^-" | wc -l ) -ge 1 ]; then - IMG_NAME=$( ls *.img | head -n 1 ) +elif [ $(ls *.img -l 2>/dev/null | grep "^-" | wc -l) -ge 1 ]; then + IMG_NAME=$(ls *.img | head -n 1) echo -e "Update using [ ${IMG_NAME} ] ] file. Please wait a moment ..." -elif [ $( ls *.img.xz -l 2>/dev/null | grep "^-" | wc -l ) -ge 1 ]; then - xz_file=$( ls *.img.xz | head -n 1 ) +elif [ $(ls *.img.xz -l 2>/dev/null | grep "^-" | wc -l) -ge 1 ]; then + xz_file=$(ls *.img.xz | head -n 1) echo -e "Update using [ ${xz_file} ] file. Please wait a moment ..." xz -d ${xz_file} 2>/dev/null - IMG_NAME=$( ls *.img | head -n 1 ) -elif [ $( ls *.img.gz -l 2>/dev/null | grep "^-" | wc -l ) -ge 1 ]; then - gz_file=$( ls *.img.gz | head -n 1 ) + IMG_NAME=$(ls *.img | head -n 1) +elif [ $(ls *.img.gz -l 2>/dev/null | grep "^-" | wc -l) -ge 1 ]; then + gz_file=$(ls *.img.gz | head -n 1) echo -e "Update using [ ${gz_file} ] file. Please wait a moment ..." gzip -df ${gz_file} 2>/dev/null - IMG_NAME=$( ls *.img | head -n 1 ) -elif [ $( ls *.7z -l 2>/dev/null | grep "^-" | wc -l ) -ge 1 ]; then - gz_file=$( ls *.7z | head -n 1 ) + IMG_NAME=$(ls *.img | head -n 1) +elif [ $(ls *.7z -l 2>/dev/null | grep "^-" | wc -l) -ge 1 ]; then + gz_file=$(ls *.7z | head -n 1) echo -e "Update using [ ${gz_file} ] file. Please wait a moment ..." bsdtar -xmf ${gz_file} 2>/dev/null [ $? -eq 0 ] || 7z x ${gz_file} -aoa -y 2>/dev/null - IMG_NAME=$( ls *.img | head -n 1 ) -elif [ $( ls *.zip -l 2>/dev/null | grep "^-" | wc -l ) -ge 1 ]; then - zip_file=$( ls *.zip | head -n 1 ) + IMG_NAME=$(ls *.img | head -n 1) +elif [ $(ls *.zip -l 2>/dev/null | grep "^-" | wc -l) -ge 1 ]; then + zip_file=$(ls *.zip | head -n 1) echo -e "Update using [ ${zip_file} ] file. Please wait a moment ..." unzip -o ${zip_file} 2>/dev/null - IMG_NAME=$( ls *.img | head -n 1 ) + IMG_NAME=$(ls *.img | head -n 1) else echo -e "Please upload or specify the update openwrt firmware file." echo -e "Upload method: system menu → Amlogic Service → Manually Upload Update" @@ -100,7 +103,7 @@ fi sync # check file -if [ ! -f "${IMG_NAME}" ]; then +if [ ! -f "${IMG_NAME}" ]; then echo "No update file found." exit 1 else @@ -110,9 +113,9 @@ fi # Check the necessary dependencies DEPENDS="lsblk uuidgen grep awk btrfs mkfs.fat mkfs.btrfs perl md5sum fatlabel" echo "Check the necessary dependencies..." -for dep in ${DEPENDS};do +for dep in ${DEPENDS}; do WITCH=$(which ${dep}) - if [ "${WITCH}" == "" ];then + if [ "${WITCH}" == "" ]; then echo "Dependent command: ${dep} does not exist, upgrade cannot be performed, only flash through U disk/TF card!" exit 1 else @@ -121,9 +124,9 @@ for dep in ${DEPENDS};do done echo "Check passed" -# find boot partition +# find boot partition BOOT_PART_MSG=$(lsblk -l -o NAME,PATH,TYPE,UUID,MOUNTPOINT | awk '$3~/^part$/ && $5 ~ /^\/boot$/ {print $0}') -if [ "${BOOT_PART_MSG}" == "" ]; then +if [ "${BOOT_PART_MSG}" == "" ]; then echo "Boot The partition does not exist, so the update cannot be continued!" exit 1 fi @@ -141,31 +144,36 @@ else read yn fi case $yn in - n*|N*) BR_FLAG=0;; +n* | N*) + BR_FLAG=0 + ;; esac -# find root partition +# find root partition ROOT_PART_MSG=$(lsblk -l -o NAME,PATH,TYPE,UUID,MOUNTPOINT | awk '$3~/^part$/ && $5 ~ /^\/$/ {print $0}') ROOT_NAME=$(echo $ROOT_PART_MSG | awk '{print $1}') ROOT_PATH=$(echo $ROOT_PART_MSG | awk '{print $2}') ROOT_UUID=$(echo $ROOT_PART_MSG | awk '{print $4}') -case $ROOT_NAME in - ${EMMC_NAME}${PARTITION_NAME}2) NEW_ROOT_NAME="${EMMC_NAME}${PARTITION_NAME}3" - NEW_ROOT_LABEL="${LB_PRE}ROOTFS2" - ;; - ${EMMC_NAME}${PARTITION_NAME}3) NEW_ROOT_NAME="${EMMC_NAME}${PARTITION_NAME}2" - NEW_ROOT_LABEL="${LB_PRE}ROOTFS1" - ;; - *) echo "ROOTFS The partition location is incorrect, so the update cannot continue!" - exit 1 - ;; +case $ROOT_NAME in +${EMMC_NAME}${PARTITION_NAME}2) + NEW_ROOT_NAME="${EMMC_NAME}${PARTITION_NAME}3" + NEW_ROOT_LABEL="${LB_PRE}ROOTFS2" + ;; +${EMMC_NAME}${PARTITION_NAME}3) + NEW_ROOT_NAME="${EMMC_NAME}${PARTITION_NAME}2" + NEW_ROOT_LABEL="${LB_PRE}ROOTFS1" + ;; +*) + echo "ROOTFS The partition location is incorrect, so the update cannot continue!" + exit 1 + ;; esac echo "NEW_ROOT_NAME: [ ${NEW_ROOT_NAME} ]" # find new root partition NEW_ROOT_PART_MSG=$(lsblk -l -o NAME,PATH,TYPE,UUID,MOUNTPOINT | grep "${NEW_ROOT_NAME}" | awk '$3 ~ /^part$/ && $5 !~ /^\/$/ && $5 !~ /^\/boot$/ {print $0}') -if [ "${NEW_ROOT_PART_MSG}" == "" ]; then +if [ "${NEW_ROOT_PART_MSG}" == "" ]; then echo "The new ROOTFS partition does not exist, so the update cannot continue!" exit 1 fi @@ -176,7 +184,7 @@ NEW_ROOT_MP=$(echo $NEW_ROOT_PART_MSG | awk '{print $5}') echo "NEW_ROOT_MP: [ ${NEW_ROOT_MP} ]" # backup old bootloader -if [ ! -f /root/BackupOldBootloader.img ]; then +if [ ! -f /root/BackupOldBootloader.img ]; then echo "Backup bootloader -> [ BackupOldBootloader.img ] ... " dd if=/dev/${EMMC_NAME} of=/root/BackupOldBootloader.img bs=1M count=4 conv=fsync echo "Backup bootloader complete." @@ -185,9 +193,9 @@ fi # losetup losetup -f -P $IMG_NAME -if [ $? -eq 0 ]; then +if [ $? -eq 0 ]; then LOOP_DEV=$(losetup | grep "$IMG_NAME" | awk '{print $1}') - if [ "$LOOP_DEV" == "" ]; then + if [ "$LOOP_DEV" == "" ]; then echo "loop device not found!" exit 1 fi @@ -199,21 +207,21 @@ fi WAIT=3 echo "The loopdev is [ $LOOP_DEV ], wait [ ${WAIT} ] seconds. " while [ $WAIT -ge 1 ]; do - sleep 1 - WAIT=$(( WAIT - 1 )) + sleep 1 + WAIT=$((WAIT - 1)) done # umount loop devices (openwrt will auto mount some partition) MOUNTED_DEVS=$(lsblk -l -o NAME,PATH,MOUNTPOINT | grep "$LOOP_DEV" | awk '$3 !~ /^$/ {print $2}') for dev in $MOUNTED_DEVS; do - while : ; do + while :; do echo "umount [ $dev ] ... " umount -f $dev sleep 1 mnt=$(lsblk -l -o NAME,PATH,MOUNTPOINT | grep "$dev" | awk '$3 !~ /^$/ {print $2}') - if [ "$mnt" == "" ]; then + if [ "$mnt" == "" ]; then break - else + else echo "Retry ..." fi done @@ -227,7 +235,7 @@ mkdir -p $P1 $P2 echo "Mount [ ${LOOP_DEV}p1 ] -> [ ${P1} ] ... " mount -t vfat -o ro ${LOOP_DEV}p1 ${P1} -if [ $? -ne 0 ]; then +if [ $? -ne 0 ]; then echo "Mount p1 [ ${LOOP_DEV}p1 ] failed!" losetup -D exit 1 @@ -235,7 +243,7 @@ fi echo "Mount [ ${LOOP_DEV}p2 ] -> [ ${P2} ] ... " mount -t btrfs -o ro,compress=zstd ${LOOP_DEV}p2 ${P2} -if [ $? -ne 0 ]; then +if [ $? -ne 0 ]; then echo "Mount p2 [ ${LOOP_DEV}p2 ] failed!" umount -f ${P1} losetup -D @@ -256,13 +264,13 @@ echo -e "Update from [ ${MODULES_OLD} ] to [ ${MODULES_NOW} ]" k510_ver=${VERSION_NOW%%.*} k510_maj=${VERSION_NOW##*.} -if [ "${k510_ver}" -eq "5" ];then - if [ "${k510_maj}" -ge "10" ];then +if [ "${k510_ver}" -eq "5" ]; then + if [ "${k510_maj}" -ge "10" ]; then K510="1" else K510="0" fi -elif [ "${k510_ver}" -gt "5" ];then +elif [ "${k510_ver}" -gt "5" ]; then K510="1" else K510="0" @@ -274,7 +282,7 @@ MAINLINE_UBOOT="" ANDROID_UBOOT="" env_openwrt_file="" -if [ -f "${P2}/etc/flippy-openwrt-release" ]; then +if [ -f "${P2}/etc/flippy-openwrt-release" ]; then env_openwrt_file="${P2}/etc/flippy-openwrt-release" elif [ -f "/etc/flippy-openwrt-release" ]; then env_openwrt_file="/etc/flippy-openwrt-release" @@ -302,7 +310,7 @@ fi #format NEW_ROOT echo "umount [ ${NEW_ROOT_MP} ]" umount -f "${NEW_ROOT_MP}" -if [ $? -ne 0 ]; then +if [ $? -ne 0 ]; then echo "Mount [ ${NEW_ROOT_MP} ] failed, Please restart and try again!" umount -f ${P1} umount -f ${P2} @@ -313,7 +321,7 @@ fi echo "Format [ ${NEW_ROOT_PATH} ]" NEW_ROOT_UUID=$(uuidgen) mkfs.btrfs -f -U ${NEW_ROOT_UUID} -L ${NEW_ROOT_LABEL} -m single ${NEW_ROOT_PATH} -if [ $? -ne 0 ]; then +if [ $? -ne 0 ]; then echo "Format [ ${NEW_ROOT_PATH} ] failed!" umount -f ${P1} umount -f ${P2} @@ -323,7 +331,7 @@ fi echo "Mount [ ${NEW_ROOT_PATH} ] -> [ ${NEW_ROOT_MP} ]" mount -t btrfs -o compress=zstd ${NEW_ROOT_PATH} ${NEW_ROOT_MP} -if [ $? -ne 0 ]; then +if [ $? -ne 0 ]; then echo "Mount [ ${NEW_ROOT_PATH} ] -> [ ${NEW_ROOT_MP} ] failed!" umount -f ${P1} umount -f ${P2} @@ -336,12 +344,12 @@ cd ${NEW_ROOT_MP} echo "Start copying data, From [ ${P2} ] TO [ ${NEW_ROOT_MP} ] ..." ENTRYS=$(ls) for entry in $ENTRYS; do - if [ "$entry" == "lost+found" ]; then + if [ "$entry" == "lost+found" ]; then continue fi echo "Remove old [ $entry ] ... " - rm -rf $entry - if [ $? -ne 0 ]; then + rm -rf $entry + if [ $? -ne 0 ]; then echo "failed." exit 1 fi @@ -362,9 +370,9 @@ for src in $COPY_SRC; do sync done -# if not backup, then force rewrite the etc/docker/daemon.json -if [ "${BR_FLAG}" -eq 0 ];then - cat > ./etc/docker/daemon.json <./etc/docker/daemon.json < ./etc/fstab <./etc/fstab < ./etc/config/fstab <./etc/config/fstab </dev/null;then - if find ../../lib/modules -name 'shortcut-fe-cm.ko';then + if grep "sfe_flow '1'" ../config/turboacc >/dev/null; then + if find ../../lib/modules -name 'shortcut-fe-cm.ko'; then ln -sf ../init.d/shortcut-fe S99shortcut-fe fi fi ) # move /etc/config/balance_irq to /etc/balance_irq -[ -f "./etc/config/balance_irq" ] && mv ./etc/config/balance_irq ./etc/ +[ -f "./etc/config/balance_irq" ] && mv ./etc/config/balance_irq ./etc/ sync echo "Create initial etc snapshot -> .snapshots/etc-000" @@ -434,11 +442,11 @@ sync [ -d /mnt/${EMMC_NAME}${PARTITION_NAME}4/docker ] || mkdir -p /mnt/${EMMC_NAME}${PARTITION_NAME}4/docker rm -rf opt/docker && ln -sf /mnt/${EMMC_NAME}${PARTITION_NAME}4/docker/ opt/docker -if [ -f /mnt/${NEW_ROOT_NAME}/etc/config/AdGuardHome ]; then +if [ -f /mnt/${NEW_ROOT_NAME}/etc/config/AdGuardHome ]; then [ -d /mnt/${EMMC_NAME}${PARTITION_NAME}4/AdGuardHome/data ] || mkdir -p /mnt/${EMMC_NAME}${PARTITION_NAME}4/AdGuardHome/data - if [ ! -L /usr/bin/AdGuardHome ]; then - [ -d /usr/bin/AdGuardHome ] && \ - cp -a /usr/bin/AdGuardHome/* /mnt/${EMMC_NAME}${PARTITION_NAME}4/AdGuardHome/ + if [ ! -L /usr/bin/AdGuardHome ]; then + [ -d /usr/bin/AdGuardHome ] && + cp -a /usr/bin/AdGuardHome/* /mnt/${EMMC_NAME}${PARTITION_NAME}4/AdGuardHome/ fi ln -sf /mnt/${EMMC_NAME}${PARTITION_NAME}4/AdGuardHome /mnt/${NEW_ROOT_NAME}/usr/bin/AdGuardHome fi @@ -450,11 +458,11 @@ sync echo "Copy data complete ..." BACKUP_LIST=$(${P2}/usr/sbin/openwrt-backup -p) -if [[ "${BR_FLAG}" -eq "1" && -n "${BACKUP_LIST}" ]];then +if [[ "${BR_FLAG}" -eq "1" && -n "${BACKUP_LIST}" ]]; then echo -n "Start restoring configuration files ... " ( - cd / - eval tar czf ${NEW_ROOT_MP}/.reserved/openwrt_config.tar.gz "${BACKUP_LIST}" 2>/dev/null + cd / + eval tar czf ${NEW_ROOT_MP}/.reserved/openwrt_config.tar.gz "${BACKUP_LIST}" 2>/dev/null ) tar xzf ${NEW_ROOT_MP}/.reserved/openwrt_config.tar.gz @@ -473,7 +481,7 @@ echo "Modify the configuration file ... " rm -f "./etc/rc.local.orig" "./etc/first_run.sh" "./etc/part_size" rm -rf "./opt/docker" && ln -sf "/mnt/${EMMC_NAME}${PARTITION_NAME}4/docker" "./opt/docker" rm -f ./etc/bench.log -cat >> ./etc/crontabs/root << EOF +cat >>./etc/crontabs/root <> ./etc/passwd - echo "sshd:x:22:sshd" >> ./etc/group - echo "sshd:x:${ddd}:0:99999:7:::" >> ./etc/shadow +if [ $(grep "sshd:x:22:22" ./etc/passwd | wc -l) -eq 0 ]; then + echo "sshd:x:22:22:sshd:/var/run/sshd:/bin/false" >>./etc/passwd + echo "sshd:x:22:sshd" >>./etc/group + echo "sshd:x:${ddd}:0:99999:7:::" >>./etc/shadow fi if [ "${BR_FLAG}" -eq "1" ]; then @@ -496,10 +504,10 @@ if [ "${BR_FLAG}" -eq "1" ]; then fi sed -e "s/option hw_flow '1'/option hw_flow '0'/" -i ./etc/config/turboacc ( - cd etc/rc.d + cd etc/rc.d rm -f S??shortcut-fe - if grep "sfe_flow '1'" ../config/turboacc >/dev/null;then - if find ../../lib/modules -name 'shortcut-fe-cm.ko';then + if grep "sfe_flow '1'" ../config/turboacc >/dev/null; then + if find ../../lib/modules -name 'shortcut-fe-cm.ko'; then ln -sf ../init.d/shortcut-fe S99shortcut-fe fi fi @@ -507,8 +515,8 @@ sed -e "s/option hw_flow '1'/option hw_flow '0'/" -i ./etc/config/turboacc eval tar czf .reserved/openwrt_config.tar.gz "${BACKUP_LIST}" 2>/dev/null rm -f ./etc/part_size ./etc/first_run.sh -if [ -x ./usr/sbin/balethirq.pl ]; then - if grep "balethirq.pl" "./etc/rc.local"; then +if [ -x ./usr/sbin/balethirq.pl ]; then + if grep "balethirq.pl" "./etc/rc.local"; then echo "balance irq is enabled" else echo "enable balance irq" @@ -517,7 +525,7 @@ if [ -x ./usr/sbin/balethirq.pl ]; then fi mv ./etc/rc.local ./etc/rc.local.orig -cat > ./etc/rc.local <./etc/rc.local < .snapshots/etc-001" btrfs subvolume snapshot -r etc .snapshots/etc-001 cd ${WORK_DIR} - + #echo -n "umount /boot ... " #umount -f /boot #if [ $? -ne 0 ];then @@ -596,7 +606,7 @@ cd ${WORK_DIR} #echo "reformat ${BOOT_PATH} ..." #if mkfs.fat -n "${LB_PRE}BOOT" -F 32 ${BOOT_PATH} 2>/dev/null;then # echo -n "mount /boot ..." -# mount -t vfat -o "errors=remount-ro" ${BOOT_PATH} /boot +# mount -t vfat -o "errors=remount-ro" ${BOOT_PATH} /boot # if [ $? -eq 0 ];then # echo "ok" # else @@ -615,7 +625,7 @@ echo "Delete the old boot file ..." rm -rf * && sync echo "Copy the new boot file ... " -(cd ${P1} && tar cf - . ) | tar xf - 2>/dev/null +(cd ${P1} && tar cf - .) | tar xf - 2>/dev/null sync if [ -f ${P1}/uInitrd ]; then @@ -659,14 +669,14 @@ else exit 1 fi -if [ ${ROOT_DISK_TYPE} == "EMMC" ];then +if [ ${ROOT_DISK_TYPE} == "EMMC" ]; then rm -f s905_autoscript* aml_autoscript* mv -f boot-emmc.ini boot.ini mv -f boot-emmc.cmd boot.cmd mv -f boot-emmc.scr boot.scr fi -if [ ${K510} -eq 1 ]; then +if [ ${K510} -eq 1 ]; then if [ -f "u-boot.ext" ]; then cp -vf u-boot.ext u-boot.emmc elif [ -f ${P1}/${UBOOT_OVERLOAD} ]; then @@ -680,15 +690,15 @@ fi sync echo "Update boot parameters ... " -if [ -f /tmp/uEnv.txt ]; then - lines=$(wc -l < /tmp/uEnv.txt) - lines=$(( lines - 1 )) - head -n $lines /tmp/uEnv.txt > uEnv.txt - cat >> uEnv.txt <uEnv.txt + cat >>uEnv.txt < uEnv.txt <uEnv.txt </dev/null && sync if [[ "${IMG_NAME}" == *.img ]]; then echo -e "Update using [ ${IMG_NAME} ] file. Please wait a moment ..." -elif [ $( ls *.img -l 2>/dev/null | grep "^-" | wc -l ) -ge 1 ]; then - IMG_NAME=$( ls *.img | head -n 1 ) +elif [ $(ls *.img -l 2>/dev/null | grep "^-" | wc -l) -ge 1 ]; then + IMG_NAME=$(ls *.img | head -n 1) echo -e "Update using [ ${IMG_NAME} ] ] file. Please wait a moment ..." -elif [ $( ls *.img.xz -l 2>/dev/null | grep "^-" | wc -l ) -ge 1 ]; then - xz_file=$( ls *.img.xz | head -n 1 ) +elif [ $(ls *.img.xz -l 2>/dev/null | grep "^-" | wc -l) -ge 1 ]; then + xz_file=$(ls *.img.xz | head -n 1) echo -e "Update using [ ${xz_file} ] file. Please wait a moment ..." xz -d ${xz_file} 2>/dev/null - IMG_NAME=$( ls *.img | head -n 1 ) -elif [ $( ls *.img.gz -l 2>/dev/null | grep "^-" | wc -l ) -ge 1 ]; then - gz_file=$( ls *.img.gz | head -n 1 ) + IMG_NAME=$(ls *.img | head -n 1) +elif [ $(ls *.img.gz -l 2>/dev/null | grep "^-" | wc -l) -ge 1 ]; then + gz_file=$(ls *.img.gz | head -n 1) echo -e "Update using [ ${gz_file} ] file. Please wait a moment ..." gzip -df ${gz_file} 2>/dev/null - IMG_NAME=$( ls *.img | head -n 1 ) -elif [ $( ls *.7z -l 2>/dev/null | grep "^-" | wc -l ) -ge 1 ]; then - gz_file=$( ls *.7z | head -n 1 ) + IMG_NAME=$(ls *.img | head -n 1) +elif [ $(ls *.7z -l 2>/dev/null | grep "^-" | wc -l) -ge 1 ]; then + gz_file=$(ls *.7z | head -n 1) echo -e "Update using [ ${gz_file} ] file. Please wait a moment ..." bsdtar -xmf ${gz_file} 2>/dev/null [ $? -eq 0 ] || 7z x ${gz_file} -aoa -y 2>/dev/null - IMG_NAME=$( ls *.img | head -n 1 ) -elif [ $( ls *.zip -l 2>/dev/null | grep "^-" | wc -l ) -ge 1 ]; then - zip_file=$( ls *.zip | head -n 1 ) + IMG_NAME=$(ls *.img | head -n 1) +elif [ $(ls *.zip -l 2>/dev/null | grep "^-" | wc -l) -ge 1 ]; then + zip_file=$(ls *.zip | head -n 1) echo -e "Update using [ ${zip_file} ] file. Please wait a moment ..." unzip -o ${zip_file} 2>/dev/null - IMG_NAME=$( ls *.img | head -n 1 ) + IMG_NAME=$(ls *.img | head -n 1) else echo -e "Please upload or specify the update openwrt firmware file." echo -e "Upload method: system menu → Amlogic Service → Manually Upload Update" @@ -98,16 +101,16 @@ fi sync # check file -if [ ! -f "${IMG_NAME}" ]; then +if [ ! -f "${IMG_NAME}" ]; then echo "No update file found." exit 1 else echo "Start update from [ ${IMG_NAME} ]" fi -# find boot partition +# find boot partition BOOT_PART_MSG=$(lsblk -l -o NAME,PATH,TYPE,UUID,MOUNTPOINT | awk '$3~/^part$/ && $5 ~ /^\/boot$/ {print $0}') -if [ "${BOOT_PART_MSG}" == "" ];then +if [ "${BOOT_PART_MSG}" == "" ]; then echo "The boot partition is not exists or not mounted, so it cannot be upgraded with this script!" exit 1 fi @@ -122,33 +125,38 @@ else read yn fi case $yn in - n*|N*) BR_FLAG=0;; +n* | N*) + BR_FLAG=0 + ;; esac BOOT_NAME=$(echo $BOOT_PART_MSG | awk '{print $1}') BOOT_PATH=$(echo $BOOT_PART_MSG | awk '{print $2}') BOOT_UUID=$(echo $BOOT_PART_MSG | awk '{print $4}') -# find root partition +# find root partition ROOT_PART_MSG=$(lsblk -l -o NAME,PATH,TYPE,UUID,MOUNTPOINT | awk '$3~/^part$/ && $5 ~ /^\/$/ {print $0}') ROOT_NAME=$(echo $ROOT_PART_MSG | awk '{print $1}') ROOT_PATH=$(echo $ROOT_PART_MSG | awk '{print $2}') ROOT_UUID=$(echo $ROOT_PART_MSG | awk '{print $4}') -case $ROOT_NAME in - ${EMMC_NAME}${PARTITION_NAME}2) NEW_ROOT_NAME="${EMMC_NAME}${PARTITION_NAME}3" - NEW_ROOT_LABEL="${LB_PRE}ROOTFS2" - ;; - ${EMMC_NAME}${PARTITION_NAME}3) NEW_ROOT_NAME="${EMMC_NAME}${PARTITION_NAME}2" - NEW_ROOT_LABEL="${LB_PRE}ROOTFS1" - ;; - *) echo "The root partition location is invalid, so it cannot be upgraded with this script!" - exit 1 - ;; +case $ROOT_NAME in +${EMMC_NAME}${PARTITION_NAME}2) + NEW_ROOT_NAME="${EMMC_NAME}${PARTITION_NAME}3" + NEW_ROOT_LABEL="${LB_PRE}ROOTFS2" + ;; +${EMMC_NAME}${PARTITION_NAME}3) + NEW_ROOT_NAME="${EMMC_NAME}${PARTITION_NAME}2" + NEW_ROOT_LABEL="${LB_PRE}ROOTFS1" + ;; +*) + echo "The root partition location is invalid, so it cannot be upgraded with this script!" + exit 1 + ;; esac # find new root partition NEW_ROOT_PART_MSG=$(lsblk -l -o NAME,PATH,TYPE,UUID,MOUNTPOINT | grep "${NEW_ROOT_NAME}" | awk '$3 ~ /^part$/ && $5 !~ /^\/$/ && $5 !~ /^\/boot$/ {print $0}') -if [ "${NEW_ROOT_PART_MSG}" == "" ];then +if [ "${NEW_ROOT_PART_MSG}" == "" ]; then echo "The new root partition is not exists, so it cannot be upgraded with this script!" exit 1 fi @@ -159,9 +167,9 @@ NEW_ROOT_MP=$(echo $NEW_ROOT_PART_MSG | awk '{print $5}') # losetup losetup -f -P $IMG_NAME -if [ $? -eq 0 ];then +if [ $? -eq 0 ]; then LOOP_DEV=$(losetup | grep "$IMG_NAME" | awk '{print $1}') - if [ "$LOOP_DEV" == "" ];then + if [ "$LOOP_DEV" == "" ]; then echo "loop device not found!" exit 1 fi @@ -171,22 +179,22 @@ else fi WAIT=3 echo -n "The loopdev is $LOOP_DEV, wait ${WAIT} seconds " -while [ $WAIT -ge 1 ];do +while [ $WAIT -ge 1 ]; do echo -n "." sleep 1 - WAIT=$(( WAIT - 1 )) + WAIT=$((WAIT - 1)) done echo # umount loop devices (openwrt will auto mount some partition) MOUNTED_DEVS=$(lsblk -l -o NAME,PATH,MOUNTPOINT | grep "$LOOP_DEV" | awk '$3 !~ /^$/ {print $2}') -for dev in $MOUNTED_DEVS;do - while : ;do +for dev in $MOUNTED_DEVS; do + while :; do echo -n "umount $dev ... " umount -f $dev sleep 1 mnt=$(lsblk -l -o NAME,PATH,MOUNTPOINT | grep "$dev" | awk '$3 !~ /^$/ {print $2}') - if [ "$mnt" == "" ];then + if [ "$mnt" == "" ]; then echo "ok" break else @@ -202,29 +210,29 @@ P2=${WORK_DIR}/root mkdir -p $P1 $P2 echo -n "mount ${LOOP_DEV}p1 -> ${P1} ... " mount -t ext4 -o ro ${LOOP_DEV}p1 ${P1} -if [ $? -ne 0 ];then +if [ $? -ne 0 ]; then echo "mount failed" losetup -D exit 1 -else +else echo "ok" -fi +fi echo -n "mount ${LOOP_DEV}p2 -> ${P2} ... " mount -t btrfs -o ro,compress=zstd ${LOOP_DEV}p2 ${P2} -if [ $? -ne 0 ];then +if [ $? -ne 0 ]; then echo "mount failed" umount -f ${P1} losetup -D exit 1 else echo "ok" -fi +fi #format NEW_ROOT echo "umount ${NEW_ROOT_MP}" umount -f "${NEW_ROOT_MP}" -if [ $? -ne 0 ];then +if [ $? -ne 0 ]; then echo "umount failed, please reboot and try again!" umount -f ${P1} umount -f ${P2} @@ -235,7 +243,7 @@ fi echo "format ${NEW_ROOT_PATH}" NEW_ROOT_UUID=$(uuidgen) mkfs.btrfs -f -U ${NEW_ROOT_UUID} -L ${NEW_ROOT_LABEL} -m single ${NEW_ROOT_PATH} -if [ $? -ne 0 ];then +if [ $? -ne 0 ]; then echo "format ${NEW_ROOT_PATH} failed!" umount -f ${P1} umount -f ${P2} @@ -245,7 +253,7 @@ fi echo "mount ${NEW_ROOT_PATH} to ${NEW_ROOT_MP}" mount -t btrfs -o compress=zstd ${NEW_ROOT_PATH} ${NEW_ROOT_MP} -if [ $? -ne 0 ];then +if [ $? -ne 0 ]; then echo "mount ${NEW_ROOT_PATH} to ${NEW_ROOT_MP} failed!" umount -f ${P1} umount -f ${P2} @@ -257,13 +265,13 @@ fi cd ${NEW_ROOT_MP} echo "Start copy data from ${P2} to ${NEW_ROOT_MP} ..." ENTRYS=$(ls) -for entry in $ENTRYS;do - if [ "$entry" == "lost+found" ];then +for entry in $ENTRYS; do + if [ "$entry" == "lost+found" ]; then continue fi echo -n "remove old $entry ... " rm -rf $entry - if [ $? -eq 0 ];then + if [ $? -eq 0 ]; then echo "ok" else echo "failed" @@ -283,7 +291,7 @@ echo COPY_SRC="root etc bin sbin lib opt usr www" echo "copy data ... " -for src in $COPY_SRC;do +for src in $COPY_SRC; do echo -n "copy $src ... " (cd ${P2} && tar cf - $src) | tar xf - sync @@ -292,8 +300,8 @@ done SHFS="/mnt/${EMMC_NAME}${PARTITION_NAME}4" echo "Modify config files ... " -if [ -x ./usr/sbin/balethirq.pl ];then - if grep "balethirq.pl" "./etc/rc.local";then +if [ -x ./usr/sbin/balethirq.pl ]; then + if grep "balethirq.pl" "./etc/rc.local"; then echo "balance irq is enabled" else echo "enable balance irq" @@ -302,13 +310,13 @@ if [ -x ./usr/sbin/balethirq.pl ];then fi rm -f "./etc/rc.local.orig" "./etc/first_run.sh" "./etc/part_size" rm -f ./etc/bench.log -cat > ./etc/fstab <./etc/fstab < ./etc/config/fstab <./etc/config/fstab </dev/null;then - if find ../../lib/modules -name 'shortcut-fe-cm.ko';then + if grep "sfe_flow '1'" ../config/turboacc >/dev/null; then + if find ../../lib/modules -name 'shortcut-fe-cm.ko'; then ln -sf ../init.d/shortcut-fe S99shortcut-fe fi fi ) # move /etc/config/balance_irq to /etc/balance_irq -[ -f "./etc/config/balance_irq" ] && mv ./etc/config/balance_irq ./etc/ +[ -f "./etc/config/balance_irq" ] && mv ./etc/config/balance_irq ./etc/ sync echo "create the first etc snapshot -> .snapshots/etc-000" @@ -352,11 +360,11 @@ btrfs subvolume snapshot -r etc .snapshots/etc-000 [ -d ${SHFS}/docker ] || mkdir -p ${SHFS}/docker rm -rf opt/docker && ln -sf ${SHFS}/docker/ opt/docker -if [ -f /mnt/${NEW_ROOT_NAME}/etc/config/AdGuardHome ];then +if [ -f /mnt/${NEW_ROOT_NAME}/etc/config/AdGuardHome ]; then [ -d ${SHFS}/AdGuardHome/data ] || mkdir -p ${SHFS}/AdGuardHome/data - if [ ! -L /usr/bin/AdGuardHome ];then - [ -d /usr/bin/AdGuardHome ] && \ - cp -a /usr/bin/AdGuardHome/* ${SHFS}/AdGuardHome/ + if [ ! -L /usr/bin/AdGuardHome ]; then + [ -d /usr/bin/AdGuardHome ] && + cp -a /usr/bin/AdGuardHome/* ${SHFS}/AdGuardHome/ fi ln -sf ${SHFS}/AdGuardHome /mnt/${NEW_ROOT_NAME}/usr/bin/AdGuardHome fi @@ -366,7 +374,7 @@ echo "copy done" echo BACKUP_LIST=$(${P2}/usr/sbin/openwrt-backup -p) -if [ $BR_FLAG -eq 1 ];then +if [ $BR_FLAG -eq 1 ]; then echo -n "Restore your old config files ... " ( cd / @@ -385,27 +393,27 @@ if [ $BR_FLAG -eq 1 ];then echo fi -cat >> ./etc/crontabs/root << EOF +cat >>./etc/crontabs/root <> ./etc/passwd - echo "sshd:x:22:sshd" >> ./etc/group - echo "sshd:x:${ddd}:0:99999:7:::" >> ./etc/shadow +if [ $(grep "sshd:x:22:22" ./etc/passwd | wc -l) -eq 0 ]; then + echo "sshd:x:22:22:sshd:/var/run/sshd:/bin/false" >>./etc/passwd + echo "sshd:x:22:sshd" >>./etc/group + echo "sshd:x:${ddd}:0:99999:7:::" >>./etc/shadow fi -if [ $BR_FLAG -eq 1 ];then - if [ -x ./bin/bash ] && [ -f ./etc/profile.d/30-sysinfo.sh ];then +if [ $BR_FLAG -eq 1 ]; then + if [ -x ./bin/bash ] && [ -f ./etc/profile.d/30-sysinfo.sh ]; then sed -e 's/\/bin\/ash/\/bin\/bash/' -i ./etc/passwd fi sync @@ -414,17 +422,17 @@ if [ $BR_FLAG -eq 1 ];then fi sed -e "s/option hw_flow '1'/option hw_flow '0'/" -i ./etc/config/turboacc ( - cd etc/rc.d + cd etc/rc.d rm -f S??shortcut-fe - if grep "sfe_flow '1'" ../config/turboacc >/dev/null;then - if find ../../lib/modules -name 'shortcut-fe-cm.ko';then + if grep "sfe_flow '1'" ../config/turboacc >/dev/null; then + if find ../../lib/modules -name 'shortcut-fe-cm.ko'; then ln -sf ../init.d/shortcut-fe S99shortcut-fe fi fi ) # move /etc/config/balance_irq to /etc/balance_irq -[ -f "./etc/config/balance_irq" ] && mv ./etc/config/balance_irq ./etc/ +[ -f "./etc/config/balance_irq" ] && mv ./etc/config/balance_irq ./etc/ eval tar czf .reserved/openwrt_config.tar.gz "${BACKUP_LIST}" 2>/dev/null sync @@ -437,20 +445,20 @@ btrfs subvolume snapshot -r etc .snapshots/etc-001 #chattr +ia ./etc/config/fstab cd ${WORK_DIR} - + echo "Start copy data from ${P2} to /boot ..." cd /boot echo -n "remove old boot files ..." rm -rf * echo "done" -echo -n "copy new boot files ... " -(cd ${P1} && tar cf - . ) | tar xf - +echo -n "copy new boot files ... " +(cd ${P1} && tar cf - .) | tar xf - sync echo "done" echo echo -n "Update boot args ... " -cat > armbianEnv.txt <armbianEnv.txt <