Subversion Repositories livecd

Rev

Rev 128 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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