Ticket #10624: sysupgrade.create_config_image.diff

File sysupgrade.create_config_image.diff, 2.4 KB (added by James <sams.james@…>, 5 years ago)

Add -C/--create-config-only option to sysupgrade

  • package/base-files/files/sbin/sysupgrade

    diff --git a/package/base-files/files/sbin/sysupgrade b/package/base-files/files/sbin/sysupgrade
    index cf79114..0f2d924 100755
    a b export SAVE_OVERLAY=0 
    1111export DELAY= 
    1212export CONF_IMAGE= 
    1313export HELP=0 
     14export OUT_CONF_IMAGE= 
    1415 
    1516# parse options 
    1617while [ -n "$1" ]; do  
    while [ -n "$1" ]; do 
    2122                -q) export VERBOSE="$(($VERBOSE - 1))";; 
    2223                -n) export SAVE_CONFIG=0;; 
    2324                -c) export SAVE_OVERLAY=1;; 
     25                -C|--create-config-only) export OUT_CONF_IMAGE="$2"; shift;; 
    2426                -f) export CONF_IMAGE="$2"; shift;; 
    2527                -h|--help) export HELP=1; break;; 
    2628                -*) 
    export CONF_TAR=/tmp/sysupgrade.tgz 
    3840export ARGV="$*" 
    3941export ARGC="$#" 
    4042 
    41 [ -z "$ARGV" -o $HELP -gt 0 ] && { 
     43[ -z "$ARGV" -a -z "$OUT_CONF_IMAGE" -o $HELP -gt 0 ] && { 
    4244        cat <<EOF 
    4345Usage: $0 [options] <image file or URL> 
    4446 
    Options: 
    4749        -f <config>  restore configuration from .tar.gz (file or url) 
    4850        -i           interactive mode 
    4951        -c           attempt to preserve all changed files in /etc/ 
     52        -C / --create-config-only <file> 
     53                     create .tar.gz of files specified in sysupgrade.conf 
     54                     then exit. Does not flash an image. 
    5055        -n           do not save configuration over reflash 
    5156        -q           less verbose 
    5257        -v           more verbose 
    EOF 
    5661        exit 1 
    5762} 
    5863 
     64[ -n "$ARGV" -a -n "$OUT_CONF_IMAGE" ] && { 
     65    cat <<EOF 
     66-C/--create-config-only does not perform a firmware upgrade. Do not 
     67specify both -C and a firmware image. 
     68EOF 
     69    exit 1 
     70} 
     71 
    5972add_uci_conffiles() { 
    6073        local file="$1" 
    6174        ( find $(sed -ne '/^[[:space:]]*$/d; /^#/d; p' \ 
    sysupgrade_image_check="platform_check_image" 
    8598include /lib/upgrade 
    8699 
    87100do_save_conffiles() { 
     101    if [ -z "$1" ]; then 
     102        local conf_tar="$CONF_TAR" 
     103    else 
     104        local conf_tar="$1" 
     105    fi 
     106 
    88107        [ -z "$(rootfs_type)" ] && { 
    89108                echo "Cannot save config while running from ramdisk." 
    90109                ask_bool 0 "Abort" && exit 
    do_save_conffiles() { 
    95114 
    96115        v "Saving config files..." 
    97116        [ "$VERBOSE" -gt 1 ] && TAR_V="v" || TAR_V="" 
    98         tar c${TAR_V}zf "$CONF_TAR" -T "$CONFFILES" 2>/dev/null 
     117        tar c${TAR_V}zf "$conf_tar" -T "$CONFFILES" 2>/dev/null 
    99118} 
    100119 
     120if [ -n "$OUT_CONF_IMAGE" ]; then 
     121    do_save_conffiles "$OUT_CONF_IMAGE" 
     122    exit $? 
     123fi 
     124 
    101125type platform_check_image >/dev/null 2>/dev/null || { 
    102126        echo "Firmware upgrade is not implemented for this platform." 
    103127        exit 1