Subversion Repositories livecd

Rev

Rev 48 | 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
 
340
            # system-config-display in SL5 does not really work :-(
341
            # e.g. no Monitor and resolution set
342
 
343
	    # add Monitor Section and add Monitor0 to Screen Section
344
	    grep -q Monitor $XORG_CONF
345
	    if [ "$" != "0" ]; then
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
 
355
            # add Modes for $SCREEN
356
	    grep -q Modes $XORG_CONF
357
	    if [ "$" != "0" ]; then
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
 
364
	# simple Xserver configuration.
1 beyerle@PS 365
	else
366
	    echo "Use simple Xserver configuration."
367
	    system-config-display --noui --reconfig -v | grep Trying
368
	fi
369
    fi
370
fi
371
 
71 beyerle@PS 372
 
1 beyerle@PS 373
### enable NVIDIA driver (needs nvidia, nvidia-libs rpms)
374
if [ $NVIDIA ] && [ ! $NONVIDIA ]; then
375
    # serach for Nvidia Video Card
376
    /sbin/lspci | grep VGA | grep -i -q nvidia
377
    if [ "$?" = "0" ]; then
378
	# lib or lib64 ?
379
	LIB=lib
380
	[ $( arch ) = "x86_64" ] && LIB=lib64
381
	# find out installed Nvidia driver version
382
	libglx=$( ls /usr/X11R6/$LIB/modules/extensions/libglx.so.1.* | head -n 1 )
383
	nvidia_version=${libglx##*.so.1.}
384
	# enable Nvidia driver (normally done by nvidia-enable - does not work on LiveCD)
385
	echo -n "NVIDIA graphic card found. Enable the nvidia driver ${nvidia_version} ... " 
386
	NVLOG=/var/log/nvidia.log
387
	# assuming that the kernel modules are already build 
388
	# link to Nvidia libs
389
	ln -sf ../../usr/X11R6/$LIB/libGL.so.1.${nvidia_version} /usr/$LIB/libGL.so
390
	ln -sf libGL.so.1.${nvidia_version} /usr/X11R6/$LIB/libGL.so
43 beyerle@PS 391
	mv /usr/X11R6/$LIB/modules/extensions/libGLcore.a /usr/X11R6/$LIB/modules/extensions/xxx.libGLcore.a.saved_by_nvidia
392
	mv /usr/X11R6/$LIB/modules/extensions/libglx.a /usr/X11R6/$LIB/modules/extensions/xxx.libglx.a.saved_by_nvidia
1 beyerle@PS 393
	ln -sf libglx.so.1.${nvidia_version} /usr/X11R6/$LIB/modules/extensions/libglx.so
394
	# reconfigure X
395
	/usr/sbin/nvidia-xconfig >> $NVLOG 2>&1
396
	if [ $PSI ]; then
397
	    echo 'NVIDIA=on' >> /etc/sysconfig/cfengine
398
	fi
399
	echo "ok."
400
    fi
401
fi
402
 
403
### set special video driver options for Intel Mobile
404
 
405
#   (external VGA output: Clone)
406
if [ $I915GM ] || [ $I855GM ]; then
407
    sed -e "/Section[ \t]*\"Device\"/,/EndSection/{
408
     /^[ \t]*Option[ \t]*\"MonitorLayout\"/d
409
     /^[ \t]*Option[ \t]*\"Clone/d
410
     /EndSection/i\\
411
        Option      \"MonitorLayout\" \"CRT,LFP\"\\
412
        Option      \"Clone\" \"1\"\\
413
        Option      \"CloneRefresh\" \"60\"
71 beyerle@PS 414
     }" -i $XORG_CONF
1 beyerle@PS 415
fi
416
 
417
# Set BoardName for Intel 915GM
418
if [ $I915GM ]; then
71 beyerle@PS 419
    sed -i 's/BoardName.*VESA driver.*/BoardName   "Intel 915"/' $XORG_CONF
1 beyerle@PS 420
fi
421
 
422
 
423
### parameter KB = KEYBOARD
424
KEYBOARD=$KB
425
 
426
### ask user for keyboard layout if no keyboard given
427
if [ -x /usr/bin/system-config-keyboard ]; then
428
    if [ ! $KEYBOARD ]; then
429
	MORE_LAYOUTS="more..."
430
	keytables="U.S...........(us) \
431
	           Swiss-German..(sg-latin1) \
432
                   Swiss-French..(fr_CH-latin1) \
433
                   German........(de-latin1) \
434
                   Japanese......(jp106) \
435
                   $MORE_LAYOUTS"
436
	PS3="-> "
437
	echo
438
	echo "Please choose keyboard layout (type 1-6):"
439
	select KEYBOARD in $keytables;
440
	  do
441
	     case $KEYBOARD in
442
	        *)
443
	        # extract keyboard layout string from $KEYBOARD
444
	        KEYBOARD=${KEYBOARD##*(}
445
                KEYBOARD=${KEYBOARD%%)}
446
                break
447
                ;;
448
	     esac
449
	  done
450
    fi
451
fi
452
 
453
### set keyboard
454
if [ -x /usr/bin/system-config-keyboard ]; then
455
    if [ "$KEYBOARD" = "$MORE_LAYOUTS" ]; then
456
	system-config-keyboard --text
457
    else
458
	echo -n "Set keyboard to '$KEYBOARD', please wait ... "
459
	system-config-keyboard --noui $KEYBOARD >/dev/null 2>&1
460
	echo "done."
461
    fi
462
    echo
463
fi
464
 
465
### update AFS users and SEPP links (only for PSI)
466
if [ $PSI ] && [ $AFS ]; then
467
    echo "Update AFS users and SEPP links..."
468
    [ -x /afs/psi.ch/sys/common/update_user.pl ] && /afs/psi.ch/sys/common/update_user.pl >/dev/null 2>&1 &
469
    [ -x /afs/psi.ch/sys/common/update_sepp.pl ] && /afs/psi.ch/sys/common/update_sepp.pl >/dev/null 2>&1 &
470
    echo
471
fi
472
 
473
### create local user, if "nolocal" is not set 
474
if [ ! $NOLOCAL ]; then
475
 
476
    user=$LOCALUSER
477
    # execute useradd twice, to make it work (don't know why)
478
    if [ $PSI ] && [ ! $NOADMIN ]; then
479
	userdel -r $user 2>/dev/null
480
	useradd -G $LocalAdminGroup $user 2>/dev/null
481
	userdel -r $user 2>/dev/null
482
	useradd -G $LocalAdminGroup $user
483
    else
484
	userdel -r $user 2>/dev/null
485
	useradd $user 2>/dev/null
486
	userdel -r $user 2>/dev/null
487
	useradd $user
488
    fi
489
 
490
    # only for PSI: change users's group to GID=UID+50000
491
    if [ $PSI ]; then
492
	uid=$( id -u $user )
493
	old_gid=$( id -g $user )
494
	new_gid=$(( $old_gid + 50000 ))
495
        # fix /etc/group
496
	sed -i "s/${user}:x:${old_gid}:/${user}:x:${new_gid}:/" /etc/group
497
        # fix /etc/passwd
498
	sed -i "s/${user}:x:${uid}:${old_gid}:/${user}:x:${uid}:${new_gid}:/" /etc/passwd
499
        # fix perm of /home/${user)
500
	chgrp -R $user /home/${user}
501
    fi
502
fi
503
 
504
### copy special files for PSI user l_psi
505
if [ $PSI ] && [ ! $NOLOCAL ]; then
506
    find /usr/share/${LOCALUSER}/ -maxdepth 1 -mindepth 1 2>/dev/null | \
507
    while read dir; do 
508
	cp -a $dir /home/${LOCALUSER}/
509
    done
510
    # set owner
511
    chown -R ${LOCALUSER}.${LOCALUSER} /home/${LOCALUSER}
512
fi
513
 
514
### set password for root and local user
515
if [ ! $NOPASSWD ]; then
516
    if [ ! $NOROOT ] || [ ! $NOLOCAL ]; then
517
	echo -n "Set password for "
518
	if [ ! $NOROOT ]; then
519
	    echo -n "'root' "
520
	fi
521
	if [ ! $NOROOT ] && [ ! $NOLOCAL ]; then
522
	    echo -n "and "
523
	fi
524
	if [ ! $NOLOCAL ]; then
525
	    echo -n "local user '$user' "
526
	fi
527
	echo
528
 
529
	if [ ! $NOLOCAL ]; then
530
	    echo "Login as local user '$user' with this password."
531
	    echo
532
	fi
533
 
534
        # set password, if not yet given by $PASSWD
535
	until [ $PASSWD ]; do
536
	    echo -n "Password: "
537
	    read -s PASSWD
538
	    echo
539
	done
540
	if [ ! $NOROOT ]; then
541
	    echo $PASSWD | passwd --stdin root >/dev/null
542
	fi
543
	if [ ! $NOLOCAL ]; then
544
	    echo $PASSWD | passwd --stdin $user >/dev/null
545
	fi
546
	echo
547
    fi
548
 
549
else
550
    # set root and $LOCALUSER to empty password
551
    sed -i "s|^root:.*|root::12345:0:99999:1:::|" /etc/shadow
552
    sed -i "s|^$LOCALUSER:.*|$LOCALUSER::12345:0:99999:1:::|" /etc/shadow
553
fi
554
 
555
### try to get hostname from DNS, if not yet defined
556
if [ ! $HOSTNAME ]; then
557
    echo "Try to get hostname from DNS ..."
558
    IP=$( /sbin/ip add show dev eth0 2>/dev/null | grep "inet " | cut -d" " -f6 | sed 's|/.*||' )
559
    if [ "$IP" = "" ]; then
560
	IP=$( /sbin/ip add show dev eth1 2>/dev/null | grep "inet " | cut -d" " -f6 | sed 's|/.*||' )
561
    fi
562
    if [ "$IP" != "" ]; then
563
	host -W 1 $IP >/dev/null 2>&1
564
	if [ "$?" = "0" ]; then
565
	    HOSTNAME=$( host -W 1 $IP | cut -d" " -f 5 | cut -d"." -f 1 )
566
	    if [ "$HOSTNAME" = "3(NXDOMAIN)" ]; then
567
		HOSTNAME=$DEFAULT_HOSTNAME
568
	    fi	
569
	    if [ "$HOSTNAME" = "no" ]; then
570
		HOSTNAME=$DEFAULT_HOSTNAME
571
	    fi	
572
	fi
573
    fi
574
fi
575
 
576
### define default hostname, if $HOSTNAME still not yet set
577
if [ ! $HOSTNAME ]; then
578
    HOSTNAME=$DEFAULT_HOSTNAME
579
fi
580
 
581
### set hostname
582
export HOSTNAME=$HOSTNAME
583
hostname $HOSTNAME
584
sed -i "s/HOSTNAME=.*/HOSTNAME=${HOSTNAME}/" /etc/sysconfig/network
585
if [ $PSI ]; then
586
    sed -i "s/hostname=.*/hostname=${HOSTNAME}.psi.ch/" /etc/ssmtp/ssmtp.conf
587
    sed -i "s/HOSTNAME=.*/HOSTNAME=${HOSTNAME}/" /etc/sysconfig/cfengine
588
fi
589
for iface in eth0 eth1 eth2 eth3; do
590
    if [ -e /etc/sysconfig/network-scripts/ifcfg-${iface} ]; then
591
	echo "DHCP_HOSTNAME=${HOSTNAME}" >> /etc/sysconfig/network-scripts/ifcfg-${iface}
592
    fi
593
done
594
 
595
echo "Hostname set to: $HOSTNAME"
596
echo
597
 
598
### set cups server
599
if [ $CUPS ]; then
600
    sed -i "s|.*ServerName .*|ServerName  $CUPS|" /etc/cups/client.conf
601
fi
602
 
603
### some magic: just access this file in order that it can be sourced later
604
ls -lag /etc/X11/xinit/xinitrc-common >/dev/null 2>&1
605
sleep 1
606
 
607
### set keyboard for rdesktop
71 beyerle@PS 608
if [ -e $XORG_CONF ]; then
609
    grep -q de_CH $XORG_CONF && RDESKTOP_OPT="-k de-ch"
610
    grep -q fr_CH $XORG_CONF && RDESKTOP_OPT="-k fr-ch"
611
    grep -q jp106 $XORG_CONF && RDESKTOP_OPT="-k ja"
1 beyerle@PS 612
fi
613
 
614
if [ "$RDESKTOP_OPT" ]; then
615
    echo "alias rdesktop='rdesktop $RDESKTOP_OPT'" > /etc/profile.d/rdesktop.sh
616
    echo "export RDESKTOP_OPT='$RDESKTOP_OPT'" >> /etc/profile.d/rdesktop.sh
617
    chmod 755 /etc/profile.d/rdesktop.sh
618
fi
619
 
620
### run setup script, if found in $CONFIG_FOLDER on $FOUND_RESTORE_MNT
621
if [ -r $CONFIG_FOLDER/setup ]; then
622
    CONFIG_FOLDER=$CONFIG_FOLDER bash $CONFIG_FOLDER/setup
623
fi
624
 
625
### umount $FOUND_RESTORE_MNT
626
if [ $FOUND_RESTORE_MNT ]; then
627
    echo "Unmount $FOUND_RESTORE_MNT"
628
    umount $FOUND_RESTORE_MNT 2>/dev/null
629
    sleep 3
630
fi
631
 
632
### local home partition?
633
if [ $HOMELOCAL ]; then
634
    mv /home /home.old
635
    mkdir -p /mnt/home_par
636
    # which partition? which folder?
637
    HOMEPAR=$( echo $HOMELOCAL | cut -d":" -f1 )
638
    HOMEDIR=$( echo $HOMELOCAL | grep ":" | cut -d":" -f2 )
639
    umount $HOMEPAR 2>/dev/null
640
    # mount it with option noatime, healthy for USB flash drives
641
    mount -o noatime -rw $HOMEPAR /mnt/home_par 2>/dev/null
642
    if [ "$?" != "0" ]; then
643
	echo "ERROR: Could not mount read/write $HOMEPAR"
644
	umount $HOMEPAR >/dev/null 2&>1
645
	mv /home.old /home
646
    else
647
	echo "$HOMEPAR mounted on /mnt/home_par"
648
	# link to new home
649
	ln -s /mnt/home_par/$HOMEDIR /home
650
	if [ ! -d /mnt/home_par/$HOMEDIR ]; then
651
	    echo "$HOMELOCAL not found on $HOMEPAR"
652
	    echo mkdir -p /mnt/home_par/$HOMEDIR
653
	    if [ "$?" != "0" ]; then
654
		echo "ERROR: Could not create $HOMELOCAL on $HOMEPAR"
655
		umount $HOMEPAR >/dev/null 2&>1
656
		rm -f /home
657
		mv /home.old /home
658
	    else
659
		echo "Folder $HOMEDIR created on $HOMEPAR"
660
	    fi
661
	fi
662
	if [ -d /mnt/home_par/$HOMEDIR ]; then
663
	    echo "/home is linked to /mnt/home_par${HOMEDIR}"
664
	    # copy files from /home.old to /home, which are not yet there
665
	    /bin/cp -a -i --reply=no /home.old/* /home/ 
666
	    rm -rf /home.old
667
	fi
668
    fi
669
    sleep 2
670
fi
671
 
672
### mount all if AUTOMOUNT set
673
if [ $AUTOMOUNT ]; then
674
    mount -a
675
fi
676
 
677
### unload/load sound module for snd-card-X (timing problem?)
678
rpm -q alsa-lib | grep el5 >/dev/null
679
if [ "$?" = "0" ]; then
680
    sound_modules=$( grep snd-card- /etc/modprobe.conf | awk ' $1 ~ /alias/ { print $3 }' | tr - _ )
681
    for module in $sound_modules; do
682
	lsmod | awk '{ print $1 }' | grep $module >/dev/null 2>&1
683
	if [ "$?" = "0" ]; then
684
	    rmmod $module    >/dev/null 2>&1
685
	    sleep 2
686
	    modprobe $module >/dev/null 2>&1
687
	fi
688
    done
689
fi
690
 
691
### unmute all mixers and set volumes
692
if [ -x /usr/bin/set-volume ]; then 
693
    if [ $NOSOUND ]; then
694
	/usr/bin/set-volume 0 > /var/log/set-volume.log 2>&1 &
695
    else
696
	/usr/bin/set-volume 60 > /var/log/set-volume.log 2>&1 &
697
    fi
698
fi
699
 
700
### set kde or gnome as desktop
701
if [ $KDE ]; then
702
    sed -i "/^DESKTOP=.*/d" /etc/sysconfig/desktop 2&>/dev/null
703
    echo "DESKTOP=KDE" >> /etc/sysconfig/desktop
704
fi
705
if [ $GNOME ]; then
706
    sed -i "/^DESKTOP=.*/d" /etc/sysconfig/desktop 2&>/dev/null
707
    echo "DESKTOP=GNOME" >> /etc/sysconfig/desktop
708
fi
709