]> spindle.queued.net Git - xodist/blob - installer
installer: figure out where to install to..
[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                 exit 1
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                 exit 1
52         fi
53         
54         echo "Copying data from $ROOT_SRC => $TARGET"
55         echo "IF THIS IS INCORRECT, REBOOT NOW OR YOU WILL LOSE DATA!  (waiting 15s)"
56         # wait 15s for user realize that they've made a mistake
57         sleep 15
58
59         echo "Too late, starting copy..."
60 sleep 20
61
62
63         echo "Done.  Remove installer and reboot."
64 }
65
66 for x in $(cat /proc/cmdline); do
67         case $x in
68         installer)
69                 do_install
70                 ;;
71         esac
72 done
73