/[livecd-tools]/trunk/autoconfig
Gentoo

Contents of /trunk/autoconfig

Parent Directory Parent Directory | Revision Log Revision Log


Revision 139 - (hide annotations) (download)
Thu Dec 13 23:58:42 2007 UTC (10 years, 7 months ago) by wolf31o2
File size: 10534 byte(s)
Some minor tweaks/cleanups and adding a warning for anybody trying dosshd.
1 zhen 2 #!/sbin/runscript
2 zhen 4
3 wolf31o2 139 # 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 wolf31o2 138 ACPI="no"
7     ALSA="yes"
8     APM="no"
9     DETECT="yes"
10 zhen 2 DHCP="yes"
11 wolf31o2 24 GPM="yes"
12 zhen 2 HOTPLUG="yes"
13 wolf31o2 49 IDEDMA="yes"
14 wolf31o2 138 NFS="yes"
15     PCMCIA="yes"
16     SSHD="no"
17 wolf31o2 76 X11="yes"
18 wolf31o2 51
19 wolf31o2 68 get_config() {
20     CMDLINE="$(cat /proc/cmdline)"
21 wolf31o2 51
22 wolf31o2 68 for x in ${CMDLINE} ; do
23 wolf31o2 78 case "${x}" in
24     nodetect)
25 wolf31o2 138 ACPI="no"
26     ALSA="no"
27     APM="no"
28 wolf31o2 78 DETECT="no"
29     GPM="no"
30     HOTPLUG="no"
31 wolf31o2 138 NFS="no"
32 wolf31o2 78 X11="no"
33     ;;
34     nodhcp)
35     DHCP="no"
36     ;;
37     nogpm)
38     GPM="no"
39     ;;
40 wolf31o2 139 nohotplug)
41     HOTPLUG="no"
42 wolf31o2 78 ;;
43 wolf31o2 139 nonfs)
44     NFS="no"
45     ;;
46     nosound)
47     ALSA="no"
48     ;;
49     nox)
50     X11="no"
51     ;;
52     ide\=nodma)
53     IDEDMA="no"
54     ;;
55 wolf31o2 78 doapm)
56 wolf31o2 138 ACPI="no"
57 wolf31o2 78 APM="yes"
58     ;;
59 wolf31o2 122 acpi\=on|acpi\=force)
60 wolf31o2 138 ACPI="yes"
61 wolf31o2 78 APM="no"
62     ;;
63 wolf31o2 139 dopcmcia)
64     PCMCIA="yes"
65 wolf31o2 78 ;;
66 wolf31o2 138 dosshd)
67     SSHD="yes"
68     ;;
69 wolf31o2 78 esac
70 wolf31o2 68 done
71     }
72    
73 zhen 2 depend() {
74     need modules
75 wolf31o2 50 before net
76 wolf31o2 115 # provide gpm pcmcia apmd acpid coldplug hdparm alsasound mkxf86config x-setup
77 zhen 2 }
78    
79 wolf31o2 69 # Checks whether a service will be started by autoconfig.
80     # Usage: check_svc var service [service_alternative]
81     check_svc() {
82 wolf31o2 113 if [ "${1}" = "yes" ]
83 wolf31o2 78 then
84 wolf31o2 114 if [ -x "/etc/init.d/${2}" ]
85 wolf31o2 78 then
86 wolf31o2 113 echo "${2}"
87     elif [ -n "${3}" -a -x "/etc/init.d/${3}" ]
88 wolf31o2 78 then
89 wolf31o2 113 echo "${3}"
90 wolf31o2 69 fi
91     fi
92     }
93    
94     # Prints an ordered list of services that will be started by autoconfig.
95     list_services() {
96     get_config
97    
98     local svcs="$(check_svc ${APM} apmd)"
99     svcs="${svcs} $(check_svc ${ACPI} acpid)"
100     svcs="${svcs} $(check_svc ${IDEDMA} hdparm)"
101     svcs="${svcs} $(check_svc ${PCMCIA} pcmcia)"
102     svcs="${svcs} $(check_svc ${GPM} gpm)"
103     svcs="${svcs} $(check_svc ${HOTPLUG} coldplug hotplug)"
104     svcs="${svcs} $(check_svc ${ALSA} alsasound)"
105 wolf31o2 138 svcs="${svcs} $(check_svc ${NFS} nfsmount)"
106     svcs="${svcs} $(check_svc ${SSH} sshd)"
107 wolf31o2 115 svcs="${svcs} $(check_svc ${X11} mkxf86config x-setup)"
108 wolf31o2 69
109     echo ${svcs}
110     }
111    
112 wolf31o2 101 unpack_firmware() {
113     # This unpacks any firmware tarballs.
114     if [ -e /lib/firmware.tar.bz2 ]
115     then
116     ebegin "Unpacking hotplug firmware"
117     tar xjf /lib/firmware.tar.bz2 -C /lib/firmware
118     eend 0
119     fi
120     }
121    
122 wolf31o2 109 get_info() {
123     local tmp
124    
125     if [ ! -z "${1}" -a ! -z "${2}" ]
126     then
127 wolf31o2 112 tmp=$(grep "^$1[[:space:]]\+:" /proc/cpuinfo | head -n 1 | cut -d" " -f3-)
128 wolf31o2 114 eval "${2}='${tmp}'"
129 wolf31o2 109 fi
130     }
131    
132 wolf31o2 81 detect_mips() {
133 wolf31o2 109 get_info "cpu model" cpuinfo
134     get_info "system type" machinfo
135     cpuinfo="${cpuinfo%% FPU*}"
136 wolf31o2 79
137     case "${machinfo}" in
138     "SGI Indigo2")
139     case "${cpuinfo}" in
140     R4*)
141 wolf31o2 109 machinfo="SGI Indigo2" # I2 R4x00
142 wolf31o2 79 ;;
143     R8*)
144 wolf31o2 109 machinfo="SGI Indigo2 Power" # I2 R8000
145 wolf31o2 79 ;;
146     R10*)
147 wolf31o2 109 machinfo="SGI Indigo2 Impact" # I2 R10000
148 wolf31o2 79 ;;
149     esac
150     ;;
151     esac
152    
153 wolf31o2 109 PC="Detected an ${machinfo} w/ ${numcpu} ${cpuinfo} CPU(s)"
154 wolf31o2 79 }
155    
156 wolf31o2 109 detect_x86_amd64_ia64() {
157 wolf31o2 112 if [ "${1}" = "ia64" ]
158     then
159     get_info "family" cpuinfo
160     else
161     get_info "model name" cpuinfo
162     fi
163 wolf31o2 109 get_info "cpu MHz" mhz
164 wolf31o2 112 mhz="${mhz%%.*}MHz"
165 wolf31o2 79
166 wolf31o2 114 PC="Detected ${numcpu} ${cpuinfo} CPU(s) @ ${mhz}"
167 wolf31o2 81 }
168    
169 wolf31o2 98 detect_alpha() {
170 wolf31o2 109 get_info "platform string" machinfo
171     get_info "cpu" cpuinfo1
172     get_info "cpu model" cpuinfo2
173     get_info "cpus detected" numcpu
174    
175     PC="Detected ${numcpu} ${cpuinfo1} ${cpuinfo2} CPU(s) in a ${machinfo} system"
176 wolf31o2 98 }
177    
178 wolf31o2 89 detect_ppc() {
179 wolf31o2 109 get_info "cpu" cpuinfo
180     get_info "clock" mhz
181     get_info "detected as" machinfo
182     machinfo="${machinfo##*\(}"
183     machinfo="${machinfo%%\)*}"
184    
185 wolf31o2 89 local machtype=""
186    
187     case "${machinfo}" in
188 wolf31o2 120 "CHRP Pegasos2")
189     machtype="Pegasos 2"
190 wolf31o2 89 ;;
191 wolf31o2 120 "CHRP IBM,9124-720")
192     machtype="IBM OP720"
193 wolf31o2 90 ;;
194     "iBook 2 rev. 2")
195     machtype="Apple iBook G3"
196     ;;
197 wolf31o2 120 "iMac G5"*)
198     machtype="Apple iMac G5"
199     ;;
200     "MPC8241")
201     machtype="Kurobox"
202     ;;
203 wolf31o2 92 "PowerMac G5")
204     machtype="Apple PowerMac G5"
205     ;;
206 wolf31o2 90 "PowerMac G5 Dual Core")
207     machtype="Apple PowerMac G5 Dual Core"
208     ;;
209 wolf31o2 120 "PowerMac G4 AGP Graphics")
210     machtype="Apple PowerMac G4"
211     ;;
212     "PowerBook Titanium"|'PowerBook G4 15"')
213     machtype="Apple Powerbook G4"
214     ;;
215 wolf31o2 90 "Unknown Intrepid-based")
216     machtype="Apple Mac-Mini"
217     ;;
218 wolf31o2 89 *)
219     machtype="Unknown PPC System"
220     ;;
221     esac
222    
223 wolf31o2 109 PC="Detected a(n) ${machtype} w/ ${numcpu} ${cpuinfo} CPU(s)"
224 wolf31o2 89 }
225    
226 wolf31o2 109 detect_sparc() {
227     get_info "cpu" cpuinfo
228     get_info "ncpus active" numcpu
229     get_info "ncpus probed" numprobed
230    
231     PC="Detected ${numcpu} active ${cpuinfo} CPU(s) of ${numprobed} total"
232     }
233    
234 zhen 2 start() {
235 wolf31o2 69 echo "0" > /proc/sys/kernel/printk
236 wolf31o2 68 get_config
237 wolf31o2 130
238     # First off, we want hotplug/coldplug enabled, so let's re-enable it.
239 wolf31o2 139 # We do this even if we aren't starting up the hotplug/coldplug
240 wolf31o2 130 # services for the installer.
241     sed -i 's/RC_COLDPLUG="no"/RC_COLDPLUG="yes"/' /etc/conf.d/rc
242     # Now, we check if we're supposed to run a coldplug script.
243     if [ "${HOTPLUG}" = "yes" ]
244     then
245 wolf31o2 138 # Check whether we should be using hotplug/coldplug or whether we should
246     # just let udev do it all.
247 wolf31o2 130 if [ -x /etc/init.d/coldplug ]
248     then
249     start_service coldplug
250     elif [ -x /etc/init.d/hotplug ]
251     then
252     start_service hotplug
253     else
254     unpack_firmware
255     [ -x /sbin/udevtrigger ] && /sbin/udevtrigger
256     fi
257     else
258     ewarn "Hotplug/Coldplug disabled via cmdline ..."
259     fi
260    
261 wolf31o2 51 if [ "${DETECT}" = "yes" ]
262     then
263 wolf31o2 78 ebegin "Hardware detection started"
264 wolf31o2 112 local numcpu="$(grep -c '^processor[[:space:]]\+:' /proc/cpuinfo)"
265 wolf31o2 80 local arch="$(uname -m)"
266 wolf31o2 109
267 wolf31o2 81 case ${arch} in
268 wolf31o2 109 mips*)
269 wolf31o2 81 detect_mips
270 wolf31o2 109 ACPI="no"
271     APM="no"
272     IDEDMA="no"
273 wolf31o2 81 ;;
274 wolf31o2 113 i?86|x86_64)
275 wolf31o2 109 detect_x86_amd64_ia64
276 wolf31o2 81 ;;
277 wolf31o2 98 alpha)
278     detect_alpha
279 wolf31o2 109 ACPI="no"
280     APM="no"
281 wolf31o2 98 ;;
282 wolf31o2 109 sparc*)
283     detect_sparc
284     ACPI="no"
285     APM="no"
286     ;;
287 wolf31o2 98 powerpc*)
288     detect_ppc
289 wolf31o2 109 ACPI="no"
290     APM="no"
291 wolf31o2 98 ;;
292 wolf31o2 109 ia64)
293     detect_x86_amd64_ia64 "ia64"
294     APM="no"
295     ;;
296 wolf31o2 81 *)
297 wolf31o2 109 PC=
298 wolf31o2 81 ;;
299     esac
300 wolf31o2 109 [ -n "${PC}" ] && einfo "${PC}"
301 wolf31o2 137 [ -x /usr/sbin/hwsetup ] && hwsetup
302 zhen 2 eend
303 wolf31o2 6 else
304 wolf31o2 78 ewarn "Hardware detection disabled via cmdline ..."
305 wolf31o2 6 fi
306 zhen 2
307 wolf31o2 51 if [ "${APM}" = "yes" ]
308     then
309 wolf31o2 78 modprobe apm power_off=1 >/dev/null 2>&1 && \
310     einfo "APM BIOS found, power management functions enabled ..."
311 wolf31o2 77 [ -x /etc/init.d/apmd ] && start_service apmd
312 zhen 2 else
313 wolf31o2 109 einfo "Not Loading APM Bios support ..."
314 wolf31o2 6 fi
315 zhen 2
316 wolf31o2 51 if [ "${ACPI}" = "yes" ]
317     then
318 wolf31o2 78 modprobe processor >/dev/null 2>&1 && \
319     ebegin "ACPI power management functions enabled" && \
320     modprobe thermal >/dev/null
321 wolf31o2 29 modprobe fan >/dev/null 2>&1
322     modprobe button >/dev/null 2>&1
323     modprobe battery >/dev/null 2>&1
324     modprobe ac >/dev/null 2>&1
325 wolf31o2 131 modprobe thermal >/dev/null 2>&1
326     modprobe video >/dev/null 2>&1
327     modprobe dock >/dev/null 2>&1
328 wolf31o2 77 [ -x /etc/init.d/acpid ] && start_service acpid
329 wolf31o2 6 eend
330 wolf31o2 78 else
331 wolf31o2 109 einfo "Not Loading ACPI support ..."
332 wolf31o2 6 fi
333 zhen 2
334 wolf31o2 51 if [ "${IDEDMA}" = "yes" ]
335     then
336 wolf31o2 109 [ -x /etc/init.d/hdparm ] && start_service hdparm
337 wolf31o2 138 else
338     ewarn "Disabling IDE DMA support ..."
339 wolf31o2 49 fi
340    
341 wolf31o2 51 if [ "${PCMCIA}" = "yes" ]
342     then
343 wolf31o2 77 [ -x /etc/init.d/pcmcia ] && start_service pcmcia
344 wolf31o2 138 else
345     ewarn "PCMCIA disabled via cmdline ..."
346 wolf31o2 6 fi
347 zhen 2
348 wolf31o2 51 if [ "${DHCP}" = "no" ]
349     then
350 wolf31o2 48 sed -i -e '/^ifconfig_eth.*dhcp.*/ s/^/#/' \
351     -e '/^iface_eth.*dhcp.*/ s/^/#/' \
352 wolf31o2 55 -e '/^config_eth.*dhcp.*/ s/^/#/' \
353 wolf31o2 25 /etc/conf.d/net
354 wolf31o2 118 for i in `seq 0 4`
355     do
356 wolf31o2 139 echo "config_eth${i}=( \"none\" )" >> /etc/conf.d/net
357 wolf31o2 118 done
358 wolf31o2 138 ewarn "Skipping DHCP broadcast ..."
359 wolf31o2 6 fi
360 zhen 2
361 wolf31o2 78 # Read in what hwsetup has found
362 wolf31o2 139 [ -f /etc/sysconfig/gentoo ] && source /etc/sysconfig/gentoo
363 zhen 2
364 wolf31o2 6 # Mouse
365 wolf31o2 51 if [ -n "${MOUSE_DEVICE}" ]
366     then
367 wolf31o2 78 einfo "Mouse is ${HILITE}${MOUSE_FULLNAME}${NORMAL} at ${HILITE}${MOUSE_DEVICE}${NORMAL} ..."
368 wolf31o2 6 source /etc/sysconfig/mouse
369 wolf31o2 51 if [ -x /usr/sbin/gpm ]
370     then
371 wolf31o2 114 if [ $(grep "#MOUSE=${MOUSETYPE}" /etc/conf.d/gpm) ]
372 wolf31o2 110 then
373     sed -i "\@MOUSE=${MOUSETYPE}@s@^#@@" /etc/conf.d/gpm
374     else
375     echo "MOUSE=${MOUSETYPE}" >>/etc/conf.d/gpm
376     fi
377 wolf31o2 78
378 wolf31o2 114 if [ $(grep "#MOUSEDEV=${DEVICE}" /etc/conf.d/gpm) ]
379 wolf31o2 110 then
380     sed -i "\@MOUSEDEV=${DEVICE}@s@^#@@" /etc/conf.d/gpm
381     else
382     echo "MOUSEDEV=${DEVICE}" >>/etc/conf.d/gpm
383     fi
384 wolf31o2 78
385     [ "${GPM}" = "yes" ] \
386     && [ -x /etc/init.d/gpm ] && start_service gpm
387 wolf31o2 29 fi
388 wolf31o2 6 fi
389 zhen 2
390 wolf31o2 78 [ "${DETECT}" = "no" ] && DHCP="no"
391     [ "${DETECT}" = "yes" ] \
392     && NETDEVICES="$(awk -F: '/eth.:|tr.:|ath.:|wlan.:/{print $1}' /proc/net/dev 2>/dev/null)"
393 zhen 2
394 wolf31o2 51 if [ -n "${NETDEVICES}" ]
395     then
396 wolf31o2 74 for nics in ${NETDEVICES}
397     do
398     if [ "${DHCP}" = "yes" ]
399     then
400 wolf31o2 78 einfo "Network device ${HILITE}${nics}${NORMAL} detected, DHCP broadcasting for IP ..."
401 wolf31o2 135 if [ -f /var/run/dhcpcd-${nics}.pid ]
402     then
403 wolf31o2 137 if [ -z "$(/sbin/ifconfig ${nics} | grep 'inet addr')" ]
404 wolf31o2 135 then
405     kill $(cat /var/run/dhcpcd-${nics}.pid)
406     sleep 2
407     dhcpcd -n -h $(hostname) ${nics}
408     fi
409     fi
410 wolf31o2 74 fi
411     done
412 wolf31o2 138 [ "${NFS}" = "yes" ] \
413     && [ -x /etc/init.d/nfsmount ] && start_service nfsmount
414     if [ "${SSHD}" = "yes" ]
415     then
416     # TODO: need to add a password check/warning here
417 wolf31o2 139 ewarn "WARNING: You are starting sshd. You need to set a root password!"
418 wolf31o2 138 [ -x /etc/init.d/sshd ] && start_service sshd
419     fi
420 zhen 2 else
421 wolf31o2 78 ewarn "No Network device auto detected ..."
422 wolf31o2 6 fi
423 zhen 2
424 wolf31o2 68 if [ "${ALSA}" = "yes" ]
425 wolf31o2 51 then
426 wolf31o2 68 if [ -n "${SOUND_FULLNAME}" -o -n "${SOUND_DRIVER}" ]
427 wolf31o2 51 then
428 wolf31o2 78 local sndmsg="Soundcard:\n"
429    
430     [ -n "${SOUND_FULLNAME}" ] \
431     && sndmsg="${sndmsg} ${WARN}${SOUND_FULLNAME}\n"
432     [ -n "${SOUND_DRIVER}" ] \
433     && sndmsg="${sndmsg} driver = ${SOUND_DRIVER}\n"
434    
435     einfo "${sndmsg}"
436    
437 wolf31o2 70 if [ -x /etc/init.d/alsasound ]
438     then
439 wolf31o2 77 start_service alsasound
440 wolf31o2 70 fi
441 wolf31o2 78
442 wolf31o2 82 if [ -e /proc/asound/cards ]
443     then
444 wolf31o2 102 for i in $(cat /proc/asound/cards | awk '{print $1}' | grep ^[[:digit:]])
445 wolf31o2 82 do
446     if [ -d /proc/asound/card$i ] && [ -x /usr/bin/amixer ]
447     then
448     amixer -c $i scontrols > /etc/amixer
449     [ -n "$(grep Master /etc/amixer)" ] \
450     && amixer -c $i -q set Master 95% unmute \
451     >/dev/null 2>&1
452     [ -n "$(grep PCM /etc/amixer)" ] \
453     && amixer -c $i -q set PCM 95% unmute \
454     >/dev/null 2>&1
455     [ -n "$(grep Mic /etc/amixer)" ] \
456     && amixer -c $i -q set Mic 95% mute cap \
457     >/dev/null 2>&1
458     [ -n "$(grep Wave /etc/amixer)" ] \
459     && amixer -c $i -q set Wave 95% unmute \
460     >/dev/null 2>&1
461     [ -n "$(grep Capture /etc/amixer)" ] \
462     && amixer -c $i -q set Capture 95% unmute cap \
463     >/dev/null 2>&1
464     fi
465     done
466     fi
467 wolf31o2 15 fi
468 wolf31o2 68 else
469 wolf31o2 86 ewarn "Skipping ALSA detection as requested on command line ..."
470 wolf31o2 6 fi
471 zhen 2
472 wolf31o2 114 [ -n "${XDESC}" ] && einfo "VideoCard: ${HILITE}${XDESC}${NORMAL}"
473    
474 wolf31o2 102 if [ "${X11}" = "yes" ]
475 wolf31o2 76 then
476 wolf31o2 115 if [ -x /etc/init.d/mkxf86config ]
477     then
478     start_service mkxf86config
479     fi
480 wolf31o2 109 if [ -x /etc/init.d/x-setup ]
481     then
482     start_service x-setup
483     fi
484 wolf31o2 102 else
485     touch /etc/init.d/.noxdm
486 wolf31o2 76 fi
487    
488 wolf31o2 6 killall hwsetup 2>/dev/null
489     echo "6" > /proc/sys/kernel/printk
490 zhen 2 }
491 wolf31o2 6
492     # vim: ts=4

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.20