File: arcboot-installer.postinst

package info (click to toggle)
arcboot-installer 1.20
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 656 kB
  • sloc: sh: 68; makefile: 2
file content (109 lines) | stat: -rwxr-xr-x 3,708 bytes parent folder | download | duplicates (2)
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
#!/bin/sh
set -e

. /usr/share/debconf/confmodule

if [ -f /etc/mtab ]; then
    MTAB=/etc/mtab
else
    MTAB=/proc/mounts
fi

# detect which is the root partition: /target
rootfs=`grep ' /target ' $MTAB |cut -d' ' -f1 -s`
rootfs=`mapdevfs $rootfs`
defaultbootdev=`echo $rootfs |sed 's/[0-9]\+$//'`

db_fget arcboot/boot_device seen
[ "$RET" = true ] || db_set arcboot/boot_device "$defaultbootdev"
db_input high arcboot/boot_device || [ $? -eq 30 ]
db_go || true
db_get arcboot/boot_device

bootdev=$RET
[ "$bootdev" != '' ] || bootdev=$defaultbootdev

# Use a serial console if current default console is a serial port.
# default console is last listed
defconsole=$(sed -e 's/.*console=/console=/' /proc/cmdline)
if echo "${defconsole}" | grep -q console=ttyS; then
    defconsole=$(echo "${defconsole}" | sed -e 's/[[:space:]].*//')
    PORT=$(echo "${defconsole}" | sed -e 's%^console=ttyS%%' -e 's%,.*%%')
    SPEED=$(echo "${defconsole}" | sed -e 's%^console=ttyS[0-9]\+,*%%' -e 's%[[:space:]].*%%')
    SERIAL="${PORT}"
    if [ "${SPEED}" != '' ]; then
	SERIAL="${SERIAL},${SPEED}"
    fi

    db_subst arcboot-installer/serial-console PORT "ttyS${PORT}"
    db_subst arcboot-installer/serial-console SPEED "${SPEED}"
    db_input medium arcboot-installer/serial-console || [ $? -eq 30 ]
    db_go || true
fi

# write out arcboot.conf
{   echo 'label=Linux'
    echo '  image=/vmlinux'

    if [ "${SERIAL}" ]; then
	echo "  append=\"root=${rootfs} console=ttyS${SERIAL}\""
    else
	echo "  append=\"root=${rootfs}\""
    fi
} > /target/etc/arcboot.conf

# Install arcboot only after arcboot.conf is created since the arcboot
# postinst fails in a chroot.
#
# HACK ALERT!
# The arcboot postinst wants to read $bootdev from debconf _in the chroot_,
# which is still empty. We ignore the resulting apt-install error and do the
# install ourself. If apt-install fails for a different reason, we are lost.
#
# mount proc since arcboot needs it to find out the subarchitecture
mount -t proc proc /target/proc
set +e
apt-install arcboot
chroot /target /usr/sbin/arcboot $bootdev
set -e
umount /target/proc

#if ! apt-install arcboot; then
#	log "Calling 'apt-install arcboot' failed"
#	# What to do now?
#	db_input critical arcboot-installer/apt-install-failed || [$? -eq 30]
#	db_go
#	db_get
#	if [ true != "$RET" ] ; then
#		exit 1
#	fi
#fi

# Fill the necessary PROM variables that will need to be set before the
# system can be booted.
bootmin=$((`echo $bootdev |sed 's+/dev/sd++' |tr [a-h] [0-7]` * 16))
bootdev=`grep "^\ \+8\ \+$bootmin\ \+" /proc/partitions | sed -e "s/ \+/ /g" | cut -d " " -f5`
scsi_info=$(readlink /sys/block/$bootdev/device | sed 's/.*\///')
BOOTBUS=`echo $scsi_info | cut -d: -f2`
BOOTID=`echo $scsi_info | cut -d: -f3`
BOOTLUN=`echo $scsi_info | cut -d: -f4`

rootmin=`echo $rootfs |sed 's+/dev/sd.++'`
rootdev=`grep "^\ \+8\ \+$rootmin\ \+" /proc/partitions | sed -e "s/ \+/ /g" | cut -d " " -f5`
rootdev=$(echo $rootdev | sed 's/[0-9]\+$//')
scsi_info=$(readlink /sys/block/$rootdev/device | sed 's/.*\///')
ROOTBUS=`echo $scsi_info | cut -d: -f2`
ROOTID=`echo $scsi_info | cut -d: -f3`
ROOTLUN=`echo $scsi_info | cut -d: -f4`

ROOTPART=$(($rootmin - 1))

db_subst arcboot-installer/prom-variables BOOTBUS "${BOOTBUS}"
db_subst arcboot-installer/prom-variables BOOTID "${BOOTID}"
db_subst arcboot-installer/prom-variables BOOTLUN "${BOOTLUN}"
db_subst arcboot-installer/prom-variables ROOTBUS "${ROOTBUS}"
db_subst arcboot-installer/prom-variables ROOTID "${ROOTID}"
db_subst arcboot-installer/prom-variables ROOTLUN "${ROOTLUN}"
db_subst arcboot-installer/prom-variables ROOTPART "${ROOTPART}"
db_input high arcboot-installer/prom-variables || [ $? -eq 30 ]
db_go || true