Subversion Repositories livecd

Rev

Rev 71 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 beyerle@PS 1
#!/bin/bash
2
#
3
# Fix things during bootup - run last 
4
#
5
# Urs Beyerle, PSI
6
#
7
 
8
### -----------------------------------------------------------
9
### definitions
10
### -----------------------------------------------------------
11
 
12
# dir of mounted live system: /$MOUNTDIR/live
13
MOUNTDIR=livecd
14
 
15
# source functions
16
. /$MOUNTDIR/live/liblinuxlive
17
. /etc/init.d/functions
18
 
71 beyerle@PS 19
# defaults for xorg.conf
20
XORG_CONF=/etc/X11/xorg.conf
21
HSYNC_DEFAULT="30.0-80.0"
22
VSYNC_DEFAULT="50.0-90.0"
23
SCREEN_DEFAULT="1280x1024"
24
MODES_DEFAULT='"2048x1536" "1920x1200" "1600x1200" "1400x1050" "1280x1024" "1280x960" "1280x800" "1152x864" "1152x768" "1024x768" "800x600" "640x480"'
1 beyerle@PS 25
 
71 beyerle@PS 26
 
1 beyerle@PS 27
### -----------------------------------------------------------
28
### Get boot parameters
29
### -----------------------------------------------------------
30
 
31
# root on NFS?
32
NFSROOT=$( cmdline_value nfsroot )
33
 
34
# NFS Server
35
NFSSERVER=$( echo $NFSROOT | cut -d":" -f1 )
36
 
37
# no local user?
38
NOLOCAL=$( cmdline_parameter nolocal )
39
 
40
# no root user?
41
NOROOT=$( cmdline_parameter noroot )
42
 
43
# no localadmin?
44
NOADMIN=$( cmdline_parameter noadmin )
45
LocalAdminGroup=localadmin
46
 
47
# set password
48
PASSWD=$( cmdline_value passwd )
49
[ ! $PASSWD ] && PASSWD=$( cmdline_value pw )
50
 
51
# no password = empty password ?
52
NOPASSWD=$( cmdline_parameter nopasswd )
53
 
54
# keyboard layout (kb= or keyboard=)
55
KEYBOARD=$( cmdline_value keyboard )
56
KB=$( cmdline_value kb )
57
 
58
# PSI setup?
59
PSI=$( cmdline_parameter psi )
60
 
61
# cups server
62
CUPS=$( cmdline_value cups )
63
 
64
# failsafe X server
65
SIMPLEX=$( cmdline_parameter simplex )
66
 
67
# NVIDIA driver
68
NVIDIA=$( cmdline_parameter nvidia )
69
if [ "$XDRIVER" = "nvidia" ]; then
70
    NVIDIA=nvidia
71
fi
72
 
73
# force NO NVIDIA driver - will overwite NVIDIA option
74
NONVIDIA=$( cmdline_parameter nonvidia )
75
 
76
# VESA driver
77
VESA=$( cmdline_parameter vesa )
78
 
79
# force to use a video driver ?
80
XDRIVER=$( cmdline_value xdriver )
81
 
82
# Xserver configurations
83
HSYNC=$( cmdline_value hsync )
84
VSYNC=$( cmdline_value vsync )
85
SCREEN=$( cmdline_value screen )
86
 
87
# no SWAP
88
NOSWAP=$( cmdline_parameter noswap )
89
 
90
# should we auto mount all found devices?
91
AUTOMOUNT=$( cmdline_parameter automount )
92
if [ $AUTOMOUNT ]; then
93
    MOUNTOPT="auto,users"
94
else
95
    MOUNTOPT="noauto,users,ro"
96
fi
97
 
98
# folder where we find data which was previously stored
99
# (normally on a usbstick, but can be partition)
100
if [ $PSI ]; then
101
    SAVEFOLDER=PSI_LIVECD
102
else
103
    SAVEFOLDER=SL_LIVECD
104
fi
105
 
106
# local home partition?
107
# (e.g. /dev/hda1, /dev/hda1:/my_home)
108
HOMELOCAL=$( cmdline_value home )
109
 
110
# fast booting ?
111
FASTBOOT=$( cmdline_parameter fastboot )
112
 
113
# start afs?
114
AFS=$( cmdline_parameter afs )
115
 
116
# or force no afs
117
[ $( cmdline_parameter noafs ) ] && AFS=""
118
 
119
# turn of sound (volume=0)
120
NOSOUND=$( cmdline_parameter nosound )
121
 
122
# local user name?
123
LOCALUSER=$( cmdline_value user )
124
 
125
# hostname?
126
HOSTNAME=$( cmdline_value hostname )
127
 
128
# do we have defined a configuration directory?
129
CONFIG=$( cmdline_value config )
130
 
131
# do not udpate fstab?
132
NOFSTAB=$( cmdline_parameter nofstab )
133
 
134
# kde/gnome as desktop
135
GNOME=$( cmdline_parameter gnome )
136
KDE=$( cmdline_parameter kde )
137
 
138
 
139
### -----------------------------------------------------------
140
### Improved hardware detection
141
### -----------------------------------------------------------
142
 
143
### Improved graphic card detection?
144
 
145
if [ ! $SIMPLEX ]; then
146
 
147
    ### Intel Mobile 945GM
148
    lspci | grep -q VGA.*Intel.*Mobile.*945GM
149
    if [ "$?" = "0" ]; then
150
	I945GM=i945gm
151
	## not yet supported by i810 driver
152
        ## [ $XDRIVER ] || XDRIVER=i810
153
	I915RESOLUTION=on
154
    fi
155
    ### Intel Mobile 915GM
156
    lspci | grep -q VGA.*Intel.*Mobile.*915GM
157
    if [ "$?" = "0" ]; then
158
	I915GM=i915gm
159
	[ $XDRIVER ] || XDRIVER=i810
160
	I855RESOLUTION=on
161
    fi
162
 
163
    ### Intel Mobile 855GM
164
    lspci | grep -q VGA.*Intel.*855GM
165
    if [ "$?" = "0" ]; then
166
	I855GM=i855gm
167
	I855RESOLUTION=on
168
    fi
169
fi
170
 
171
 
172
### -----------------------------------------------------------
173
### Main
174
### -----------------------------------------------------------
175
 
176
### try load fuse kernel module
177
modprobe fuse 2>/dev/null
178
 
179
### activate SWAP
180
# delete all swap lines in fstab
181
 sed -i -e "/ swap /d" /etc/fstab
182
# search for swap partition
183
fdisk -l > /var/log/fdisk
184
swap_part=$( fdisk -l 2>/dev/null | grep -i "Linux swap" \
185
            | grep "^/dev/" | cut -f 1 -d " " | head -1 )
186
# add to /etc/fstab and activate SWAP
187
if [ $swap_part ] && [ ! $NOSWAP ]; then
188
    echo "$swap_part               swap                    swap    defaults 0 0" >>/etc/fstab
189
    # activate SWAP
190
    swapoff -a
191
    swapon -a -e
192
fi
193
 
194
### MAC Address of eth0
195
MAC_ETH0=$( ifconfig | grep eth0 | awk '{print $5}' )
196
 
197
### Get CONFIG_FOLDER for this machine from NFS Server (if existing) 
198
#   and copy it to /$MOUNTDIR
199
if [ $NFSSERVER ] && [ $CONFIG ]; then
200
    mkdir -p /mnt/config
201
    echo "Search for configuration files on the server ..."
202
    /etc/init.d/portmap start >/dev/null
203
    mount -t nfs $NFSSERVER:$CONFIG /mnt/config 2>/dev/null
204
    if [ "$?" != "0" ]; then
205
	echo "Could not mount $NFSSERVER:$CONFIG."
206
    else
207
	if [ -d /mnt/config/$MAC_ETH0 ]; then
208
	    CONFIG_FOLDER=/$MOUNTDIR/config
209
	    mkdir -p $CONFIG_FOLDER
210
	    cp -a /mnt/config/$MAC_ETH0/* /$CONFIG_FOLDER/ 2>/dev/null
211
	    if [ "$?" != "0" ]; then
212
		echo "Could not get $NFSSERVER:$CONFIG/$MAC_ETH0"
213
		CONFIG_FOLDER=""
214
	    else
215
		echo "Found configuration files on the server." 
216
	    fi	    
217
	fi
218
	umount /mnt/config
219
    fi
220
    /etc/init.d/portmap stop >/dev/null
221
fi
222
 
223
### search for partitions and update fstab 
224
### and look for $SAVEFOLDER (previously stored data)
225
if [ ! $FASTBOOT ] && [ ! $NOFSTAB ]; then
226
    echo "Update /etc/fstab ..."
227
    # disable kernel messages during mount/unmount
228
    echo 0 > /proc/sys/kernel/printk
229
    DEVICES=$( list_partition_devices )
230
    for DEVICE in $DEVICES; do
231
        # try to mount the device and unmount it. 
232
        # If OK, we can add it to fstab
233
	DEV=$( echo $DEVICE | cut -d"/" -f 3 )
234
	if [ $DEV ]; then
235
	    mkdir -p /mnt/$DEV
236
	    mount $DEVICE /mnt/$DEV >/dev/null 2>&1
237
	    # search for $SAVEFOLDER
238
	    if [ -d /mnt/$DEV/$SAVEFOLDER ]; then
239
		FOUND_RESTORE_DEV=/dev/$DEV
240
		echo "Found folder '$SAVEFOLDER' on $FOUND_RESTORE_DEV"
241
	    fi
242
	    # unmount again
243
	    umount /mnt/$DEV >/dev/null 2>&1
244
	    # if sucsessful add to fstab, if not already done
245
	    if [ "$?" = "0" ]; then
246
		grep -q "^$DEVICE " /etc/fstab
247
		if [ "$?" != "0" ]; then
248
		    echo -e "$DEVICE \t /mnt/$DEV \t auto \t $MOUNTOPT,suid,dev,exec 0 0" >> /etc/fstab
249
		fi
250
	    else
251
		rmdir /mnt/$DEV 2>/dev/null
252
	    fi
253
	fi
254
    done
255
    # enable kernel messages again
256
    echo 6 > /proc/sys/kernel/printk
257
fi
258
 
259
### if $SAVEFOLDER found, set $CONFIG_FOLDER and mount $FOUND_RESTORE_MNT 
260
if [ $FOUND_RESTORE_DEV ]; then
261
    FOUND_RESTORE_MNT=$( grep "^$FOUND_RESTORE_DEV " /etc/fstab | awk '{ print $2 }' )
262
    CONFIG_FOLDER=$FOUND_RESTORE_MNT/$SAVEFOLDER
263
    echo "Will restore data from $CONFIG_FOLDER"
264
    mount $FOUND_RESTORE_MNT
265
fi
266
 
267
### source the file "config", if found in $CONFIG_FOLDER
268
if [ -f $CONFIG_FOLDER/config ]; then
269
    . $CONFIG_FOLDER/config
270
fi
271
 
272
### do we have a shadow/passwd file in $FOUND_FOULDER 
273
if [ -r $CONFIG_FOLDER/passwd.tar.gz ] && [ -r $CONFIG_FOLDER/shadow.tar.gz ]; then
274
    # we do not need a password for local user and root
275
    NOLOCAL=nolocal
276
    NOROOT=noroot
277
fi
278
 
279
### set local user name and default hostname
280
if [ $PSI ]; then
281
    [ $LOCALUSER ] || LOCALUSER=l_psi
282
    DEFAULT_HOSTNAME=psi
283
else
284
    [ $LOCALUSER ] || LOCALUSER=sluser
285
    DEFAULT_HOSTNAME=slinux
286
fi
287
 
288
### start 855resolution?
289
[ $I855RESOLUTION ] && /etc/init.d/855resolution start 2>/dev/null
290
 
291
### start 915resolution?
292
[ $I915RESOLUTION ] && /etc/init.d/915resolution start 2>/dev/null
293
 
294
### configure Xserver
295
 
296
### check for xorg.conf in CONFIG_FOLDER
297
if [ -r $CONFIG_FOLDER/xorg.conf ]; then
71 beyerle@PS 298
    cp -af $CONFIG_FOLDER/xorg.conf $XORG_CONF
1 beyerle@PS 299
    if [ "$?" = "0" ]; then
300
	echo "Saved xorg.conf file found."
301
	XDRIVER=""
302
	HAVE_XORG_CONF="yes"
303
    fi
304
fi
305
 
306
### use vesa driver?
307
if [ $VESA ]; then
308
    echo "Force to use VESA driver!"
309
    video_driver="--set-driver=vesa"
310
else
311
    video_driver=""
312
fi
313
 
314
### force an other video driver?
315
if [ $XDRIVER ]; then
316
    echo "Force to use $XDRIVER driver!"
317
    video_driver="--set-driver=$XDRIVER"
318
fi
319
 
71 beyerle@PS 320
### configure Xserver
1 beyerle@PS 321
if [ -x /usr/bin/system-config-display ]; then
322
    echo "Configure Xserver:"
323
    if [ ! $HAVE_XORG_CONF ]; then
324
	if [ ! $SIMPLEX ]; then
71 beyerle@PS 325
 
1 beyerle@PS 326
            # default values
71 beyerle@PS 327
	    [ ! $HSYNC ]  && HSYNC="$HSYNC_DEFAULT"
328
	    [ ! $VSYNC ]  && VSYNC="$VSYNC_DEFAULT"
329
	    [ ! $SCREEN ] && SCREEN="$SCREEN_DEFAULT"
330
 
331
            # run system-config-display 
1 beyerle@PS 332
	    system-config-display \
333
		--reconfig \
334
                -v \
335
		--set-resolution=$SCREEN \
336
		--set-hsync=$HSYNC \
337
		--set-vsync=$VSYNC \
338
		$video_driver | grep Trying
71 beyerle@PS 339
 
72 beyerle@PS 340
            # system-config-display in SL5 does not work nicely :-(
341
            # e.g. No Monitor Section
71 beyerle@PS 342
 
343
	    # add Monitor Section and add Monitor0 to Screen Section
344
	    grep -q Monitor $XORG_CONF
72 beyerle@PS 345
	    if [ "$?" != "0" ]; then
71 beyerle@PS 346
		echo    "Section \"Monitor\""          >> $XORG_CONF
347
		echo -e "\tIdentifier   \"Monitor0\""  >> $XORG_CONF
348
		echo -e "\tHorizSync    $HSYNC"        >> $XORG_CONF
349
		echo -e "\tVertRefresh  $VSYNC"        >> $XORG_CONF
350
		echo -e "\tOption       \"dpms\""      >> $XORG_CONF
351
		echo -e "EndSection"                   >> $XORG_CONF
352
                sed -i "s|Device     \"Videocard0\"|Device     \"Videocard0\"\n\tMonitor    \"Monitor0\"|" $XORG_CONF
353
	    fi
354
 
72 beyerle@PS 355
            # add Modes for $SCREEN, if not yet there
71 beyerle@PS 356
	    grep -q Modes $XORG_CONF
72 beyerle@PS 357
	    if [ "$?" != "0" ]; then
71 beyerle@PS 358
		modeline=$( echo ${MODES_DEFAULT} | sed "s|.*\"$SCREEN|\"$SCREEN|" )
359
		if [ "$modeline" ]; then
360
		    sed -i "s|\tDepth.*|\tDepth     24\n\t\tModes $modeline|" $XORG_CONF
361
		fi
362
	    fi
363
 
72 beyerle@PS 364
 
71 beyerle@PS 365
	# simple Xserver configuration.
1 beyerle@PS 366
	else
367
	    echo "Use simple Xserver configuration."
368
	    system-config-display --noui --reconfig -v | grep Trying
369
	fi
370
    fi
371
fi
372
 
71 beyerle@PS 373
 
1 beyerle@PS 374
### enable NVIDIA driver (needs nvidia, nvidia-libs rpms)
375
if [ $NVIDIA ] && [ ! $NONVIDIA ]; then
376
    # serach for Nvidia Video Card
377
    /sbin/lspci | grep VGA | grep -i -q nvidia
378
    if [ "$?" = "0" ]; then
379
	# lib or lib64 ?
380
	LIB=lib
381
	[ $( arch ) = "x86_64" ] && LIB=lib64
382
	# find out installed Nvidia driver version
383
	libglx=$( ls /usr/X11R6/$LIB/modules/extensions/libglx.so.1.* | head -n 1 )
384
	nvidia_version=${libglx##*.so.1.}
385
	# enable Nvidia driver (normally done by nvidia-enable - does not work on LiveCD)
386
	echo -n "NVIDIA graphic card found. Enable the nvidia driver ${nvidia_version} ... " 
387
	NVLOG=/var/log/nvidia.log
388
	# assuming that the kernel modules are already build 
389
	# link to Nvidia libs
390
	ln -sf ../../usr/X11R6/$LIB/libGL.so.1.${nvidia_version} /usr/$LIB/libGL.so
391
	ln -sf libGL.so.1.${nvidia_version} /usr/X11R6/$LIB/libGL.so
43 beyerle@PS 392
	mv /usr/X11R6/$LIB/modules/extensions/libGLcore.a /usr/X11R6/$LIB/modules/extensions/xxx.libGLcore.a.saved_by_nvidia
393
	mv /usr/X11R6/$LIB/modules/extensions/libglx.a /usr/X11R6/$LIB/modules/extensions/xxx.libglx.a.saved_by_nvidia
1 beyerle@PS 394
	ln -sf libglx.so.1.${nvidia_version} /usr/X11R6/$LIB/modules/extensions/libglx.so
395
	# reconfigure X
396
	/usr/sbin/nvidia-xconfig >> $NVLOG 2>&1
397
	if [ $PSI ]; then
398
	    echo 'NVIDIA=on' >> /etc/sysconfig/cfengine
399
	fi
400
	echo "ok."
401
    fi
402
fi
403
 
404
### set special video driver options for Intel Mobile
405
 
406
#   (external VGA output: Clone)
407
if [ $I915GM ] || [ $I855GM ]; then
408
    sed -e "/Section[ \t]*\"Device\"/,/EndSection/{
409
     /^[ \t]*Option[ \t]*\"MonitorLayout\"/d
410
     /^[ \t]*Option[ \t]*\"Clone/d
411
     /EndSection/i\\
412
        Option      \"MonitorLayout\" \"CRT,LFP\"\\
413
        Option      \"Clone\" \"1\"\\
414
        Option      \"CloneRefresh\" \"60\"
71 beyerle@PS 415
     }" -i $XORG_CONF
1 beyerle@PS 416
fi
417
 
418
# Set BoardName for Intel 915GM
419
if [ $I915GM ]; then
71 beyerle@PS 420
    sed -i 's/BoardName.*VESA driver.*/BoardName   "Intel 915"/' $XORG_CONF
1 beyerle@PS 421
fi
422
 
423
 
424
### parameter KB = KEYBOARD
425
KEYBOARD=$KB
426
 
427
### ask user for keyboard layout if no keyboard given
428
if [ -x /usr/bin/system-config-keyboard ]; then
429
    if [ ! $KEYBOARD ]; then
430
	MORE_LAYOUTS="more..."
431
	keytables="U.S...........(us) \
432
	           Swiss-German..(sg-latin1) \
433
                   Swiss-French..(fr_CH-latin1) \
434
                   German........(de-latin1) \
435
                   Japanese......(jp106) \
436
                   $MORE_LAYOUTS"
437
	PS3="-> "
438
	echo
439
	echo "Please choose keyboard layout (type 1-6):"
440
	select KEYBOARD in $keytables;
441
	  do
442
	     case $KEYBOARD in
443
	        *)
444
	        # extract keyboard layout string from $KEYBOARD
445
	        KEYBOARD=${KEYBOARD##*(}
446
                KEYBOARD=${KEYBOARD%%)}
447
                break
448
                ;;
449
	     esac
450
	  done
451
    fi
452
fi
453
 
454
### set keyboard
455
if [ -x /usr/bin/system-config-keyboard ]; then
456
    if [ "$KEYBOARD" = "$MORE_LAYOUTS" ]; then
457
	system-config-keyboard --text
458
    else
459
	echo -n "Set keyboard to '$KEYBOARD', please wait ... "
460
	system-config-keyboard --noui $KEYBOARD >/dev/null 2>&1
461
	echo "done."
462
    fi
463
    echo
464
fi
465
 
466
### update AFS users and SEPP links (only for PSI)
467
if [ $PSI ] && [ $AFS ]; then
468
    echo "Update AFS users and SEPP links..."
469
    [ -x /afs/psi.ch/sys/common/update_user.pl ] && /afs/psi.ch/sys/common/update_user.pl >/dev/null 2>&1 &
470
    [ -x /afs/psi.ch/sys/common/update_sepp.pl ] && /afs/psi.ch/sys/common/update_sepp.pl >/dev/null 2>&1 &
471
    echo
472
fi
473
 
474
### create local user, if "nolocal" is not set 
475
if [ ! $NOLOCAL ]; then
476
 
477
    user=$LOCALUSER
478
    # execute useradd twice, to make it work (don't know why)
479
    if [ $PSI ] && [ ! $NOADMIN ]; then
480
	userdel -r $user 2>/dev/null
481
	useradd -G $LocalAdminGroup $user 2>/dev/null
482
	userdel -r $user 2>/dev/null
483
	useradd -G $LocalAdminGroup $user
484
    else
485
	userdel -r $user 2>/dev/null
486
	useradd $user 2>/dev/null
487
	userdel -r $user 2>/dev/null
488
	useradd $user
489
    fi
490
 
491
    # only for PSI: change users's group to GID=UID+50000
492
    if [ $PSI ]; then
493
	uid=$( id -u $user )
494
	old_gid=$( id -g $user )
495
	new_gid=$(( $old_gid + 50000 ))
496
        # fix /etc/group
497
	sed -i "s/${user}:x:${old_gid}:/${user}:x:${new_gid}:/" /etc/group
498
        # fix /etc/passwd
499
	sed -i "s/${user}:x:${uid}:${old_gid}:/${user}:x:${uid}:${new_gid}:/" /etc/passwd
500
        # fix perm of /home/${user)
501
	chgrp -R $user /home/${user}
502
    fi
503
fi
504
 
505
### copy special files for PSI user l_psi
506
if [ $PSI ] && [ ! $NOLOCAL ]; then
507
    find /usr/share/${LOCALUSER}/ -maxdepth 1 -mindepth 1 2>/dev/null | \
508
    while read dir; do 
509
	cp -a $dir /home/${LOCALUSER}/
510
    done
511
    # set owner
512
    chown -R ${LOCALUSER}.${LOCALUSER} /home/${LOCALUSER}
513
fi
514
 
515
### set password for root and local user
516
if [ ! $NOPASSWD ]; then
517
    if [ ! $NOROOT ] || [ ! $NOLOCAL ]; then
518
	echo -n "Set password for "
519
	if [ ! $NOROOT ]; then
520
	    echo -n "'root' "
521
	fi
522
	if [ ! $NOROOT ] && [ ! $NOLOCAL ]; then
523
	    echo -n "and "
524
	fi
525
	if [ ! $NOLOCAL ]; then
526
	    echo -n "local user '$user' "
527
	fi
528
	echo
529
 
530
	if [ ! $NOLOCAL ]; then
531
	    echo "Login as local user '$user' with this password."
532
	    echo
533
	fi
534
 
535
        # set password, if not yet given by $PASSWD
536
	until [ $PASSWD ]; do
537
	    echo -n "Password: "
538
	    read -s PASSWD
539
	    echo
540
	done
541
	if [ ! $NOROOT ]; then
542
	    echo $PASSWD | passwd --stdin root >/dev/null
543
	fi
544
	if [ ! $NOLOCAL ]; then
545
	    echo $PASSWD | passwd --stdin $user >/dev/null
546
	fi
547
	echo
548
    fi
549
 
550
else
551
    # set root and $LOCALUSER to empty password
552
    sed -i "s|^root:.*|root::12345:0:99999:1:::|" /etc/shadow
553
    sed -i "s|^$LOCALUSER:.*|$LOCALUSER::12345:0:99999:1:::|" /etc/shadow
554
fi
555
 
556
### try to get hostname from DNS, if not yet defined
557
if [ ! $HOSTNAME ]; then
558
    echo "Try to get hostname from DNS ..."
559
    IP=$( /sbin/ip add show dev eth0 2>/dev/null | grep "inet " | cut -d" " -f6 | sed 's|/.*||' )
560
    if [ "$IP" = "" ]; then
561
	IP=$( /sbin/ip add show dev eth1 2>/dev/null | grep "inet " | cut -d" " -f6 | sed 's|/.*||' )
562
    fi
563
    if [ "$IP" != "" ]; then
564
	host -W 1 $IP >/dev/null 2>&1
565
	if [ "$?" = "0" ]; then
566
	    HOSTNAME=$( host -W 1 $IP | cut -d" " -f 5 | cut -d"." -f 1 )
567
	    if [ "$HOSTNAME" = "3(NXDOMAIN)" ]; then
568
		HOSTNAME=$DEFAULT_HOSTNAME
569
	    fi	
570
	    if [ "$HOSTNAME" = "no" ]; then
571
		HOSTNAME=$DEFAULT_HOSTNAME
572
	    fi	
573
	fi
574
    fi
575
fi
576
 
577
### define default hostname, if $HOSTNAME still not yet set
578
if [ ! $HOSTNAME ]; then
579
    HOSTNAME=$DEFAULT_HOSTNAME
580
fi
581
 
582
### set hostname
583
export HOSTNAME=$HOSTNAME
584
hostname $HOSTNAME
585
sed -i "s/HOSTNAME=.*/HOSTNAME=${HOSTNAME}/" /etc/sysconfig/network
586
if [ $PSI ]; then
587
    sed -i "s/hostname=.*/hostname=${HOSTNAME}.psi.ch/" /etc/ssmtp/ssmtp.conf
588
    sed -i "s/HOSTNAME=.*/HOSTNAME=${HOSTNAME}/" /etc/sysconfig/cfengine
589
fi
590
for iface in eth0 eth1 eth2 eth3; do
591
    if [ -e /etc/sysconfig/network-scripts/ifcfg-${iface} ]; then
592
	echo "DHCP_HOSTNAME=${HOSTNAME}" >> /etc/sysconfig/network-scripts/ifcfg-${iface}
593
    fi
594
done
595
 
596
echo "Hostname set to: $HOSTNAME"
597
echo
598
 
599
### set cups server
600
if [ $CUPS ]; then
601
    sed -i "s|.*ServerName .*|ServerName  $CUPS|" /etc/cups/client.conf
602
fi
603
 
604
### some magic: just access this file in order that it can be sourced later
605
ls -lag /etc/X11/xinit/xinitrc-common >/dev/null 2>&1
606
sleep 1
607
 
608
### set keyboard for rdesktop
71 beyerle@PS 609
if [ -e $XORG_CONF ]; then
610
    grep -q de_CH $XORG_CONF && RDESKTOP_OPT="-k de-ch"
611
    grep -q fr_CH $XORG_CONF && RDESKTOP_OPT="-k fr-ch"
612
    grep -q jp106 $XORG_CONF && RDESKTOP_OPT="-k ja"
1 beyerle@PS 613
fi
614
 
615
if [ "$RDESKTOP_OPT" ]; then
616
    echo "alias rdesktop='rdesktop $RDESKTOP_OPT'" > /etc/profile.d/rdesktop.sh
617
    echo "export RDESKTOP_OPT='$RDESKTOP_OPT'" >> /etc/profile.d/rdesktop.sh
618
    chmod 755 /etc/profile.d/rdesktop.sh
619
fi
620
 
621
### run setup script, if found in $CONFIG_FOLDER on $FOUND_RESTORE_MNT
622
if [ -r $CONFIG_FOLDER/setup ]; then
623
    CONFIG_FOLDER=$CONFIG_FOLDER bash $CONFIG_FOLDER/setup
624
fi
625
 
626
### umount $FOUND_RESTORE_MNT
627
if [ $FOUND_RESTORE_MNT ]; then
628
    echo "Unmount $FOUND_RESTORE_MNT"
629
    umount $FOUND_RESTORE_MNT 2>/dev/null
630
    sleep 3
631
fi
632
 
633
### local home partition?
634
if [ $HOMELOCAL ]; then
635
    mv /home /home.old
636
    mkdir -p /mnt/home_par
637
    # which partition? which folder?
638
    HOMEPAR=$( echo $HOMELOCAL | cut -d":" -f1 )
639
    HOMEDIR=$( echo $HOMELOCAL | grep ":" | cut -d":" -f2 )
640
    umount $HOMEPAR 2>/dev/null
641
    # mount it with option noatime, healthy for USB flash drives
642
    mount -o noatime -rw $HOMEPAR /mnt/home_par 2>/dev/null
643
    if [ "$?" != "0" ]; then
644
	echo "ERROR: Could not mount read/write $HOMEPAR"
645
	umount $HOMEPAR >/dev/null 2&>1
646
	mv /home.old /home
647
    else
648
	echo "$HOMEPAR mounted on /mnt/home_par"
649
	# link to new home
650
	ln -s /mnt/home_par/$HOMEDIR /home
651
	if [ ! -d /mnt/home_par/$HOMEDIR ]; then
652
	    echo "$HOMELOCAL not found on $HOMEPAR"
653
	    echo mkdir -p /mnt/home_par/$HOMEDIR
654
	    if [ "$?" != "0" ]; then
655
		echo "ERROR: Could not create $HOMELOCAL on $HOMEPAR"
656
		umount $HOMEPAR >/dev/null 2&>1
657
		rm -f /home
658
		mv /home.old /home
659
	    else
660
		echo "Folder $HOMEDIR created on $HOMEPAR"
661
	    fi
662
	fi
663
	if [ -d /mnt/home_par/$HOMEDIR ]; then
664
	    echo "/home is linked to /mnt/home_par${HOMEDIR}"
665
	    # copy files from /home.old to /home, which are not yet there
666
	    /bin/cp -a -i --reply=no /home.old/* /home/ 
667
	    rm -rf /home.old
668
	fi
669
    fi
670
    sleep 2
671
fi
672
 
673
### mount all if AUTOMOUNT set
674
if [ $AUTOMOUNT ]; then
675
    mount -a
676
fi
677
 
678
### unload/load sound module for snd-card-X (timing problem?)
679
rpm -q alsa-lib | grep el5 >/dev/null
680
if [ "$?" = "0" ]; then
681
    sound_modules=$( grep snd-card- /etc/modprobe.conf | awk ' $1 ~ /alias/ { print $3 }' | tr - _ )
682
    for module in $sound_modules; do
683
	lsmod | awk '{ print $1 }' | grep $module >/dev/null 2>&1
684
	if [ "$?" = "0" ]; then
685
	    rmmod $module    >/dev/null 2>&1
686
	    sleep 2
687
	    modprobe $module >/dev/null 2>&1
688
	fi
689
    done
690
fi
691
 
692
### unmute all mixers and set volumes
693
if [ -x /usr/bin/set-volume ]; then 
694
    if [ $NOSOUND ]; then
695
	/usr/bin/set-volume 0 > /var/log/set-volume.log 2>&1 &
696
    else
697
	/usr/bin/set-volume 60 > /var/log/set-volume.log 2>&1 &
698
    fi
699
fi
700
 
701
### set kde or gnome as desktop
702
if [ $KDE ]; then
703
    sed -i "/^DESKTOP=.*/d" /etc/sysconfig/desktop 2&>/dev/null
704
    echo "DESKTOP=KDE" >> /etc/sysconfig/desktop
705
fi
706
if [ $GNOME ]; then
707
    sed -i "/^DESKTOP=.*/d" /etc/sysconfig/desktop 2&>/dev/null
708
    echo "DESKTOP=GNOME" >> /etc/sysconfig/desktop
709
fi
710