Subversion Repositories livecd

Rev

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

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