/[livecd-tools]/trunk/autoconfig
Gentoo

Contents of /trunk/autoconfig

Parent Directory Parent Directory | Revision Log Revision Log


Revision 148 - (show annotations) (download)
Thu Apr 3 00:29:51 2008 UTC (6 years, 3 months ago) by wolf31o2
File size: 12620 byte(s)
Make sure /etc/sysconfig exists before running hwsetup for bug #215824.
1 #!/sbin/runscript
2
3 # This script is used by Gentoo release media to start certain services and to
4 # ensure a sane setup for a CD-based boot.
5
6 ACPI="yes"
7 ALSA="yes"
8 APM="no"
9 BRLTTY="no"
10 DETECT="yes"
11 DHCP="yes"
12 DMRAID="yes"
13 EVMS="no"
14 FIREWIRE="yes"
15 GPM="yes"
16 HALD="yes"
17 HOTPLUG="yes"
18 IDEDMA="yes"
19 LVM="no"
20 MDADM="yes"
21 NET="yes"
22 NFS="yes"
23 PASSWD="yes"
24 PATA="yes"
25 PCMCIA="yes"
26 SATA="yes"
27 SCSI="no"
28 SSHD="no"
29 USB="yes"
30 X11="yes"
31
32 get_config() {
33 CMDLINE="$(cat /proc/cmdline)"
34
35 for x in ${CMDLINE} ; do
36 case "${x}" in
37 # We put nodetect first, so we can override it with do* commands
38 nodetect)
39 ACPI="no"
40 ALSA="no"
41 APM="no"
42 DETECT="no"
43 DMRAID="no"
44 EVMS="no"
45 FIREWIRE="no"
46 GPM="no"
47 HALD="no"
48 HOTPLUG="no"
49 LVM="no"
50 MDADM="no"
51 NET="no"
52 NFS="no"
53 PCMCIA="no"
54 PATA="no"
55 SATA="no"
56 SCSI="no"
57 USB="no"
58 X11="no"
59 ;;
60 noapm)
61 APM="no"
62 ;;
63 nodhcp)
64 DHCP="no"
65 ;;
66 nodmraid)
67 DMRAID="no"
68 ;;
69 noevms|noevms2)
70 EVMS="no"
71 ;;
72 nofirewire)
73 FIREWIRE="no"
74 ;;
75 nogpm)
76 GPM="no"
77 ;;
78 nohotplug)
79 HOTPLUG="no"
80 ;;
81 noload=*)
82 NOLOAD="$*"
83 ;;
84 nolvm|nolvm2)
85 LVM="no"
86 ;;
87 nomdadm)
88 MDADM="no"
89 ;;
90 nonet)
91 NET="no"
92 ;;
93 nonfs)
94 NFS="no"
95 ;;
96 nopata)
97 PATA="no"
98 ;;
99 nopcmcia)
100 PCMCIA="no"
101 ;;
102 nosata)
103 SATA="no"
104 ;;
105 noscsi)
106 SCSI="no"
107 ;;
108 nosshd)
109 SSHD="no"
110 ;;
111 nosound)
112 ALSA="no"
113 ;;
114 nousb)
115 USB="no"
116 ;;
117 nox)
118 X11="no"
119 ;;
120 acpi\=on|acpi\=force)
121 ACPI="yes"
122 APM="no"
123 ;;
124 brltty=*)
125 BRLTTY="yes"
126 ;;
127 ide\=nodma)
128 IDEDMA="no"
129 ;;
130 doapm)
131 ACPI="no"
132 APM="yes"
133 ;;
134 dodhcp)
135 DHCP="yes"
136 ;;
137 dodmraid)
138 DMRAID="yes"
139 ;;
140 doevms|doevms2)
141 EVMS="yes"
142 ;;
143 dofirewire)
144 FIREWIRE="yes"
145 ;;
146 dogpm)
147 GPM="yes"
148 ;;
149 dohotplug)
150 HOTPLUG="yes"
151 ;;
152 dolvm|dolvm2)
153 LVM="yes"
154 ;;
155 domdadm)
156 MDADM="yes"
157 ;;
158 donet)
159 NET="yes"
160 ;;
161 dopata)
162 PATA="yes"
163 ;;
164 dopcmcia)
165 PCMCIA="yes"
166 ;;
167 dosata)
168 SATA="yes"
169 ;;
170 doscsi)
171 SCSI="yes"
172 ;;
173 dosshd)
174 SSHD="yes"
175 ;;
176 dosound)
177 SOUND="yes"
178 ;;
179 dousb)
180 USE="yes"
181 ;;
182 dox)
183 X11="yes"
184 ;;
185 passwd=*)
186 PASSWD="no"
187 PASSWORD="$*"
188 ;;
189 esac
190 done
191 }
192
193 depend() {
194 need modules
195 before net
196 }
197
198 # Checks whether a service will be started by autoconfig.
199 # Usage: check_svc var service [service_alternative]
200 check_svc() {
201 if [ "${1}" = "yes" ]
202 then
203 if [ -x "/etc/init.d/${2}" ]
204 then
205 echo "${2}"
206 elif [ -n "${3}" -a -x "/etc/init.d/${3}" ]
207 then
208 echo "${3}"
209 fi
210 fi
211 }
212
213 # Prints an ordered list of services that will be started by autoconfig.
214 list_services() {
215 get_config
216
217 local svcs="$(check_svc ${ACPI} acpid)"
218 svcs="${svcs} $(check_svc ${ALSA} alsasound)"
219 svcs="${svcs} $(check_svc ${APM} apmd)"
220 svcs="${svcs} $(check_svc ${GPM} gpm)"
221 svcs="${svcs} $(check_svc ${HALD} hald)"
222 svcs="${svcs} $(check_svc ${HOTPLUG} coldplug hotplug)"
223 svcs="${svcs} $(check_svc ${IDEDMA} hdparm)"
224 svcs="${svcs} $(check_svc ${NFS} nfsmount)"
225 svcs="${svcs} $(check_svc ${PASSWD} pwgen)"
226 svcs="${svcs} $(check_svc ${PCMCIA} pcmcia)"
227 svcs="${svcs} $(check_svc ${SSH} sshd)"
228 svcs="${svcs} $(check_svc ${X11} mkxf86config x-setup)"
229
230 ### TODO: make this baselayout-2 compatible
231 ### TODO: make these checks accurate using service dependencies
232
233 echo ${svcs}
234 }
235
236 unpack_firmware() {
237 # This unpacks any firmware tarballs.
238 if [ -e /lib/firmware.tar.bz2 ]
239 then
240 ebegin "Unpacking hotplug firmware"
241 tar xjf /lib/firmware.tar.bz2 -C /lib/firmware
242 eend 0
243 fi
244 }
245
246 get_info() {
247 local tmp
248
249 if [ ! -z "${1}" -a ! -z "${2}" ]
250 then
251 tmp=$(grep "^$1[[:space:]]\+:" /proc/cpuinfo | head -n 1 | cut -d" " -f3-)
252 eval "${2}='${tmp}'"
253 fi
254 }
255
256 detect_mips() {
257 get_info "cpu model" cpuinfo
258 get_info "system type" machinfo
259 cpuinfo="${cpuinfo%% FPU*}"
260
261 case "${machinfo}" in
262 "SGI Indigo2")
263 case "${cpuinfo}" in
264 R4*)
265 machinfo="SGI Indigo2" # I2 R4x00
266 ;;
267 R8*)
268 machinfo="SGI Indigo2 Power" # I2 R8000
269 ;;
270 R10*)
271 machinfo="SGI Indigo2 Impact" # I2 R10000
272 ;;
273 esac
274 ;;
275 esac
276
277 PC="Detected an ${machinfo} w/ ${numcpu} ${cpuinfo} CPU(s)"
278 }
279
280 detect_x86_amd64_ia64() {
281 if [ "${1}" = "ia64" ]
282 then
283 get_info "family" cpuinfo
284 else
285 get_info "model name" cpuinfo
286 fi
287 get_info "cpu MHz" mhz
288 mhz="${mhz%%.*}MHz"
289
290 PC="Detected ${numcpu} ${cpuinfo} CPU(s) @ ${mhz}"
291 }
292
293 detect_alpha() {
294 get_info "platform string" machinfo
295 get_info "cpu" cpuinfo1
296 get_info "cpu model" cpuinfo2
297 get_info "cpus detected" numcpu
298
299 PC="Detected ${numcpu} ${cpuinfo1} ${cpuinfo2} CPU(s) in a ${machinfo} system"
300 }
301
302 detect_ppc() {
303 get_info "cpu" cpuinfo
304 get_info "clock" mhz
305 get_info "detected as" machinfo
306 machinfo="${machinfo##*\(}"
307 machinfo="${machinfo%%\)*}"
308
309 local machtype=""
310
311 case "${machinfo}" in
312 "CHRP Pegasos2")
313 machtype="Pegasos 2"
314 ;;
315 "CHRP IBM,9124-720")
316 machtype="IBM OP720"
317 ;;
318 "iBook 2 rev. 2")
319 machtype="Apple iBook G3"
320 ;;
321 "iMac G5"*)
322 machtype="Apple iMac G5"
323 ;;
324 "MPC8241")
325 machtype="Kurobox"
326 ;;
327 "PowerMac G5")
328 machtype="Apple PowerMac G5"
329 ;;
330 "PowerMac G5 Dual Core")
331 machtype="Apple PowerMac G5 Dual Core"
332 ;;
333 "PowerMac G4 AGP Graphics")
334 machtype="Apple PowerMac G4"
335 ;;
336 "PowerBook Titanium"|"PowerBook G4 15\"")
337 machtype="Apple Powerbook G4"
338 ;;
339 "Unknown Intrepid-based")
340 machtype="Apple Mac-Mini"
341 ;;
342 *)
343 machtype="Unknown PPC System"
344 ;;
345 esac
346
347 PC="Detected a(n) ${machtype} w/ ${numcpu} ${cpuinfo} CPU(s)"
348 }
349
350 detect_sparc() {
351 get_info "cpu" cpuinfo
352 get_info "ncpus active" numcpu
353 get_info "ncpus probed" numprobed
354
355 PC="Detected ${numcpu} active ${cpuinfo} CPU(s) of ${numprobed} total"
356 }
357
358 start() {
359 echo "0" > /proc/sys/kernel/printk
360 get_config
361
362 # First off, we want hotplug/coldplug enabled, so we re-enable it.
363 # We do this even if we are not starting up the hotplug/coldplug
364 # services for the installer.
365 sed -i 's/RC_COLDPLUG="no"/RC_COLDPLUG="yes"/' /etc/conf.d/rc
366
367 if [ "${BRLTTY}" = "yes" ]
368 then
369 [ -x /etc/init.d/brltty ] && start_service brltty
370 fi
371
372 if [ "${DETECT}" = "yes" ]
373 then
374 ebegin "Hardware detection started"
375 local numcpu="$(grep -c '^processor[[:space:]]\+:' /proc/cpuinfo)"
376 local arch="$(uname -m)"
377
378 case ${arch} in
379 mips*)
380 detect_mips
381 ACPI="no"
382 APM="no"
383 IDEDMA="no"
384 ;;
385 i?86|x86_64)
386 detect_x86_amd64_ia64
387 ;;
388 alpha)
389 detect_alpha
390 ACPI="no"
391 APM="no"
392 ;;
393 sparc*)
394 detect_sparc
395 ACPI="no"
396 APM="no"
397 ;;
398 powerpc*)
399 detect_ppc
400 ACPI="no"
401 APM="no"
402 ;;
403 ia64)
404 detect_x86_amd64_ia64 "ia64"
405 APM="no"
406 ;;
407 *)
408 PC=
409 ;;
410 esac
411 [ -n "${PC}" ] && einfo "${PC}"
412 eend
413 else
414 ewarn "Hardware detection disabled via cmdline ..."
415 fi
416
417 # Now, we check if we are supposed to run a coldplug script.
418 if [ "${HOTPLUG}" = "yes" ]
419 then
420 # Check whether we should be using hotplug/coldplug or whether we should
421 # just let udev do it all.
422 if [ -x /etc/init.d/coldplug ]
423 then
424 start_service coldplug
425 elif [ -x /etc/init.d/hotplug ]
426 then
427 start_service hotplug
428 else
429 unpack_firmware
430 [ -x /sbin/udevtrigger ] && /sbin/udevtrigger
431 fi
432 [ -e /etc/sysconfig ] || mkdir -p /etc/sysconfig
433 [ -x /usr/sbin/hwsetup ] && hwsetup
434 else
435 ewarn "Hotplug/Coldplug disabled via cmdline ..."
436 fi
437
438 if [ "${APM}" = "yes" ]
439 then
440 modprobe apm power_off=1 >/dev/null 2>&1 && \
441 einfo "APM BIOS found, power management functions enabled ..."
442 [ -x /etc/init.d/apmd ] && start_service apmd
443 else
444 einfo "Not Loading APM Bios support ..."
445 fi
446
447 if [ "${ACPI}" = "yes" ]
448 then
449 modprobe processor >/dev/null 2>&1 && \
450 ebegin "ACPI power management functions enabled" && \
451 modprobe thermal >/dev/null
452 modprobe fan >/dev/null 2>&1
453 modprobe button >/dev/null 2>&1
454 modprobe battery >/dev/null 2>&1
455 modprobe ac >/dev/null 2>&1
456 modprobe thermal >/dev/null 2>&1
457 modprobe video >/dev/null 2>&1
458 modprobe dock >/dev/null 2>&1
459 [ -x /etc/init.d/acpid ] && start_service acpid
460 eend
461 else
462 einfo "Not Loading ACPI support ..."
463 fi
464
465 if [ "${IDEDMA}" = "yes" ]
466 then
467 [ -x /etc/init.d/hdparm ] && start_service hdparm
468 else
469 ewarn "Disabling IDE DMA support ..."
470 fi
471
472 if [ "${PCMCIA}" = "yes" ]
473 then
474 [ -x /etc/init.d/pcmcia ] && start_service pcmcia
475 else
476 ewarn "PCMCIA disabled via cmdline ..."
477 fi
478
479 if [ "${DHCP}" = "no" ]
480 then
481 sed -i -e '/^ifconfig_eth.*dhcp.*/ s/^/#/' \
482 -e '/^iface_eth.*dhcp.*/ s/^/#/' \
483 -e '/^config_eth.*dhcp.*/ s/^/#/' \
484 /etc/conf.d/net
485 for i in `seq 0 4`
486 do
487 echo "config_eth${i}=( \"none\" )" >> /etc/conf.d/net
488 done
489 ewarn "Skipping DHCP broadcast ..."
490 fi
491
492 # Read in what hwsetup has found
493 [ -f /etc/sysconfig/gentoo ] && source /etc/sysconfig/gentoo
494
495 # Mouse
496 if [ -n "${MOUSE_DEVICE}" ]
497 then
498 einfo "Mouse is ${HILITE}${MOUSE_FULLNAME}${NORMAL} at ${HILITE}${MOUSE_DEVICE}${NORMAL} ..."
499 source /etc/sysconfig/mouse
500 if [ -x /usr/sbin/gpm ]
501 then
502 if [ $(grep "#MOUSE=${MOUSETYPE}" /etc/conf.d/gpm) ]
503 then
504 sed -i "\@MOUSE=${MOUSETYPE}@s@^#@@" /etc/conf.d/gpm
505 else
506 echo "MOUSE=${MOUSETYPE}" >>/etc/conf.d/gpm
507 fi
508
509 if [ $(grep "#MOUSEDEV=${DEVICE}" /etc/conf.d/gpm) ]
510 then
511 sed -i "\@MOUSEDEV=${DEVICE}@s@^#@@" /etc/conf.d/gpm
512 else
513 echo "MOUSEDEV=${DEVICE}" >>/etc/conf.d/gpm
514 fi
515
516 [ "${GPM}" = "yes" ] \
517 && [ -x /etc/init.d/gpm ] && start_service gpm
518 fi
519 fi
520
521 [ "${DETECT}" = "no" ] && DHCP="no"
522 [ "${DETECT}" = "yes" ] \
523 && NETDEVICES="$(awk -F: '/eth.:|tr.:|ath.:|wlan.:/{print $1}' /proc/net/dev 2>/dev/null)"
524
525 if [ -n "${NETDEVICES}" ]
526 then
527 for nics in ${NETDEVICES}
528 do
529 if [ "${DHCP}" = "yes" ]
530 then
531 einfo "Network device ${HILITE}${nics}${NORMAL} detected, DHCP broadcasting for IP ..."
532 if [ -f /var/run/dhcpcd-${nics}.pid ]
533 then
534 if [ -z "$(/sbin/ifconfig ${nics} | grep 'inet addr')" ]
535 then
536 kill $(cat /var/run/dhcpcd-${nics}.pid)
537 sleep 2
538 dhcpcd -n -h $(hostname) ${nics}
539 fi
540 fi
541 fi
542 done
543 if [ "${NFS}" = "yes" ]
544 then
545 [ -x /etc/init.d/portmap ] && start_service portmap
546 [ -x /etc/init.d/nfsmount ] && start_service nfsmount
547 fi
548 if [ "${PASSWD}" = "no" ]
549 then
550 echo "root:${PASSWORD}" | chpasswd > /dev/null 2>&1
551 else
552 start_service pwgen
553 fi
554 if [ "${SSHD}" = "yes" ]
555 then
556 # If we have passwd= on the command line, we do not run pwgen and we
557 # set the root password to PASSWORD.
558 if [ "${PASSWD}" = "yes" ]
559 then
560 ewarn "WARNING: You are starting sshd with a scrambled root password!!!"
561 ewarn "WARNING: You need to set a root password to be able to login remotely."
562 fi
563 [ -x /etc/init.d/sshd ] && start_service sshd
564 fi
565 else
566 ewarn "No Network device auto detected ..."
567 fi
568
569 if [ "${ALSA}" = "yes" ]
570 then
571 if [ -n "${SOUND_FULLNAME}" -o -n "${SOUND_DRIVER}" ]
572 then
573 local sndmsg="Soundcard:\n"
574
575 [ -n "${SOUND_FULLNAME}" ] \
576 && sndmsg="${sndmsg} ${WARN}${SOUND_FULLNAME}\n"
577 [ -n "${SOUND_DRIVER}" ] \
578 && sndmsg="${sndmsg} driver = ${SOUND_DRIVER}\n"
579
580 einfo "${sndmsg}"
581
582 if [ -x /etc/init.d/alsasound ]
583 then
584 start_service alsasound
585 fi
586
587 if [ -e /proc/asound/cards ]
588 then
589 for i in $(cat /proc/asound/cards | awk '{print $1}' | grep ^[[:digit:]])
590 do
591 if [ -d /proc/asound/card$i ] && [ -x /usr/bin/amixer ]
592 then
593 amixer -c $i scontrols > /etc/amixer
594 [ -n "$(grep Master /etc/amixer)" ] \
595 && amixer -c $i -q set Master 95% unmute \
596 >/dev/null 2>&1
597 [ -n "$(grep PCM /etc/amixer)" ] \
598 && amixer -c $i -q set PCM 95% unmute \
599 >/dev/null 2>&1
600 [ -n "$(grep Mic /etc/amixer)" ] \
601 && amixer -c $i -q set Mic 95% mute cap \
602 >/dev/null 2>&1
603 [ -n "$(grep Wave /etc/amixer)" ] \
604 && amixer -c $i -q set Wave 95% unmute \
605 >/dev/null 2>&1
606 [ -n "$(grep Capture /etc/amixer)" ] \
607 && amixer -c $i -q set Capture 95% unmute cap \
608 >/dev/null 2>&1
609 fi
610 done
611 fi
612 fi
613 else
614 ewarn "Skipping ALSA detection as requested on command line ..."
615 fi
616
617 [ -n "${XDESC}" ] && einfo "VideoCard: ${HILITE}${XDESC}${NORMAL}"
618
619 if [ "${X11}" = "yes" ]
620 then
621 if [ -x /etc/init.d/mkxf86config ]
622 then
623 start_service mkxf86config
624 fi
625 if [ -x /etc/init.d/x-setup ]
626 then
627 start_service x-setup
628 fi
629 else
630 touch /etc/init.d/.noxdm
631 fi
632
633 killall hwsetup 2>/dev/null
634 echo "6" > /proc/sys/kernel/printk
635 }
636
637 # vim: ts=4

Properties

Name Value
svn:eol-style native
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.20