summaryrefslogtreecommitdiff
blob: 565400a8e433fd06215ba949bc25f0e27a1b42f1 (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
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
#!/sbin/runscript

# This script is used by Gentoo release media to start certain services and to
# ensure a sane setup for a CD-based boot.

ACPI="yes"
ALSA="yes"
APM="no"
BRLTTY="no"
COLDPLUG="yes"
DETECT="yes"
DHCP="yes"
DMRAID="yes"
EVMS="no"
FIREWIRE="yes"
GPM="yes"
IDEDMA="yes"
LVM="no"
MDADM="yes"
NET="yes"
NFS="yes"
PASSWD="yes"
PATA="yes"
PCMCIA="yes"
SATA="yes"
SCSI="no"
SPEAKUP="no"
SPEAKUP_MODULE=""
SPEAKUP_OPTIONS=""
SSHD="no"
USB="yes"
X11="yes"

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

	for x in ${CMDLINE} ; do
		case "${x}" in
			# We put nodetect first, so we can override it with do* commands
			nodetect)
				ACPI="no"
				ALSA="no"
				APM="no"
				COLDPLUG="no"
				DETECT="no"
				DMRAID="no"
				EVMS="no"
				FIREWIRE="no"
				GPM="no"
				LVM="no"
				MDADM="no"
				NET="no"
				NFS="no"
				PCMCIA="no"
				PATA="no"
				SATA="no"
				SCSI="no"
				USB="no"
				X11="no"
			;;
			noapm)
				APM="no"
			;;
			nocoldplug|nohotplug)
				COLDPLUG="no"
			;;
			nodhcp)
				DHCP="no"
			;;
			nodmraid)
				DMRAID="no"
			;;
			noevms|noevms2)
				EVMS="no"
			;;
			nofirewire)
				FIREWIRE="no"
			;;
			nogpm)
				GPM="no"
			;;
			noload=*)
				NOLOAD="$*"
			;;
			nolvm|nolvm2)
				LVM="no"
			;;
			nomdadm)
				MDADM="no"
			;;
			nonet)
				NET="no"
			;;
			nonfs)
				NFS="no"
			;;
			nopata)
				PATA="no"
			;;
			nopcmcia)
				PCMCIA="no"
			;;
			nosata)
				SATA="no"
			;;
			noscsi)
				SCSI="no"
			;;
			nosshd)
				SSHD="no"
			;;
			nosound)
				ALSA="no"
			;;
			nousb)
				USB="no"
			;;
			nox)
				X11="no"
			;;
			acpi\=on|acpi\=force)
				ACPI="yes"
				APM="no"
			;;
			brltty=*)
				BRLTTY="yes"
				X11="no"
			;;
			ide\=nodma)
				IDEDMA="no"
			;;
			doapm)
				ACPI="no"
				APM="yes"
			;;
			docoldplug|dohotplug)
				COLDPLUG="yes"
			;;
			dodhcp)
				DHCP="yes"
			;;
			dodmraid)
				DMRAID="yes"
			;;
			doevms|doevms2)
				EVMS="yes"
			;;
			dofirewire)
				FIREWIRE="yes"
			;;
			dogpm)
				GPM="yes"
			;;
			dolvm|dolvm2)
				LVM="yes"
			;;
			domdadm)
				MDADM="yes"
			;;
			donet)
				NET="yes"
			;;
			dopata)
				PATA="yes"
			;;
			dopcmcia)
				PCMCIA="yes"
			;;
			dosata)
				SATA="yes"
			;;
			doscsi)
				SCSI="yes"
			;;
			dosshd)
				SSHD="yes"
			;;
			dosound)
				SOUND="yes"
			;;
			dousb)
				USE="yes"
			;;
			dox)
				X11="yes"
			;;
			passwd=*)
				PASSWD="no"
				PASSWORD="${x#*=}"
			;;
			speakup.synth=*)
				SPEAKUP="yes"
				SPEAKUP_MODULE="speakup_${x#*=}"
				X11="no"
			;;
			speakup_*.{ser,port}=*)
				SPEAKUP_OPTIONS="${SPEAKUP_OPTIONS} ${x#*.}"
			;;
		esac
	done
}

depend() {
	need modules $(list_services)
	before net
}

# Checks whether a service will be started by autoconfig.
# Usage: check_svc var service [service_alternative]
check_svc() {
	if yesno "${1}"
	then
		if rc-service -e "${2}"
		then
			echo "${2}"
		elif [ -n "${3}" ] && rc-service -e "${3}"
		then
			echo "${3}"
		fi	
	fi	
}

# Prints an ordered list of services that will be started by autoconfig.
list_services() {
	get_config
	# Must not print anything here
	if yesno "${DETECT}"
	then
		local arch="$(uname -m)"

		case ${arch} in
			mips*)
				ACPI="no"
				APM="no"
				IDEDMA="no"
			;;
			i?86|x86_64)
				:
			;;
			alpha)
				ACPI="no"
				APM="no"
			;;
			sparc*)
				ACPI="no"
				APM="no"
			;;
			powerpc*)
				ACPI="no"
				APM="no"
			;;
			ia64)
				APM="no"
			;;
		esac
	fi

	local svcs="$(check_svc ${ACPI} acpid)"
	svcs="${svcs} $(check_svc ${ALSA} alsasound)"
	svcs="${svcs} $(check_svc ${APM} apmd)"
	svcs="${svcs} $(check_svc ${BRLTTY} brltty)"
	svcs="${svcs} $(check_svc ${COLDPLUG} coldplug hotplug)"
	svcs="${svcs} $(check_svc ${GPM} gpm)"
	svcs="${svcs} $(check_svc ${IDEDMA} hdparm)"
	svcs="${svcs} $(check_svc ${NFS} nfsmount)"
	svcs="${svcs} $(check_svc ${PASSWD} pwgen)"
	svcs="${svcs} $(check_svc ${PCMCIA} pcmcia)"
	svcs="${svcs} $(check_svc ${SSHD} sshd)"

	### TODO: make this baselayout-2 compatible
	### TODO: make these checks accurate using service dependencies

	echo ${svcs}
}

unpack_firmware() {
	# This unpacks any firmware tarballs.
	if [ -e /lib/firmware.tar.bz2 ]
	then
		ebegin "Unpacking firmware"
		mkdir -p /lib/firmware
		tar xjf /lib/firmware.tar.bz2 -C /lib/firmware
		eend 0
	fi
}

get_info() {
	local tmp

	if [ ! -z "${1}" -a ! -z "${2}" ]
	then
		tmp=$(grep "^$1[[:space:]]\+:" /proc/cpuinfo | head -n 1 | cut -d" " -f3-)
		eval "${2}='${tmp}'"
	fi
}

detect_mips() {
	get_info "cpu model" cpuinfo
	get_info "system type" machinfo
	cpuinfo="${cpuinfo%%  FPU*}"

	case "${machinfo}" in
		"SGI Indigo2")
			case "${cpuinfo}" in
				R4*)
					machinfo="SGI Indigo2" # I2 R4x00
				;;
				R8*)
					machinfo="SGI Indigo2 Power" # I2 R8000
				;;
				R10*)
					machinfo="SGI Indigo2 Impact" # I2 R10000
				;;
			esac
		;;
	esac

	PC="Detected an ${machinfo} w/ ${numcpu} ${cpuinfo} CPU(s)"
}

detect_x86_amd64_ia64() {
	if [ "${1}" = "ia64" ]
	then
		get_info "family" cpuinfo
	else
		get_info "model name" cpuinfo
	fi
	get_info "cpu MHz" mhz
	mhz="${mhz%%.*}MHz"

	PC="Detected ${numcpu} ${cpuinfo} CPU(s) @ ${mhz}"
}

detect_alpha() {
	get_info "platform string" machinfo
	get_info "cpu" cpuinfo1
	get_info "cpu model" cpuinfo2
	get_info "cpus detected" numcpu

	PC="Detected ${numcpu} ${cpuinfo1} ${cpuinfo2} CPU(s) in a ${machinfo} system"
}

detect_ppc() {
	get_info "cpu" cpuinfo
	get_info "clock" mhz
	get_info "detected as" machinfo
	machinfo="${machinfo##*\(}"
	machinfo="${machinfo%%\)*}"

	local machtype=""

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

	PC="Detected a(n) ${machtype} w/ ${numcpu} ${cpuinfo} CPU(s)"
}

detect_sparc() {
	get_info "cpu" cpuinfo
	get_info "ncpus active" numcpu
	get_info "ncpus probed" numprobed

	PC="Detected ${numcpu} active ${cpuinfo} CPU(s) of ${numprobed} total"
}

start() {
	echo "0" > /proc/sys/kernel/printk
	get_config

	if yesno "${SPEAKUP}"
	then
		modprobe ${SPEAKUP_MODULE} ${SPEAKUP_OPTIONS}
	fi

	if yesno "${DETECT}"
	then
		ebegin "Hardware detection started"
			local numcpu="$(grep -c '^processor[[:space:]]\+:' /proc/cpuinfo)"
			local arch="$(uname -m)"

			case ${arch} in
				mips*)
					detect_mips
					ACPI="no"
					APM="no"
					IDEDMA="no"
				;;
				i?86|x86_64)
					detect_x86_amd64_ia64
				;;
				alpha)
					detect_alpha
					ACPI="no"
					APM="no"
				;;
				sparc*)
					detect_sparc
					ACPI="no"
					APM="no"
				;;
				powerpc*)
					detect_ppc
					ACPI="no"
					APM="no"
				;;
				ia64)
					detect_x86_amd64_ia64 "ia64"
					APM="no"
				;;
				*)
					PC=
				;;
			esac
			[ -n "${PC}" ] && einfo "${PC}"
		eend
	else
		ewarn "Hardware detection disabled via cmdline ..."
	fi

	# Now, we check if we are supposed to run a coldplug script.
	if yesno "${COLDPLUG}"
	then
		# Check whether we should be using hotplug/coldplug or whether we should
		# just let udev do it all.
		# coldplug+hotplug would already be up due to list_services
		if ! rc-service -e coldplug && ! rc-service -e hotplug
		then
			# TODO: This needs to go to a seperate script, so that hwsetup can depend on it.
			unpack_firmware
			[ -x /sbin/udevtrigger ] && /sbin/udevtrigger
		fi
		[ -e /etc/sysconfig ] || mkdir -p /etc/sysconfig
		[ -x /usr/sbin/hwsetup ] && hwsetup
	else
		ewarn "Hotplug/Coldplug disabled via cmdline ..."
	fi

	if yesno "${APM}"
	then
		modprobe apm power_off=1 >/dev/null 2>&1 && \
			einfo "APM BIOS found, power management functions enabled ..."
		if ! service_started apmd
		then
			rc-service -i apmd start
		fi
	else
		einfo "Not Loading APM Bios support ..."
	fi

	if yesno "${ACPI}"
	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
		modprobe thermal >/dev/null 2>&1
		modprobe video >/dev/null 2>&1
		modprobe dock >/dev/null 2>&1
		if ! service_started acpid
		then
			rc-service -i acpid start
		fi
		eend
	else
		einfo "Not Loading ACPI support ..."
	fi

	if ! yesno "${IDEDMA}"
	then
		ewarn "Disabling IDE DMA support ..."
	fi

	if ! yesno "${PCMCIA}"
	then
		ewarn "PCMCIA disabled via cmdline ..."
	fi

	if ! yesno "${DHCP}"
	then
		sed -i -e '/^ifconfig_eth.*dhcp.*/ s/^/#/' \
			-e '/^iface_eth.*dhcp.*/ s/^/#/' \
			-e '/^config_eth.*dhcp.*/ s/^/#/' \
			/etc/conf.d/net
		for i in `seq 0 4`
		do
			echo "config_eth${i}=( \"none\" )" >> /etc/conf.d/net
		done
		ewarn "Skipping DHCP broadcast ..."
	fi

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

	# Mouse
	# FIXME: If MOUSE_DEVICE is empty, we actually do not want to do anything, not even start gpm.
	if [ -n "${MOUSE_DEVICE}" ]
	then
		:
		# Migrated to autoconfig-gpm-pre
	fi

	if yesno "${DETECT}"
	then
		NETDEVICES="$(awk -F: '/eth.:|tr.:|ath.:|wlan.:/{print $1}' /proc/net/dev 2>/dev/null)"
	else
		DHCP="no"
	fi

	if [ -n "${NETDEVICES}" ]
	then
		for nics in ${NETDEVICES}
		do
			if yesno "${DHCP}"
			then
				einfo "Network device ${HILITE}${nics}${NORMAL} detected, DHCP broadcasting for IP ..."
				if [ -f /var/run/dhcpcd-${nics}.pid ]
				then
					if [ -z "$(/sbin/ifconfig ${nics} | grep 'inet addr')" ]
					then
						kill $(cat /var/run/dhcpcd-${nics}.pid)
						sleep 2
						dhcpcd -n -h $(hostname) ${nics}
					fi
				fi
			fi
		done
		if ! yesno "${PASSWD}"
		then
			echo "root:${PASSWORD}" | chpasswd  > /dev/null 2>&1
		fi
		if yesno "${SSHD}"
		then
			# If we have passwd= on the command line, we do not run pwgen and we
			# set the root password to PASSWORD.
			if yesno "${PASSWD}"
			then
				ewarn "WARNING: You are starting sshd with a scrambled root password!!!"
				ewarn "WARNING: You need to set a root password to be able to login remotely."
			fi
		fi
	else
		ewarn "No Network device auto detected ..."
	fi

	if yesno "${ALSA}"
	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 [ -e /proc/asound/cards ]
			then
				for i in $(cat /proc/asound/cards | awk '{print $1}' | grep ^[[:digit:]])
				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 Front /etc/amixer)" ] \
							&& amixer -c $i -q set Front 95% unmute \
							>/dev/null 2>&1
						[ -n "$(grep HDMI /etc/amixer)" ] \
							&& amixer -c $i -q set HDMI 95% unmute \
							>/dev/null 2>&1
						[ -n "$(grep IEC958 /etc/amixer)" ] \
							&& amixer -c $i -q set IEC958 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 Speaker /etc/amixer)" ] \
							&& amixer -c $i -q set Speaker 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

				if [ "${SPEAKUP_MODULE}" = "speakup_soft" ]
				then
					rc-service -i espeakup start
				fi
			fi
		fi
	else
		ewarn "Skipping ALSA detection as requested on command line ..."
	fi

	[ -n "${XDESC}" ] && einfo "VideoCard:   ${HILITE}${XDESC}${NORMAL}"

	if ! yesno "${X11}"
	then
		touch /etc/.noxdm
	fi

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

# vim: ts=4