summaryrefslogtreecommitdiffstats
path: root/src/initramfs/distro-specs/rhel/functions-default
blob: 58eb3c474189948fd634b027c50dd278e6527f1b (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
# Copyright (c) 2012 - 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 general RHEL to configure linux 
# stateless clients (included by init, hwautocfg, servconfig within Initial-
# RamFS after inclusion of the main functions file). This file is the main
# base for the several RedHat based Scientific Linux versions.

# settings of central variables
# D_DIRINBINDMNT - lists of directories to be created in bind mounted rw
# part of the client filesystem
# D_RODIRSINRW - ReadOnly Directories in RW part of filesystem to save on 
# TempFS usage
# D_DIRINDXS - directories in client filesystem which should be present 
# anyhow
D_BINDMPTS="tmp root media home"
D_DIRINBINDMNT="/var/run /var/log /var/tmp"
D_RODIRSINRW="/etc/bootsplash /etc/gconf /var/adm /var/lib/texmf /var/lib/rpm \
/var/cache/fontconfig"
D_DIRINDXS="/var/lib/rpm /var/lib/nobody /var/lib/alternatives/ /var/db/nscd \
/var/lib/bluetooth /var/lib/scrollkeeper /var/lib/nfs/sm /var/lib/nfs/sm.bak \
/var/lib/nfs/rpc_pipefs /mnt/var/lib/nfs/statd /var/run/netreport /var/lib/misc \
/var/spool/cron"

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

# distro specific function called from servconfig script
config_distro () {
  # clean the runlevel directories which will be populated by the stage3 setup
  for dir in rc0.d rc1.d rc2.d rc3.d rc4.d rc5.d rc6.d ; do
    rm -rf /mnt/etc/${dir}/*
  done
  # set some system/environment information
  echo -e "SLX VERSION = $SLXVERSION\nINITRAMFS GENERATION DATE = $date" \
    >>/mnt/etc/redhat-release
  # simple bash configuration for root
  echo -e "# Generated in OpenSLX stage3\n. /etc/bashrc" >/mnt/root/.profile
  # enable sysrq
  sed -e "1i# Configuration modified by $0 during stage3 bootup." \
      -e "s/kernel.sysrq =.*/kernel.sysrq = 1/" -i /mnt/etc/sysctl.conf
  # set some networking stuff if needed
  [ -e /mnt/etc/sysconfig/network ] && \
    sed -e "s/HOSTNAME=.*/HOSTNAME=$host_name.$domain/" \
        -e "s/GATEWAY=.*/GATEWAY=$gateway/" -i /mnt/etc/sysconfig/network
  [ -e /mnt/etc/init.d/functions ] && \
    sed -i "s,\(^__sed_discard_ignored_files.*\.rpmsave\)\(.*\),\1\\\|-eth0\2,"\
        /mnt/etc/init.d/functions
  testmkd /var/lib/nfs/rpc_pipefs
  testmkd /mnt/var/lib/nfs/statd 700 rpcuser:rpcuser
  testmkd /var/run/netreport
# Create IP configurations
  ## no grep -B 1 in busybox
  #IFACES=$(ip a \
  #  | grep -B 1 "/ether" \
  #  | sed -r '/^--$/d;$!N;s#^[0-9]+: ([a-z0-9\.:]+): .*?/ether ([0-9a-fA-F:]+) .*$#\1=\2#')
  IFACES=$(ip a \
    | awk '/^[0-9]+: /,/ brd /' \
    | sed -r '$!N;s,\n,,' \
    | grep -o '.*/ether .*' \
    | sed -r 's#^[0-9]+: ([a-z0-9\.:]+): .*?/ether ([0-9a-fA-F:]+) .*$#\1=\2#')
  for line in $IFACES; do
    IFACE=$(echo $line | cut -d= -f1)
    IFMAC=$(echo $line | cut -d= -f2)
    cat << "EOF" > "/mnt/etc/sysconfig/network-scripts/ifcfg-$IFACE"
DEVICE=$IFACE
HWADDR=$IFMAC
BOOTPROTO=dhcp
ONBOOT=no
EOF
done
  # check for inittab file
  #test -f /mnt/etc/inittab || error "$df_erritab"
}

# initial (boot time) runlevel scripts
initial_boot () {
# delete all classical disk base rootfs stuff from rc.sysinit
sed -e "6i# Script modified by $0 during stage3 bootup." \
    -e "/relabel_se/,/^}/d" \
    -e "/# Start up swap/,/# Set up bin/d" \
    -e "/^remount_needed/,/^fi$/d" -e "/^# Clean out/,/in_sysinit/d" \
    -e "/# Mount all o/,/# Start the g/d" \
    -e "/# Boot time/,/# let's/d" -i /mnt/etc/rc.d/rc.sysinit
# delete all classical disk base rootfs stuff from halt
sed -e "7i#                Modified by $0 during stage3 bootup." \
    -e "/# Save mixer/,/Saving random/d" -e "/quotaoff/,/^# Now halt/d" \
    -i /mnt/etc/init.d/halt
# boot.slx is a special runlevel script generated within initialramfs which
# should be executed before the normal runlevel scripts.
echo -e "# Run OpenSLX init runlevel script\n/etc/init.d/boot.slx" \
  >>/mnt/etc/rc.d/rc.sysinit
# switch off SElinux enforcing
sed -e "1i# Configuration modified by $0 during stage3 bootup." \
    -e "s/SELINUX=.*/SELINUX=permissive/" -i /mnt/etc/selinux/config
# switch off display manager start via inittab
sed -e "s/x:5:re.*/# line deleted in stage3, re-enable via desktop plugin/" \
    -i /mnt/etc/inittab
# link halt and reboot scripts
ln -s ../init.d/killall /mnt/etc/rc.d/rc0.d/S00killall
ln -s ../init.d/halt /mnt/etc/rc.d/rc0.d/S01halt
ln -s ../init.d/killall /mnt/etc/rc.d/rc6.d/S00killall
ln -s ../init.d/halt /mnt/etc/rc.d/rc6.d/S01reboot
}

# linking runlevel scripts
rllinker () {
local script="$1"
if [ $2 -lt 10 ] ; then
  local start="0$2"; else local start="$2"
fi
if [ $3 -lt 10 ] ; then
  local stop="0$3"; else local stop="$3"
fi
# empty runlevel links - decision on running certain services is passed via
# configuration
for i in rc3.d/K$stop$script rc5.d/K$stop$script \
         rc3.d/S$start$script rc5.d/S$start$script ; do
  ln -sf ../init.d/$script /mnt/etc/$i
done
}

# group of functions for the normal runlevels - first parameter is start
# second stop
# function for ntp configuration
config_ntp () {
if [ -e /mnt/etc/init.d/ntpd ] ; then
  if ! strinfile "ntp:" /mnt/etc/passwd ; then
    echo -e "ntp:x:38:38:NTP daemon:/var/lib/ntp:/sbin/nologin" \
      >>/mnt/etc/passwd
    echo -e "ntp:!:13099:0:99999:7:::" >>/mnt/etc/shadow
  fi
  testmkd /mnt/var/lib/ntp ntp:ntp
  if [ "x$start_ntp" = "xyes" ] ; then
    rllinker "ntpd" 7 14
  fi
fi
}
# function for atd
config_atd () {
if [ "x$start_atd" = "xyes" ]; then
  rllinker "atd" 14 4
fi
}
# function for configuration of cron services
config_cron () {
if [ "x$start_cron" = "xyes" ] ; then
  if [ -f /mnt/etc/init.d/cron ] ; then
    rllinker "cron" 18 2
    testmkd /mnt/var/spool/anacron
    echo -e "# /etc/crontab - file generated by $0:\n\
" >/mnt/etc/crontab
  else
    error "$df_errcron" nonfatal
  fi 
fi
}
# name service caching daemon (useful in most cases)
config_nscd () {
  if [ -f /mnt/etc/init.d/nscd ] ; then
	testmkd /mnt/var/db/nscd
    rllinker "nscd" 20 5
  fi
}
# secure shell service
config_sshd () {
if [ "x$start_sshd" = "xyes" ] ; then
  if [ -f /mnt/etc/init.d/sshd ] ; then
    testmkd /mnt/var/empty/sshd/dev
    if ! strinfile "sshd:" /mnt/etc/passwd ; then
      echo -e "sshd:x:74:74::/var/empty/sshd:/sbin/nologin" \
        >>/mnt/etc/passwd
      echo -e "sshd:!:13099:0:99999:7:::" >>/mnt/etc/shadow
    fi
    rllinker "sshd" 25 10
  else
    error "$df_errsshd" nonfatal
  fi
fi
}
# snmp agent for remote monitoring
config_snmp () {
if [ "x$start_snmp" = "xyes" ] ; then
  if [ -f /mnt/etc/init.d/snmpd ] ; then
    rllinker "snmpd" 24 2
    testmkd /mnt/var/lib/net-snmp
  fi
    # fixme!!
    # write service monitor depending on services started
  fi
}
# configure print server (lpd or cups)
config_printer () {
if [ "x${start_printdaemon}" != "x" ] && \
  [ "x${start_printdaemon}" != "xno" ]; then
  case ${start_printdaemon} in
    yes|cups*|CUPS*)
      rllinker "cups" 25 1
      testmkd /mnt/var/spool/cups/tmp root:sys
    ;;
    lp*|LP*|PLP*)
      rllinker "lpd" 25 1
      testmkd /mnt/var/spool/lpd
    ;;
    *)
    #logwrite "Do not know print-server $start_printdaemon; \
    #specify 'cups' or 'lpd'."
    ;;
  esac
fi   
# configure cups printer client, avoid to overwrite admin provided printer
# configuration file
if [ "x$lpr_servers" != "x" ] && [ ! -e /rootfs/etc/cups/client.conf ] ; then
  echo -e "# /etc/cups/client.conf - file generated by\n#\t$0:\n\
#\t$date\n#\nServerName\t$lpr_servers" >/mnt/etc/cups/client.conf
fi
}
# configure bluetooth services
config_bt () {
if [ -e /mnt/etc/sysconfig/bluetooth ] ; then
  sed -e "1i# /etc/sysconfig/bluetooth - file modified by $0" \
      -e "s,HID2HCI_ENABLE.*,HID2HCI_ENABLE=true," \
      -i /mnt/etc/sysconfig/bluetooth
else
  : # no bluetooth components installed
fi
}
# set up localization like keytable and consolefont
dlocale () {
echo -e "\t# entries added by $0: $date" >> /mnt/etc/init.d/boot.slx
sed -e "s,KEYTABLE=.*,KEYTABLE=\"${KEYTABLE}\"," \
  -i /mnt/etc/sysconfig/keyboard
#echo -e "\tsetfont ${CONSOLE_FONT} >${LOGFILE} 2>&1\n" \
#  >>/mnt/etc/init.d/boot.slx
}
# acpi and powersave daemons, required e.g. to shutdown the machine via
# power button, no need for early start
config_acpi () {
rllinker acpid 01 22
}
# configure dbus (inter application communication for kde and gnome), hal
# (hardware abstraction layer - used e.g. by powersaved) and resmgr
# (resource manager - the user gets permissions to devices when loggin on)
# runlevel script for haldaemon is now haldaemon instead of hal
config_dreshal () {
local start=4
local stop=18
if [ "x$start_dreshal" = "xyes" ]; then
  testmkd /mnt/var/run/dbus 
  if [ -f /mnt/etc/init.d/messagebus ] ; then
    testmkd /mnt/var/lib/dbus
    strinfile "dbus:" /mnt/etc/passwd || \
      echo "dbus:x:81:81:System Message Bus:/var/run/dbus:/sbin/nologin" \
        >> /mnt/etc/passwd
    strinfile "dbus:" /mnt/etc/group || echo "dbus:!:81:" >> /mnt/etc/group
    rllinker "messagebus" $start $stop
  fi
  if [ -f /mnt/etc/init.d/haldaemon ] ; then
    testmkd /mnt/var/lib/hal haldaemon:haldaemon
    testmkd /mnt/var/run/hal haldaemon:haldaemon
    testmkd /mnt/var/cache/hald haldaemon:haldaemon
    strinfile "haldaemon:" /mnt/etc/passwd || \
      echo "haldaemon:x:68:68:User for haldaemon:/var/run/hal:/sbin/nologin" \
        >> /mnt/etc/passwd
    strinfile "haldaemon:" /mnt/etc/group || \
      echo "haldaemon:!:103:" >> /mnt/etc/group
    start=$(($start + 1))
    stop=$(($stop - 1))
    rllinker "haldaemon" $start $stop
  fi
fi
}
# configure automounter (fixme: to be moved into plugin)
config_automount () {
if [ -e /mnt/etc/sysconfig/autofs ] ; then
  testmkd /mnt/var/lock/subsys
  sed -e "1i# /etc/sysconfig/autofs - file modified by\n#\t$0:\n#" \
      -e "s,DAEMONOPTIONS.*,DAEMONOPTIONS=\"--timeout 3\"," \
      -i /mnt/etc/sysconfig/autofs
  rllinker "autofs" 18 4
else
  error "$df_erramt" nonfatal
fi
}
# start name service caching daemon
config_nscd () {
if [ -e /mnt/etc/init.d/nscd ] ; then
  testmkd /mnt/var/run/nscd
  rllinker "nscd" 16 16
else
  error "$df_errnsc" nonfatal
fi
}
# start portmapper (needed at least for nfs and nis services)
config_portmap () {
  rllinker "portmap" 2 20
}
# start NIS (mostly deprecated)
config_nis () {
if [ -f /mnt/etc/init.d/ypbind ] ; then
  rllinker "ypbind" 6 16
  config_portmap
  testmkd /mnt/var/yp/nicknames
else
  error "$df_erryp" nonfatal
fi
}
# initialize runlevel skript to be executed during system startup
# (before most of the normal boot init scripts)
# this script should operate like a normal runlevel script
d_mkrlscript () {
local switch="$1"
local name="$2"
local info="$3"
case "$1" in
  init)
    echo -e "#!/bin/sh\n# skeleton of /etc/init.d/${name} created \
by $0\n# after you applied changes to the creation scripts you have to \
rerun\n# the mkdxsinitrd script to get them applied\n\
. /etc/rc.d/init.d/functions\n#. /etc/sysconfig/logfile\ncase \
\"\$1\" in\n    start)\n\techo -n \"$info\"" >>/mnt/etc/init.d/${name}
    chmod u+x /mnt/etc/init.d/${name}
  ;;
  entry)
    echo -e "\t${info}" >>/mnt/etc/init.d/${name}
  ;;
  close)
    echo -e "\t;;\n    stop)\n\t;;\nesac" \
      >>/mnt/etc/init.d/${name}
  ;;
esac
}