Subversion Repositories livecd

Rev

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

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