remove /etc/firewall.* from being kept as they no longer are used in trunk
[openwrt/svn-archive/archive.git] / package / base-files / files / sbin / sysupgrade
1 #!/bin/sh
2 . /etc/functions.sh
3
4 # initialize defaults
5 RAMFS_COPY_BIN="" # extra programs for temporary ramfs root
6 RAMFS_COPY_DATA="" # extra data files
7 export INTERACTIVE=0
8 export VERBOSE=1
9 export SAVE_CONFIG=1
10
11 # parse options
12 while [ -n "$1" ]; do
13 case "$1" in
14 -i) export INTERACTIVE=1;;
15 -v) export VERBOSE="$(($VERBOSE + 1))";;
16 -q) export VERBOSE="$(($VERBOSE - 1))";;
17 -*)
18 echo "Invalid option: $1"
19 exit 1
20 ;;
21 *) break;;
22 esac
23 shift;
24 done
25
26 export CONFFILES=/tmp/sysupgrade.conffiles
27 export CONF_TAR=/tmp/sysupgrade.tgz
28
29 export ARGV="$*"
30 export ARGC="$#"
31
32 [ -z "$ARGV" ] && {
33 cat <<EOF
34 Usage: $0 [options] <image file or URL>
35
36 Options:
37 -i interactive mode
38 -v more verbose
39 -q less verbose
40
41 EOF
42 exit 1
43 }
44
45 add_uci_conffiles() {
46 local file="$1"
47 find /etc/config /etc/passwd /etc/group /etc/dropbear > "$file"
48 return 0
49 }
50
51 # hooks
52 sysupgrade_image_check="platform_check_image"
53 sysupgrade_init_conffiles="add_uci_conffiles"
54
55 include /lib/upgrade
56
57 do_save_conffiles() {
58 [ -z "$(rootfs_type)" ] && {
59 echo "Cannot save config while running from ramdisk."
60 ask_bool 0 "Abort" && exit
61 return 0
62 }
63 run_hooks "$CONFFILES" $sysupgrade_init_conffiles
64 ask_bool 0 "Edit config file list" && vi "$CONFFILES"
65
66 v "Saving config files..."
67 [ "$VERBOSE" -gt 1 ] && TAR_V="v" || TAR_V=""
68 tar c${TAR_V}zf "$CONF_TAR" -T "$CONFFILES" 2>/dev/null
69 }
70
71 type platform_check_image >/dev/null 2>/dev/null || {
72 echo "Firmware upgrade is not implemented for this platform."
73 exit 1
74 }
75
76 for check in $sysupgrade_image_check; do
77 ( eval "$check \"\$ARGV\"" ) || {
78 echo "Image check '$check' failed."
79 exit 1
80 }
81 done
82
83 if ask_bool $SAVE_CONFIG "Keep config files over reflash"; then
84 do_save_conffiles
85 export SAVE_CONFIG=1
86 else
87 export SAVE_CONFIG=0
88 fi
89 run_hooks "" $sysupgrade_pre_upgrade
90
91 v "Switching to ramdisk..."
92 run_ramfs '. /etc/functions.sh; include /lib/upgrade; do_upgrade'