Subversion Repositories livecd

Rev

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