summaryrefslogtreecommitdiffstats
path: root/initrd/initrd-stuff/bin/servconfig
blob: 13a8b4b45b18629c6c053fff50213ae1e463a5c2 (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
#!/bin/sh
#
# Description:  universal (distro independent) configuration script
#		for linux diskless clients (executed within initial
#		ramdisk) 
#
# Author(s):    Dirk von Suchodoletz <dirk@goe.net>, 11-04-2006
#
# Copyright:    (c) 2006 - RZ Universitaet Freiburg
# 
# Version:      0.1.0a

# check for configuration files to source

# functions common for all distros, messages contains all error and info
# output
. /etc/messages
. /etc/functions
# load distro specific configuration variables and functions. distro
# specific functions may overwrite functions defined in /etc/functions
. /etc/sysconfig/config
. /etc/distro-functions
# get location of logfile definition
. /mnt/etc/${D_SYSCONFDIR}/logfile

# heavy debugging output in level 3 and above ...
[ $DEBUGLEVEL -gt 3 ] && set -x

#######################################################################
# copy distro specific scripts, programs, libraries and configs
cp -a /etc/sysconfig/files/* /mnt 2>/dev/null &
# boot.local file (different for several distros)
[ -f "/etc/boot.local" -a -n "${D_BOOTLOCAL}" ] && {
  echo "# added by $0 (initramfs from $date)" >> /mnt/etc/${D_BOOTLOCAL}
  cat /etc/boot.local >> /mnt/etc/${D_BOOTLOCAL}
}

# set greeting
echo "
            WELCOME TO                       \n (\l)
                  __      __  ___  __  __   __  __   __     __
                 |  |    |  ||    |  ||  | |  ||  |_|  |   |  |
                 |  |    |  ||       ||  | |  |       /    |__|
                 |  |___ |  ||  |    ||  |_|  | /  _        __
                 |______||__||__| |__|  _____/ |__| |__|   |__|

            Diskless Workstation (v4.0)      (c) <dirk@goe.net>
">/mnt/etc/issue

#######################################################################
# read and unify configuration options - default configuration file, 
# from dhcp, ldap ...
# wait for the appearance of configuration via dhcp 
# do not wait if dhcp is not used (how?)
waitfor /tmp/dhcp-done 10000 || error "  Did not get any configuration \
data via dhcp until now ..." nonfatal
waitfor /tmp/ldap-done 10000 || error "  Did not get any configuration \
data via dhcp until now ..." nonfatal
. /etc/machine-setup
# hack for replacing variables ($serverip, $clientip, $host_name) in 
# machine-setup
sed -e "s/\$serverip/$serverip/;s/\$clientip/$clientip/" \
  /etc/machine-setup > /etc/machine-setup.new
cp /etc/machine-setup.new /etc/machine-setup
. /etc/machine-setup

#######################################################################
# set localization
if [ -z "$country" ] ; then
  msg "servconfig" "No configuration for localization found in config file. \
Using default\ncountry setting '${D_DEFAULTCOUNTRY}' defined in $0."
  country=${D_DEFAULTCOUNTRY}
fi
localization $country

#######################################################################
# setup passwd and shadow for local system users like root, bin, daemon
# and nobody ... all other users should be added externally or with the
# corresponding services
basepasswd

#######################################################################
# dns and ip configuration
# hostname of the machine
echo "$host_name" >/proc/sys/kernel/hostname
echo -e "# /etc/hosts - file generated by\n#\t$0:\n#\t$date\
\n#\n# IP-Address  Full-Qualified-Hostname  Short-Hostname\n#\n\
127.0.0.1\tlocalhost\n::1\t\tlocalhost ipv6-localhost ipv6-loopback\n\
fe00::0\t\tipv6-localnet\nff00::0\t\tipv6-mcastprefix\nff02::1\
\t\tipv6-allnodes\nff02::2\t\tipv6-allrouters\nff02::3\t\t\
ipv6-allhosts\n" >/mnt/etc/hosts
echo -e "$clientip\t$host_name.$domain $host_name\n" >>/mnt/etc/hosts

# set up domainname and resolving
test -n "$domain_name" && \
  echo -e "# /etc/resolv.conf - file generated by\n#\t$0:\n\
#\t$date\n#options timeout:1 attempts:1 rotate\n\
search "$domain_name >/mnt/etc/resolv.conf
test -n "$domain_name_servers" && {
  for nameserver in $domain_name_servers; do
    echo nameserver $nameserver >>/mnt/etc/resolv.conf;
  done; }

#######################################################################
# initial boot scripts
# delete and create runlevel links for initial booting (SuSE, Debian,
# ...)
case ${DISTRO} in
  suse*|debian*|ubuntu*)
    for i in ${D_RCDIRS} ${D_INITBOOTD} ; do
      rm -f /mnt/etc/$i/*
    done
    count=10
    # boot.ld is a special runlevel script generated within initial ramdisk
    # which should be executed before the rest
    for i in boot.ld ${D_INITSCRIPTS}; do 
      count=`expr $count + 1`
      revcnt=`expr 41 - $count`
      ln -sf /etc${D_INITDIR}/$i /mnt/etc/${D_INITBOOTD}/S${count}$i
      ln -sf /etc${D_INITDIR}/$i /mnt/etc/${D_INITBOOTD}/K${revcnt}$i
    done
  ;;
  gentoo*)
    # rather different runlevel concept
    rm /mnt/etc/runlevels/*/.critical 2>/dev/null
    for i in ${D_INITSCRIPTS}; do
      ln -sf /etc${D_INITDIR}/$i /mnt/etc/${D_INITBOOTD}/$i
      echo $i >> /mnt/etc/${D_INITBOOTD}/.critical
      echo $i >> /mnt/etc/runlevels/default/.critical
    done
    
#    ( for i in /mnt/etc/init.d/*; do
#      strinstr ".sh" "$i" && continue
#      script=${i#/mnt/etc/init.d/*}
#      if ! strinstr "$script " "${D_INITSCRIPTS} " ; then
#        for j in /mnt/etc/init.d/*; do
#          strinstr ".sh" "$j" && continue
#          link=${j#/mnt/etc/init.d/*}
#          if ! strinstr "$script" "$link" ; then
#            sed "/depend/,/}/s/$script //;/depend/,/}/s/$script$//" \
#              /mnt/etc/init.d/$link > /tmp/rlvscript
#            cp /tmp/rlvscript /mnt/etc/init.d/$link
#          fi
#        done
#      fi
#    done ) &
  ;;
esac

#######################################################################
# 
# run distro specific configuration function
config_distro


#######################################################################
# 
# boot.local
if [ -n "$bootlocal_script" ]; then
  echo -e "# entries added by $0:\n#\t$date\n\n\
$bootlocal_script" >> /mnt/etc/${D_INITDIR}/boot.local
fi

#######################################################################
# basic (non network) services

# at daemon - calling distro specific function config_atd
config_atd "14" "04"

# configuration of cron services - calling distro specific function 
# config_cron (runlevel links, directories, ...)
[ "x$crontab_entries" != "x" ] && \
    echo -e "$crontab_entries" >> /mnt/etc/crontab
config_cron "16" "04"

# setup system log services - distro dependent function config_syslog
config_syslog "02" "20"

# configure dbus - distro dependent function config_dreshal - handle all
# stuff regarding dependent services like dbus, resmgr, hal ...
# (check for runlevel scripts, passwd entries, directories ...)
config_dreshal

# acpi and powersave - distro dependent function config_acpi
config_acpi

# configure automounter
config_automount

# configure bluetooth services
config_bt

#######################################################################
# network(ed) services

# network time service (ntp) configuration file
if [ -n "$ntp_servers" ]; then
  echo -e "# /etc/ntp.conf - file generated by $0: \
$date\n" >/mnt/etc/ntp.conf;
  for ntpserver in $ntp_servers; do
    echo server $ntpserver >>/mnt/etc/ntp.conf;
  done
fi
# copy timezone file defined with language settings
[ -z "$TZ" ] && TZ="$timezone"
cp /mnt/usr/share/zoneinfo/${TZ} /mnt/etc/localtime 2>/dev/null || \
  error "  No such timezone data file (needed for ntp time service \
configuration)." nonfatal
config_ntp 07 14

# secure shell server
config_sshd 12 10

# simple network management protocol agent
config_snmp 24 02

#######################################################################
# vmware stuff: two scenarios
# * VM images in /usr/share/vmware - then simply link
# * VM images via additional mount (mount source NFS, NBD, ...)

# create needed directories and files
if [ "x$vmware" != "x" ] && [ "x$vmware" != "xno" ] ; then
  # in the future other types of sources besides NFS should be supported
  for i in /var/lib/vmware /etc/vmware/vmnet1 /etc/vmware/vmnet8 \
           /var/run/vmware ; do
    testmkd /mnt/$i
  done
  # mount the vmware image source or link it (compatibility to ver. 3)
  if [ -d /mnt/usr/share/vmware ] ; then
    ln -sf /usr/share/vmware /var/lib/vmware
  elif [ -n "${imgsrv}" ] ; then
    # nfsmnt script should be used here ...
    ( nfsmnt ${imgsrv} /mnt/var/lib/vmware || error "$scfg_nfs" nonfatal ) &
    #mount -n -t nfs -o ro,nolock,intr,nodev,soft,timeo=2,nosuid \
    #  ${imgsrv} 
  fi
  # generate a runlevel script
  d_mkrlscript init vmware-prep "Starting preparation of vmware environment"
  sed "s,^#.*,,;/^$/d;s,^,\t," /etc/vmware-prep >> \
    /mnt/etc/${D_INITDIR}/vmware-prep
  d_mkrlscript close vmware-prep ""
  chmod u+x /mnt/etc/${D_INITDIR}/vmware-prep
  config_vmware
  chmod 1777 /mnt/var/run/vmware
  rm /mnt/etc/vmware/not_configured 2>/dev/null
  # define a variable where gdm/kdm should look for additional sessions
  export vmsessions=/var/lib/vmware/vmsessions
fi

#######################################################################
# NIS
# setup nis configuration if needed
if [ "x$nis_domain" != "x" ] && [ "x$nis_servers" != "x" ] ; then
  echo $nis_domain >/mnt/etc/defaultdomain
  echo -e "# /etc/yp.conf - file generated by $0:\n#\t\
$date\n\nypserver "$nis_servers >/mnt/etc/yp.conf
  # should be last in passwd file
  strinfile "+::::::" /mnt/etc/passwd||echo "+::::::" >>/mnt/etc/passwd
fi

#######################################################################
# name service caching daemon if networked user database
config_nscd

#######################################################################
# preparation of /tmp directory (partition 44, nfs scratch, ramdisk)
waitfor /tmp/tmpready 10000
# create some directories and correct permissions
tmpisdisk=`sed -n '/\/tmp/p' /mnt/etc/fstab`
# if there is no local disk partition for /tmp then try to mount a rw
# NFS scratch space (if defined in $scratch) and prepared on server
if [ -n "$scratch" -a -z "$tmpisdisk" ] ; then
  mkdir -p /tmp/scratch >/dev/null 2>&1
  mount -t nfs -o rw,nolock,intr,nodev,soft,timeo=2,nosuid ${scratch} \
      /tmp/scratch >/dev/null 2>&1 && {
    mkdir -p /tmp/scratch/${clientip} >/dev/null 2>&1
    umount /tmp/scratch
    mount -t nfs -o rw,nolock,intr,nodev,soft,timeo=2,nosuid \
      ${scratch}/${clientip} /mnt/tmp >/dev/null 2>&1; }
fi
chmod 1777 /mnt/tmp

#######################################################################
# X11/GUI stuff
if [ "x$start_x" != "xno" ] ; then
  # creating directories commonly needed for X11 in all distros
  # rest should be done via config_x11 function (distro specific)
  for i in /var/lib/xkb/ \
           /etc/X11/xdm \
           /etc/X11/sessions \
           /var/X11R6/bin \
           /var/run/xdmctl \
           /tmp/.ICE-unix \
           /tmp/.X11-unix ; do testmkd /mnt/$i; done
  chmod a+rwxt /mnt/tmp/.ICE-unix
  chmod a+rwxt /mnt/tmp/.X11-unix
  echo "" > /mnt/etc/X11/xdm/Xservers
  # define additional sessions offered to the user (via dhcp/ldap config)
  # descsession -> deprecated by new vmware integration concept
  # write available X display manager to /etc/X11/xdm/Xaccess
  [ -n "$x_display_manager" ] && \
  echo -e "# /etc/X11/xdm/Xaccess - file generated by $0: \
$date\n*\n%hostlist\t$x_display_manager\n*\t\tCHOOSER %hostlist"\
    >/mnt/etc/X11/xdm/Xaccess
  
  # define type of X session
  dsx="no"
  init="#7:5:respawn:/usr/X11R6/bin/X vt7 -quiet"
  case "$start_x" in
    yes|YES|direct|DIRECT|query|QUERY)
      # direct connection onto the own displaymanager, which
      # should be enabled then
      [ "x$start_xdmcp" = "xno" ] && $start_xdmcp="yes"
      init=""
      dsx="yes"
      xdmcp="false"
      echo -e "# /etc/X11/Xservers - file generated by \
$0: $date\n:0 local /usr/X11R6/bin/X :0 vt07\n" >/mnt/etc/X11/xdm/Xservers
    ;;
    broadcast|BROADCAST)
      # the client will XDMCP broadcast and choose first available
      # X11 server
      [ "x$start_xdmcp" = "xgdm" ] || init="$init -broadcast"
    ;;
    indirect|INDIRECT)
      # the client will try to XDMCP connect list of X11 servers
      if [ "x$start_xdmcp" = "xgdm" ] ; then
        init=""
      else
        init="$init -indirect $host_name"
      fi
      [ "x$start_xdmcp" = "xno" ] && start_xdmcp="yes"
      xdmcp="true"
    ;;
    *)
      # fixme!! not optimal for fast start
      # no display manager needed in kiosk mode
      # in this mode you have to provide the type of X session to start
      [ x$start_xdmcp != "x" ] || start_xdmcp="no";
      init="#7:5:respawn:/var/X11R6/bin/kiosk /dev/tty7"
      echo -e "#!/bin/sh\n# /var/X11R6/bin/kiosk - file generated by $0: \
$date\nresmgr login nobody tty7\nresmgr grant nobody desktop\n\
chown nobody /dev/dsp*\n\
su -c 'xinit /etc/init.d/startgui $start_x -- vt7 -quiet' -l nobody &>/dev/null\n\
resmgr revoke nobody\nresmgr logout tty7\nkillall X\nsleep 2" \
        >/mnt/var/X11R6/bin/kiosk
      chmod a+x /mnt/var/X11R6/bin/kiosk &
    ;;
  esac
  # enable runlevel 5 (X11 gui under SuSE linux)
  #      grep -v -e "7:[35]" /etc/inittab > /etc/inittab.new
  #      [ -z "$init" ] || {
  echo -e "# entry made by $0 $date\n$init" >> /mnt/etc/inittab
fi

# setup requested display manager
if [ "x$start_xdmcp" != "xno" ] ; then
  testmkd /mnt/var/lib/xdm/authdir/authfiles
  testmkd /mnt/var/run/xdmctl
  if [ "$start_xdmcp" = "yes" ] ; then
    start_xdmcp=kdm
  fi
  # just ensure lowercase
  start_xdmcp=`echo $start_xdmcp|sed -e "y/'KGWXDM'/'kgwxdm'/"`
  case "$start_xdmcp" in
    wdm)
      # anywhere in use!?
    ;;
    kdm)
      # config is most probably not common in all distros?
      # distro specific function config_kdm
      config_kdm
    ;;
    gdm)
      # config is most probably not common in all distros?
      # distro specific function config_gdm
      config_gdm
    ;;
    *)
      # setup xdm (should be the same over the several distros)
      echo -e "# /etc/X11/xdm/xdm-config - file generated by\n\
#\t$0: $date\n\nDisplayManager.errorLogFile:\t/var/log/xdm.errors\n\
DisplayManager.pidFile:\t\t/var/run/xdm.pid\n\
DisplayManager.authDir:\t\t/var/lib/xdm\n\
DisplayManager.keyFile:\t\t/etc/X11/xdm/xdm-keys\n\
DisplayManager.servers:\t\t/etc/X11/xdm/Xservers\n\
DisplayManager.accessFile:\t/etc/X11/xdm/Xaccess\n\
DisplayManager.willing:\t\tsu nobody -c /etc/X11/xdm/Xwilling\n\
DisplayManager.*.authName:\tMIT-MAGIC-COOKIE-1\n\
DisplayManager.*.authComplain:\tfalse\n\
DisplayManager.*.setup:\t\t/etc/X11/xdm/Xsetup\n\
DisplayManager.*.chooser:\t/etc/X11/xdm/RunChooser\n\
DisplayManager.*.startup:\t/etc/X11/xdm/Xstartup\n\
DisplayManager.*.session:\t/etc/X11/xdm/Xsession\n\
DisplayManager.*.reset:\t\t/etc/X11/xdm/Xreset" >/mnt/etc/X11/xdm/xdm-config
      [ "$xdmcp" = "false" ] && echo -e \
      "DisplayManager.requestPort:\t0\n" >>/mnt/etc/X11/xdm/xdm-config
      # distro specific function config_xdm (at least for runlevel links)
      config_xdm
    ;;
  esac
fi

# servconfig finished successfully
echo "finished" > /tmp/svcfg