summaryrefslogtreecommitdiff
blob: dde30e5c9f1e067518ba5df7777a9787e1d84601 (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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
#!/sbin/runscript
# Copyright 1999-2005 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo/src/livecd-tools/autoconfig,v 1.54 2006/01/21 22:49:57 wolf31o2 Exp $

DHCP="yes"
DETECT="yes"
GPM="yes"
PCMCIA="no"
HOTPLUG="yes"
APM="no"
ACPI="no"
IDEDMA="yes"
ALSA="yes"
X11="yes"

get_config() {
	CMDLINE="$(cat /proc/cmdline)"

	for x in ${CMDLINE} ; do
		case "${x}" in
			nodetect)
				DETECT="no"
				GPM="no"
				HOTPLUG="no"
				APM="no"
				ACPI="no"
				ALSA="no"
				X11="no"
			;;
			nodhcp)
				DHCP="no"
			;;
			nogpm)
				GPM="no"
			;;
			dopcmcia)
				PCMCIA="yes"
			;;
			doapm)
				APM="yes"
				ACPI="no"
			;;
			acpi=on|acpi=force)
				APM="no"
				ACPI="yes"
			;;
			ide=nodma)
				IDEDMA="no"
			;;
			nohotplug)
				HOTPLUG="no"
			;;
			nosound)
				ALSA="no"
			;;
			nox)
				X11="no"
			;;
		esac
	done
}

depend() {
	need modules
	before net
#	provide gpm pcmcia apmd acpid coldplug hdparm alsasound x-setup
}

# Checks whether a service will be started by autoconfig.
# Usage: check_svc var service [service_alternative]
check_svc() {
	if [ "$1" = "yes" ]
	then
		if [ -x "/etc/init.d/$2" ]
		then
			echo "$2"
		elif [ -n "$3" -a -x "/etc/init.d/$3" ]
		then
			echo "$3"		
		fi	
	fi	
}

# Prints an ordered list of services that will be started by autoconfig.
list_services() {
	get_config

	local svcs="$(check_svc ${APM} apmd)"
	svcs="${svcs} $(check_svc ${ACPI} acpid)"
	svcs="${svcs} $(check_svc ${IDEDMA} hdparm)"
	svcs="${svcs} $(check_svc ${PCMCIA} pcmcia)"
	svcs="${svcs} $(check_svc ${GPM} gpm)"
	svcs="${svcs} $(check_svc ${HOTPLUG} coldplug hotplug)"
	svcs="${svcs} $(check_svc ${ALSA} alsasound)"

	echo ${svcs}
}

# Only used on SGI CDs, this determines:
# A) CPU Type
# B) System
detect_mips() {
	local cpuinfo="$(awk -F: '/^cpu model/{printf $2};/^$/{print ""}' /proc/cpuinfo 2>/dev/null | head -n 1 | cut -d" " -f2,3)"
	local machinfo="$(awk -F: '/^system type/{printf $2};/^$/{print ""}' /proc/cpuinfo 2>/dev/null | cut -d" " -f2-)"
	local machtype=""

	case "${machinfo}" in
		"SGI Indy")
			machtype="SGI Indy" # Indy R4x00/R5000
		;;
		"SGI Indigo2")
			case "${cpuinfo}" in
				R4*)
					machtype="SGI Indigo2" # I2 R4x00
				;;
				R8*)
					machtype="SGI Indigo2 Power" # I2 R8000
				;;
				R10*)
					machtype="SGI Indigo2 Impact" # I2 R10000
				;;
			esac
			;;
		"SGI O2"|"SGI IP32")
			machtype="SGI O2" # O2 R5K/RM5K2/RM7K/R10K/R12K
		;;
		"SGI Octane"|"SGI IP30")
			machtype="SGI Octane" # Octane R10K/R12K/R14K
		;;
		"SGI Origin"|"SGI IP27")
			machtype="SGI Origin" # Origin R10K/R12K
		;;
		*)
			machtype="Unknown SGI MIPS" # ???
		;;
	esac

	PC="Detected an ${machtype} w/ ${numcpu} ${cpuinfo} ${bit}"
}

detect_x86_amd64() {
	local cpuinfo="$(awk -F: '/^model name/{printf $2};/^$/{print ""}' /proc/cpuinfo 2>/dev/null | head -n 1)"
	local mhz="$(awk -F: '/^cpu MHz/{printf " %dMHz",int($2)};/^$/{print ""}' /proc/cpuinfo 2>/dev/null | head -n 1)"

	PC="Detected ${numcpu} ${cpuinfo} ${mhz} ${bit}"
}

detect_ppc() {
	local cpuinfo="$(awk -F: '/^cpu/{printf $2};/^$/{print ""}' /proc/cpuinfo 2>/dev/null | head -n 1)"
	local mhz="$(awk -F: '/^clock/{printf " %dMHz",int($2)};/^$/{print ""}' /proc/cpuinfo 2>/dev/null | head -n 1)"
	local machinfo="$(awk -F: '/^detected as/{printf $2}' /proc/cpuinfo | cut -d'(' -f2 | cut -d')' -f1)"
	local machtype=""
	# if [ -z "machinfo" ]
	# then
	#	machinfo=$(awk -F: '/^machine/{printf $2}' /proc/cpuinfo)"
	# fi

	case "${machinfo}" in
		"PowerMac G4 AGP Graphics")
			machtype="Apple PowerMac G4"
			;;
		"PowerBook Titanium"|'PowerBook G4 15"')
			machtype="Apple Powerbook G4"
			;;
		"iBook 2 rev. 2")
			machtype="Apple iBook G3"
			;;
		"PowerMac G5")
			machtype="Apple PowerMac G5"
			;;
		"PowerMac G5 Dual Core")
			machtype="Apple PowerMac G5 Dual Core"
			;;
		"Unknown Intrepid-based")
			machtype="Apple Mac-Mini"
			;;
		"MPC8241")
			machtype="Kurobox"
			;;
		"CHRP Pegasos2")
			machtype="Pegasos 2"
			;;
		*)
			machtype="Unknown PPC System"
			;;
	esac

	PC="Detected an ${machtype} w/ ${numcpu} ${cpuinfo} ${bit}"
}

start() {
	echo "0" > /proc/sys/kernel/printk
	get_config
	if [ "${DETECT}" = "yes" ]
	then
		ebegin "Hardware detection started"
			local numcpu="$(awk -F: '/^processor/{printf $2};/^$/{print ""}' /proc/cpuinfo 2>/dev/null | wc -l)"
			local arch="$(uname -m)"
			local ismips="no"
			[ "${numcpu}" -gt '1' ] && bit="CPUs" || bit="CPU"
			case ${arch} in
				mips|mips64)
					detect_mips
					ismips="yes"
				;;
				i?86|x86_64)
					detect_x86_amd64
				;;
				*)
					PC="$(awk -F: '/^processor/{printf "Processor"$2" is"};/^model name/{printf $2};/^vendor_id/{printf vendor};/^cpu MHz/{printf " %dMHz",int($2)};/^cache size/{printf ","$2" Cache"};/^$/{print ""}' /proc/cpuinfo 2>/dev/null)"
				;;
			esac
			einfo "${PC}"
			[ -x /usr/sbin/hwsetup ] && hwsetup -p >/dev/null
		eend
	else
		ewarn "Hardware detection disabled via cmdline ..."
	fi

	if [ "${APM}" = "yes" ]
	then
		modprobe apm power_off=1 >/dev/null 2>&1 && \
			einfo "APM BIOS found, power management functions enabled ..."
		[ -x /etc/init.d/apmd ] && start_service apmd
	else
		[ "${ismips}" = "no" ] && ewarn "Not Loading APM Bios support ..."
	fi

	if [ "${ACPI}" = "yes" ]
	then
		modprobe processor >/dev/null 2>&1 && \
			ebegin "ACPI power management functions enabled" && \
			modprobe thermal >/dev/null
		modprobe fan >/dev/null 2>&1
		modprobe button >/dev/null 2>&1
		modprobe battery >/dev/null 2>&1
		modprobe ac >/dev/null 2>&1
		[ -x /etc/init.d/acpid ] && start_service acpid
		eend
	else
		[ "${ismips}" = "no" ] && ewarn "Not Loading ACPI support ..."
	fi

	if [ "${IDEDMA}" = "yes" ]
	then
		if [ "${ismips}" = "no" ]; then
			[ -x /etc/init.d/hdparm ] && start_service hdparm
		fi
	fi

	if [ "${PCMCIA}" = "yes" ]
	then
		einfo "PCMCIA enabled via cmdline ..."
		[ -x /etc/init.d/pcmcia ] && start_service pcmcia
	fi

	if [ "${DHCP}" = "no" ]
	then
		sed -i -e '/^ifconfig_eth.*dhcp.*/ s/^/#/' \
			-e '/^iface_eth.*dhcp.*/ s/^/#/' \
			-e '/^config_eth.*dhcp.*/ s/^/#/' \
			/etc/conf.d/net
		ewarn "Skipping DHCP broadcast detection as requested on boot commandline ..."
	fi

	# Read in what hwsetup has found
	[ -f /etc/sysconfig/knoppix ] && . /etc/sysconfig/knoppix
	[ -f /etc/sysconfig/gentoo ] && . /etc/sysconfig/gentoo

	# Mouse
	if [ -n "${MOUSE_DEVICE}" ]
	then
		einfo "Mouse is ${HILITE}${MOUSE_FULLNAME}${NORMAL} at ${HILITE}${MOUSE_DEVICE}${NORMAL} ..."
		source /etc/sysconfig/mouse
		if [ -x /usr/sbin/gpm ]
		then
			[ $(grep "#MOUSE=${MOUSETYPE}" /etc/conf.d/gpm) ] \
				&& sed -i "\@MOUSE=${MOUSETYPE}@s@^#@@" /etc/conf.d/gpm \
				|| echo "MOUSE=${MOUSETYPE}" >>/etc/conf.d/gpm

			[ $(grep "#MOUSEDEV=${DEVICE}" /etc/conf.d/gpm) ] \
				&& sed -i "\@MOUSEDEV=${DEVICE}@s@^#@@" /etc/conf.d/gpm \
				|| echo "MOUSEDEV=${DEVICE}" >>/etc/conf.d/gpm

			[ "${GPM}" = "yes" ] \
				&& [ -x /etc/init.d/gpm ] && start_service gpm
		fi
	fi

	if [ "${HOTPLUG}" = "yes" ]
	then
		# Check whether we should be using hotplug or coldplug
		if [ -x /etc/init.d/coldplug ]
		then
			start_service coldplug
		elif [ -x /etc/init.d/hotplug ]
		then
			start_service hotplug
		fi
	else
		ewarn "Hotplug disabled via cmdline ..."
	fi

	[ "${DETECT}" = "no" ] && DHCP="no"
	[ "${DETECT}" = "yes" ] \
		&& NETDEVICES="$(awk -F: '/eth.:|tr.:|ath.:|wlan.:/{print $1}' /proc/net/dev 2>/dev/null)"

	if [ -n "${NETDEVICES}" ]
	then
		for nics in ${NETDEVICES}
		do
			if [ "${DHCP}" = "yes" ]
			then
				einfo "Network device ${HILITE}${nics}${NORMAL} detected, DHCP broadcasting for IP ..."
				dhcpcd -n -h $(hostname) &
			fi
		done
	else
		ewarn "No Network device auto detected ..."
	fi

	if [ "${ALSA}" = "yes" ]
	then
		if [ -n "${SOUND_FULLNAME}" -o -n "${SOUND_DRIVER}" ]
		then
			local sndmsg="Soundcard:\n"

			[ -n "${SOUND_FULLNAME}" ] \
				&& sndmsg="${sndmsg}              ${WARN}${SOUND_FULLNAME}\n"
			[ -n "${SOUND_DRIVER}" ] \
				&& sndmsg="${sndmsg}              driver = ${SOUND_DRIVER}\n"

			einfo "${sndmsg}"


			if [ -x /etc/init.d/alsasound ]
			then
				start_service alsasound
			fi

			if [ -e /proc/asound/cards ]
			then
				for i in $(cat /proc/asound/cards | cut -d" " -f1)
				do
					if [ -d /proc/asound/card$i ] && [ -x /usr/bin/amixer ]
					then
						amixer -c $i scontrols > /etc/amixer
						[ -n "$(grep Master /etc/amixer)" ] \
							&& amixer -c $i -q set Master 95% unmute \
							>/dev/null 2>&1
						[ -n "$(grep PCM /etc/amixer)" ] \
							&& amixer -c $i -q set PCM 95% unmute \
							>/dev/null 2>&1
						[ -n "$(grep Mic /etc/amixer)" ] \
							&& amixer -c $i -q set Mic 95% mute cap \
							>/dev/null 2>&1
						[ -n "$(grep Wave /etc/amixer)" ] \
							&& amixer -c $i -q set Wave 95% unmute \
							>/dev/null 2>&1
						[ -n "$(grep Capture /etc/amixer)" ] \
							&& amixer -c $i -q set Capture 95% unmute cap \
							>/dev/null 2>&1
					fi
				done
			fi
		fi
	else
		ewarn "Skipping ALSA detection as requested on command line ..."
	fi

	if [ "${DETECT}" = "yes" ]
	then
		[ -x /etc/init.d/x-setup ] && start_service x-setup
	fi

	[ "${X11}" = "no" ] && touch /etc/init.d/.noxdm
	[ -n "${XDESC}" ] && einfo "VideoCard:   ${HILITE}${XDESC}${NORMAL}"

	killall hwsetup 2>/dev/null
	echo "6" > /proc/sys/kernel/printk
}

# vim: ts=4