Initial import from FreeBSD RELENG_4:
[dragonfly.git] / tools / tools / upgrade / doupgrade.sh
1 #!/bin/sh
2
3 # Simple helper script for upgrade target.
4
5 # Expects MACHINE to be passed in with the environment, the "pass number"
6 # as the first argument the name of the file to leave its droppings in
7 # as the second.  CURDIR is also passed in the environment from ${.CURDIR}
8
9 PASS=$1
10 CONF=$2
11
12 cd ${CURDIR}/sys/${MACHINE}/conf
13
14 # Create kernel configuration file for pass #1
15 if [ $PASS -eq 1 ]; then
16         echo "The following files are in ${CURDIR}/sys/${MACHINE}/conf:"; echo
17         ls -C
18         echo; echo -n "Which config file do you wish to use? [GENERIC] "
19         read answer
20         if [ -z "${answer}" ]; then
21                 KERN=GENERIC
22         else
23                 KERN="${answer}"
24         fi
25         if [ ! -f ${KERN} ]; then
26                 KERN=GENERIC
27         fi
28         if ! grep -q atkbdc0 ${KERN}; then
29                 if [ ! -f ${KERN}.bkup ]; then
30                         cp ${KERN} ${KERN}.bkup
31                 fi
32                 sed -e 's/^device.*sc0.*$/ \
33 controller      atkbdc0 at isa? port IO_KBD tty \
34 device          atkbd0  at isa? tty irq 1 \
35 device          vga0    at isa? port ? conflicts \
36 device          sc0     at isa? tty \
37 pseudo-device   splash \
38 /' -e 's/sd\([0-9]\)/da\1/' -e 's/st\([0-9]\)/sa\1/' < ${KERN}.bkup > ${KERN}
39         fi
40
41         ROOTDEV=`awk '$2~/\/$/{print substr($1, 6, 3)}' /etc/fstab`
42         echo -n "What is your boot device (e.g. wd0 or sd0)? [${ROOTDEV}] "
43         read answer
44         if [ -n "${answer}" ]; then
45                 ROOTDEV="${answer}"
46         fi
47         echo "KERNEL=${KERN}" > ${CONF}
48         echo "ROOTDEV=${ROOTDEV}" >> ${CONF}
49         if ! file /kernel | grep -q ELF; then
50                 echo "NEWBOOT=YES" >> ${CONF}
51         fi
52 fi
53
54 # Build and install kernel as pass #2
55 if [ $PASS -eq 2 -a -f ${CONF} ]; then
56         . ${CONF}
57         if [ "x${NEWBOOT}" = "xYES" ]; then
58            echo "--------------------------------------------------------------"
59            echo " Installing new boot blocks"
60            echo "--------------------------------------------------------------"
61            if [ ! -f /boot/loader ]; then
62               (cd ${CURDIR}/lib/libstand; make obj; make -B depend all install)
63               (cd ${CURDIR}/sys/boot; make obj; make -B depend all install)
64            fi
65            if ! disklabel -B ${ROOTDEV}; then
66                 echo "Installation of new boot blocks failed!  Please correct"
67                 echo "this manually BEFORE you reboot your system!"
68                 exit 1
69            fi
70         fi
71         if ! file /kernel | grep -q ELF; then
72                 echo "--------------------------------------------------------------"
73                 echo " Building an elf kernel for ${KERNEL} using the new tools"
74                 echo "--------------------------------------------------------------"
75                 config -r ${KERNEL}
76                 cd ${CURDIR}/sys/compile/${KERNEL} && make -B depend -DFORCE all install
77         fi
78 fi