summaryrefslogtreecommitdiffstats
path: root/initramfs/distro-specs/gentoo/functions-default
blob: 988e7412f0aedac7f9e835fd20b7d8b20823dded (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
# 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 ${SLXVERSION}\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"
  # fixme: check for strange udev rules which want to rename eth* names!
}

# 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.slx ${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 scripts=$*
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.slx $scripts ; 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.slx - 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.slx - 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" = "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}
}

# 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.slx
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"
}

# 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"
}