This commit was manufactured by cvs2svn to create tag
[opensuse:installation-images.git] / data / initrd / s390 / inst_source
1 #!/bin/sh
2 #
3 #       Ask the user for the installation-Source
4 #
5 : ${INST_INFO:=nothing}
6 : ${INST_IP_ADDR:=250.250.250.250}
7 : ${INST_IP_DIR:=empty}
8 : ${INST_SCREEN:=nothing}
9 : ${INST_X_ADDR:=251.251.251.251}
10 : ${VNC_PASSWORD:=1234}
11 ANSW=empty
12 #
13 #
14 #
15 # to preserve the script from doing anything real, call it with
16 # CONDOM=echo
17 : ${CONDOM:=}
18 #
19 #
20 #
21 SOURCE_TXT1="Please specify the installation Source:\n\n    1) NFS\n    2) SAMBA\n    3) FTP\n    0) Abort\n\nChoice: "
22 IP_TXT1="Please enter the IP-Number of the host providing the installation media: "
23 IP_SERVER_TXT1="Please enter the IP-Number of the host running the X-Server: "
24 IP_ERROR1="\n Host is not reponding. please enter a new number\n"
25 DIR_TXT1="Please enter the directory of the installation media: "
26 ASK_VALID="Is the following correct?\\\n\\\n    Installation Source:  \$INST_INFO\\\n    IP-Address:           \$INST_IP_ADDR\\\n    Directory:            \$INST_IP_DIR\\\n\\\nYes/No: "
27 SCREEN_TXT1="Which terminal do want to use?\n\n    1) X-Window\n    2) VNC (VNC-Client or Java enabled Browser)\n    3) ssh\n    Choice: "
28 MOUNT_ERR="CD not mounted. Please check parameters."
29 ENTER_YES_NO="Please enter yes or no."
30 FTPUSERTXT="Please enter the username for the FTP-access (for anonymous just press enter): "
31 FTPPASSWORDTXT="Please enter the password for the FTP-Access (for anonymous just press enter): "
32 FTP_ERR="FTP-Server or directory not acessable. Please check parameters."
33 SMBUSERTXT="Please enter the username for the SMB-access (for guest just press enter): "
34 SMBPASSWORDTXT="Please enter the password for the SMB-Access (for guest just press enter): "
35 WORKDOMAINTXT="Please enter the Domain (for no domain just press enter): "
36 FTP_ASK_VALID="Is the following correct?\\\n\\\n    FTP User:  \$FTPUSER\\\n    FTP Password:           \$FTPPASSWORD\\\n\\\nYes/No: "
37 SMB_ASK_VALID="Is the following correct?\\\n\\\n    SMB User:  \$FTPUSER\\\n    SMB Password:           \$FTPPASSWORD\\\n    Domain:   \$WORKDOMAIN\\\n\\\nYes/No: "
38 VNC_PASSWORD_TXT="Please enter the Password for VNC-Access (6 to 8 characters): "
39 VNC_PASSWORD_ERROR="Passwort is too short. Please enter a new one.\n"
40 #
41 # checks an IP to have numbers only between 0 and 255:
42 #
43 # example:
44 # if echo $IP_ADDR | check_ip; then ...
45 #
46 function check_ip()
47 {
48         IFS=". " read ip1 ip2 ip3 ip4 rest
49         for i in ip1 ip2 ip3 ip4
50         do
51                 eval x=\$$i
52                 [ "$x" = "" ] && return 1
53                 if [ "$x" -lt 0 -o "$x" -gt 255 ]; then
54                         echo "$x: Value must be between 0 and 255"
55                         return 1
56                 fi
57         done
58         return 0
59 }
60 #
61 #
62 #
63 ask_source()
64 {
65 #
66 while :
67 do
68    echo -en $SOURCE_TXT1
69    source=$INST_INFO
70    [ "$AUTOINSTALL" = "yes" ] || read source
71    case $source in
72         1|nfs) INST_INFO=nfs ; break ;;
73         2|SAMBA) INST_INFO=SAMBA ; break ;;
74         3|ftp) INST_INFO=ftp ; break ;;
75         0) INST_INFO=ABORT ; break ;;
76         *) ;;
77    esac
78    INST_INFO="nothing"
79 done
80 #
81 } # ask_source
82 #
83 #
84 # yes_no reads either a yes or a no into $ANSW
85 #
86 function yes_no () {
87   while :; do
88     read ANSW
89     case "$ANSW" in
90       [yY] | [yY][eE][sS]) ANSW=yes
91                      break;;
92       [nN] | [nN][oO])  ANSW=no
93                      break;;
94     esac
95     echo $ENTER_YES_NO
96   done
97 }
98
99 #
100 # asks user whether to ignore the previous error
101 #
102 function continue_anyway()
103 {
104         echo
105         echo 'Do you want to ignore this error and continue anyway? (Yes/No)'
106         yes_no
107         if test "$ANSW" = "yes"
108         then
109                 return 0
110         else
111                 return 1
112         fi
113 }
114
115 #
116 #       Ask for the IP-Number of the server for nfs/samba/ftp/http
117 #
118 ask_ip()
119 {
120 while :
121 do
122         echo -en $IP_TXT1
123         ip=$INST_IP_ADDR
124         [ "$AUTOINSTALL" = "yes" ] || read ip
125         [ "$ip" = "" ] && continue
126         if echo $ip | check_ip
127         then
128                 INST_IP_ADDR=$ip
129                 $CONDOM ping -w 10 -n -c 3 $INST_IP_ADDR
130                 [ $? -eq 0 ] && break
131                 echo -en $IP_ERROR1
132                 continue_anyway && break
133         fi
134 done
135 } # ask_ip
136 #
137 #       Ask for the IP-Number of the X-server
138 #
139 ask_ip_server()
140 {
141 while :
142 do
143         echo -en $IP_SERVER_TXT1
144         ip=$INST_X_ADDR
145         [ "$AUTOINSTALL" = "yes" ] || read ip
146         [ "$ip" = "" ] && continue
147         if echo $ip | check_ip
148         then
149                 INST_X_ADDR=$ip
150                 $CONDOM ping -w 10 -n -c 3 $INST_X_ADDR
151                 [ $? -eq 0 ] && break
152                 echo -en $IP_ERROR1
153                 continue_anyway && break
154         fi
155 done
156 } # ask_ip_server
157 #
158 #       Ask for the directory of the install image
159 #
160 ask_dir()
161 {
162 while :
163 do
164         echo -en $DIR_TXT1
165         [ "$AUTOINSTALL" = "yes" ] || read INST_IP_DIR
166         [ -z "$INST_IP_DIR" ] && continue
167         if `echo $INST_IP_DIR | grep -v "^/" > /dev/null`
168         then
169                 INST_IP_DIR=/$INST_IP_DIR
170         fi
171         break;
172 done
173 } # ask_dir
174 #
175 #
176 #
177 ask_screen()
178 {
179 while :
180 do
181         echo -en $SCREEN_TXT1
182         [ "$AUTOINSTALL" = "yes" ] || read INST_SCREEN
183         case $INST_SCREEN in
184                 1|X) INST_SCREEN=X
185                    break
186                 ;;
187                 2|VNC) INST_SCREEN=VNC
188                    while :
189                    do
190                            echo -en $VNC_PASSWORD_TXT
191                            [ "$VNC_PASSWORD" = "1234" ] && read VNC_PASSWORD
192                            [ ${#VNC_PASSWORD} -gt 5 ] && break
193                            echo -en $VNC_PASSWORD_ERROR
194                            VNC_PASSWORD="1234"
195                    done
196                    break
197                 ;;
198                 3|SSH) INST_SCREEN=SSH
199                    break
200                 ;;
201                 *) INST_SCREEN=nothing
202                 ;;
203         esac
204 done
205 } # ask_screen
206 #
207 #       Installation via NFS
208 #
209 nfs_install()
210 {
211 #
212 #       Mount filesystems and start yast
213 #
214 $CONDOM mount -t nfs $INST_IP_ADDR:$INST_IP_DIR /var/adm/mount -o ro
215 if [ ! \( -d /var/adm/mount/boot -o -d /var/adm/mount/CD1/boot \) -a -z "$CONDOM" ]
216 then
217         echo $MOUNT_ERR
218         NO_ERROR=no
219         return 0
220 fi
221 umount /var/adm/mount
222 return 1
223 }
224 #
225 #       Installation via SAMBA
226 #
227 samba_install()
228 {
229 #
230 #     Ask for domain/username/PW
231 #
232 while :
233 do
234         echo -en $SMBUSERTXT
235         FTPUSER=$SAMBAUSER
236         [ "$AUTOINSTALL" = "yes" -a "$NO_ERROR" = "yes" ] || read FTPUSER
237 #       [ -z "$FTPUSER" ] && continue
238         echo -en $SMBPASSWORDTXT
239         FTPPASSWORD=$SAMBAPASSWORD
240         [ "$AUTOINSTALL" = "yes" -a "$NO_ERROR" = "yes" ] || read FTPPASSWORD
241 #       [ -z "$FTPPASSWORD" ] && continue
242         echo -en $WORKDOMAINTXT
243         [ "$AUTOINSTALL" = "yes" -a "$NO_ERROR" = "yes" ] || read WORKDOMAIN
244 #       [ -z "$WORKDOMAIN" ] && continue
245         eval echo -en $SMB_ASK_VALID
246         ANSW=yes
247         [ "$AUTOINSTALL" = "yes" -a "$NO_ERROR" = "yes" ] || yes_no
248         [ "$ANSW" = "yes" ] && break
249 done
250 #
251 #       Mount filesystems and start yast
252 #
253 # $CONDOM mount -t smbfs //$INST_IP_ADDR/$INST_IP_DIR /var/adm/mount -o ro
254 # if [ ! \( -d /var/adm/mount/boot -o -d /var/adm/mount/CD1/boot \) -a -z "$CONDOM" ]
255 # then
256         # echo $MOUNT_ERR
257         # return 0
258 # fi
259 # umount /var/adm/mount
260 return 1
261 }
262 #
263 #       Installation via FTP
264 #
265 ftp_install()
266 {
267 while :
268 do
269         echo -en $FTPUSERTXT
270         [ "$AUTOINSTALL" = "yes" -a "$NO_ERROR" = "yes" ] || read FTPUSER
271 #       [ -z "$FTPUSER" ] && continue
272         echo -en $FTPPASSWORDTXT
273         [ "$AUTOINSTALL" = "yes" -a "$NO_ERROR" = "yes" ] || read FTPPASSWORD
274 #       [ -z "$FTPPASSWORD" ] && continue
275         eval echo -en $FTP_ASK_VALID
276         ANSW=yes
277         [ "$AUTOINSTALL" = "yes" -a "$NO_ERROR" = "yes" ] || yes_no
278         [ ! "$ANSW" = "yes" ] && continue
279         IP_FTP_USER=$FTPUSER
280         IP_FTP_PASSWORD=$FTPPASSWORD
281         [ -z "$IP_FTP_USER" ] && IP_FTP_USER=anonymous
282         [ -z "$IP_FTP_PASSWORD" ] && IP_FTP_PASSWORD=bla_fasel
283 #
284         NETRC=/tmp/.netrc
285         HOME=/tmp
286 #
287         echo "machine $INST_IP_ADDR" > $NETRC
288         echo "login $IP_FTP_USER" >> $NETRC
289         echo "password $IP_FTP_PASSWORD" >> $NETRC
290         chmod 0600 $NETRC
291 #
292         ftp  <<EOF 2>&1 > /dev/null
293 open $INST_IP_ADDR
294 cd $INST_IP_DIR
295 get content /tmp/content
296 quit
297 EOF
298         if [ -f /tmp/content ]
299         then
300                 rm /tmp/content
301                 break
302         else
303                 echo $FTP_ERR
304                 NO_ERROR=no
305                 return 0
306         fi
307 done
308 return 1
309 }
310 #
311 #       Write /etc/install.inf and /etc/netsetup.inf
312 #
313 write_info_file()
314 {
315 #       SetupNetIf: 0 prevents linuxrc from configuring the interface
316         echo -en "Language: en_US\nKeytable: us\nSetupNetIF: 0\nTextmode: 0\nManual: 0\n" > $INFOFILENAME
317         grep "^IP:"  $NETSETUPFILE >> $INFOFILENAME
318         grep "^Gateway:"  $NETSETUPFILE >> $INFOFILENAME
319         grep "^Nameserver:"  $NETSETUPFILE >> $INFOFILENAME
320         grep "^Machinename:"  $NETSETUPFILE | sed -e "s/Machinename/Hostname/">> $INFOFILENAME
321         grep "^Netmask:"  $NETSETUPFILE >> $INFOFILENAME
322         echo "Server: $INST_IP_ADDR" >> $INFOFILENAME
323         echo "Serverdir: $INST_IP_DIR" >> $INFOFILENAME
324         echo "Instmode: $INST_INFO" >> $INFOFILENAME
325         [ "$INST_INFO" = "ftp" ] && echo "Install: ftp://$INST_IP_ADDR$INST_IP_DIR" >> $INFOFILENAME
326         [ "$INST_INFO" = "SAMBA" ] && echo "Install: smb://$INST_IP_ADDR$INST_IP_DIR" >> $INFOFILENAME
327         [ ! -z "$FTPUSER" ] && echo "Username: $FTPUSER" >> $INFOFILENAME
328         [ ! -z "$FTPPASSWORD" ] && echo "Password: $FTPPASSWORD" >> $INFOFILENAME
329         [ ! -z "$WORKDOMAIN" ] && echo "WorkDomain: $WORKDOMAIN" >> $INFOFILENAME
330         case $INST_SCREEN in
331                 X)
332                         echo "Display_IP: $INST_X_ADDR" >> $INFOFILENAME
333                         echo "Display_IP: $INST_X_ADDR" >> $NETSETUPFILE
334                 ;;
335                 VNC)
336                         echo "VNC: 1" >> $INFOFILENAME
337                         echo "VNCPassword: $VNC_PASSWORD" >> $INFOFILENAME
338                 ;;
339                 SSH)
340                         echo "UseSSH: 1" >> $NETSETUPFILE
341 #
342 #                       Setting console to this value
343 #                       means, that yast is asking for the terminaltype
344 #
345 #                       echo "Console: ttyS0,9600" >> $NETSETUPFILE
346                 ;;
347                 *)
348                 ;;
349         esac
350 } # write_info_file
351 #
352 #       MAIN
353 #
354 if [ ! -z "$CONDOM" ]
355 then
356         INFOFILENAME="./info.txt"
357         NETSETUPFILE="./netsetup.inf"
358 else
359         INFOFILENAME="/info"
360         NETSETUPFILE="/etc/netsetup.inf"
361 fi
362 #
363 #       if INST_INFO is not set, turn off AUTOINSTALL
364 #
365 [ "$INST_INFO" = "nothing" ] && AUTOINSTALL=no
366 #
367 #
368 #
369 NO_ERROR=yes
370         while :
371         do
372                 ask_source
373                 echo
374                 [ "$INST_INFO" = ABORT ] && break
375 #               echo $INST_INFO
376 #
377                 ask_ip
378                 echo
379 #               echo $INST_IP_ADDR
380 #
381                 ask_dir
382                 echo
383 #               echo $INST_IP_DIR
384
385                 eval echo -en $ASK_VALID
386                 ANSW=yes
387                 [ "$AUTOINSTALL" = "yes" -a "$NO_ERROR" = "yes" ] || yes_no
388                 [ "$ANSW" = "no" ] && continue
389 #
390 #               Parameters are valid
391 #               Get the source
392 #
393                 case $INST_INFO in
394                         nfs)
395                                 nfs_install || break
396                         ;;
397                         SAMBA)
398                                 samba_install || break
399                         ;;
400                         ftp)
401                                 ftp_install || break;
402                         ;;
403                         *)
404                         ;;
405                 esac
406                 NO_ERROR=no
407         done
408 #
409 #       Filesystem and files are ready
410 #       Ask the user for VNC or X-Windows
411 #
412 if [ "$INST_INFO" != "ABORT" ]
413 then
414         while :
415         do
416 #
417 #               Ask what to use: X, VNC or ssh
418 #
419                 ask_screen
420                 echo
421                 if [ "$INST_SCREEN" = "X" ]
422                 then
423 #
424 #                       We use X-Windows. Ask for IP-Number of Server
425 #
426                         ask_ip_server
427                         echo
428                 fi
429 #               export INSTSYS=/var/adm/mnt
430                 case $INST_SCREEN in
431                         X)
432                                 export DISPLAY=$INST_X_ADDR:0.0
433                                 break
434                         ;;
435                         VNC)
436                                 export VNC=1
437                                 break
438                         ;;
439                         SSH)
440                                 break
441                         ;;
442                         *)
443                         ;;
444                 esac
445         done
446 #
447 #
448 #
449         write_info_file
450 #
451 #       kill portmap (#18461)
452 #
453 for i in /proc/[0-9]*
454 do
455         grep -s portmap $i/cmdline > /dev/null
456         if [ $? = 0 ]
457         then
458                 OLDIFS=$IFS
459                 IFS="/$OLDIFS"
460                 set -- $i
461                 IFS=$OLDIFS
462                 kill $3
463         fi
464 done
465 #
466 #       Start linuxrc
467 #
468 $CONDOM /bin/linuxrc
469 #
470         [ ! -z "$CONDOM" ] && set
471 #
472 #       Endif !ABORT
473 fi
474 :