Differences

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

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revisionBoth sides next revision
docs:guide-user:advanced:sysupgrade_extras [2023/04/02 18:13] – process standard sysupgrade options vgaeteradocs:guide-user:advanced:sysupgrade_extras [2023/12/01 01:36] – [Instructions] minimize write operations vgaetera
Line 10: Line 10:
   * Download the firmware image and verify its checksum.   * Download the firmware image and verify its checksum.
   * Allow to force/skip upgrade matching the current release.   * Allow to force/skip upgrade matching the current release.
 +  * Save/restore the state of enabled/disabled services.
  
 ===== Options ===== ===== Options =====
 ^ Option ^ Description ^ ^ Option ^ Description ^
-| ''**-A**''Upgrade firmware if a newer one is available. | +| ''**-A**''Download and upgrade firmware if a newer stable release is available. | 
-| ''**-U**''Force firmware upgrade. |+| ''**-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 23: Line 26:
 sysupgrade() { sysupgrade() {
 local SYSUP_CMD="${1}" local SYSUP_CMD="${1}"
-local SYSUP_FORCE 
 case "${SYSUP_CMD}" in case "${SYSUP_CMD}" in
-(-A) shift +(-A|-Usysupgrade_proc "${@}" ;; 
-sysupgrade_auto "${@}" ;; +(-Sservice_save ;; 
-(-Ushift +(-R) service_restore ;;
-SYSUP_FORCE="1" +
-sysupgrade_auto "${@}" ;;+
 (*) command sysupgrade "${@}" ;; (*) command sysupgrade "${@}" ;;
 esac esac
 } }
  
-sysupgrade_auto() { +sysupgrade_proc() { 
-. /etc/openwrt_release+. /etc/os-release
 local SYSUP_VER="$(sysupgrade_ver)" local SYSUP_VER="$(sysupgrade_ver)"
 local SYSUP_URL="$(sysupgrade_url)" local SYSUP_URL="$(sysupgrade_url)"
 local SYSUP_REV="$(sysupgrade_rev)" local SYSUP_REV="$(sysupgrade_rev)"
-if [ "${SYSUP_REV}" != "${DISTRIB_REVISION}" ] \ +if [ "${SYSUP_REV}" != "${BUILD_ID}" ] \ 
-|| [ -n "${SYSUP_FORCE}" ] +|| [ "${SYSUP_CMD}" = "-U" ] 
-then+then shift
 local SYSUP_DEV="$(sysupgrade_dev)" local SYSUP_DEV="$(sysupgrade_dev)"
 local SYSUP_PROF="$(sysupgrade_prof)" local SYSUP_PROF="$(sysupgrade_prof)"
Line 47: Line 47:
 local SYSUP_TYPE="$(sysupgrade_type)" local SYSUP_TYPE="$(sysupgrade_type)"
 local SYSUP_EFI="$(sysupgrade_efi)" local SYSUP_EFI="$(sysupgrade_efi)"
-local SYSUP_JSON="$(sysupgrade_json)" 
 local SYSUP_IMG="$(sysupgrade_img)" local SYSUP_IMG="$(sysupgrade_img)"
 sysupgrade "${@}" "${SYSUP_URL}/${SYSUP_IMG}" sysupgrade "${@}" "${SYSUP_URL}/${SYSUP_IMG}"
Line 54: Line 53:
  
 sysupgrade_ver() { sysupgrade_ver() {
-case "${DISTRIB_RELEASE}" in +case "${VERSION_ID}" in 
-(SNAPSHOT) echo "../snapshots" ;; +(snapshot) echo "../snapshots" ;; 
-(*) uclient-fetch -O - \+(*) wget -O - \
 "https://api.github.com/repos/openwrt/openwrt/tags" \ "https://api.github.com/repos/openwrt/openwrt/tags" \
 | jsonfilter -e "$[*]['name']" \ | jsonfilter -e "$[*]['name']" \
Line 65: Line 64:
 sysupgrade_url() { sysupgrade_url() {
 echo "https://downloads.openwrt.org/\ echo "https://downloads.openwrt.org/\
-releases/${SYSUP_VER}/targets/${DISTRIB_TARGET}"+releases/${SYSUP_VER}/targets/${OPENWRT_BOARD}"
 } }
  
 sysupgrade_rev() { sysupgrade_rev() {
-uclient-fetch -O - "${SYSUP_URL}/version.buildinfo"+wget -O - "${SYSUP_URL}/version.buildinfo"
 } }
  
Line 78: Line 77:
  
 sysupgrade_prof() { sysupgrade_prof() {
-case "${DISTRIB_TARGET}" in +case "${OPENWRT_BOARD}" in 
-(x86*) echo "generic" ;;+(x86/*) echo "generic" ;;
 (*) echo "${SYSUP_DEV//,/_}" ;; (*) echo "${SYSUP_DEV//,/_}" ;;
 esac esac
Line 90: Line 89:
  
 sysupgrade_type() { sysupgrade_type() {
-case "${DISTRIB_TARGET}" in +case "${OPENWRT_BOARD}" in 
-(x86*) echo "combined" ;;+(x86/*) echo "combined" ;;
 (*) echo "sysupgrade" ;; (*) echo "sysupgrade" ;;
 esac esac
Line 102: Line 101:
 } }
  
-sysupgrade_json() { +sysupgrade_img() { 
-uclient-fetch -O - "${SYSUP_URL}/profiles.json"+wget -O - "${SYSUP_URL}/profiles.json"
-| jsonfilter -e "$['profiles']['${SYSUP_PROF}']\ +| jsonfilter -e "$['profiles']['${SYSUP_PROF}'
-['images'][@['type']='${SYSUP_TYPE}${SYSUP_EFI}'\ +['images'][@['type']='${SYSUP_TYPE}${SYSUP_EFI}' 
-&&@['filesystem']='${SYSUP_FS}']"+&&@['filesystem']='${SYSUP_FS}']['name']"
 } }
  
-sysupgrade_img() { +service_save() { 
-jsonfilter -e "$['name']" << EOI +local SVC_NAME="$(ls /etc/init.d)" 
-${SYSUP_JSON}+local SVC_STATE 
 +for SVC_NAME in ${SVC_NAME} 
 +do if command service "${SVC_NAME}" enabled 
 +then SVC_STATE="enable" 
 +else SVC_STATE="disable" 
 +fi 
 +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 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
 . /etc/profile.d/sysupgrade.sh . /etc/profile.d/sysupgrade.sh
 +
 +# Configure startup scripts
 +cat << "EOF" > /etc/uci-defaults/60-service-restore
 +if [ ! -e /etc/service-restore ]
 +then . /etc/profile.d/sysupgrade.sh
 +sysupgrade -R
 +touch /etc/service-restore
 +fi
 +exit 1
 +EOF
 +cat << "EOF" >> /etc/sysupgrade.conf
 +/etc/uci-defaults/60-service-restore
 +EOF
 </code> </code>
  
Line 129: Line 164:
 ===== 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