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
488
    if [ $PSI ] && [ ! $NOADMIN ]; then
172 beyerle@PS 489
	groupadd $user   2>/dev/null
145 beyerle@PS 490
        # add user to fuse group ?
491
	grep -q "^fuse:" /etc/group
492
	if [ "$?" = "0" ]; then
172 beyerle@PS 493
	    useradd -g $user -G ${LocalAdminGroup},fuse $user  2>/dev/null
145 beyerle@PS 494
	else
172 beyerle@PS 495
	    useradd -g $user -G ${LocalAdminGroup} $user       2>/dev/null
145 beyerle@PS 496
	fi
1 beyerle@PS 497
    else
172 beyerle@PS 498
	groupadd $user  2>/dev/null
499
        # add user to fuse group ?
145 beyerle@PS 500
	grep -q "^fuse:" /etc/group
501
	if [ "$?" = "0" ]; then
172 beyerle@PS 502
	    useradd -g $user -G fuse $user  2>/dev/null
145 beyerle@PS 503
	else
172 beyerle@PS 504
	    useradd -g $user $user          2>/dev/null
145 beyerle@PS 505
	fi
1 beyerle@PS 506
    fi
507
 
508
fi
509
 
510
### copy special files for PSI user l_psi
511
if [ $PSI ] && [ ! $NOLOCAL ]; then
512
    find /usr/share/${LOCALUSER}/ -maxdepth 1 -mindepth 1 2>/dev/null | \
513
    while read dir; do 
514
	cp -a $dir /home/${LOCALUSER}/
515
    done
516
    # set owner
517
    chown -R ${LOCALUSER}.${LOCALUSER} /home/${LOCALUSER}
518
fi
519
 
74 beyerle@PS 520
### autostart kmix and krandrtray in KDE
521
if [ ! $NOLOCAL ]; then
522
    mkdir -p /home/${LOCALUSER}/.kde/Autostart
523
    cp -a /usr/share/applications/kde/krandrtray.desktop /home/${LOCALUSER}/.kde/Autostart 2>/dev/null
524
    cp -a /usr/share/applications/kde/kmix.desktop /home/${LOCALUSER}/.kde/Autostart 2>/dev/null
525
    chown -R ${LOCALUSER}.${LOCALUSER} /home/${LOCALUSER}/.kde/Autostart
526
fi
527
 
87 beyerle@PS 528
 
529
### first set empty password
530
if [ ! $NOROOT ]; then
531
    sed -i "s|^root:.*|root::12345:0:99999:1:::|" /etc/shadow
532
fi
533
if [ ! $NOLOCAL]; then
534
    sed -i "s|^$LOCALUSER:.*|$LOCALUSER::12345:0:99999:1:::|" /etc/shadow
535
fi
536
 
1 beyerle@PS 537
### set password for root and local user
538
if [ ! $NOPASSWD ]; then
539
    if [ ! $NOROOT ] || [ ! $NOLOCAL ]; then
540
	echo -n "Set password for "
541
	if [ ! $NOROOT ]; then
542
	    echo -n "'root' "
543
	fi
544
	if [ ! $NOROOT ] && [ ! $NOLOCAL ]; then
545
	    echo -n "and "
546
	fi
547
	if [ ! $NOLOCAL ]; then
548
	    echo -n "local user '$user' "
549
	fi
550
	echo
103 beyerle@PS 551
	echo "or hit return for empty password."
1 beyerle@PS 552
 
553
	if [ ! $NOLOCAL ]; then
554
	    echo "Login as local user '$user' with this password."
87 beyerle@PS 555
	fi
556
	echo
557
 
558
        # ask for password, if not yet given by $PASSWD
559
	if [ ! $PASSWD ]; then 
560
	    echo -n "Password: "
561
	    read -s PASSWD
1 beyerle@PS 562
	    echo
563
	fi
564
 
87 beyerle@PS 565
	# set password - or - set empty password
86 beyerle@PS 566
	if [ ! $NOROOT ] && [ "$PASSWD" ]; then
1 beyerle@PS 567
	    echo $PASSWD | passwd --stdin root >/dev/null
568
	fi
86 beyerle@PS 569
	if [ ! $NOLOCAL] && [ "$PASSWD" ]; then
1 beyerle@PS 570
	    echo $PASSWD | passwd --stdin $user >/dev/null
571
	fi
572
	echo
573
    fi
574
fi
575
 
576
### try to get hostname from DNS, if not yet defined
577
if [ ! $HOSTNAME ]; then
578
    echo "Try to get hostname from DNS ..."
579
    IP=$( /sbin/ip add show dev eth0 2>/dev/null | grep "inet " | cut -d" " -f6 | sed 's|/.*||' )
580
    if [ "$IP" = "" ]; then
581
	IP=$( /sbin/ip add show dev eth1 2>/dev/null | grep "inet " | cut -d" " -f6 | sed 's|/.*||' )
582
    fi
583
    if [ "$IP" != "" ]; then
584
	host -W 1 $IP >/dev/null 2>&1
585
	if [ "$?" = "0" ]; then
586
	    HOSTNAME=$( host -W 1 $IP | cut -d" " -f 5 | cut -d"." -f 1 )
587
	    if [ "$HOSTNAME" = "3(NXDOMAIN)" ]; then
588
		HOSTNAME=$DEFAULT_HOSTNAME
589
	    fi	
590
	    if [ "$HOSTNAME" = "no" ]; then
591
		HOSTNAME=$DEFAULT_HOSTNAME
592
	    fi	
593
	fi
594
    fi
595
fi
596
 
128 beyerle@PS 597
### define default hostname, if $HOSTNAME is still not yet set
1 beyerle@PS 598
if [ ! $HOSTNAME ]; then
599
    HOSTNAME=$DEFAULT_HOSTNAME
600
fi
601
 
602
### set hostname
603
export HOSTNAME=$HOSTNAME
604
hostname $HOSTNAME
605
sed -i "s/HOSTNAME=.*/HOSTNAME=${HOSTNAME}/" /etc/sysconfig/network
606
if [ $PSI ]; then
607
    sed -i "s/hostname=.*/hostname=${HOSTNAME}.psi.ch/" /etc/ssmtp/ssmtp.conf
125 beyerle@PS 608
    sed -i "s/HOSTNAME=.*/HOSTNAME=${HOSTNAME}/" /etc/sysconfig/psi
1 beyerle@PS 609
fi
610
for iface in eth0 eth1 eth2 eth3; do
611
    if [ -e /etc/sysconfig/network-scripts/ifcfg-${iface} ]; then
612
	echo "DHCP_HOSTNAME=${HOSTNAME}" >> /etc/sysconfig/network-scripts/ifcfg-${iface}
613
    fi
614
done
615
 
616
echo "Hostname set to: $HOSTNAME"
617
echo
618
 
619
### set cups server
620
if [ $CUPS ]; then
621
    sed -i "s|.*ServerName .*|ServerName  $CUPS|" /etc/cups/client.conf
138 beyerle@PS 622
    grep -q ServerName /etc/cups/client.conf || echo "ServerName  $CUPS" >> /etc/cups/client.conf 
1 beyerle@PS 623
fi
624
 
625
### some magic: just access this file in order that it can be sourced later
626
ls -lag /etc/X11/xinit/xinitrc-common >/dev/null 2>&1
627
 
628
### set keyboard for rdesktop
71 beyerle@PS 629
if [ -e $XORG_CONF ]; then
630
    grep -q de_CH $XORG_CONF && RDESKTOP_OPT="-k de-ch"
631
    grep -q fr_CH $XORG_CONF && RDESKTOP_OPT="-k fr-ch"
632
    grep -q jp106 $XORG_CONF && RDESKTOP_OPT="-k ja"
1 beyerle@PS 633
fi
634
 
635
if [ "$RDESKTOP_OPT" ]; then
636
    echo "alias rdesktop='rdesktop $RDESKTOP_OPT'" > /etc/profile.d/rdesktop.sh
637
    echo "export RDESKTOP_OPT='$RDESKTOP_OPT'" >> /etc/profile.d/rdesktop.sh
638
    chmod 755 /etc/profile.d/rdesktop.sh
639
fi
640
 
641
### run setup script, if found in $CONFIG_FOLDER on $FOUND_RESTORE_MNT
642
if [ -r $CONFIG_FOLDER/setup ]; then
643
    CONFIG_FOLDER=$CONFIG_FOLDER bash $CONFIG_FOLDER/setup
644
fi
645
 
646
### umount $FOUND_RESTORE_MNT
647
if [ $FOUND_RESTORE_MNT ]; then
648
    echo "Unmount $FOUND_RESTORE_MNT"
649
    umount $FOUND_RESTORE_MNT 2>/dev/null
650
    sleep 3
651
fi
652
 
653
### local home partition?
654
if [ $HOMELOCAL ]; then
655
    mv /home /home.old
656
    mkdir -p /mnt/home_par
657
    # which partition? which folder?
658
    HOMEPAR=$( echo $HOMELOCAL | cut -d":" -f1 )
659
    HOMEDIR=$( echo $HOMELOCAL | grep ":" | cut -d":" -f2 )
660
    umount $HOMEPAR 2>/dev/null
661
    # mount it with option noatime, healthy for USB flash drives
662
    mount -o noatime -rw $HOMEPAR /mnt/home_par 2>/dev/null
663
    if [ "$?" != "0" ]; then
664
	echo "ERROR: Could not mount read/write $HOMEPAR"
665
	umount $HOMEPAR >/dev/null 2&>1
666
	mv /home.old /home
667
    else
668
	echo "$HOMEPAR mounted on /mnt/home_par"
669
	# link to new home
670
	ln -s /mnt/home_par/$HOMEDIR /home
671
	if [ ! -d /mnt/home_par/$HOMEDIR ]; then
672
	    echo "$HOMELOCAL not found on $HOMEPAR"
673
	    echo mkdir -p /mnt/home_par/$HOMEDIR
674
	    if [ "$?" != "0" ]; then
675
		echo "ERROR: Could not create $HOMELOCAL on $HOMEPAR"
676
		umount $HOMEPAR >/dev/null 2&>1
677
		rm -f /home
678
		mv /home.old /home
679
	    else
680
		echo "Folder $HOMEDIR created on $HOMEPAR"
681
	    fi
682
	fi
683
	if [ -d /mnt/home_par/$HOMEDIR ]; then
684
	    echo "/home is linked to /mnt/home_par${HOMEDIR}"
685
	    # copy files from /home.old to /home, which are not yet there
686
	    /bin/cp -a -i --reply=no /home.old/* /home/ 
687
	    rm -rf /home.old
688
	fi
689
    fi
690
    sleep 2
691
fi
692
 
693
### mount all if AUTOMOUNT set
694
if [ $AUTOMOUNT ]; then
695
    mount -a
696
fi
697
 
698
### unmute all mixers and set volumes
699
if [ -x /usr/bin/set-volume ]; then 
700
    if [ $NOSOUND ]; then
701
	/usr/bin/set-volume 0 > /var/log/set-volume.log 2>&1 &
702
    else
703
	/usr/bin/set-volume 60 > /var/log/set-volume.log 2>&1 &
704
    fi
705
fi
706
 
707
### set kde or gnome as desktop
708
if [ $KDE ]; then
709
    sed -i "/^DESKTOP=.*/d" /etc/sysconfig/desktop 2&>/dev/null
710
    echo "DESKTOP=KDE" >> /etc/sysconfig/desktop
711
fi
712
if [ $GNOME ]; then
713
    sed -i "/^DESKTOP=.*/d" /etc/sysconfig/desktop 2&>/dev/null
714
    echo "DESKTOP=GNOME" >> /etc/sysconfig/desktop
715
fi
716
 
78 beyerle@PS 717
### reload sound module (second time)
718
reload_soundmodule
83 beyerle@PS 719
 
720
### bring up all network interfaces (useful to enable WLAN devices)
721
if [ ! $NONET ]; then
722
    devices=$( ls /etc/sysconfig/network-scripts/ifcfg-* \
723
               | sed "s|/etc/sysconfig/network-scripts/ifcfg-||" | grep -v lo )
724
    for device in $devices; do
725
	ifconfig $device up > /dev/null 2>&1 &
726
    done
727
fi
728