summaryrefslogblamecommitdiffstats
path: root/src/initramfs/distro-specs/ubuntu/functions-default
blob: d28796bc50b8a9d5a5618a662f3885353de34f5b (plain) (tree)
1
2
3
4
5
6
7
8
9
                                            
                                         


                                                                         
 

                                                                         
 
                                                                         
 
                                                                    
                                                                      
 








                                                                              



                                                                         



                                                                          

                                                                         
 

                                     
                                



                                      






                                                                               
                                         





                                                                              

                                                        

                                                                         


                                                                 

                                                                     

                                                 


                                                                              
                                           

                                                                     
                                     
                                                                     
                                             

                                                                       
                                                            
                                                                        
      
 

                                                                        

                       



                                             
 


                                                                         

 
                                                   
                                          
                 




                                                                 
 
 


                          
                          





                                                                       
                                  









                                                                                         
                                              





                                                                                           





                                                                            




















                                                                                        
    
                                                                                           
  
 

 





                                                                      
                                                     
                                                         
                                                  

 

                                
                                                              

                                                               
                                                   
  

  





                                                          




                                               

  
                                                                               

                                     

                                                   










                                                                              


                                     
                                                  
                                          
                                                    




                                
                                                                    

                                     
                                                    
                                 

                                                      

                                                         
     
    
  
 

                    






                                                         
 
                                                        

                                       
                           

                             

                                                       
                                                 

                                                    


                                                                          


  
                                                                         





                                                                    
                                                

                 
                                                                 
                                                                          
                                                        
                                                   
                                                                          

                                   
    


                                                 
        
                                                                    
                             


    
                                   
                     

                                                     
                              
                                                                  
                                                             
                
            

  
                                                              
                   
                                                   

                                                      


                              
 









                                                           
                                                                           
               

                                                       





                                 
                                                 
                



                                                   
                                         


                                                  
 
# Copyright (c) 2003..2006 - RZ Uni Freiburg
# Copyright (c) 2006..2011 - 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 Ubuntu to configure OpenSLX Linux
# stateless clients (executed within initial ramdisk after genconfig) 

# distro specific configuration variables used in the setup functions
# (formerly done via config-*, these variables are disputable ...)
# D_ETCEXCL - list of files, wildcards to be excluded from /etc when using 
# bind mounts
# 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 home media"
D_DIRINBINDMNT="/var/run /var/log /var/tmp /var/lib/gdm"
D_RODIRSINRW="/etc/X11/xkb /var/lib/gconf /var/lib/dpkg /var/lib/aspell \
/var/lib/pango /var/lib/defoma /var/cache/fontconfig /var/lib/dkms"
# creating required(?) directories like /var/run/sysconfig/tmp or 
# /var/run/console does not make much sense here as they get overmounted, 
# see ticket #813
D_DIRINDXS="/var/lib/nobody /var/lib/misc /var/lib/pam \
/var/lib/bluetooth /var/lib/texmf /var/lib/nfs/sm /var/lib/acpi_support \
/var/spool/cron /var/lib/alsa"

# distro specific stuff to initialize
postinit () {
  if [ $DEBUGLEVEL -gt 3 ]; then
    export DEBUG_UPSTART=" -v --debug"
  fi
}

config_netconsole () {
	local MY_IP=$1
	local MY_OLDDEV=$2
	local MY_DEV=$3
	local T_IP=$4
	local T_MAC=$(arp -n |grep $T_IP| awk '{print $5}')
	# FIXME: we need to set a valid ip for ethx if we use the bridge config
        # from the virtualization plugins
	[ "$MY_OLDDEV" = "$MY_DEV" ] || ip a a $MY_IP dev $MY_OLDDEV
	modprobe netconsole netconsole=4444@$MY_IP/$MY_OLDDEV,514@$T_IP/$T_MAC
	dmesg -n 8
}


# distro specific function called from servconfig script
config_distro () {
  # runlevel system changed significantly compared to pre 9.10 sys-v-init
  # clean up nevertheless
  for dir in rc0.d rc1.d rc2.d rc3.d rc4.d rc5.d rc6.d rcS.d ; do
    rm -rf /mnt/etc/${dir}/*
  done
  # remove unneeded init scripts (stuff handled in stage3 which would
  # interface with already existing setup)
  # copy all event scripts to a special directory
  testmkd /mnt/etc/init.inactive
  echo -e "# This directory was created in OpenSLX stage3 and contains all \
disabled\n# upstart scripts. They are moved by servconfig to init if this is \
required." >/mnt/etc/init.inactive/README
  mv /mnt/etc/init/* /mnt/etc/init.inactive
  # remove plymouth component from *dm.conf (not needed with splashy)
  sed "/# Check kernel c/,/done/d" -i /mnt/etc/init.inactive/*dm.conf
  # copy initial upstart scripts back
  for file in alsa-mixer-save control-alt-delete console-setup dbus \
              container-detect console-font \
              dmesg hwclock hwclock-save irqbalance module-init-tools \
              mountall mounted* networking procps rc* tty* udev* \
              upstart-socket-bridge upstart-udev-bridge ; do
    mv /mnt/etc/init.inactive/${file}.conf /mnt/etc/init >/dev/null 2>&1
  done

  # remove annoying udev rule set for changing eth interface and cd/dvds
  rm /mnt/etc/udev/rules.d/*persistent*.rules >/dev/null 2>&1

  # for screen sessions
  testmkd /mnt/var/run/screen root:utmp 0777

  # apt stuff
  testmkd /mnt/var/cache/apt/archives/partial

  # add the slx specific path (/var/opt/openslx/bin) to the PATH variable
  echo -e "# stuff generated by $0 (out of InitRamFS written $date)\n\
export PATH=\"\$PATH:/var/opt/openslx/bin\"" >>/mnt/etc/profile
}

# initial boot looks different since ubuntu upstart
# (executed after plugin config in stage3)
initial_boot () {
	# fix depenencies of upstart files (remove network stuff)
	upstart_set_starton rc-sysinit filesystem
	upstart_set_starton autofs filesystem
	upstart_set_starton portmap filesystem
	
}

upstart_set_starton () {
	local script="$1"
	local starton="$2"
  local file_not_found="f"
	
	if [ -e /mnt/etc/init.inactive/${script}.conf ]; then
		local script_path=/mnt/etc/init.inactive/${script}.conf
	elif [ -e /mnt/etc/init/${script}.conf ]; then
		local script_path=/mnt/etc/init/${script}.conf
	else
	  local file_not_found="t"
	fi
	
	if [ "$file_not_found" = "f" ]; then	
		# replace multi-line dependencies with ##starton##
		sed -n '1h;1!H;${;g;s/start on[\t ]*([^)]*)/start on ##starton##/g;p;}' \
		    -i $script_path
		# replace single-line dependencies with ##starton## 
		sed -e 's/start on.*$/start on ##starton##/' \
		    -i $script_path
		# replace placeholder with our new value
	    sed -e "s,##starton##,$starton," \
	        -i $script_path
	else
		error "Script: ${script} does not exist. Skipping modification.." nonfatal}
	fi
}

# runlevel linker - mostly deprecated in the old form because of new upstart
# mechanism (with backward compatibility)
rllinker () {
local script="$1"
# activating the new way, check if a appropriate script is available, else
# try the traditional approach

if [ -e /mnt/etc/init.inactive/${script}.conf -o -e /mnt/etc/init/${script}.conf ]; then
    # we have upstart scripts
    if [ -e /mnt/etc/init.inactive/${script}.conf ] ; then
      mv /mnt/etc/init.inactive/${script}.conf /mnt/etc/init
    fi
elif [ -e /mnt/etc/init.d/${script} ]; then
    # we old rc scripts
    if [ -e /mnt/etc/init.d/${script} -a -n "$1" -a -n "$2" ] ; then
      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
      for i in rc2.d/K$stop$script rc3.d/K$stop$script \
             rc2.d/S$start$script rc3.d/S$start$script ; do
        ln -sf ../init.d/$script /mnt/etc/$i
        [ "$DEBUGLEVEL" == 5 ] && echo "Linked $script"
      done
    fi
else
  error "Script: ${script} does not exist. Skipping setup of startscipts/events.." nonfatal
fi

}

# set up localization like keytable, console
dlocale () {
# fixme -- use keytable setup script here
# echo -e "\t# entries added by $0: $date" >> /mnt/etc/init.d/boot.slx
sed -e "1i# File modified during SLX stage3 bootup (config_distro)" \
    -e "s/LANG.*/LANG=\"${LANG}\"/" -i /mnt/etc/default/locale
echo "LC_ALL=\"${LANG}\"" >>  /mnt/etc/default/locale
echo "LANGUAGE=\"${LANG}:en\"" >> /mnt/etc/default/locale
echo "LC_ALL=\"${LANG}\"" >>  /mnt/etc/environment
}

# function for ntp configuration
config_ntp () {
if [ -f /mnt/etc/init.d/ntp -a "x$start_ntp" != "xno" ] ; then
  echo -e "ntp:x:74:65534:NTP daemon:/var/lib/ntp:/bin/false" \
    >>/mnt/etc/passwd
  # testmkd /mnt/var/lib/ntp/var/run/ntp # see #813
  
fi
}
# function for atd
config_atd () {
if [ "x$start_atd" = "xyes" ]; then
  # testmkd /mnt/var/spool/atjobs
  # testmkd /mnt/var/spool/atspool
  # chown 1:1 /mnt/var/spool/atjobs /mnt/var/spool/atspool
  if [ -f /mnt/etc/init.inactive/atd ] ; then
    mv /mnt/etc/init.inactive/atd /mnt/etc/init
  else
    error "$df_erratd" nonfatal
  fi
fi
}
# function for configuration of cron services (fixme: to be moved to a plugin?)
config_cron () {
if [ "x$start_cron" = "xyes" ] ; then
  if [ -f /mnt/etc/init.inactive/anacron ] ; then
    mv /mnt/etc/init.inactive/anacron /mnt/etc/init
    # fixme! check for proper permissions!
    testmkd /mnt/var/spool/crontabs
    echo -e "# /etc/crontab - file generated by $0:\n\
#\t$date\nSHELL=/bin/sh\nPATH=/usr/bin:/usr/sbin:/sbin:/bin:/usr/lib/news/bin\
\nMAILTO=\n-*/15 * * * *\troot\ttest -x /usr/lib/cron/run-crons && \
/usr/lib/cron/run-crons >/dev/null 2>&1\n" >/mnt/etc/crontab
  else
    error "$df_errcron" nonfatal
  fi 
fi
}
# secure shell service
config_sshd () {
if [ "x$start_sshd" = "xyes" ] ; then
  if [ -f /mnt/etc/init.inactive/ssh.conf ] ; then
    # testmkd /mnt/var/run/sshd # see #813
    mv /mnt/etc/init.inactive/ssh.conf /mnt/etc/init
  else
    error "$df_errsshd" nonfatal
  fi
fi
}
# snmp agent for remote monitoring (upstart functionality unchecked)
config_snmp () {
if [ "x$start_snmp" = "xyes" ] ; then
  if [ -f /mnt/etc/init.inactive/snmpd.conf ] ; then
    testmkd /mnt/var/lib/net-snmp
    mv /mnt/etc/init.inactive/snmpd.conf /mnt/etc/init
  else
    # fixme!!
    # write service monitor depending on services started
    :
  fi
fi
}
# acpi and powersave
config_acpi () {
  if [ -f /mnt/etc/init.inactive/acpid.conf ] ; then
    mv /mnt/etc/init.inactive/acpid.conf /mnt/etc/init
  else
    # fixme!!
    # write service monitor depending on services started
    :
  fi
}
# configure hal, dbus, policykitd and services like that
config_dreshal () {
if [ "x$start_dreshal" = "xyes" ]; then
  testmkd /mnt/var/lib/dbus
  testmkd /mnt/var/lib/misc
  testmkd /mnt/var/cache/hald
  rm -rf /mnt/etc/dbus-1/system.d/*etwork*anager.conf \
         /mnt/etc/dbus-1/system.d/nm-* \
         /mnt/etc/dbus-1/event.d/*NetworkManager*
  sed -i /mnt/etc/dbus-1/system.d/hal.conf \
      -e "s/^\([^d]*\)deny\(.*Volume.*\)/\1allow\2/"
  for dir in 10-vendor.d 20-org.d 30-site.d 50-local.d 90-mandatory.d ; do
    testmkd /mnt/var/lib/polkit-1/localauthority/${dir}
  done
fi
}

# 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"
# ToDo: needs to be adapted to upstart mechanism
case "$switch" in
  init)
    echo -e "#!/bin/sh\n# skeleton of /etc/init.d/$name written \
from $0\n# after you applied changes to the creation scripts you have to \
rerun\n# the mkdxsinitrd script to get them applied\n\n\
. /lib/lsb/init-functions\n" >/mnt/etc/init.d/$name
    echo -e "\n\ncase \"\$1\" in\n    start)\n\tlog_begin_msg \"$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 "\tlog_end_msg 0\n\t;;\n    stop)\n\t;;\nesac\nexit 0" \
      >>/mnt/etc/init.d/$name
  ;;
esac
}
# configure automounter (unchecked)
config_automount () {
if [ -f /mnt/etc/init.inactive/autofs.conf ] ; then
  mv /mnt/etc/init.inactive/autofs.conf /mnt/etc/init
  testmkd /mnt/var/lock/subsys
  sed -e "1i# /etc/default/autofs - file modified by\n#\t$0:\n#" \
      -e "s,TIMEOUT.*,TIMEOUT=60," -i /mnt/etc/default/autofs
  config_portmap
  config_nfs
fi
}
# start portmapper (needed at least for nfsN and nis services)
config_portmap () {
if [ -f /mnt/etc/init.inactive/portmap.conf ]; then
  mv /mnt/etc/init.inactive/portmap.conf /mnt/etc/init
  mv /mnt/etc/init.inactive/statd.conf /mnt/etc/init
else
  error "$df_errpmap" nonfatal
fi
}
# mostly unused yet (needs to be properly integrated)
config_nfs () {
  [ -e /mnt/etc/init.inactive/gssd.conf ] && \
    mv /mnt/etc/init.inactive/gssd.conf /mnt/etc/init
  [ -e /mnt/etc/init.inactive/rpc_pipefs.conf ] && \
    mv /mnt/etc/init.inactive/rpc_pipefs.conf /mnt/etc/init
  [ -e /mnt/etc/init.inactive/idmapd.conf ] && \
    mv /mnt/etc/init.inactive/idmapd.conf /mnt/etc/init
}

# start NIS (unchecked!! fixme - does the service is really named ypbind??)
config_nis () {
  if [ -f /mnt/etc/init.inactive/ypbind.conf ] ; then
    mv /mnt/etc/init.inactive/ypbind.conf /mnt/etc/init
    config_portmap
    testmkd /mnt/var/yp/nicknames
  else
    error "$df_erryp" nonfatal
  fi
}
# name service caching daemon (really existing!?)
config_nscd () {
# if upstart compatible
  if [ -f /mnt/etc/init.inactive/nscd.conf ] ; then
    testmkd /mnt/var/cache/nscd
  # otherwise the old method
  elif [ -f /mnt/etc/init.d/nscd ] ; then
    ln -sf /etc/init.d/nscd /mnt/etc/rc2.d/S10nscd
    ln -sf /etc/init.d/nscd /mnt/etc/rc3.d/S10nscd
  fi
}