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