]> spindle.queued.net Git - xodist/blob - installer
mkext3: fix sparse image creation
[xodist] / installer
1 #!/bin/sh -e
2
3 PREREQS=""
4
5 prereqs()
6 {
7         echo "$PREREQS"
8 }
9
10 case "$1" in
11         prereqs)
12                 prereqs
13                 exit 0
14         ;;
15 esac
16
17 # find the disk to install to
18 find_target()
19 {
20         SRC=$1
21         
22         for f in /sys/block/[sh]d[a-z]; do
23                 bdev=$(basename $f)
24                 if [ "$bdev" = "$SRC" ]; then
25                         continue
26                 fi
27                 # the first block device that's not root?  take it!
28                 echo "$bdev"
29                 break
30         done
31 }
32
33 do_install()
34 {
35         echo
36         echo
37         echo
38         echo "Starting installer!"
39         if [ ! -d /root/etc ]; then
40                 echo "Error: /root doesn't appear to have a valid filesystem mounted!"
41                 sleep 9999999999
42         fi
43
44         ROOT_SRC=$(grep ' /root ' /proc/mounts | cut -d' ' -f1)
45         ROOT_SRC=$(readlink -f $ROOT_SRC | sed 's/.*\/\([hs]d[a-z]\)[0-9]\+$/\1/')
46
47         TARGET=$(find_target "$ROOT_SRC")
48
49         if [ -z "$TARGET" ]; then
50                 echo "Error: couldn't find drive to install to!"
51                 sleep 9999999999
52         fi
53
54         # don't keep fs mounted while copying it
55         umount /root
56         
57         # wait 15s for user realize that they've made a mistake
58         echo "Copying data from [$ROOT_SRC]  =>  [$TARGET]"
59         echo "IF THIS IS INCORRECT, REBOOT NOW OR YOU WILL LOSE DATA!  (waiting 15s)"
60         sleep 15
61
62         echo "Too late, starting copy..."
63         # ideally, we'll resize the filesystem/partitions later..
64         dd if=/dev/$ROOT_SRC of=/dev/$TARGET bs=4k
65
66         echo "Done.  Remove installer media."
67         while [ -d /sys/block/$ROOT_SRC ]; do
68                 sleep 1
69         done
70         reboot
71 }
72
73 for x in $(cat /proc/cmdline); do
74         case $x in
75         installer)
76                 do_install
77                 ;;
78         esac
79 done
80