* Mördercommit ;-)
[project/luci.git] / contrib / package / luci-addons / dist / sbin / ffluci-flash
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 KEEP_PATTERN=""
8 export VERBOSE=1
9
10 # parse options
11 while [ -n "$1" ]; do
12 case "$1" in
13 -k)
14 shift
15 export KEEP_PATTERN="$1"
16 ;;
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 [ -f $CONFFILES ] && rm $CONFFILES
30 [ -f $CONF_TAR ] && rm $CONF_TAR
31
32 export ARGV="$*"
33 export ARGC="$#"
34
35 [ -z "$ARGV" ] && {
36 cat <<EOF
37 Usage: $0 [options] <image file or URL>
38
39 Options:
40 -k <"file 1, file 2, ..."> Files to be kept
41 EOF
42 exit 1
43 }
44
45 add_pattern_conffiles() {
46 local file="$1"
47 find $KEEP_PATTERN >> "$file" 2>/dev/null
48 return 0
49 }
50
51 # hooks
52 sysupgrade_image_check="platform_check_image"
53 sysupgrade_init_conffiles=""
54
55 [ -n "$KEEP_PATTERN" ] && append sysupgrade_init_conffiles "add_pattern_conffiles"
56
57 include /lib/upgrade
58
59 do_save_conffiles() {
60 [ -z "$(rootfs_type)" ] && {
61 echo "Cannot save config while running from ramdisk."
62 exit 3
63 return 0
64 }
65 run_hooks "$CONFFILES" $sysupgrade_init_conffiles
66
67 v "Saving config files..."
68 [ "$VERBOSE" -gt 1 ] && TAR_V="v" || TAR_V=""
69 tar c${TAR_V}zf "$CONF_TAR" -T "$CONFFILES" 2>/dev/null
70 }
71
72 type platform_check_image >/dev/null 2>/dev/null || {
73 echo "Firmware upgrade is not implemented for this platform."
74 exit 1
75 }
76
77 for check in $sysupgrade_image_check; do
78 ( eval "$check \"\$ARGV\"" ) || {
79 echo "Image check '$check' failed."
80 exit 2
81 }
82 done
83
84 [ -n "$sysupgrade_init_conffiles" ] && do_save_conffiles
85 run_hooks "" $sysupgrade_pre_upgrade
86
87 v "Switching to ramdisk..."
88 run_ramfs '. /etc/functions.sh; include /lib/upgrade; do_upgrade'