summaryrefslogblamecommitdiffstats
path: root/initrd/initrd-stuff/bin/servconfig
blob: e9eb572c573eebd329c6cacc906542190487bd5b (plain) (tree)
1
2
3
4
5
6
7
8
9
10


                                                                   
                                                                   
                        
 
                                                               
                                                 

                                                         

                                                   

                                              
                      


                                         


                                                                        





                                                                      
                                  
 
                                                 

                                                                      
 

                                                                       





                                                                        

              

                          
                          


                      
      
                                                         




                                                      
 
                                                           


                                                                       
                                                                    
                     

                                                               
                    
 
                                                             
                                                             


                                                                       

                                                                       




                                                               
                             



                                                                      
                                                    






                                         
                                    

                                              

      

    
 
                                                                       

                           
                                
                             



                                                                       
                                                                       





                                                                       

                                                                       
























                                                                       
            
 
                                                                       
 
                                            
             
 

                                                                       
 


                                                
                                                      

  


                                                                       
                                                         
          
 
                                                                   
                                                
           

                                                  
 
                                                                     
             
 


                                                                        
              

                                                            
           
 
                       
                    

                                                        
                                            





                                                                              
                      
  





                                                                
                                                           
                                                                

                                         



                                                         
                                                                    
                                   

                                                                        


                                               
                
    



                              













                                                                       
                              
          
 


                                                                    
           

                                          
           

                                                                       
















                                                                       

                                     
                                                          
                                                                        
                                                                 
                                                 

                   
                               
                                                                      



                                                      
                                                                              
     
                              
                                                                            
                                                          


                                             
                                                                        
                                
                                








                                                                          








                                                                       



                                                             

                                                          

                                                                     
                                               

                                                         







                                                                      

        


                                                                       
                                                                    

                                                                       

                                                 
                                                    
                                                                     
                                                               
                                              

                                     
                                       
                                   

                     
       

      



                                                              


                                                                
                                                                      

      



                                                                       







                                                                 




                                                    
                                                                         
                                                                         
                                                               



                                                                 
                             
 





























                                                                          


                                                                       
                                                       
                                                                          
                                                                


                                                                         
                                                                              

                                                                   
                                 
                                                          
                                         
                                                 
                                                                   
        

                                                                    
                                       

      









                                                               

                                                               
                        
        

                         




                                                          
        

                                                          


                
                                                               
                                                               













                                                                            

                                                                      
                                                                         


                
  
 
                                  
                            
#!/bin/sh
#
# Description:  universal (distro independent) configuration script
#               for linux diskless clients (executed within initial
#               ramdisk)
#
# Author(s):    Dirk von Suchodoletz <dirk@goe.net>, 20-08-2006
#               Michael Janczyk <mj0>, 31-05-2006
#               Lars Mueller <lm@openslx.org>, 23-06-2006
#               Oliver Tappe <ot@openslx.org>, 23-06-2006
#
# Copyright:    (c) 2006 - RZ Universitaet Freiburg
#               (c) 2006 - openslx.org project
#
# Version:      0.1.2c

# 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 -a $DEBUGLEVEL -lt 10 -o $DEBUGLEVEL -eq 12 ] && \
  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
len=$(expr length $DISTRO)
dstr="$DISTRO)"
while [ $len -le 11 ] ; do
  dstr="$dstr "
  len=$(expr $len + 1)
done
echo "
         WELCOME TO                               \n (\l)
                  _____    ______     __       _____
                 /  _     |   _      |  |     |   _  |
                |  | |  | |  | |  |  |  |     |  |_| |
                |  |_|  | |  |_|  |  |  |___  |   ___/
                  _____/  |______/   |______| |__|

         Diskless Workstation (v4.0/$dstr (c) <odl project>
">/mnt/etc/issue

#######################################################################
# read and unify configuration options - default configuration file,
# from dhcp, ldap ...
# wait for the appearance of configuration from several sources
cfgcomplete
. /etc/machine-setup

# copy additional configuration and var files and directories
# admins can place there files in /var/lib/openslx/config/...
# to be packed during stage2 into (/srv/dxs)/tftpboot/client-config...)
# ... in the near future ...
cp -a /rootfs/* /mnt 2>/dev/null

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

if [ "x$vmware" != "x" ] && [ "x$vmware" != "xno" ] ; then
  testmkd /mnt/var/lib/vmware
  # mount the vmware image source or link it (compatibility to ver. 3)
  if [ -d /mnt/usr/share/vmware ] ; then
    ln -sf /usr/share/vmware /mnt/var/lib/vmware
  elif [ -n "${imgsrv}" ] ; then
  # get type, server and path of VMware image export
  vmimgsprot=$(uri_token $imgsrv prot)
  vmimgsserv=$(uri_token $imgsrv server)
  vmimgspath="/$(uri_token $imgsrv path)"
  case "$vmimgsprot" in
    *nbd)
    ;;
    *)
    # we expect nfs mounts here ... 
    nfsmnt ${imgsrv} /mnt/var/lib/vmware || {
      error "$scfg_nfs" nonfatal; noimg=yes; }
    ;;
  esac
  fi
fi

#######################################################################
# set localization
if [ -z "$country" ] ; then
  error "$scfg_country" nonfatal
  country=${D_DEFAULTCOUNTRY}
fi
localization $country

#######################################################################
# setup passwd and shadow for local system users like root, bin, daemon
# and nobody if no user/admin provided passwd exists ...
# the root password provided by machine-setup is used only if no passwd
# file is provided (default case)
if [ ! -f /rootfs/etc/passwd ] ; then
  basepasswd
fi

#######################################################################
# 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,
# ...)
initial_boot

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

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

# setup system log services - distro dependent function config_syslog
config_syslog

# 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
# if automounter=yes
if [ -d /mnt/misc ] ; then
  echo -e "# /etc/auto.master - file generated by $0:\n\
/misc\t/etc/auto.misc" >/mnt/etc/auto.master
  echo -e "# /etc/auto.misc - file generated by $0:" >/mnt/etc/auto.misc
else
  echo -e "# /etc/auto.master - file generated by $0:\n\
/misc\t#/etc/auto.misc" >/mnt/etc/auto.master
  echo -e "# /etc/auto.misc - file generated by $0:\nautomount for removable \
devices is mostly deprecated, so /misc is not\nactivated in auto.master." \
  > /mnt/etc/auto.misc
fi
if [ -n "${automnt_src}" ] ; then
  # local directory and home directory server from machine-setup
  [ -z "${automnt_dir}" ] && automnt_dir="/home"
  # remove leading and trailing slash
  automnt_dir=${automnt_dir#/}
  automnt_dir=${automnt_dir%/}
  test -d /${automnt_dir} || error "$scfg_erradir" nonfatal
  strinstr "/" ${automnt_dir} && error "$scfg_erratpld" nonfatal
  amserv=$(uri_token $automnt_src server)
  ampath=$(uri_token $automnt_src path)
  echo -e "/${automnt_dir}\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${amserv}:/${ampath}/&" \
    >> /mnt/etc/auto.${automnt_dir}
  # no tempfs needed if automounter operates on /home
  [ "${automnt_dir}" = "home" ] && umount -t tmpfs /mnt/home 2>/dev/null
  # portmapper is needed for remote NFS sources
  config_portmap
fi
config_automount
# fi

# 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 "$scfg_ntptz" nonfatal
config_ntp

# secure shell server - at the moment all clients share one "secret"
# key or the key has to be regenerated on every bootup or fetched on
# every bootup from somewhere
config_sshd

# simple network management protocol agent
config_snmp

#######################################################################
# 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
  config_nis
fi

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

#######################################################################
# vmware stuff second part: setting up the environment

# 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/X11R6/bin /etc/vmware/vmnet1 /etc/vmware/vmnet8 \
           /var/run/vmware /etc/X11/sessions ; do
    testmkd /mnt/$i
  done
  # moved up within this file!!
  # 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
  #  # more general mount script should be used here!?
  #  ( nfsmnt ${imgsrv} /mnt/var/lib/vmware || error "$scfg_nfs" nonfatal ) #&
  #fi
  # generate a runlevel script
  d_mkrlscript init vmware-prep "Starting preparation of vmware environment"
  sed "s,^#.*,,;/^$/d;s,^,        ," /etc/vmware-prep >> \
    /mnt/etc/${D_INITDIR}/vmware-prep
  d_mkrlscript close vmware-prep ""
  chmod u+x /mnt/etc/${D_INITDIR}/vmware-prep
  # check here that mount finished and the important files are available
  if [ "$noimg" = "yes" ] ; then
    error "$scfg_vmdir" nonfatal
  else
    # add special sessions to the display managers session menu
    # check here that mount finished and the important files are available
    # default kdm session. Xdialog with WM and VMware images
    cp /mnt/var/lib/vmware/templ/runvmware /mnt/var/X11R6/bin
    chmod 755 /mnt/var/X11R6/bin/runvmware >/dev/null 2>&1
    cp /mnt/var/lib/vmware/templ/defaultwm /mnt/var/X11R6/bin
    chmod 755 /mnt/var/X11R6/bin/defaultwm >/dev/null 2>&1
  fi
  config_vmware
  chmod 1777 /mnt/var/run/vmware
  # define a variable where gdm/kdm should look for additional sessions
  export vmsessions=/var/lib/vmware/vmsessions
  # create default.desktop for kdm
  echo -e "[Desktop Entry]\nEncoding=UTF-8\nName=Default\n\
Name[de]=Standard\nExec=defaultwm\nTryExec=/var/X11R6/bin/defaultwm\n\
Type=Application" >/mnt/etc/X11/sessions/default.desktop
  rm /mnt/etc/vmware/not_configured 2>/dev/null
  echo -e "#!/bin/sh\n#\n# file generated by ${0} at ${date}\
    \n# set to black background\nxsetroot -solid \"black\"\
    \nstartvm=\$(echo \$0 | sed -e \"s,.*/,,\")\
    \nxterm -bg black -fg white -geometry 100x30+0-0 +sb \
    -e \"/var/X11R6/bin/runvmware -s \${startvm}\"\n" \
    > /mnt/var/X11R6/bin/desktop-session #${debug} removed
  chmod 755 /mnt/var/X11R6/bin/desktop-session
  sessions=$(ls /mnt/var/lib/vmware/vmsessions/*.desktop 2>/dev/null)
  # fixme: the following part is to be tested!!
  if [ -n "${sessions}" ]; then
    for i in /mnt/var/lib/vmware/vmsessions/*.desktop; do
      #session_name=$(cat ${i} | grep -iw "exec" \
      #  | awk -F "=" '{print $2}')
      session_name=$(cat ${i}|sed -n "/^[Ee]xec/p"|sed -e "s,Exec=,,")
      #copy bacause of initrd
      cp /mnt/var/X11R6/bin/desktop-session \
        /mnt/var/X11R6/bin/${session_name}
      #ln -s /mnt/var/X11R6/bin/desktop-session \
      #  /mnt/var/X11R6/bin/${session_name}
    done
  fi
fi

#######################################################################
# preparation of /tmp directory (partition 44, nfs scratch, ramdisk)
# there might be the chance that we have a disk partition available, so
# wait for completion of detection, setup process
waitfor /tmp/tmpready 10000
# create some directories and correct permissions
tmpisdisk=`sed -n '/\/tmp/p' /tmp/fstab 2>/dev/null`
# if there is no local disk partition for /tmp then try to mount a rw
# scratch space (if defined in $scratch) and prepared on server
if [ -n "$scratch" -a -z "$tmpisdisk" ] ; then
  scrproto=$(uri_token $FILESRC prot)
  scrpath=$(uri_token $FILESRC path)
  mkdir -p /tmp/scratch >/dev/null 2>&1
  # exports have to be per client!!
  case "$scrproto" in
    nbd)
      :
    ;;
    *)
    tmpserv=$(uri_token $scratch server)
    tmppath=$(uri_token $scratch path)
    mount -t nfs -o rw,nolock,intr,nodev,soft,timeo=2,nosuid \
      ${tmpserv}:/${tmppath} /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 \
        ${tmpserv}:/${tmppath}/${clientip} /mnt/tmp >/dev/null 2>&1; }
    ;;
  esac
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 "# file emtied by $0 during initramfs" > /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"
    ;;
    *)
      # 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\nwhile ps aux|grep -i kiosk|grep -v \"grep\" &>/dev/null;\
do\n  test -f /var/run/kiosk || break; sleep 3;\ndone\ntouch \
 /var/run/kiosk\nresmgr login nobody tty7\nresmgr grant nobody desktop\n\
chown nobody /dev/dsp* /dev/audio* /dev/mixer* /dev/snd/control*\n\
chown -R nobody:nobody /var/lib/nobody\nsu -c 'xinit /var/X11R6/bin/startgui \
$start_x -- vt7 -quiet' -l nobody &>/dev/null\nrm /var/run/kiosk\n\
resmgr revoke nobody\nresmgr logout tty7\nkillall X" \
        >/mnt/var/X11R6/bin/kiosk
      # early start of kiosk session if not late_dm is set
      if [ "x$late_dm" != "xyes" ] ; then
        echo -e "\t# kiosk start added by $0\n\t\
/var/X11R6/bin/kiosk &>/dev/null &" >>/mnt/etc/${D_INITDIR}/boot.ld
      fi
      cp /etc/startgui /mnt/var/X11R6/bin
      chmod a+x /mnt/var/X11R6/bin/kiosk /mnt/var/X11R6/bin/startgui
      rm /mnt/var/run/kiosk 2>/dev/null
    ;;
  esac
  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