Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
Next revisionBoth sides next revision
docs:guide-user:advanced:sysupgrade_extras [2021/11/16 08:18] – created vgaeteradocs:guide-user:advanced:sysupgrade_extras [2023/12/01 01:36] – [Instructions] minimize write operations vgaetera
Line 1: Line 1:
 ====== Sysupgrade extras ====== ====== Sysupgrade extras ======
-{{section>meta:infobox:howto_links#cli_skills&noheader&nofooter&noeditbutton}}+{{section>meta:infobox:howto_links#basic_skills&noheader&nofooter&noeditbutton}}
  
-{{page>meta:infobox:wip&noheader&nofooter&noeditbtn}}+===== Introduction ===== 
 +  * This instruction extends the functionality of [[docs:techref:sysupgrade|Sysupgrade]] on [[docs:guide-user:installation:openwrt_x86|x86]] target. 
 +  * Follow the [[docs:guide-user:advanced:sysupgrade_extras#automated|automated]] section for quick setup. 
 + 
 +===== Features ===== 
 +  * Check the latest firmware release available. 
 +  * Download the firmware image and verify its checksum. 
 +  * Allow to force/skip upgrade matching the current release. 
 +  * Save/restore the state of enabled/disabled services.
  
 ===== Options ===== ===== Options =====
 ^ Option ^ Description ^ ^ Option ^ Description ^
-| ''**-a**''Initialize automated upgrade. |+| ''**-A**'' | Download and upgrade firmware if newer stable release is available. | 
 +| ''**-U**''Download and upgrade firmware for the latest stable release. | 
 +| ''**-S**'' | Save the current state of enabled/disabled services to UCI. | 
 +| ''**-R**'' | Restore the state of enabled/disabled services. |
  
 ===== Instructions ===== ===== Instructions =====
Line 16: Line 27:
 local SYSUP_CMD="${1}" local SYSUP_CMD="${1}"
 case "${SYSUP_CMD}" in case "${SYSUP_CMD}" in
-(-asysupgrade_auto ;;+(-A|-Usysupgrade_proc "${@}" ;; 
 +(-S) service_save ;; 
 +(-R) service_restore ;;
 (*) command sysupgrade "${@}" ;; (*) command sysupgrade "${@}" ;;
 esac esac
 } }
  
-sysupgrade_auto() { +sysupgrade_proc() { 
-. /etc/openwrt_release +. /etc/os-release 
-if grep -q -e "\s/\soverlay\s/etc/mtab +local SYSUP_VER="$(sysupgrade_ver)" 
-then SYSUP_TYPE="generic-squashfs-combined+local SYSUP_URL="$(sysupgrade_url)" 
-else SYSUP_TYPE="generic-ext4-combined"+local SYSUP_REV="$(sysupgrade_rev)" 
 +if "${SYSUP_REV}" != "${BUILD_ID}"\ 
 +|| [ "${SYSUP_CMD}" = "-U" ] 
 +then shift 
 +local SYSUP_DEV="$(sysupgrade_dev)
 +local SYSUP_PROF="$(sysupgrade_prof)" 
 +local SYSUP_FS="$(sysupgrade_fs)" 
 +local SYSUP_TYPE="$(sysupgrade_type)" 
 +local SYSUP_EFI="$(sysupgrade_efi)" 
 +local SYSUP_IMG="$(sysupgrade_img)" 
 +sysupgrade "${@}" "${SYSUP_URL}/${SYSUP_IMG}"
 fi fi
-case "${DISTRIB_RELEASE}" in +
-(SNAPSHOT+ 
-SYSUP_IMG="openwrt-${DISTRIB_ARCH/_/-}-${SYSUP_TYPE}.img.gz+sysupgrade_ver() { 
-SYSUP_URL="https://downloads.openwrt.org/+case "${VERSION_ID}" in 
-snapshots/targets/${DISTRIB_TARGET}/${SYSUP_IMG}" ;; +(snapshot) echo "../snapshots" ;; 
-(*) +(*) wget -O - \ 
-SYSUP_URL="https://api.github.com/repos/openwrt/openwrt/tags+"https://api.github.com/repos/openwrt/openwrt/tags"
-SYSUP_VER="$(uclient-fetch -O - "${SYSUP_URL}" \ +| jsonfilter -e "$[*]['name']"
-| jsonfilter -e "@[*]['name']" +| sed -e "/-rc/d;s/^v//;q" ;;
-| sort -r -V +
-| sed -e "/-rc/d;s/^v//;q")" +
-SYSUP_IMG="openwrt-${SYSUP_VER}-${DISTRIB_ARCH/_/-}-${SYSUP_TYPE}.img.gz" +
-SYSUP_URL="https://downloads.openwrt.org/+
-releases/${SYSUP_VER}/targets/${DISTRIB_TARGET}/${SYSUP_IMG}" ;;+
 esac esac
-uclient-fetch -P /tmp "${SYSUP_URL}" 
-gunzip -k /tmp/"${SYSUP_IMG}" 
-sysupgrade -i /tmp/"${SYSUP_IMG%.gz}" 
 } }
-EOF 
  
-# Configure uci-defaults +sysupgrade_url() { 
-cat << "EOF" > /etc/uci-defaults/70-root-resize +echo "https://downloads.openwrt.org/\ 
-if [ ! -e /etc/root-resize ] +releases/${SYSUP_VER}/targets/${OPENWRT_BOARD}" 
-&& lock -n /var/lock/root-resize \ +} 
-&& [ -e /etc/opkg-restore-init ] + 
-then +sysupgrade_rev() { 
-BOOT="$(sed --"/\s\/boot\s.*$/{s///p;q}/etc/mtab)+wget -- "${SYSUP_URL}/version.buildinfo
-DISK="${BOOT%%[0-9]*}+
-PART="$((${BOOT##*[^0-9]}+1))" + 
-ROOT="${DISK}${PART}" +sysupgrade_dev() { 
-OFFS="$(fdisk "${DISK}-l -o "device,start" \ +ubus call system board \ 
-| sed -n -e "\|^${ROOT}\s*|s///p")" +| jsonfilter -e "$['board_name']" 
-echo -e "p\nd\n${PART}\nn\np\n${PART}\n${OFFS}\n\nn\np\nw" \ +
-| fdisk "${DISK}" + 
-touch /etc/root-resize +sysupgrade_prof(
-lock -/var/lock/root-resize+case "${OPENWRT_BOARD}" in 
 +(x86/*) echo "generic;; 
 +(*) echo "${SYSUP_DEV//,/_};; 
 +esac 
 +
 + 
 +sysupgrade_fs({ 
 +ubus call system board \ 
 +| jsonfilter -e "$['rootfs_type']" 
 +} 
 + 
 +sysupgrade_type() 
 +case "${OPENWRT_BOARD}" in 
 +(x86/*) echo "combined" ;; 
 +(*) echo "sysupgrade" ;; 
 +esac 
 +
 + 
 +sysupgrade_efi() { 
 +if [ -/sys/firmware/efi ] 
 +then echo "-efi"
 fi fi
-exit 1 +} 
-EOF + 
-cat << "EOF" > /etc/uci-defaults/80-ext4-resize +sysupgrade_img() { 
-if grep --"\s/\sext4\s/etc/mtab +wget -- "${SYSUP_URL}/profiles.json" \ 
-&& [ ! -e /etc/ext4-resize \ +| jsonfilter -e "$['profiles']['${SYSUP_PROF}'
-&& lock -n /var/lock/ext4-resize \ +['images'][@['type']='${SYSUP_TYPE}${SYSUP_EFI}' 
-&& -e /etc/opkg-restore-init ] +&&@['filesystem']='${SYSUP_FS}']['name']" 
-then +} 
-BOOT="$(sed -n -e "/\s\/boot\s.*$/{s///p;q}" /etc/mtab)" + 
-DISK="${BOOT%%[0-9]*}" +service_save() 
-PART="$((${BOOT##*[^0-9]}+1))+local SVC_NAME="$(ls /etc/init.d)" 
-ROOT="${DISK}${PART}" +local SVC_STATE 
-LOOP="$(losetup -f)" +for SVC_NAME in ${SVC_NAME} 
-losetup "${LOOP}"${ROOT}" +do if command service "${SVC_NAME}" enabled 
-fsck.ext4 -y "${LOOP}+then SVC_STATE="enable
-resize2fs "${LOOP}" +else SVC_STATE="disable"
-touch /etc/ext4-resize +
-lock -u /var/lock/ext4-resize +
-reboot+
 fi fi
-exit 1+uci -q batch << EOI 
 +set system.service='service' 
 +del_list system.service.enable='${SVC_NAME}' 
 +del_list system.service.disable='${SVC_NAME}' 
 +add_list system.service.'${SVC_STATE}'='${SVC_NAME}' 
 +EOI 
 +done 
 +uci commit system 
 +
 + 
 +service_restore() { 
 +local SVC_NAME 
 +local SVC_STATE="enable disable" 
 +for SVC_STATE in ${SVC_STATE} 
 +do SVC_NAME="$(uci -q get system.service."${SVC_STATE}")" 
 +for SVC_NAME in ${SVC_NAME} 
 +do command service "${SVC_NAME}" "${SVC_STATE}" 
 +done 
 +done 
 +}
 EOF EOF
-cat << "EOF" > /etc/uci-defaults/80-f2fs-resize +. /etc/profile.d/sysupgrade.sh 
-if grep -q -e "\s/\soverlay\s" /etc/mtab \ + 
-&& [ ! -e /etc/f2fs-resize \ +# Configure startup scripts 
-&& lock -n /var/lock/f2fs-resize \ +cat << "EOF" > /etc/uci-defaults/60-service-restore 
-&& [ -e /etc/opkg-restore-init ] +if [ ! -e /etc/service-restore 
-then +then . /etc/profile.d/sysupgrade.sh 
-LOOP="$(losetup -n -O "NAME"+sysupgrade -R 
-| sed -n -e "1p")" +touch /etc/service-restore
-ROOT="$(losetup -n -O "BACK-FILE" "${LOOP}"+
-| sed -e "s|^|/dev|")" +
-OFFS="$(losetup -n -O "OFFSET" "${LOOP}")" +
-LOOP="$(losetup -f)" +
-losetup -o "${OFFS}" "${LOOP}" "${ROOT}" +
-fsck.f2fs -f "${LOOP}" +
-mount "${LOOP}" /mnt +
-umount "${LOOP}" +
-resize.f2fs "${LOOP}" +
-touch /etc/f2fs-resize +
-lock -u /var/lock/f2fs-resize +
-reboot+
 fi fi
 exit 1 exit 1
 EOF EOF
 cat << "EOF" >> /etc/sysupgrade.conf cat << "EOF" >> /etc/sysupgrade.conf
-/etc/uci-defaults+/etc/uci-defaults/60-service-restore
 EOF EOF
 +</code>
 +
 +===== Examples =====
 +<code bash>
 +# Automated interactive Sysupgrade
 +sysupgrade -A -i
 +
 +# Forced interactive Sysupgrade
 +sysupgrade -U -i
 </code> </code>
  
 ===== Automated ===== ===== Automated =====
 <code bash> <code bash>
-uclient-fetch -O sysupgrade-extras.sh "https://openwrt.org/_export/code/docs/guide-user/advanced/sysupgrade_extras?codeblock=0"+wget -U "" -O sysupgrade-extras.sh "https://openwrt.org/_export/code/docs/guide-user/advanced/sysupgrade_extras?codeblock=0"
 . ./sysupgrade-extras.sh . ./sysupgrade-extras.sh
 </code> </code>
  
  • Last modified: 2024/06/12 13:16
  • by vgaetera