summaryrefslogtreecommitdiffstats
path: root/installers/data/pc.sh
blob: 0818437e83d8c2ea12062b95d71474f45f4fc831 (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
set -u

_read()
{
	# The miniprokit call in the installer redirects this script to stdin,
	# so we need to reconnect stdin to the tty.  We can't do this for the
	# whole script with exec, because the shell reads the script in parts.
	read "${@}" 0<&1
}

_select()
{
	# Field width of the prompt numbers.
	select_width=$(expr ${#} : '.*')

	select_i=

	while :; do
		case "${select_i}" in
			'')
				select_i=0
				for select_word in "${@}"; do
					select_i=$(expr ${select_i} + 1)
					printf "%${select_width}d) %s\\n" \
						${select_i} "${select_word}"
				done
				;;
			*[!0-9]*)
				printf 'Please enter a number in range.\n' >&2
				;;
			*)
				if [ ${select_i} -gt 0 ] && \
						[ ${select_i} -le ${#} ]; then
					shift $(expr $select_i - 1)
					select_result="${1}"
					break
				fi
				printf 'Please enter a number in range.\n' >&2
				;;
		esac

		# Prompt and read input.
		printf '%s' "${PS3-#? }" >&2
		_read -r select_i || exit
	done
}

printf '\nConfigure the network'
printf '\n=====================\n\n'
printf 'Hostname: '
_read -r hostname
printf '%s\n' "${hostname}" >/etc/hostname
printf 'Network configuration method:\n'
_select 'Static' 'DHCP'
if [ "x${select_result}" = 'xStatic' ]; then
	printf 'Network interface (e.g. "eth0"): '
	_read -r netiface
	printf 'Network address (e.g. "192.168.1.2"): '
	_read -r netaddr
	printf 'Network mask (e.g. "255.255.255.0"): '
	_read -r netmask
	printf 'Network gateway (e.g. "192.168.1.1"): '
	_read -r netgw
	cat >/etc/network/interfaces.local <<EOF
auto lo
iface lo inet loopback

auto ${netiface}
iface ${netiface} inet static
	address ${netaddr}
	netmask ${netmask}
	gateway ${netgw}
EOF
fi

printf '\nSet up users and passwords'
printf '\n==========================\n\n'
while ! passwd 0<&1; do
	:
done
printf '\n'

tzpkgs="$(opkg info 'tzdata-*' | sed -n 's/^Package: //p')"
opkg install tzcode tzdata ${tzpkgs}
printf '\nConfigure the time zone'
printf '\n=======================\n\n'
tz="$(tzselect 0<&2)"
printf '\n'
ln -sf "/usr/share/zoneinfo/${tz}" /etc/localtime
seltzpkg="$(opkg search "/usr/share/zoneinfo/${tz}" | cut -d ' ' -f 1)"
rmtzpkgs=''
for tzpkg in ${tzpkgs}; do
	if ! [ "x${tzpkg}" = "x${seltzpkg}" ]; then
		rmtzpkgs="${rmtzpkgs} ${tzpkg}"
	fi
done
opkg remove tzcode ${rmtzpkgs}

opkg install lilo
boot="$(mountpoint -n /boot | cut -d ' ' -f 1)"
boot="${boot%%[0-9]}"
printf '\nInstall the boot loader'
printf '\n=======================\n\n'
printf 'Name of root partition on running system (e.g. "sda1"): '
_read -r root
printf '\n'
# XXX: Temporary kludge.
cp -p /boot/vmlinuz /boot/vmlinuz.old
install-lilo "${boot}" "/dev/${root}" >&2

printf '\nInstallation complete!\n'