Subversion Repositories livecd

Rev

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