summaryrefslogblamecommitdiffstats
path: root/src/initramfs/distro-specs/scientific/functions-default
blob: f6cd0adff06840b953c541984278b5ce6abc314c (plain) (tree)



























                                                                               

                                                                                 


















                                                                              
                                                         
                                                                         



                                                                                

                                                    



















                                                                                            


























































































































































































                                                                             


                                                   







































































                                                                              
# 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 Scientific Linux 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#')
  IFS=$(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 $IFS; do
    IF=$(echo $line | cut -d= -f1)
    IFMAC=$(echo $line | cut -d= -f2)
    cat << EOF > "/mnt/etc/sysconfig/network-scripts/ifcfg-$IFACE"
DEVICE=$IF
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
}