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