summaryrefslogtreecommitdiffstats
path: root/installer/ld4-inst
blob: f4d42f8f2e7f55ebf7f2bcca80debfc44a98c79e (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
#! /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

  # check for existing programs: 
    # rsync (server-side) -> which
    # 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
  {!2}=$back
  echo "$2=\"$back\"" >> .config
}

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

  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

  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

  . config-${server_distro}
  
  # das grosse frage-antwort-spiel:
  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"

  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?
}


copy_system() {
  rsync -avDe ssh --delete --exclude-from=distro-specs/exclude-${client_distro} ${rsyncsource} ${rootdir}
    
  # mksquashfs
}

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

  # atftpd
  if [ -f ${atftpd_conf} ] ; then
    echo "Copying old atftpd config file to ${atftpd_conf}.bak"
    cp ${atftpd_conf} ${atftpd_conf}.bak
  fi
  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}.bak"
    mv ${exports_conf} ${exports_conf}.bak
  fi
  
  # make services start
}


create_initrd() {

}


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

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