source: trunk/package/base-files/files/sbin/sysupgrade @ 19964

Last change on this file since 19964 was 19964, checked in by thepeople, 6 years ago

grab all config files for installed packages, closes #3718

  • Property svn:executable set to *
File size: 2.7 KB
Line 
1#!/bin/sh
2. /etc/functions.sh
3
4# initialize defaults
5RAMFS_COPY_BIN=""       # extra programs for temporary ramfs root
6RAMFS_COPY_DATA=""      # extra data files
7export INTERACTIVE=0
8export VERBOSE=1
9export SAVE_CONFIG=1
10export DELAY=
11export CONF_IMAGE=
12# parse options
13while [ -n "$1" ]; do
14        case "$1" in
15                -i) export INTERACTIVE=1;;
16                -d) export DELAY="$2"; shift;;
17                -v) export VERBOSE="$(($VERBOSE + 1))";;
18                -q) export VERBOSE="$(($VERBOSE - 1))";;
19                -n) export SAVE_CONFIG=0;;
20                -f) export CONF_IMAGE="$2"; shift;;
21                -*)
22                        echo "Invalid option: $1"
23                        exit 1
24                ;;
25                *) break;;
26        esac
27        shift;
28done
29
30export CONFFILES=/tmp/sysupgrade.conffiles
31export CONF_TAR=/tmp/sysupgrade.tgz
32
33export ARGV="$*"
34export ARGC="$#"
35
36[ -z "$ARGV" ] && {
37        cat <<EOF
38Usage: $0 [options] <image file or URL>
39
40Options:
41        -d <delay>   add a delay before rebooting
42        -f <config>  restore configuration from .tar.gz (file or url)
43        -i           interactive mode
44        -n           do not save configuration over reflash
45        -q           less verbose
46        -v           more verbose
47
48EOF
49        exit 1
50}
51
52add_uci_conffiles() {
53        local file="$1"
54        find /etc/config/httpd /etc/config/network /etc/config/system /etc/config/wireless /etc/config/fstab \
55                /etc/firewall.user /etc/rc.local /etc/passwd /etc/group /etc/hosts -type f > "$file"
56        find `cat /usr/lib/opkg/status | grep "Conffiles:" | grep -v -e "/etc/banner" -e "/etc/opkg.conf" |cut -d':' -f2` -type f >> "$file"
57        return 0
58}
59
60# hooks
61sysupgrade_image_check="platform_check_image"
62sysupgrade_init_conffiles="add_uci_conffiles"
63
64include /lib/upgrade
65
66do_save_conffiles() {
67        [ -z "$(rootfs_type)" ] && {
68                echo "Cannot save config while running from ramdisk."
69                ask_bool 0 "Abort" && exit
70                return 0
71        }
72        run_hooks "$CONFFILES" $sysupgrade_init_conffiles
73        ask_bool 0 "Edit config file list" && vi "$CONFFILES"
74
75        v "Saving config files..."
76        [ "$VERBOSE" -gt 1 ] && TAR_V="v" || TAR_V=""
77        tar c${TAR_V}zf "$CONF_TAR" -T "$CONFFILES" 2>/dev/null
78}
79
80type platform_check_image >/dev/null 2>/dev/null || {
81        echo "Firmware upgrade is not implemented for this platform."
82        exit 1
83}
84
85for check in $sysupgrade_image_check; do
86        ( eval "$check \"\$ARGV\"" ) || {
87                echo "Image check '$check' failed."
88                exit 1
89        }
90done
91
92if [ -n "$CONF_IMAGE" ]; then
93        case "$(get_magic_word $CONF_IMAGE cat)" in
94                # .gz files
95                1f8b) ;;
96                *)
97                        echo "Invalid config file. Please use only .tar.gz files"
98                        exit 1
99                ;;
100        esac
101        get_image "$CONF_IMAGE" "cat" > "$CONF_TAR"
102        export SAVE_CONFIG=1
103elif ask_bool $SAVE_CONFIG "Keep config files over reflash"; then
104        do_save_conffiles
105        export SAVE_CONFIG=1
106else
107        export SAVE_CONFIG=0
108fi
109run_hooks "" $sysupgrade_pre_upgrade
110
111if [ -n "$(rootfs_type)" ]; then
112        v "Switching to ramdisk..."
113        run_ramfs '. /etc/functions.sh; include /lib/upgrade; do_upgrade'
114else
115        do_upgrade
116fi
Note: See TracBrowser for help on using the repository browser.