summaryrefslogblamecommitdiffstats
path: root/installer/ld4-inst
blob: 3ba6dbb40717eecbf1d974bf6610dfe94690d82d (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16















                                                                        
 


                                      
                               
                                                                                  






                                
                                                                             



                                                                 
 

                                   








                                          
                               

                   
                             
    
                     


                                
 


                                  
                          

                             
                           



                    
                          

                          
                            



                    
                          

                     
                              



                                    
                        

                     
                           

             
                            

            
                            




          
 
 













                                                       

                                                             
                                                                            









                                                                           













                                                                       
                                                










                                                                           
 
                                   






                                                            
                                                      
 




                                                               
  










                                                                                      
                                              

                                                                 


                                                                 


                                       



                                                                                   



               
                                                                                  
                                                                                                         
                                                              
  
                                      

 
 

                                                 
                                                 

                                

                                                       

                                           


                                                                                                                                                                


                                 

                                                                   
    
                                           
                                                        



                                  

                                                                 
    
                                                                                     
  


                                                                   
                                            


                                             
                                                                                                                                                                                                                                                                                                    


                                                         



                 
                                                                






                                                


 




                                                                             
 








                                   
      
#! /bin/bash
#
# Description:  Script for generating dxs filesystem by
#               cloning from rsync source for Diskless X Stations (v4.0)
#
# Author(s):    Dirk von Suchodoletz <dirk@goe.net>, 02-11-2005
# Copyright:    (c) 2003, 2005 - RZ Universitaet Freiburg
#


header() {
  echo
  echo "Welcome to the LD4 installation"
  echo
}


# check needed things for installation
precheck() {
  # check if running as root
  if [ "`id -u`" != "0" ]; then
    echo -e "\nYou don't have the needed permission. Please rerun as root user!\n"
    exit 1
  fi
  
  # check for existing programs:
  # rsync (server-side)
  which rsync >/dev/null
  if [ $? != 0 ] ; then
    echo -e "\nYou need to install rsync on server side before installing!\n"
    exit 1
  fi
  
  # ssh, rsync (referenz-system-side) -> not possible in precheck

  # nfs-kernel-server, atftpd 
  #  -> not needed for installation
}


# ask question variable_name default_value
ask() {
  echo
  echo "$1"
  echo -n "* [ $3 ] "
  read userinput
  if [ -z "$userinput" ] ; then
      local back=$3
  else
      local back="$userinput"
  fi
  eval "$2=\"$back\""
  echo "$2=\"$back\"" >> .config
}


distro_check() {
  case "${!1}" in
    Debian*|debian*|Sarge*|sarge*)
      eval "$1=\"debian\""
      case "${!2}" in
        Sarge*|sarge*|3.1*|*)
          eval "$2=\"3.1\""
        ;;
      esac
    ;;
    Ubuntu*|ubuntu*)
      eval "$1=\"ubuntu\""
      case "${!2}" in
        Breezy*|breezy*|*)
          eval "$2=\"5.10\""
        ;;
      esac
      ;;
    Gentoo*|gentoo*)
      eval "$1=\"gentoo\""
      case "${!2}" in
        2005*|*)
          eval "$2=\"2005.1\""
        ;;
      esac
    ;;
    SuSE*|suse*|Suse*|SuSe*|SUSE*|*)
      eval "$1=\"suse\""
      case "${!2}" in
        9*)
          eval "$2=\"9.3\""
        ;;
        10.0)
          eval "$2=\"10.0\""
        ;;
        10*)
          eval "$2=\"10.1\""
        ;;
      esac
    ;;
  esac
}


configure() {
  export LANG="c"
  
  if [ -f .config ] ; then
    echo -n "Use values from last installation? [Y/n] "
    read userinput
    if [ "x$userinput" = "xn" ] ; then
      cp .config.default .config
    fi
  else
    cp .config.default .config
  fi
  . .config

  # TODO: assure that values get entered only once in .config

  # TODO: bash doesnt allow concatenation of more than 2 logical expressions
  if ! [ -z $netmask -a -z $broadcast -a -z $netname -a -z $server ] ; then
    ipcfg=( `ifconfig eth0 | grep "inet addr" | sed -e "s,[a-zA-Z]*:,,g"` )
    netmask=${ipcfg[3]}
    broadcast=${ipcfg[2]}
  # quickhack (more intelligent solution needed ...)
    netname=`route -n | grep -m 1 eth0 | grep -v "UG" | awk '{ print $1 }'`
    server=${ipcfg[1]}
  fi


  # try to detect server architecture
  if [ -z "${server_distro}" ] ; then
    for i in /bin/lsb_release /usr/bin/lsb_release; do
      if [ -e $i ] ; then
        $i > /dev/null 2>&1 || break
        server_distro=`. $i -i | sed "s/.*\t//"`
        server_distro_ver=`. $i -r | sed "s/.*\t//"`
        break
      fi
    done
  fi

  # if still no distro name set, try to find it using significant files
  if [ -z "${server_distro}" ] ; then
    if [ -e ${rootdir}/etc/SuSE-release ] ; then
      server_distro=suse
      server_distro_ver=`grep "VERSION" /etc/SuSE-release | sed "s/.*= //"`
    elif [ -e /etc/lsb-release ] ; then
      . /etc/lsb-release
      server_distro=${DISTRIB_ID}
      server_distro_ver=${DISTRIB_RELEASE}
    elif [ -e /etc/debian_version ] ; then
      server_distro=debian
      server_distro_ver=`cat /etc/debian_version`
    fi
  fi

  # das grosse frage-antwort-spiel:
  ask "Server distribution: " server_distro ${server_distro}
  distro_check server_distro server_distro_ver
  echo "Using ${server_distro} as server distribution"
  
  # ask for client distro
  ask "Client distribution: " client_distro ${client_distro}
  distro_check client_distro client_distro_ver
  echo "Using ${client_distro} as client distribution"

  if [ -z ${rootdir} ] ; then
    ${rootdir}="/nfsroot/"${client_distro}-${client_distro_ver}
  fi

  . distro-specs/config-${server_distro}
  
  ask "Path for client system: " rootdir $rootdir
  ask "Path for tftpboot: " tftpbootdir $tftpbootdir
  ask "Which network do you want to use for DXS? (A.B.C.0) " netname $netname
  ask "Which netmask should be used? (255.B.C.0): " netmask $netmask
  ask "What is your servers IP for NFS, DHCP and TFTP? " server $server
  # noetig??
  ask "Broadcast Address: " broadcast $broadcast

  # evtl. optional?
  ask "Where automount home directories from? (A.B.C.D:/home-dir)" amt $server":/home"

  # more information here!! set useful default
  ask "Which debug level should be used? " debuglevel $debuglevel

  # wo ist das referenzsystem? - was ist default ???
  ask "IP + Path to reference system: " rsyncsource "localhost:/"
  
  # hier auch dns-server etc abfragen??

  # nfs / nbd / squash-fs?


  # password for pxeboot-menu (caution: you can easily retrieve it in clear text!!)
  pxe_passwd="master"
}


copy_system() {
  echo -e "\n\nSyncing system now\nPlease enter root password of client machine\n"
  rsync -avDe ssh --delete --exclude-from=distro-specs/exclude-${client_distro} ${rsyncsource} ${rootdir}
  # generate error message in case rsync didn't work and exit.
  
  # mksquashfs (background process)   
}


# setting up server site configuration files etc.
setup_server () {
  echo -e "\n\nSetting up server configuration\n"
  # dhcp
  if [ -f ${dhcpd_conf} ] ; then
    echo "Copying old dhcpd.conf to dhcpd.conf.dxs.bak"
    mv ${dhcpd_conf} ${dhcpd_conf}.dxs.bak
  fi
  cp default_files/dhcpd.conf ${dhcpd_conf}
  sed -e "s,@@@server@@@,${server},g" -e "s,@@@netname@@@,${netname},g" -e "s,@@@netmask@@@,${netmask},g" -e "s,@@@broadcast@@@,${broadcast},g" -i ${dhcpd_conf}

  # TODO: sed -e @@@example1@@@, netname+1 etc.

  # atftpd
  if [ -f ${atftpd_conf} ] ; then
    echo "Copying old atftpd config file to ${atftpd_conf}.dxs.bak"
    cp ${atftpd_conf} ${atftpd_conf}.dxs.bak
  fi
  ## TODO: MISSING COPY - DISTRO SPECIFIC!!
  sed -e "s,/tftpboot,${tftpbootdir}," -i ${atftpd_conf}

  # nfs
  exports_conf="/etc/exports"
  if [ -f ${exports_conf} ] ; then
    echo "Copying old nfs export file to ${exports_conf}.dxs.bak"
    mv ${exports_conf} ${exports_conf}.dxs.bak
  fi
  echo "${rootdir} ${netname}/${netmask}(ro,no_root_squash,async)" >> ${exports_conf}
  
  # pxe
  if [ -e ${tftpbootdir} ] ; then
    echo "Copying old tftpboot directory to ${tftpbootdir}.dxs.bak"
    rm -rf ${tftpbootdir}.dxs.bak >/dev/null
    mv ${tftpbootdir} ${tftpbootdir}.dxs.bak
  fi
  cp -r default_files/tftpboot ${tftpbootdir}
  sed -e "s,@@@server@@@,${server},g" -e "s,@@@tftpbootdir@@@,${tftpbootdir},g" -e "s,@@@pxe_passwd@@@,${pxe_passwd},g" -e "s,@@@client_distro@@@,${client_distro},g" -e "s,@@@client_distro_ver@@@,${client_distro_ver},g" -e "s,@@@rootdir@@@,${rootdir},g" -i ${tftpbootdir}/pxelinux.cfg/default

  
  # make services start  -- do we really want to do this?
}


create_initrd() {
  # FIXME: mkdxsinitrd currently wants to run from own directory
  ../initrd/mkdxsinitrd -r ${rootdir}
  
  # generate links to kernel and initial ramdisk
  ln -s ${rootdir}/boot/vmlinuz ${tftpbootdir}
  ln -s ${rootdir}/boot/initrd ${tftpbootdir}

  # TODO: assure that vmlinuz and initrd exist!!
}


footer() {
  echo -e "\nPlease assure to restart atftpd, nfs-kernel-server and dhcpd!\n"
  echo -e "\nInstallation finished.\n"
}


## ------ MAIN ------ ##

header
precheck #(run as root, rsync etc.)
configure
copy_system
setup_server
create_initrd

footer