base-files: firstboot: only ask for confirmation on TTY
[librecmc/librecmc.git] / package / base-files / files / sbin / firstboot
index 4da299189e7da7bb9fe5a9eaf3bc3e11601c40f8..06b64c31332e48bb1025a7fd3dad9a3c139e6376 100755 (executable)
@@ -4,7 +4,7 @@ switch2jffs_hook=
 jffs2reset_hook=
 no_fo_hook=
 
-. /lib/functions/boot.sh
+. /lib/functions.sh
 
 firstboot_skip_next=false
 
@@ -20,15 +20,25 @@ set_jffs_part
 if [ "${0##*/}" = "firstboot" ]; then
     if [ "$1" = "switch2jffs" ]; then
        boot_run_hook switch2jffs
-    elif [ -n "$jffs" ]; then
-       reset_has_fo=true
-       echo "firstboot has already been run"
-       echo "jffs2 partition is mounted, only resetting files"
-       boot_run_hook jffs2reset
     else
-       mtd erase "$partname"
-       mount "$mtdpart" /overlay -t jffs2
-       fopivot /overlay /rom 1
+       if [ -t 0 ] && [ "$1" != "-y" ]; then
+               local input
+
+               echo -n "firstboot will erase all settings and remove any installed packages. Are you sure? [N/y]"
+               read input
+               [ "$input" = "y" ] || [ "$input" = "Y" ] || return 0
+       fi
+
+       if [ -n "$jffs" ]; then
+           reset_has_fo=true
+           echo "firstboot has already been run"
+           echo "jffs2 partition is mounted, only resetting files"
+           boot_run_hook jffs2reset
+       else
+           mtd erase "$partname"
+           mount -o noatime "$mtdpart" /overlay -t jffs2
+           fopivot /overlay /rom 1
+       fi
     fi
 fi