Subversion Repositories livecd

Rev

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

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