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