Subversion Repositories livecd

Rev

Rev 86 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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