viewsky11的专栏

Openwrt中的sysupgrade脚本提供了固件升级的快捷方式,该脚本位于: /sbin/sysupgrade 脚本内容:

#!/bin/sh. /lib/functions.sh. /lib/functions/system.sh# initialize defaultsRAMFS_COPY_BIN=””# extra programs for temporary ramfs rootRAMFS_COPY_DATA=MTD_CONFIG_ARGS=VERBOSE=SAVE_OVERLAY=0export DELAY=export CONF_IMAGE=export CONF_BACKUP_LIST=0export CONF_BACKUP=export CONF_RESTORE=export NEED_IMAGE=TEST=[ -n ” in-i) export INTERACTIVE=1;;-d) export DELAY=”$2″; shift;;-v) export VERBOSE=”$(($VERBOSE + 1))”;;-q) export VERBOSE=”$(($VERBOSE – 1))”;;-n) export SAVE_CONFIG=0;;-c) export SAVE_OVERLAY=1;;-b|–create-backup) export CONF_BACKUP=”$2″ NEED_IMAGE=1; shift;;-r|–restore-backup) export CONF_RESTORE=”$2″ NEED_IMAGE=1; shift;;-l|–list-backup) export CONF_BACKUP_LIST=1; break;;-f) export CONF_IMAGE=”$2″; shift;;-F|–force) export FORCE=1;;-T|–test) export TEST=1;;-h|–help) export HELP=1; break;;-*);;*) break;;esacshift;doneexport CONFFILES=/tmp/sysupgrade.conffilesexport CONF_TAR=/tmp/sysupgrade.tgzexport ARGV=”$*”export ARGC=”$#”[ -z ] && {cat <<EOFUsage: $0 [<upgrade-option>…] <image file or URL>$0 [-q] [-i] <backup-command> <file>upgrade-option:-d <delay> add a delay before rebooting-f <config> restore configuration from .tar.gz (file or url)-iinteractive mode-cattempt to preserve all changed files in /etc/-ndo not save configuration over reflash-T | –testVerify image and config .tar.gz but do not actually flash.-F | –forceFlash image even if image checks fail, this is dangerous!-qless verbose-vmore verbose-h | –help display this helpbackup-command:-b | –create-backup <file>create .tar.gz of files specified in sysupgrade.confthen exit. Does not flash an image. If file is ‘-‘,i.e. stdout, verbosity is set to 0 (i.e. quiet).-r | –restore-backup <file>restore a .tar.gz created with sysupgrade -bthen exit. Does not flash an image. If file is ‘-‘,the archive is read from stdin.-l | –list-backuplist the files that would be backed up when callingsysupgrade -b. Does not create a backup file.EOFexit 1}[ -n “$ARGV” -a -n “$NEED_IMAGE” ] && {cat <<-EOF-b|–create-backup and -r|–restore-backup do not perform a firmware upgrade.Do not specify both -b|-r and a firmware image.EOFexit 1}# prevent messages from clobbering the tarball when using stdout[ “$CONF_BACKUP” = “-” ] && export VERBOSE=0add_uci_conffiles() {local file=”$1″( find $(sed -ne ‘/^[[:space:]]*$/d; /^#/d; p’ \/etc/sysupgrade.conf /lib/upgrade/keep.d/* 2>/dev/null) \-type f -o -type l 2>/dev/null;opkg list-changed-conffiles ) | sort -u > }add_overlayfiles() {local file=”$1″if [ -d /overlay/upper ]; thenlocal overlaydir=”/overlay/upper”elselocal overlaydir=”/overlay”fifind $overlaydir/etc/ -type f -o -type l | sed \-e ‘s,^/overlay/,/,’ \-e ‘\,/META_[a-zA-Z0-9]*$,d’ \-e ‘\,/functions.sh$,d’ \-e ‘\,/[^/]*-opkg$,d’ \&; }# hookssysupgrade_image_check=”platform_check_image”[ $SAVE_OVERLAY = 0 -o ! -d /overlay/etc ] && \sysupgrade_init_conffiles=”add_uci_conffiles” || \sysupgrade_init_conffiles=”add_overlayfiles”include /lib/upgrade[ “$1” = “nand” ] && nand_upgrade_stage2 $@do_save_conffiles() {local conf_tar=”${1:-$CONF_TAR}”[ -z “$(rootfs_type)” ] && {echo “Cannot save config while running from ramdisk.”ask_bool }run_hooks “$CONFFILES” $sysupgrade_init_conffilesask_bool 0 “Edit config file list” && vi “$CONFFILES”v “Saving config files…”[ ] && TAR_V=”v” || TAR_V=””tar c${TAR_V}zf “$conf_tar” -T “$CONFFILES” 2>/dev/nullrm -f “$CONFFILES”}]; thenadd_uci_conffiles “$CONFFILES”cat “$CONFFILES”rm [ -n $?[ ‘ not found.”[ ] && TAR_V=”v” || TAR_V=””tar -C / -x${TAR_V}zf “$CONF_RESTORE”exit $?fitype platform_check_image >/dev/null 2>/dev/null || {}for check in $sysupgrade_image_check; do( eval “$check \”\$ARGV\”” ) || {]; ‘ failed but –force given – will update anyway!”‘ failed.”}” f8b) ;;*);;esacget_image SAVE_CONFIG=; then[ ] || do_save_conffilesSAVE_CONFIG=[ ]; run_hooks >/dev/null 2>/dev/null; thenplatform_pre_upgrade “$ARGV”fiubus call system upgradetouch /tmp/sysupgradeif [ ! -f /tmp/failsafe ] ; thenkill_remaining TERMsleep 3kill_remaining KILLfiif [ -n “$(rootfs_type)” ]; thenv “Switching to ramdisk…”run_ramfs _upgradefi

,以一种进取的和明智的方式同它们奋斗。

viewsky11的专栏

相关文章:

你感兴趣的文章:

标签云: