Subversion Repositories livecd

Rev

Details | 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
 
74 beyerle@PS 517
### autostart kmix and krandrtray in KDE
518
if [ ! $NOLOCAL ]; then
519
    mkdir -p /home/${LOCALUSER}/.kde/Autostart
520
    cp -a /usr/share/applications/kde/krandrtray.desktop /home/${LOCALUSER}/.kde/Autostart 2>/dev/null
521
    cp -a /usr/share/applications/kde/kmix.desktop /home/${LOCALUSER}/.kde/Autostart 2>/dev/null
522
    chown -R ${LOCALUSER}.${LOCALUSER} /home/${LOCALUSER}/.kde/Autostart
523
fi
524
 
1 beyerle@PS 525
### set password for root and local user
526
if [ ! $NOPASSWD ]; then
527
    if [ ! $NOROOT ] || [ ! $NOLOCAL ]; then
528
	echo -n "Set password for "
529
	if [ ! $NOROOT ]; then
530
	    echo -n "'root' "
531
	fi
532
	if [ ! $NOROOT ] && [ ! $NOLOCAL ]; then
533
	    echo -n "and "
534
	fi
535
	if [ ! $NOLOCAL ]; then
536
	    echo -n "local user '$user' "
537
	fi
538
	echo
539
 
540
	if [ ! $NOLOCAL ]; then
541
	    echo "Login as local user '$user' with this password."
542
	    echo
543
	fi
544
 
545
        # set password, if not yet given by $PASSWD
546
	until [ $PASSWD ]; do
547
	    echo -n "Password: "
548
	    read -s PASSWD
549
	    echo
550
	done
551
	if [ ! $NOROOT ]; then
552
	    echo $PASSWD | passwd --stdin root >/dev/null
553
	fi
554
	if [ ! $NOLOCAL ]; then
555
	    echo $PASSWD | passwd --stdin $user >/dev/null
556
	fi
557
	echo
558
    fi
559
 
560
else
561
    # set root and $LOCALUSER to empty password
562
    sed -i "s|^root:.*|root::12345:0:99999:1:::|" /etc/shadow
563
    sed -i "s|^$LOCALUSER:.*|$LOCALUSER::12345:0:99999:1:::|" /etc/shadow
564
fi
565
 
566
### try to get hostname from DNS, if not yet defined
567
if [ ! $HOSTNAME ]; then
568
    echo "Try to get hostname from DNS ..."
569
    IP=$( /sbin/ip add show dev eth0 2>/dev/null | grep "inet " | cut -d" " -f6 | sed 's|/.*||' )
570
    if [ "$IP" = "" ]; then
571
	IP=$( /sbin/ip add show dev eth1 2>/dev/null | grep "inet " | cut -d" " -f6 | sed 's|/.*||' )
572
    fi
573
    if [ "$IP" != "" ]; then
574
	host -W 1 $IP >/dev/null 2>&1
575
	if [ "$?" = "0" ]; then
576
	    HOSTNAME=$( host -W 1 $IP | cut -d" " -f 5 | cut -d"." -f 1 )
577
	    if [ "$HOSTNAME" = "3(NXDOMAIN)" ]; then
578
		HOSTNAME=$DEFAULT_HOSTNAME
579
	    fi	
580
	    if [ "$HOSTNAME" = "no" ]; then
581
		HOSTNAME=$DEFAULT_HOSTNAME
582
	    fi	
583
	fi
584
    fi
585
fi
586
 
587
### define default hostname, if $HOSTNAME still not yet set
588
if [ ! $HOSTNAME ]; then
589
    HOSTNAME=$DEFAULT_HOSTNAME
590
fi
591
 
592
### set hostname
593
export HOSTNAME=$HOSTNAME
594
hostname $HOSTNAME
595
sed -i "s/HOSTNAME=.*/HOSTNAME=${HOSTNAME}/" /etc/sysconfig/network
596
if [ $PSI ]; then
597
    sed -i "s/hostname=.*/hostname=${HOSTNAME}.psi.ch/" /etc/ssmtp/ssmtp.conf
598
    sed -i "s/HOSTNAME=.*/HOSTNAME=${HOSTNAME}/" /etc/sysconfig/cfengine
599
fi
600
for iface in eth0 eth1 eth2 eth3; do
601
    if [ -e /etc/sysconfig/network-scripts/ifcfg-${iface} ]; then
602
	echo "DHCP_HOSTNAME=${HOSTNAME}" >> /etc/sysconfig/network-scripts/ifcfg-${iface}
603
    fi
604
done
605
 
606
echo "Hostname set to: $HOSTNAME"
607
echo
608
 
609
### set cups server
610
if [ $CUPS ]; then
611
    sed -i "s|.*ServerName .*|ServerName  $CUPS|" /etc/cups/client.conf
612
fi
613
 
614
### some magic: just access this file in order that it can be sourced later
615
ls -lag /etc/X11/xinit/xinitrc-common >/dev/null 2>&1
616
sleep 1
617
 
618
### set keyboard for rdesktop
71 beyerle@PS 619
if [ -e $XORG_CONF ]; then
620
    grep -q de_CH $XORG_CONF && RDESKTOP_OPT="-k de-ch"
621
    grep -q fr_CH $XORG_CONF && RDESKTOP_OPT="-k fr-ch"
622
    grep -q jp106 $XORG_CONF && RDESKTOP_OPT="-k ja"
1 beyerle@PS 623
fi
624
 
625
if [ "$RDESKTOP_OPT" ]; then
626
    echo "alias rdesktop='rdesktop $RDESKTOP_OPT'" > /etc/profile.d/rdesktop.sh
627
    echo "export RDESKTOP_OPT='$RDESKTOP_OPT'" >> /etc/profile.d/rdesktop.sh
628
    chmod 755 /etc/profile.d/rdesktop.sh
629
fi
630
 
631
### run setup script, if found in $CONFIG_FOLDER on $FOUND_RESTORE_MNT
632
if [ -r $CONFIG_FOLDER/setup ]; then
633
    CONFIG_FOLDER=$CONFIG_FOLDER bash $CONFIG_FOLDER/setup
634
fi
635
 
636
### umount $FOUND_RESTORE_MNT
637
if [ $FOUND_RESTORE_MNT ]; then
638
    echo "Unmount $FOUND_RESTORE_MNT"
639
    umount $FOUND_RESTORE_MNT 2>/dev/null
640
    sleep 3
641
fi
642
 
643
### local home partition?
644
if [ $HOMELOCAL ]; then
645
    mv /home /home.old
646
    mkdir -p /mnt/home_par
647
    # which partition? which folder?
648
    HOMEPAR=$( echo $HOMELOCAL | cut -d":" -f1 )
649
    HOMEDIR=$( echo $HOMELOCAL | grep ":" | cut -d":" -f2 )
650
    umount $HOMEPAR 2>/dev/null
651
    # mount it with option noatime, healthy for USB flash drives
652
    mount -o noatime -rw $HOMEPAR /mnt/home_par 2>/dev/null
653
    if [ "$?" != "0" ]; then
654
	echo "ERROR: Could not mount read/write $HOMEPAR"
655
	umount $HOMEPAR >/dev/null 2&>1
656
	mv /home.old /home
657
    else
658
	echo "$HOMEPAR mounted on /mnt/home_par"
659
	# link to new home
660
	ln -s /mnt/home_par/$HOMEDIR /home
661
	if [ ! -d /mnt/home_par/$HOMEDIR ]; then
662
	    echo "$HOMELOCAL not found on $HOMEPAR"
663
	    echo mkdir -p /mnt/home_par/$HOMEDIR
664
	    if [ "$?" != "0" ]; then
665
		echo "ERROR: Could not create $HOMELOCAL on $HOMEPAR"
666
		umount $HOMEPAR >/dev/null 2&>1
667
		rm -f /home
668
		mv /home.old /home
669
	    else
670
		echo "Folder $HOMEDIR created on $HOMEPAR"
671
	    fi
672
	fi
673
	if [ -d /mnt/home_par/$HOMEDIR ]; then
674
	    echo "/home is linked to /mnt/home_par${HOMEDIR}"
675
	    # copy files from /home.old to /home, which are not yet there
676
	    /bin/cp -a -i --reply=no /home.old/* /home/ 
677
	    rm -rf /home.old
678
	fi
679
    fi
680
    sleep 2
681
fi
682
 
683
### mount all if AUTOMOUNT set
684
if [ $AUTOMOUNT ]; then
685
    mount -a
686
fi
687
 
688
### unload/load sound module for snd-card-X (timing problem?)
689
rpm -q alsa-lib | grep el5 >/dev/null
690
if [ "$?" = "0" ]; then
691
    sound_modules=$( grep snd-card- /etc/modprobe.conf | awk ' $1 ~ /alias/ { print $3 }' | tr - _ )
692
    for module in $sound_modules; do
693
	lsmod | awk '{ print $1 }' | grep $module >/dev/null 2>&1
694
	if [ "$?" = "0" ]; then
695
	    rmmod $module    >/dev/null 2>&1
696
	    sleep 2
697
	    modprobe $module >/dev/null 2>&1
698
	fi
699
    done
700
fi
701
 
702
### unmute all mixers and set volumes
703
if [ -x /usr/bin/set-volume ]; then 
704
    if [ $NOSOUND ]; then
705
	/usr/bin/set-volume 0 > /var/log/set-volume.log 2>&1 &
706
    else
707
	/usr/bin/set-volume 60 > /var/log/set-volume.log 2>&1 &
708
    fi
709
fi
710
 
711
### set kde or gnome as desktop
712
if [ $KDE ]; then
713
    sed -i "/^DESKTOP=.*/d" /etc/sysconfig/desktop 2&>/dev/null
714
    echo "DESKTOP=KDE" >> /etc/sysconfig/desktop
715
fi
716
if [ $GNOME ]; then
717
    sed -i "/^DESKTOP=.*/d" /etc/sysconfig/desktop 2&>/dev/null
718
    echo "DESKTOP=GNOME" >> /etc/sysconfig/desktop
719
fi
720