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