Subversion Repositories livecd

Rev

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