base-files: make firstboot ask for confirmation
[openwrt.git] / package / base-files / files / sbin / firstboot
1 #!/bin/sh
2
3 switch2jffs_hook=
4 jffs2reset_hook=
5 no_fo_hook=
6
7 . /lib/functions.sh
8
9 firstboot_skip_next=false
10
11 for fb_source_file in /lib/firstboot/*; do
12     . $fb_source_file
13 done
14
15 set_mtd_part
16 set_rom_part
17 set_jffs_part
18
19 # invoked as an executable
20 if [ "${0##*/}" = "firstboot" ]; then
21     if [ "$1" = "switch2jffs" ]; then
22         boot_run_hook switch2jffs
23     else
24         local input
25
26         echo -n  "firstboot will erase all settings and remove any installed packages. Are you sure? [N/y]"
27         read input
28         [ "$input" = "y" ] || [ "$input" = "Y" ] || return 0
29
30         if [ -n "$jffs" ]; then
31             reset_has_fo=true
32             echo "firstboot has already been run"
33             echo "jffs2 partition is mounted, only resetting files"
34             boot_run_hook jffs2reset
35         else
36             mtd erase "$partname"
37             mount -o noatime "$mtdpart" /overlay -t jffs2
38             fopivot /overlay /rom 1
39         fi
40     fi
41 fi
42