summaryrefslogtreecommitdiff
path: root/etc/etc.i386/files.kc/copy_kernel
blob: 8a2b567cf6ebc3b4dd0a4e425996759e514f2144 (plain)
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#	$Id: copy_kernel,v 1.2 1996/06/11 09:05:32 deraadt Exp $
#
#	Kernel copy script

DEFAULT_PARTITON=sd0a
MOUNT_POINT=/mnt
KERNEL_NAME=/bsd
#TEST=testfn

testfn() {
	echo	$*
	sleep	5
}

cancel() {
	echo	""
	echo	"Copy cancelled."
	exit 1
}

umountfs() {
	echo	"Unmounting filesystem; please wait."
	trap 2 3
	${TEST} umount ${MOUNT_POINT}
	case $? in
	0)
		;;
	*)
		echo	"Warning: Unmount of ${MOUNT_POINT} failed."
		;;
	esac	
}

warning() {
	echo	""
	echo	"Copy failed or was interrupted."
	echo	"Warning: Copied kernel my be corrupted!"
}

trap "cancel;" 2 3
echo	"OpenBSD kernel copy program"
echo	""
echo	"Default answers are displayed in brackets.  You may hit Control-C"
echo	"at any time to cancel this operation (though if you hit Control-C at"
echo	"a prompt, you need to hit return for it to be noticed)."

echo	""
echo	"What disk partition should the kernel be installed on?"
echo	"(For example, \"sd0a\", \"wd0a\", etc.)"
echo	""
echo -n	"Partition? [${DEFAULT_PARTITON}] "
read diskpart
if [ "X${diskpart}" = "X" ]; then
	diskpart=${DEFAULT_PARTITON}
fi
rawdiskpart="r${diskpart}"

echo	""
echo -n	"Are you sure you want to copy a new kernel to ${diskpart}? [n] "
read reply
case ${reply} in
y*|Y*)
	;;
*)
	cancel
	;;
esac

echo	""
echo	"Checking ${diskpart} partition; please wait."
${TEST} fsck -p "/dev/${rawdiskpart}"
case $? in
0)
	;;
*)
	echo	"File system check failed or aborted!"
	cancel
	;;
esac

echo	"Mounting /dev/${diskpart} on ${MOUNT_POINT}."
trap "echo ''; umountfs; cancel;" 2 3
${TEST} mount "/dev/${diskpart}" ${MOUNT_POINT}
case $? in
0)
	;;
*)
	echo	"Mount failed!"
	cancel
	;;
esac

echo	"Copying kernel to ${MOUNT_POINT}."
trap "warning; umountfs; cancel;" 2 3
${TEST} cp ${KERNEL_NAME} ${MOUNT_POINT}
case $? in
0)
	;;
*)
	warning
	umountfs
	cancel
	;;
esac

umountfs

echo	""
echo	"Copy completed."
echo	""
echo	"Use \"halt\" to halt the system, then (when the system is halted)"
echo	"eject the floppy disk and hit any key to reboot from the hard disk."
exit 0