summaryrefslogtreecommitdiffstats
path: root/initramfs/distro-specs/gentoo/functions-default
blob: 488879fd0d5bad846ec2ce8edb0827fbd903867c (plain) (blame)
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
# Copyright (c) 2003 - 2006 - RZ Uni Freiburg
# Copyright (c) 2006, 2007 - OpenSLX GmbH
#
# This program/file is free software distributed under the GPL version 2.
# See http://openslx.org/COPYING
#
# If you have any feedback please consult http://openslx.org/feedback and
# send your feedback to feedback@openslx.org
#
# General information about OpenSLX can be found under http://openslx.org
#
# configuration script for Gentoo linux distribution to configure OpenSLX
# linux diskless clients (executed within initialramfs after genconfig) 

# empty functions are defined at the beginning of /etc/functions

# distro specific general function called from servconfig script
config_distro () {
echo -e "OpenSLX version 4.0.6\ninitramfs generation date $date" \
  >> /mnt/etc/gentoo-release
echo -e "# changes made to this file by $0 (initramfs from $date)" \
  > /etc/rc.conf
# keytable is set by hwautocfg script (added just for convenience here)
config_rc_entry "KEYMAP" "${KEYTABLE}" "conf.d/keymaps"
}

# udev service - not verified!
udev_hotplug () {
ln -s /bin/udevd /bin/udevstart && udevstart &
if [ -x /bin/udevd ] ; then
  export UDEVD_EXPECTED_SEQNUM=$(cat /sys/kernel/hotplug_seqnum)
  export UDEVD_EVENT_TIMEOUT=1
  echo "" > /proc/sys/kernel/hotplug
  udevd &
else error "$df_errudev" nonfatal
fi
}

# linking runlevel scripts and defining execution order
rllinker () {
local script="$1"
local after="$2"
# empty runlevel links - decision on running certain services is
# passed via configuration
if strinstr "$script" "boot boot.ld ${D_INITSCRIPTS}" ; then
  ln -s /etc/${D_INITDIR}/$script /mnt/etc/runlevels/boot/$script
  echo $script >> /mnt/etc/runlevels/boot/.critical
else
  ln -s /etc/${D_INITDIR}/$script /mnt/etc/runlevels/default/$script
  echo $script >> /mnt/etc/runlevels/default/.critical
fi
if [ -n "$after" ] ; then
  sedscript "$after"
  sed -f /tmp/sedscript -i /mnt/etc/${D_INITDIR}/$script
else
  sed "/depend/,/}/d" -i /mnt/etc/${D_INITDIR}/$script
fi
}

# sed script writer
sedscript () {
echo -e "/depend/,/}/{\n/^[[:space:]]/d\n/depend/i\\" >/tmp/sedscript
echo -e "# modified within initial ramfs/stage3\n/depend/a\\" >>/tmp/sedscript
echo -e "\tafter $1\n}" >> /tmp/sedscript
}

# setup initial boot scripts (rather strange concept I did not get 
# completely)
initial_boot () {
local after=""
local script
d_mkrlscript init boot "Starting Gentoo base initialization"
cat >>/mnt/etc/${D_INITDIR}/boot <<EOF
        #"Mounting /proc, /sys and /dev/pts filesystems"
        # file /etc/fstab in some scenarios not available
        mount -t proc proc /proc &>/dev/null
        if [ -d /sys ] ; then
          while read a b c ; do
            case "\$b" in
              sysfs)
                #echo -n "Mounting /sys filesystem"
                echo -e "sysfs\t\t/sys\t\tsysfs\t\trw\t\t 0 0\n" >>/etc/fstab
                mount -t sysfs sysfs /sys
                ret=0                
                break
                ;;
            esac
          done < /proc/filesystems
        fi
        # Function try() needed by udev, since it's a critical task...
        # Originally from /sbin/rc gentoo-sysinit-script
        try() {
        	local errstr
        	local retval=0
        	
        	if [ -c /dev/null ]; then
        		errstr="\$((eval \$*) 2>&1 >/dev/null)"
        	else
        		errstr="\$((eval \$*) 2>&1)"
        	fi
        	retval=\$?
        	if [ "\${retval}" -ne 0 ]
        	then
        		splash "critical" &
        
        		echo -e "\${ENDCOL}\${NORMAL}[\${BAD} oops \${NORMAL}]"
        		echo
        		eerror "The \"\${1}\" command failed with error:"
        		echo
        		echo "\${errstr#*: }"
        		echo
        		eerror "Since this is a critical task, startup cannot continue."
        		echo
        		/sbin/sulogin \${CONSOLE}
        		einfo "Unmounting filesystems"
        		if [ -c /dev/null ]; then
        			/bin/mount -a -o remount,ro &>/dev/null
        		else
        			/bin/mount -a -o remount,ro
        		fi
        		einfo "Rebooting"
        		/sbin/reboot -f
        	fi
        	
        	return \${retval}
        }
        # Starting udev (normally handled by /sbin/rc sysinit)
        source "\${svclib}/addons/udev-start.sh"
        mount -t devpts -o mode=0620,gid=5 devpts /dev/pts
        rm -rf /dev/.rcsysinit
        #/bin/bash
        eend \${ret} "\${errstr}"
EOF
d_mkrlscript close boot
for script in boot boot.ld ${D_INITSCRIPTS} ; do
  # to get a certain order of scripts the after token of depends () might be
  # used
  rllinker "$script" "$after"
  after=$script
done
# avoid the bullshit of "system initialization"
sed -e "s/# System init.*//;s/si::.*//" -i /mnt/etc/inittab
# initial script which is executed last
lastinit="$after"
}

# initialize boot.ld - skript to be executed during early system startup
# (before most of the normal boot init scripts)
# this script should operate like a normal runlevel script
# initialize boot.ld - skript to be executed during early system startup
# (before most of the normal boot init scripts)
# this script should operate like a normal runlevel script (fixme!!)
d_mkrlscript () {
local switch="$1"
local name="$2"
local info="$3"
case "$switch" in
  init)
    echo -e "#!/sbin/runscript\n# skeleton of /etc/${D_INITDIR}/$name \
generated by $0\ndepend() {\n\t:\n}" >/mnt/etc/${D_INITDIR}/$name
    echo -e "\n\nstart() {\n\tebegin \"$info\"" \
      >>/mnt/etc/${D_INITDIR}/$name
    chmod u+x /mnt/etc/${D_INITDIR}/$name
  ;;
  close)
    echo -e "\n}\n\nstop() {\n\t:\n}\n# vim:ts=4" \
      >>/mnt/etc/${D_INITDIR}/$name
  ;;
esac
}

# group of functions for the normal runlevels
# function for ntp configuration (unchecked)
config_ntp () {
if [ -e /mnt/etc/${D_INITDIR}/ntp ] ; then
  if ! strinfile "ntp:" /mnt/etc/passwd ; then
    echo -e "ntp:x:74:65534:NTP daemon:/var/lib/ntp:/bin/false" \
      >>/mnt/etc/passwd
    echo -e "ntp:!:13099:0:99999:7:::" >>/mnt/etc/shadow
  fi
  testmkd /mnt/var/lib/ntp/var/run/ntp &>/dev/null
  if [ "x$start_ntp" = "xinitial" ] ; then
    echo -e "\t# entries added by $0 (InitRamFS from $date)\n\
\t( ntpdate -s -b $ntp_servers >${LOGFILE} 2>&1 && {\n\t  which \
hwclock &>/dev/null && hwclock -w;} ) &" \
      >>/mnt/etc/${D_INITDIR}/boot.ld
  elif [ "x$start_ntp" = "xyes" ] ; then
    rllinker "ntp"
  fi
fi
}

# function for atd (unchecked)
config_atd () {
if [ "x$start_atd" = "xyes" ]; then
  rllinker "atd"
fi
}

# cron service
config_cron () {
if [ "x$start_cron" = "xyes" ] ; then
  if [ -f /mnt/etc/${D_INITDIR}/vixie-cron ] ; then
    :
  else
    error "$df_errcron" nonfatal
  fi
fi
}

# syslog service
config_syslog () {
if [ "x$start_syslog" = "xyes" ] ; then
  if [ -f /mnt/etc/${D_INITDIR}/syslog-ng ] ; then
    rllinker syslog-ng
  else
    error "$df_errsysl" nonfatal
  fi
fi
}

# secure shell service
config_sshd () {
if [ "x$start_sshd" = "xyes" ] ; then
  if [ -f /mnt/etc/${D_INITDIR}/sshd ] ; then
    rllinker "sshd"
  else
    error "$df_errsshd" nonfatal
  fi
fi
}

# snmp agent for remote monitoring (unchecked)
config_snmp () {
if [ "x$start_snmp" = "xyes" ] ; then
  if [ -f /mnt/etc/${D_INITDIR}/snmpd ] ; then
    rllinker "snmpd"
    testmkd /mnt/var/lib/net-snmp >/dev/null 2>&1
  fi
  # fixme!!
  # write service monitor depending on services started
fi
}

# change entries in rc.conf (mostly for convenience only)
config_rc_entry () {
local var=$1
local value=$2
local file=$3
[ -z $file ] && file=rc.conf
sed -e "s,$var=.*,$var=\"$value\"," -i /mnt/etc/${file}
}

# general display manager stuff like runlevel link and config file entry
config_dm_entry () {
local displmng=$1
if [ -f /mnt/etc/${D_INITDIR}/xdm ] ; then
  config_rc_entry "DISPLAYMANAGER" "${displmng}"
  if [ "x$late_dm" = "xyes" ] ; then
    rllinker xdm
  else
    D_INITSCRIPTS="${D_INITSCRIPTS} ${displmng}"
    rllinker xdm "${lastinit}"
  fi
else
  error "" nonfatal
fi
}


# configure X display manager (runlevel links and kind of manager)
config_xdm () {
# runlevel and config stuff
config_dm_entry xdm
}

# configure gdm
config_gdm () {
# runlevel stuff
config_dm_entry gdm
# fixme!! check for needed directories and permissions
#testmkd /mnt/var/lib/gdm
#testmkd /mnt/var/log/gdm
#strinfile "gdm:" /mnt/etc/passwd || echo "gdm:x:50:15:Gnome Display Manager \
#Daemon:/var/lib/gdm:/bin/false" >>/mnt/etc/passwd
# hack - gdm should be user 50 and shadow group 15
#chown 50:15 /mnt/var/lib/gdm /mnt/var/log/gdm
#chmod 0750 /mnt/var/lib/gdm /mnt/var/log/gdm
}

# configure kdm as display manager
config_kdm () {
config_dm_entry kdm

# first define directories for kdm
kdmrcdir=/var/lib/openslx/themes/displaymanager/
xdmdir=/etc/X11/xdm
testmkd /mnt/${kdmrcdir}

# setting the path for kdmrc-file 
# FIXME: hack - there is no other way in gentoo?!?
# FIXME: only if user wants kdm...
sed -e 's,\(save_options .*\)"$,\1 -- -config /var/lib/openslx/themes/displaymanager/kdmrc",g'\
    -i /mnt/etc/init.d/xdm


# write configuration file - NOT using general config in /etc/functions
##config_kdm_template

usetheme=false
themeconf=$(ls /mnt/var/lib/openslx/themes/displaymanager/*.xml 2>/dev/null)
[ -r "${themeconf}" ] && usetheme=true
# check if a kdmrc was provided via ConfTGZ
[ -f /rootfs/${kdmrcdir}/kdmrc ] || \
  echo -e "# ${kdmrcdir}/kdmrc - \
file generated by
#\t$0: $date\n\
[General]
ConfigVersion=2.3
StaticServers=:0
ReserveServers=:1,:2,:3
ServerVTs=-7
ConsoleTTYs=tty1,tty2,tty3,tty4,tty5,tty6
PidFile=/var/run/kdm.pid
[Xdmcp]
Enable=false
Willing=/usr/kde/3.5/share/config/kdm/Xwilling
[Shutdown]
[X-*-Core]
ServerCmd=${D_XORGBIN} -br
Setup=/usr/kde/3.5/share/config/kdm/Xsetup
Startup=/usr/kde/3.5/share/config/kdm/Xstartup
Reset=/usr/kde/3.5/share/config/kdm/Xreset
Session=/usr/kde/3.5/share/config/kdm/Xsession
AllowRootLogin=false
AllowNullPasswd=false
AllowShutdown=Root
SessionsDirs=/etc/X11/sessions,/usr/share/xsessions
ClientLogFile=.xsession-errors-%s
[X-*-Greeter]
LogoArea=Logo
LogoPixmap=/usr/kde/3.5/share/apps/kdm/pics/kdelogo.png
MinShowUID=1000
MaxShowUID=65000
ForgingSeed=1165509407
Preloader=/usr/kde/3.5/bin/preloadkde
Theme=/var/lib/openslx/themes/displaymanager
UseBackground=true
BackgroundCfg=/var/lib/openslx/themes/displaymanager/backgroundrc
[X-:*-Core]
ServerCmd=/usr/bin/X -br
ServerArgsLocal=-nolisten tcp
AllowNullPasswd=true
AllowShutdown=All
[X-:*-Greeter]
PreselectUser=Previous
FocusPasswd=true
LoginMode=DefaultLocal
AllowClose=false
[X-:0-Core]
ClientLogFile=.xsession-errors
[X-:0-Greeter]
ShowUsers=Selected
SelectedUsers=
UserList=false
GUIStyle=default
LogoArea=Clock
GreetString=Diskless Linux (%h)
GreetFont=Nimbus Sans l,20,-1,5,48,0,0,0,0,0" >/mnt/${kdmrcdir}/kdmrc
echo -e "[Desktop0]
BackgroundMode=Flat
BlendBalance=100
BlendMode=NoBlending
ChangeInterval=60
Color1=0,51,102
Color2=255,255,255
CurrentWallpaper=0
LastChange=0
MinOptimizationDepth=1
MultiWallpaperMode=NoMulti
Pattern=triangles
Program=
ReverseBlending=false
UseSHM=false
Wallpaper=
WallpaperList=
WallpaperMode=NoWallpaper" \
  >/mnt/var/lib/openslx/themes/displaymanager/backgroundrc



#Gentoo specifics??
#sed -e 's,\(save_options .*\)"$,\1 -- -config /var/lib/openslx/themes/displaymanager/kdmrc",g'\
#    -i /mnt/etc/init.d/xdm
#sed -e "s,\(ServerCmd=\).*,\1${D_XORGBIN} -br,g"\
#    -e "s,ShowLog=false,,g"\
#    -e "s,LogSource=false,,g"\
#    -e "s,UseAdminSession=.*,,g"\
#    -e "s,\(Startup=\).*$,\1/etc/X11/Sessions/Xsession,g"\
#    -i /mnt/var/lib/openslx/themes/displaymanager/kdmrc

}

# configure bluetooth services
config_bt () {
if [ -f /mnt/etc/init.d/bluetooth ] ; then
  rllinker "bluetooth"
else
  error "" nonfatal
fi
}

# set consolefont
consolefont () {
echo -e "\tsetfont ${CONSOLE_FONT} >${LOGFILE} 2>&1\n" \
  >>/mnt/etc/${D_INITDIR}/boot.ld
config_rc_entry "CONSOLEFONT" "${CONSOLE_FONT}" "conf.d/consolefont"
}

# acpi and powersave
config_acpi () {
rllinker acpid
}

# configure automounter
config_automount () {
if [ -f /mnt/etc/${D_INITDIR}/autofs ] ; then
  rllinker autofs
  if [ -n "${automnt_src}" ] ; then
    # local directory and home directory server from machine-setup
    [ -z "${automnt_dir}" ] && automnt_dir="/home"
    strinstr "/" "${automnt_dir}" && error "$df_erratpld" nonfatal
    automnt_dir=${automnt_dir#/}
    echo -e "/home\t/etc/auto.${automnt_dir}\n" >> /mnt/etc/auto.master
    echo -e "# /etc/auto.${automnt_dir} created by $0:\n" \
      > /mnt/etc/auto.${automnt_dir}
    echo -e "*\t-rsize=32768,wsize=32768,rw\t${automnt_src}/&" \
      >> /mnt/etc/auto.${automnt_dir}
    config_portmap
  fi
else
  error "$df_erramnt" nonfatal
fi
}

# start name service caching daemon (recommended in combination with 
# ldap source as user admin base)
config_nscd () {
if [ -f /mnt/etc/${D_INITDIR}/nscd ] ; then
  #testmkd /mnt/var/run/nscd
  rllinker "nscd"
fi
}

# start portmapper (needed at least for nfs and nis services - unchecked)
# gentoo: netmount???
config_portmap () {
rllinker "portmap"
}

# start NIS (fixmee: does the start script is really named ypbind?)
config_nis () {
rllinker "ypbind"
}

# start vmware and vmware preparation services
config_vmware () {
rllinker "vmware-prep"
# ensure that vmware is started after preparation
rllinker "vmware" "vmware-prep"
# during vmware sessions linux should not handle usb events/devices
testmkd /mnt/var/X11R6/bin
echo '#!/bin/sh'>> /mnt/etc/udev/rules.d/01-udev-vm.rules
echo -e "# Script for blocking linux from handling usb \
devices\n# during vmware sessions. If you like to remove certain modules \
add them\n# to the list below - Dirk von Suchodoletz, <dirk@goe.net>\n\
STATE=1\nps aux|grep -i vmware|grep -v \"grep\" &>/dev/null && { STATE=0; \
/sbin/rmmod usb-storage &>/tmp/null; }\n\
[ x\$ACTION = xremove ] && { [ \$STATE = 0 ] && /sbin/rmmod usb-storage \
&>/dev/null; }\nexit \$STATE" > /mnt/var/X11R6/bin/vm-udev
chmod u+x /mnt/var/X11R6/bin/vm-udev
echo -e "# special entry to block linux from reacting to usb events during \
running\n# vmware sessions, generated by $0 during initramfs\n# Dirk von \
Suchodoletz, <dirk@goe.net>\nSUBSYSTEM==\"usb\", ACTION==\"add\", \
PROGRAM=\"/var/X11R6/bin/vm-udev\", OPTIONS=\"ignore_device\"\n\
SUBSYSTEM==\"usb\", ACTION==\"remove\", PROGRAM=\"/var/X11R6/bin/vm-udev\"" \
  >> /mnt/etc/udev/rules.d/01-udev-vm.rules
}

# Xorg variable settings. Lots of stuff changed for newer Xorg servers
displayvars () {
Files='\tModulePath\t"/etc/X11/modules"\n
\tModulePath\t"/usr/lib/xorg/modules"\n
\tRgbPath\t\t"/usr/share/X11/rgb"\n
\tFontPath\t"/usr/share/fonts/TTF/"\n
\tFontPath\t"/usr/share/fonts/OTF/"\n
\tFontPath\t"/usr/share/fonts/Type1/"\n
\tFontPath\t"/usr/share/fonts/CID/"\n
\tFontPath\t"/usr/share/fonts/misc/"\n
\tFontPath\t"/usr/share/fonts/75dpi/"\n
\tFontPath\t"/usr/share/fonts/100dpi/"'
InputDevice='\tIdentifier\t"Keyboard1"\n
\tDriver\t\t"kbd"\n
\tOption\t\t"XkbRules"\t\t"xorg"\n
\tOption\t\t"XkbLayout"\t\t"XKEYBOARD"\n
\tOption\t\t"XkbModel"\t\t"pc105"\n
\tOption\t\t"XkbOptions"\t\t"lv3:ralt_switch"\n
\tOption\t\t"XkbVariant"\t\t"nodeadkeys"'
synapticsdrv="/usr/lib/xorg/modules/input/synaptics_drv.o"
}