Subversion Repositories livecd

Rev

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

Rev 219 Rev 220
1
#!/bin/bash
1
#!/bin/bash
2
#
2
#
3
###############################################################
3
###############################################################
4
#
4
#
5
# Installes the LiveCD on local hard disk
5
# Installes the LiveCD on local hard disk
6
# 
6
# 
7
# Boot LiveCD and run this script as root
7
# Boot LiveCD and run this script as root
8
#
8
#
9
# Urs Beyerle
9
# Urs Beyerle
10
# Brent L. Bates
10
# Brent L. Bates
11
#
11
#
12
###############################################################
12
###############################################################
13
 
13
 
14
 
14
 
15
###############################################################
15
###############################################################
16
# Definitions
16
# Definitions
17
###############################################################
17
###############################################################
18
 
18
 
19
# set PATH
19
# set PATH
20
PATH="/usr/bin:/usr/sbin:/bin:/sbin:/usr/X11R6/bin"
20
PATH="/usr/bin:/usr/sbin:/bin:/sbin:/usr/X11R6/bin"
21
 
21
 
22
# RPMs that are no longer needed and may break future udpates
22
# RPMs that are no longer needed and may break future udpates
23
RPMS_TO_REMOVE="kernel-module-squashfs \
23
RPMS_TO_REMOVE="kernel-module-squashfs \
24
                kernel-module-unionfs \
24
                kernel-module-unionfs \
25
                kernel-module-aufs \
25
                kernel-module-aufs \
26
                unionfs-.* \
26
                unionfs-.* \
27
                aufs-.* \
27
                aufs-.* \
28
                squashfs-.*"
28
                squashfs-.*"
29
 
29
 
30
# RPMs that can break future Scientific Linux updates
30
# RPMs that can break future Scientific Linux updates
31
# because there are not part of Scientific Linux
31
# because there are not part of Scientific Linux
32
RPMS_TO_REMOVE_SL=""
32
RPMS_TO_REMOVE_SL=""
33
                   
33
                   
34
# RPMs that can break future PSI SL updates
34
# RPMs that can break future PSI SL updates
35
# because there are not part of PSI Scientific Linux
35
# because there are not part of PSI Scientific Linux
36
RPMS_TO_REMOVE_PSI=""
36
RPMS_TO_REMOVE_PSI=""
37
                   
37
                   
38
# files which should be restored from .ori files
38
# files which should be restored from .ori files
39
FILES_RESTORE="/etc/init.d/netfs \
39
FILES_RESTORE="/etc/init.d/netfs \
40
           /etc/init.d/autofs \
40
           /etc/init.d/autofs \
41
           /etc/init.d/halt \
41
           /etc/init.d/halt \
42
           /etc/init.d/network
42
           /etc/init.d/network
43
           /etc/init.d/functions \
43
           /etc/init.d/functions \
44
           /etc/rc.d/rc.sysinit \
44
           /etc/rc.d/rc.sysinit \
45
           /etc/sysconfig/afs \
45
           /etc/sysconfig/afs \
46
           /etc/motd \
46
           /etc/motd \
47
           /etc/redhat-release \
47
           /etc/redhat-release \
48
           /etc/rc.d/rc.local"
48
           /etc/rc.d/rc.local"
49
 
49
 
50
# LiveCD init scripts will be removed
50
# LiveCD init scripts will be removed
51
LIVECD_INIT_SCRIPTS="runfirst \
51
LIVECD_INIT_SCRIPTS="runfirst \
52
                    runveryfirst \
52
                    runveryfirst \
53
                    runlast \
53
                    runlast \
54
                    kudzu-auto \
54
                    kudzu-auto \
55
                    login"
55
                    login"
56
 
56
 
57
# Main directories which should be not be copied
57
# Main directories which should be not be copied
58
DIR_NOT_COPY="/proc \
58
DIR_NOT_COPY="/proc \
59
              /dev \
59
              /dev \
60
              /livecd \
60
              /livecd \
61
              /boot \
61
              /boot \
62
              /afs \
62
              /afs \
63
              /sys \
63
              /sys \
64
              /media \
64
              /media \
65
              /misc \
65
              /misc \
66
              /mnt \
66
              /mnt \
67
              /net \
67
              /net \
68
              /initrd"
68
              /initrd"
69
 
69
 
70
# Mount point of the new SL system
70
# Mount point of the new SL system
71
NEW=/mnt/harddisk
71
NEW=/mnt/harddisk
72
 
72
 
73
# Name of the script
73
# Name of the script
74
SCRIPTNAME=$( basename $0 )
74
SCRIPTNAME=$( basename $0 )
75
 
75
 
76
# dir of mounted /$MOUNTDIR/live
76
# dir of mounted /$MOUNTDIR/live
77
MOUNTDIR=livecd
77
MOUNTDIR=livecd
78
 
78
 
79
# Default File System Type
79
# Default File System Type
80
FS_TYPE=ext3
80
FS_TYPE=ext3
81
 
81
 
82
 
82
 
83
###############################################################
83
###############################################################
84
# Functions
84
# Functions
85
###############################################################
85
###############################################################
86
 
86
 
87
function usage() {
87
function usage() {
88
 
88
 
89
   ## Usage
89
   ## Usage
90
   # ----------------------------------------------------------
90
   # ----------------------------------------------------------
91
 
91
 
92
   cat <<EOF
92
   cat <<EOF
93
   
93
   
94
  $SCRIPTNAME [OPTIONS] -mbr=[DEVICE] [PARTITION | MOUNTED FILE SYSTEM]
94
  $SCRIPTNAME [OPTIONS] -mbr=[DEVICE] [PARTITION | MOUNTED FILE SYSTEM]
95
 
95
 
96
    Installes LiveCD on PARTITION and the bootloader grub into 
96
    Installes LiveCD on PARTITION and the bootloader grub into 
97
    the Master Boot Record (MBR) of DEVICE. The MBR will be 
97
    the Master Boot Record (MBR) of DEVICE. The MBR will be 
98
    backed up to PARTITION.
98
    backed up to PARTITION.
99
 
99
 
100
  OPTIONS:
100
  OPTIONS:
101
 
101
 
102
    -h   --help          : Print this screen
102
    -h   --help          : Print this screen
103
    -swap=[partition(s)] : Use [partition(s)] as swap ("," or "|" separated)
103
    -swap=[partition(s)] : Use [partition(s)] as swap ("," or "|" separated)
104
    -win=[partition]     : Your active Windows partition. If not given, 
104
    -win=[partition]     : Your active Windows partition. If not given, 
105
                           $SCRIPTNAME tries to find it
105
                           $SCRIPTNAME tries to find it
106
    -nogrub              : Do not install grub. You have to install 
106
    -nogrub              : Do not install grub. You have to install 
107
                           manually a bootloader (not recommended)
107
                           manually a bootloader (not recommended)
108
    -floppy              : Needed, if grub should be installed on floppy
108
    -floppy              : Needed, if grub should be installed on floppy
109
                           In this case use -mbr=/dev/fd0 -floppy
109
                           In this case use -mbr=/dev/fd0 -floppy
110
    -norpmremove         : Do not remove RPMs that can break future 
110
    -norpmremove         : Do not remove RPMs that can break future 
111
                           updates (not recommended)
111
                           updates (not recommended)
112
    -fstype              : File system type (ext3,xfs,etc.), default is $FS_TYPE
112
    -fstype              : File system type (ext3,xfs,etc.), default is $FS_TYPE
113
    -y                   : Answer all questions with yes
113
    -y                   : Answer all questions with yes
114
    -f                   : force formating 
-
 
115
 
114
 
116
  Example:
115
  Example:
117
 
116
 
118
  $SCRIPTNAME -swap=/dev/sda3 -mbr=/dev/sda /dev/sda2
117
  $SCRIPTNAME -swap=/dev/sda3 -mbr=/dev/sda /dev/sda2
119
 
118
 
120
    Will install LiveCD on /dev/sda2 (= second partition on 
119
    Will install LiveCD on /dev/sda2 (= second partition on 
121
    first SATA disk). All data on /dev/sda2 will be deleted.
120
    first SATA disk). All data on /dev/sda2 will be deleted.
122
    /dev/sda3 has to be a Linux Swap partion. GRUB will be 
121
    /dev/sda3 has to be a Linux Swap partion. GRUB will be 
123
    installed in the MBR of /dev/sda (= first SATA disk).
122
    installed in the MBR of /dev/sda (= first SATA disk).
124
   
123
   
125
  Remarks:
124
  Remarks:
126
 
125
 
127
    To display your hard disk partitions, user 'fdisk -l'.
126
    To display your hard disk partitions, user 'fdisk -l'.
128
    Use fdisk, qtparted or parted to create an empty Linux
127
    Use fdisk, qtparted or parted to create an empty Linux
129
    partition.
128
    partition.
130
 
129
 
131
EOF
130
EOF
132
}
131
}
133
 
132
 
134
 
133
 
135
function exit_now() {
134
function exit_now() {
136
 
135
 
137
    local exitcode=$1
136
    local exitcode=$1
138
    umount $INSTALL_PART 2>/dev/null
137
    umount $INSTALL_PART 2>/dev/null
139
    exit $exitcode
138
    exit $exitcode
140
}
139
}
141
 
140
 
142
 
141
 
143
 
142
 
144
###############################################################
143
###############################################################
145
# Main
144
# Main
146
###############################################################
145
###############################################################
147
 
146
 
148
### are we root?
147
### are we root?
149
### -----------------------------------------------------------
148
### -----------------------------------------------------------
150
if [ "$( whoami )" != "root" ]; then
149
if [ "$( whoami )" != "root" ]; then
151
    echo; echo "Please run this script as root: 'su - -c $SCRIPTNAME'"; echo
150
    echo; echo "Please run this script as root: 'su - -c $SCRIPTNAME'"; echo
152
    exit_now 1
151
    exit_now 1
153
fi
152
fi
154
 
153
 
155
 
154
 
156
### read options from command-line
155
### read options from command-line
157
### -----------------------------------------------------------
156
### -----------------------------------------------------------
158
while [ $# -gt 0 ]; do
157
while [ $# -gt 0 ]; do
159
 
158
 
160
    case "$1" in
159
    case "$1" in
161
       -h)
160
       -h)
162
            usage; exit_now;;
161
            usage; exit_now;;
163
 
162
 
164
       --help)
163
       --help)
165
            usage; exit_now;;
164
            usage; exit_now;;
166
 
165
 
167
       -swap*)
166
       -swap*)
168
           if echo $1 | grep -q '=' ; then
167
           if echo $1 | grep -q '=' ; then
169
               SWAP_PART=$( echo $1 | sed 's/^-swap=//' )
168
               SWAP_PART=$( echo $1 | sed 's/^-swap=//' )
170
           else
169
           else
171
               shift
170
               shift
172
               SWAP_PART=$1
171
               SWAP_PART=$1
173
           fi
172
           fi
174
           ;;
173
           ;;
175
 
174
 
176
       -mbr*)
175
       -mbr*)
177
           if echo $1 | grep -q '=' ; then
176
           if echo $1 | grep -q '=' ; then
178
               MBR_DEV=$( echo $1 | sed 's/^-mbr=//' )
177
               MBR_DEV=$( echo $1 | sed 's/^-mbr=//' )
179
           else
178
           else
180
               shift
179
               shift
181
               MBR_DEV=$1
180
               MBR_DEV=$1
182
           fi
181
           fi
183
           MBR_DEV=$( echo "$MBR_DEV" | sed -e 's%\([sh]d[a-z]\)[0-9]*$%\1%' )
182
           MBR_DEV=$( echo "$MBR_DEV" | sed -e 's%\([sh]d[a-z]\)[0-9]*$%\1%' )
184
           ;;
183
           ;;
185
 
184
 
186
       -win*)
185
       -win*)
187
           if echo $1 | grep -q '=' ; then
186
           if echo $1 | grep -q '=' ; then
188
               WIN_PART=$( echo $1 | sed 's/^-win=//' )
187
               WIN_PART=$( echo $1 | sed 's/^-win=//' )
189
           else
188
           else
190
               shift
189
               shift
191
               WIN_PART=$1
190
               WIN_PART=$1
192
           fi
191
           fi
193
           ;;
192
           ;;
194
 
193
 
195
       -nogrub)
194
       -nogrub)
196
            NOGRUB=$1;;
195
            NOGRUB=$1;;
197
 
196
 
198
       -norpmremove)
197
       -norpmremove)
199
            NORPMREMOVE=$1;;
198
            NORPMREMOVE=$1;;
200
 
199
 
201
       -floppy)
200
       -floppy)
202
            FLOPPY=$1;;
201
            FLOPPY=$1;;
203
 
202
 
204
       -fstype)
203
       -fstype)
205
            $FS_TYPE=$1;;
204
            shift
206
 
-
 
207
       -f)
-
 
208
            $FORCE=$1;;
205
	    FS_TYPE=$1;;
209
 
206
 
210
       -y)
207
       -y)
211
            YES=$1;;
208
            YES=$1;;
212
 
209
 
213
       *)
210
       *)
214
            INSTALL_PART=$1;;
211
            INSTALL_PART=$1;;
215
    esac
212
    esac
216
 
213
 
217
    shift
214
    shift
218
 
215
 
219
done
216
done
220
echo
217
echo
221
 
218
 
222
 
219
 
223
### display fdisk -l
220
### display fdisk -l
224
### -----------------------------------------------------------
221
### -----------------------------------------------------------
225
echo "Output of 'fdisk -l' ..."
222
echo "Output of 'fdisk -l' ..."
226
fdisk -l 2>/dev/null
223
fdisk -l 2>/dev/null
227
echo
224
echo
228
 
225
 
229
 
226
 
230
### test if $INSTALL_PART is defined
227
### test if $INSTALL_PART is defined
231
### -----------------------------------------------------------
228
### -----------------------------------------------------------
232
if [ ! $INSTALL_PART ]; then
229
if [ ! $INSTALL_PART ]; then
233
    echo "No partition defined for installation."
230
    echo "No partition defined for installation."
234
    echo "Please see '$SCRIPTNAME -h'."; echo
231
    echo "Please see '$SCRIPTNAME -h'."; echo
235
    exit_now 1
232
    exit_now 1
236
fi
233
fi
237
 
234
 
238
 
235
 
239
### test if MBR_DEV is given
236
### test if MBR_DEV is given
240
### -----------------------------------------------------------
237
### -----------------------------------------------------------
241
if [ ! $NOGRUB ]; then
238
if [ ! $NOGRUB ]; then
242
    if [ ! $MBR_DEV ]; then
239
    if [ ! $MBR_DEV ]; then
243
        echo "No MBR device defined."
240
        echo "No MBR device defined."
244
        echo "Please see '$SCRIPTNAME -h'."
241
        echo "Please see '$SCRIPTNAME -h'."
245
        echo
242
        echo
246
        exit_now 1
243
        exit_now 1
247
    fi
244
    fi
248
fi
245
fi
249
 
246
 
250
 
247
 
251
### test if $INSTALL_PART is mounted
248
### test if $INSTALL_PART is mounted
252
### -----------------------------------------------------------
249
### -----------------------------------------------------------
253
df -T -l | sed -e 's/  */ /g' | grep -q "${INSTALL_PART}"
250
df -T -l | sed -e 's/  */ /g' | grep -q "${INSTALL_PART}"
254
 
251
 
255
if [ "$?" = "0" ]; then
252
if [ "$?" = "0" ]; then
256
   ### This is a mounted partition
253
   ### This is a mounted partition
257
   ### -----------------------------------------------------------
254
   ### -----------------------------------------------------------
258
   MOUNTED=1
255
   MOUNTED=1
259
 
256
 
260
   df -T -l | sed -e 's/  */ /g' | cut -d" " -f7 | grep -q "^${INSTALL_PART}$"
257
   df -T -l | sed -e 's/  */ /g' | cut -d" " -f7 | grep -q "^${INSTALL_PART}$"
261
   if [ "$?" = "0" ]; then
258
   if [ "$?" = "0" ]; then
262
 
259
 
263
      ### Was given the mount point
260
      ### Was given the mount point
264
      ### -----------------------------------------------------------
261
      ### -----------------------------------------------------------
265
      NEW=${INSTALL_PART}
262
      NEW=${INSTALL_PART}
266
      INSTALL_PART=`df -T -l | grep "${INSTALL_PART}$" | cut -d" " -f1`
263
      INSTALL_PART=`df -T -l | grep "${INSTALL_PART}$" | cut -d" " -f1`
267
   else
264
   else
268
 
265
 
269
      ### Was given the mount partition
266
      ### Was given the mount partition
270
      ### -----------------------------------------------------------
267
      ### -----------------------------------------------------------
271
      NEW=`df -T -l | grep "^${INSTALL_PART}" | sed -e 's/  */ /g' | cut -d" " -f7`
268
      NEW=`df -T -l | grep "^${INSTALL_PART}" | sed -e 's/  */ /g' | cut -d" " -f7`
272
   fi
269
   fi
273
   FS_TYPE=`df -T -l | sed -e 's/  */ /g' | grep "^${INSTALL_PART}" | cut -d" " -f2`
270
   FS_TYPE=`df -T -l | sed -e 's/  */ /g' | grep "^${INSTALL_PART}" | cut -d" " -f2`
274
 
271
 
275
   ### Get boot defice information
272
   ### Get boot defice information
276
   ###    Check for separate mounted boot partition
273
   ###    Check for separate mounted boot partition
277
   ### -----------------------------------------------------------
274
   ### -----------------------------------------------------------
278
   INSTALL_DEV=`df -T -l | sed -e 's/  */ /g' | grep "boot$" | cut -d" " -f1`
275
   INSTALL_DEV=`df -T -l | sed -e 's/  */ /g' | grep "boot$" | cut -d" " -f1`
279
   if [ "$?" = "0" ]; then
276
   if [ "$?" = "0" ]; then
280
      ###    Separate boot partition
277
      ###    Separate boot partition
281
      ### -----------------------------------------------------------
278
      ### -----------------------------------------------------------
282
      INSTALL_BOOT_DIR=""
279
      INSTALL_BOOT_DIR=""
283
   else
280
   else
284
      ###    Install and boot all one partition
281
      ###    Install and boot all one partition
285
      ### -----------------------------------------------------------
282
      ### -----------------------------------------------------------
286
      INSTALL_DEV=${INSTALL_PART}
283
      INSTALL_DEV=${INSTALL_PART}
287
      INSTALL_BOOT_DIR="/boot"
284
      INSTALL_BOOT_DIR="/boot"
288
   fi
285
   fi
289
 
286
 
290
   ### Is the boot device a RAID device
287
   ### Is the boot device a RAID device
291
   ### -----------------------------------------------------------
288
   ### -----------------------------------------------------------
292
   mdadm -D $INSTALL_DEV 2>/dev/null | grep -q -i Version
289
   mdadm -D $INSTALL_DEV 2>/dev/null | grep -q -i Version
293
   if [ "$?" = "0" ]; then
290
   if [ "$?" = "0" ]; then
294
      ### Boot device is RAID
291
      ### Boot device is RAID
295
      ### -----------------------------------------------------------
292
      ### -----------------------------------------------------------
296
      BOOT_DRIVE=`mdadm -D $INSTALL_DEV | grep -v ':$' | grep "/dev/" | sed -e 's/  */ /g' | cut -d" " -f8 |head -1`
293
      BOOT_DRIVE=`mdadm -D $INSTALL_DEV | grep -v ':$' | grep "/dev/" | sed -e 's/  */ /g' | cut -d" " -f8 |head -1`
297
      INSTALL_PART_NR=$( echo "$BOOT_DRIVE" | sed -e 's%.*/[sh]d[a-z]\([0-9]*\)$%\1%' )
294
      INSTALL_PART_NR=$( echo "$BOOT_DRIVE" | sed -e 's%.*/[sh]d[a-z]\([0-9]*\)$%\1%' )
298
      BOOT_DRIVE=$( echo "$BOOT_DRIVE" | sed -e 's%\([sh]d[a-z]\)[0-9]*$%\1%' )
295
      BOOT_DRIVE=$( echo "$BOOT_DRIVE" | sed -e 's%\([sh]d[a-z]\)[0-9]*$%\1%' )
299
   else
296
   else
300
      ### Boot device not RAID
297
      ### Boot device not RAID
301
      ### -----------------------------------------------------------
298
      ### -----------------------------------------------------------
302
      INSTALL_PART_NR=$( echo "$INSTALL_DEV" | sed -e 's%.*/[sh]d[a-z]\([0-9]*\)$%\1%' )
299
      INSTALL_PART_NR=$( echo "$INSTALL_DEV" | sed -e 's%.*/[sh]d[a-z]\([0-9]*\)$%\1%' )
303
      INSTALL_DEV=$( echo "$INSTALL_DEV" | sed -e 's%\([sh]d[a-z]\)[0-9]*$%\1%' )
300
      INSTALL_DEV=$( echo "$INSTALL_DEV" | sed -e 's%\([sh]d[a-z]\)[0-9]*$%\1%' )
304
      BOOT_DRIVE=$INSTALL_DEV
301
      BOOT_DRIVE=$INSTALL_DEV
305
   fi
302
   fi
306
else
303
else
307
   ### Partition is NOT mounted
304
   ### Partition is NOT mounted
308
   ### -----------------------------------------------------------
305
   ### -----------------------------------------------------------
309
   MOUNTED=0
306
   MOUNTED=0
310
 
307
 
311
   ### test if $INSTALL_PART exists
308
   ### test if $INSTALL_PART exists
312
   ### -----------------------------------------------------------
309
   ### -----------------------------------------------------------
313
   fdisk -l 2>/dev/null | cut -d" " -f1 | grep -q "^${INSTALL_PART}$"
310
   fdisk -l 2>/dev/null | cut -d" " -f1 | grep -q "^${INSTALL_PART}$"
314
   if [ "$?" != "0" ]; then
311
   if [ "$?" != "0" ]; then
315
       echo "Partition $INSTALL_PART not found! See 'fdisk -l'."
312
       echo "Partition $INSTALL_PART not found! See 'fdisk -l'."
316
       echo "Or you have to reboot first to make the partition table active." 
313
       echo "Or you have to reboot first to make the partition table active." 
317
       echo
314
       echo
318
       exit_now 1
315
       exit_now 1
319
   fi
316
   fi
320
 
317
 
321
 
318
 
322
   ### test if $INSTALL_PART is a Linux partition
319
   ### test if $INSTALL_PART is a Linux partition
323
   ### -----------------------------------------------------------
320
   ### -----------------------------------------------------------
324
   fdisk -l 2>/dev/null | grep "Linux$" | cut -d" " -f1 | grep -q "^${INSTALL_PART}$"
321
   fdisk -l 2>/dev/null | grep "Linux$" | cut -d" " -f1 | grep -q "^${INSTALL_PART}$"
325
   if [ "$?" != "0" ]; then
322
   if [ "$?" != "0" ]; then
326
       echo "Partition $INSTALL_PART is not a Linux partition! (see 'fdisk -l')."
323
       echo "Partition $INSTALL_PART is not a Linux partition! (see 'fdisk -l')."
327
       echo "Use fdisk and/or qtparted to create a Linux partition!"
324
       echo "Use fdisk and/or qtparted to create a Linux partition!"
328
       echo "You have to reboot first to make the partition table active."
325
       echo "You have to reboot first to make the partition table active."
329
       echo
326
       echo
330
       exit_now 1
327
       exit_now 1
331
   fi
328
   fi
332
 
329
 
333
   ### set $INSTALL_DEV (eg. /dev/sda)
330
   ### set $INSTALL_DEV (eg. /dev/sda)
334
   ### -----------------------------------------------------------
331
   ### -----------------------------------------------------------
335
   INSTALL_DEV=$( echo "$INSTALL_PART" | sed -e 's%\([sh]d[a-z]\)[0-9]*$%\1%' )
332
   INSTALL_DEV=$( echo "$INSTALL_PART" | sed -e 's%\([sh]d[a-z]\)[0-9]*$%\1%' )
336
   BOOT_DRIVE=$INSTALL_DEV
333
   BOOT_DRIVE=$INSTALL_DEV
337
   INSTALL_PART_NR=$( echo "$INSTALL_PART" | sed -e 's%.*/[sh]d[a-z]\([0-9]*\)$%\1%' )
334
   INSTALL_PART_NR=$( echo "$INSTALL_PART" | sed -e 's%.*/[sh]d[a-z]\([0-9]*\)$%\1%' )
338
   INSTALL_BOOT_DIR="/boot"
335
   INSTALL_BOOT_DIR="/boot"
339
fi
336
fi
340
 
337
 
341
 
338
 
342
### test if $SWAP_PART exists and is a Linux Swap partition
339
### test if $SWAP_PART exists and is a Linux Swap partition
343
### -----------------------------------------------------------
340
### -----------------------------------------------------------
344
if [ "$SWAP_PART" ]; then
341
if [ "$SWAP_PART" ]; then
345
    SWAP_PART=`echo ${SWAP_PART} |tr '[,|]' ' '`
342
    SWAP_PART=`echo ${SWAP_PART} |tr '[,|]' ' '`
346
    for SWAP_PARTITION in $SWAP_PART ; do
343
    for SWAP_PARTITION in $SWAP_PART ; do
347
       fdisk -l 2>/dev/null | cut -d" " -f1 | grep -q "^${SWAP_PARTITION}$"
344
       fdisk -l 2>/dev/null | cut -d" " -f1 | grep -q "^${SWAP_PARTITION}$"
348
       if [ "$?" != "0" ]; then
345
       if [ "$?" != "0" ]; then
349
           echo "Swap partition $SWAP_PARTITION not found! (see 'fdisk -l')."
346
           echo "Swap partition $SWAP_PARTITION not found! (see 'fdisk -l')."
350
           echo "Or you have to reboot first to make the partition table active."
347
           echo "Or you have to reboot first to make the partition table active."
351
           echo
348
           echo
352
           exit_now 1
349
           exit_now 1
353
       fi
350
       fi
354
       fdisk -l 2>/dev/null | grep "Linux swap" | cut -d" " -f1 | grep -q "^${SWAP_PARTITION}$"
351
       fdisk -l 2>/dev/null | grep "Linux swap" | cut -d" " -f1 | grep -q "^${SWAP_PARTITION}$"
355
       if [ "$?" != "0" ]; then
352
       if [ "$?" != "0" ]; then
356
           echo "Partition(s) $SWAP_PARTITION is/are not a Linux swap partition! (see 'fdisk -l')."
353
           echo "Partition(s) $SWAP_PARTITION is/are not a Linux swap partition! (see 'fdisk -l')."
357
           echo "Use fdisk and/or qtparted to create a Linux Swap partition !"
354
           echo "Use fdisk and/or qtparted to create a Linux Swap partition !"
358
           echo "You have to reboot first to make the partition table active."
355
           echo "You have to reboot first to make the partition table active."
359
           echo
356
           echo
360
           exit_now 1
357
           exit_now 1
361
       fi
358
       fi
362
    done
359
    done
363
fi
360
fi
364
 
361
 
365
 
362
 
366
### print warning
363
### print warning
367
### -----------------------------------------------------------
364
### -----------------------------------------------------------
368
echo                     "------------------------------------------------------------"
365
echo                     "------------------------------------------------------------"
369
echo                     "   LiveCD will be installed on partition $INSTALL_PART"
366
echo                     "   LiveCD will be installed on partition $INSTALL_PART"
370
[ "$SWAP_PART" ] && echo " Partition(s) $SWAP_PART will be used as swap partition(s)."
367
[ "$SWAP_PART" ] && echo " Partition(s) $SWAP_PART will be used as swap partition(s)."
371
[ ! $NOGRUB ]    && echo " GRUB will be installed in Master Boot Record of $MBR_DEV"
368
[ ! $NOGRUB ]    && echo " GRUB will be installed in Master Boot Record of $MBR_DEV"
372
echo                     "       !! All data on $INSTALL_PART will be lost !!"
369
echo                     "       !! All data on $INSTALL_PART will be lost !!"
373
echo                     "------------------------------------------------------------"
370
echo                     "------------------------------------------------------------"
374
echo
371
echo
375
 
372
 
376
 
373
 
377
### continue?
374
### continue?
378
### -----------------------------------------------------------
375
### -----------------------------------------------------------
379
if [ ! $YES ]; then
376
if [ ! $YES ]; then
380
    echo -n "Continue (y/N)? "
377
    echo -n "Continue (y/N)? "
381
    read key
378
    read key
382
    echo
379
    echo
383
    [ "$key" != "y" ] && exit_now 0
380
    [ "$key" != "y" ] && exit_now 0
384
fi
381
fi
385
 
382
 
386
 
383
 
387
### format $SWAP_PART (don't format swap, if already formated)
384
### format $SWAP_PART (don't format swap, if already formated)
388
### -----------------------------------------------------------
385
### -----------------------------------------------------------
389
if [ "$SWAP_PART" ]; then
386
if [ "$SWAP_PART" ]; then
390
    echo "Make swap on $SWAP_PART ..."
387
    echo "Make swap on $SWAP_PART ..."
391
    swapoff -a >/dev/null 2>&1
388
    swapoff -a >/dev/null 2>&1
392
    swapon -p 1 $SWAP_PART 2>/dev/null
389
    swapon -p 1 $SWAP_PART 2>/dev/null
393
    if [ "$?" != "0" ]; then
390
    if [ "$?" != "0" ]; then
394
        for SWAP_PARTITION in $SWAP_PART; do
391
        for SWAP_PARTITION in $SWAP_PART; do
395
           echo "Format $SWAP_PARTITION as swap." 
392
           echo "Format $SWAP_PARTITION as swap." 
396
           mkswap $SWAP_PARTITION
393
           mkswap $SWAP_PARTITION
397
        done
394
        done
398
    fi
395
    fi
399
    echo
396
    echo
400
fi
397
fi
401
 
398
 
402
 
399
 
403
if [ $MOUNTED = "0" ]; then
400
if [ $MOUNTED = "0" ]; then
404
    ### format $INSTALL_PART
401
    ### format $INSTALL_PART
405
    ### -----------------------------------------------------------
402
    ### -----------------------------------------------------------
406
 
403
 
407
    # define force option for mkfs command
404
    # define force option for mkfs command
408
    if [ "$FORCE" ] && [ "$FS_TYPE" = "ext3" ];     then  FORCE="-F"; fi
-
 
409
    if [ "$FORCE" ] && [ "$FS_TYPE" = "ext2" ];     then  FORCE="-F"; fi
405
    FORCE=""
410
    if [ "$FORCE" ] && [ "$FS_TYPE" = "xfs" ];      then  FORCE="-f"; fi
406
    [ "$FS_TYPE" = "xfs" ] && FORCE="-f"
411
    if [ "$FORCE" ] && [ "$FS_TYPE" = "reiserfs" ]; then  FORCE=""; fi
-
 
412
    
407
    
413
    echo -n "Format $INSTALL_PART, please wait ... " 
408
    echo -n "Format $INSTALL_PART as $FS_TYPE, please wait ... " 
414
    mkfs.$FS_TYPE $FORCE -q $INSTALL_PART || exit_now 1
409
    mkfs.$FS_TYPE $FORCE -q $INSTALL_PART || exit_now 1
415
    echo "done."; echo
410
    echo "done."; echo
416
 
411
 
417
    ### mount $INSTALL_PART
412
    ### mount $INSTALL_PART
418
    ### -----------------------------------------------------------
413
    ### -----------------------------------------------------------
419
    echo -n "Try to mount $INSTALL_PART to $NEW ... "
414
    echo -n "Try to mount $INSTALL_PART to $NEW ... "
420
    mkdir -p $NEW
415
    mkdir -p $NEW
421
    mount $INSTALL_PART $NEW || exit_now 1
416
    mount $INSTALL_PART $NEW || exit_now 1
422
    echo "done."; echo
417
    echo "done."; echo
423
fi
418
fi
424
 
419
 
425
 
420
 
426
### copy root dirs
421
### copy root dirs
427
### -----------------------------------------------------------
422
### -----------------------------------------------------------
428
echo "Copy Live System to $INSTALL_PART ..."
423
echo "Copy Live System to $INSTALL_PART ..."
429
root_dirs=$( ls / )
424
root_dirs=$( ls / )
430
for dir in $root_dirs; do
425
for dir in $root_dirs; do
431
    # check if dir is not in $DIR_NOT_COPY
426
    # check if dir is not in $DIR_NOT_COPY
432
    do_not_copy=""
427
    do_not_copy=""
433
    for not_dir in $DIR_NOT_COPY; do
428
    for not_dir in $DIR_NOT_COPY; do
434
        if [ "$not_dir" = "/$dir" ]; then 
429
        if [ "$not_dir" = "/$dir" ]; then 
435
            do_not_copy="yes"
430
            do_not_copy="yes"
436
            break
431
            break
437
        fi
432
        fi
438
    done
433
    done
439
    # do not copy links
434
    # do not copy links
440
    [ -L /$dir ] && do_not_copy="yes"
435
    [ -L /$dir ] && do_not_copy="yes"
441
 
436
 
442
    fail=""
437
    fail=""
443
    if [ ! $do_not_copy ]; then
438
    if [ ! $do_not_copy ]; then
444
        echo -n "  * Copy  /$dir ... "
439
        echo -n "  * Copy  /$dir ... "
445
        cp -a -f /$dir $NEW || fail=true
440
        cp -a -f /$dir $NEW || fail=true
446
        echo "done."
441
        echo "done."
447
    fi
442
    fi
448
    fail=""
443
    fail=""
449
done
444
done
450
echo
445
echo
451
if [ $fail ]; then
446
if [ $fail ]; then
452
    echo "ERROR: Not everything was copied to $INSTALL_PART"
447
    echo "ERROR: Not everything was copied to $INSTALL_PART"
453
    exit_now 1
448
    exit_now 1
454
fi
449
fi
455
 
450
 
456
 
451
 
457
### move /usr/opt back to /opt
452
### move /usr/opt back to /opt
458
### -----------------------------------------------------------
453
### -----------------------------------------------------------
459
if [ -d $NEW/usr/opt ]; then
454
if [ -d $NEW/usr/opt ]; then
460
    echo -n "Move /opt back ... "
455
    echo -n "Move /opt back ... "
461
    mv $NEW/usr/opt $NEW/
456
    mv $NEW/usr/opt $NEW/
462
    echo "done."; echo
457
    echo "done."; echo
463
fi
458
fi
464
 
459
 
465
 
460
 
466
### create dirs which were not copied
461
### create dirs which were not copied
467
### -----------------------------------------------------------
462
### -----------------------------------------------------------
468
for dir in $DIR_NOT_COPY; do
463
for dir in $DIR_NOT_COPY; do
469
   if [ ! -d $NEW$dir ]; then
464
   if [ ! -d $NEW$dir ]; then
470
       mkdir $NEW$dir
465
       mkdir $NEW$dir
471
   fi
466
   fi
472
done
467
done
473
# we do not need this directory
468
# we do not need this directory
474
rmdir $NEW/livecd
469
rmdir $NEW/livecd
475
# if not yet existing, create
470
# if not yet existing, create
476
mkdir -p $NEW/srv
471
mkdir -p $NEW/srv
477
mkdir -p $NEW/selinux
472
mkdir -p $NEW/selinux
478
 
473
 
479
 
474
 
480
### copy back original files
475
### copy back original files
481
### -----------------------------------------------------------
476
### -----------------------------------------------------------
482
echo -n "Restore original files ... " 
477
echo -n "Restore original files ... " 
483
for file in $FILES_RESTORE; do
478
for file in $FILES_RESTORE; do
484
    [ -r $NEW${file}.ori ] && mv -f $NEW${file}.ori $NEW${file} 
479
    [ -r $NEW${file}.ori ] && mv -f $NEW${file}.ori $NEW${file} 
485
done
480
done
486
echo "done."; echo
481
echo "done."; echo
487
 
482
 
488
 
483
 
489
### define kernel version
484
### define kernel version
490
### -----------------------------------------------------------
485
### -----------------------------------------------------------
491
rpm --quiet -q kernel     && UP_installed=true
486
rpm --quiet -q kernel     && UP_installed=true
492
rpm --quiet -q kernel-smp && SMP_installed=true
487
rpm --quiet -q kernel-smp && SMP_installed=true
493
[ $UP_installed ]  && KERNEL_VERSION=$( rpm -q --qf "%{V}-%{R}" kernel 2>/dev/null )
488
[ $UP_installed ]  && KERNEL_VERSION=$( rpm -q --qf "%{V}-%{R}" kernel 2>/dev/null )
494
[ $SMP_installed ] && KERNEL_VERSION=$( rpm -q --qf "%{V}-%{R}" kernel-smp  2>/dev/null )
489
[ $SMP_installed ] && KERNEL_VERSION=$( rpm -q --qf "%{V}-%{R}" kernel-smp  2>/dev/null )
495
if [ ! $KERNEL_VERSION ]; then
490
if [ ! $KERNEL_VERSION ]; then
496
    echo "ERROR: Kernel version could not be determined - installation failed"; echo
491
    echo "ERROR: Kernel version could not be determined - installation failed"; echo
497
    exit_now 1
492
    exit_now 1
498
fi    
493
fi    
499
 
494
 
500
 
495
 
501
 
496
 
502
if [ ! $NOGRUB ]; then
497
if [ ! $NOGRUB ]; then
503
 
498
 
504
    ### Backup Master Boot Record MBR
499
    ### Backup Master Boot Record MBR
505
    ### -----------------------------------------------------------
500
    ### -----------------------------------------------------------
506
    # do we have already a backup?
501
    # do we have already a backup?
507
    MBR_FILENAME="MBR$( echo $MBR_DEV | tr / _ ).bak"
502
    MBR_FILENAME="MBR$( echo $MBR_DEV | tr / _ ).bak"
508
    if [ ! -e /tmp/$MBR_FILENAME ]; then
503
    if [ ! -e /tmp/$MBR_FILENAME ]; then
509
        echo "Backup Master Boot Record (MBR) of $MBR_DEV ..."
504
        echo "Backup Master Boot Record (MBR) of $MBR_DEV ..."
510
        dd if=$MBR_DEV of=/tmp/$MBR_FILENAME bs=512 count=1
505
        dd if=$MBR_DEV of=/tmp/$MBR_FILENAME bs=512 count=1
511
    fi
506
    fi
512
    cp -a /tmp/$MBR_FILENAME $NEW/$MBR_FILENAME
507
    cp -a /tmp/$MBR_FILENAME $NEW/$MBR_FILENAME
513
    echo "MBR saved as $MBR_FILENAME on $INSTALL_PART and on /tmp"
508
    echo "MBR saved as $MBR_FILENAME on $INSTALL_PART and on /tmp"
514
    echo
509
    echo
515
 
510
 
516
 
511
 
517
    ### install grub
512
    ### install grub
518
    ### -----------------------------------------------------------
513
    ### -----------------------------------------------------------
519
    echo "Run grub-install ... "
514
    echo "Run grub-install ... "
520
    mkdir -p $NEW/boot/grub
515
    mkdir -p $NEW/boot/grub
521
    if [ $FLOPPY ]; then
516
    if [ $FLOPPY ]; then
522
        grub-install --root-directory=$NEW $MBR_DEV 2>/dev/null || GRUB_FAILED="yes"
517
        grub-install --root-directory=$NEW $MBR_DEV 2>/dev/null || GRUB_FAILED="yes"
523
    else
518
    else
524
        grub-install --no-floppy --root-directory=$NEW $MBR_DEV 2>/dev/null || GRUB_FAILED="yes"
519
        grub-install --no-floppy --root-directory=$NEW $MBR_DEV 2>/dev/null || GRUB_FAILED="yes"
525
    fi
520
    fi
526
    echo "done."; echo
521
    echo "done."; echo
527
 
522
 
528
 
523
 
529
    ### check for device.map file 
524
    ### check for device.map file 
530
    ### -----------------------------------------------------------
525
    ### -----------------------------------------------------------
531
    DEVICE_MAP=$NEW/boot/grub/device.map
526
    DEVICE_MAP=$NEW/boot/grub/device.map
532
    if [ ! -e $NEW/boot/grub/device.map ]; then
527
    if [ ! -e $NEW/boot/grub/device.map ]; then
533
        echo "ERROR: $NEW/boot/grub/device.map not found"
528
        echo "ERROR: $NEW/boot/grub/device.map not found"
534
        exit_now 1
529
        exit_now 1
535
    fi
530
    fi
536
 
531
 
537
 
532
 
538
    ### convert dev syntax to grub syntax
533
    ### convert dev syntax to grub syntax
539
    ### -----------------------------------------------------------
534
    ### -----------------------------------------------------------
540
    GRUB_INSTALL_DEV=$( grep $BOOT_DRIVE $DEVICE_MAP | awk '{ print $1 }' )
535
    GRUB_INSTALL_DEV=$( grep $BOOT_DRIVE $DEVICE_MAP | awk '{ print $1 }' )
541
    GRUB_ROOT_PART=$( echo "$GRUB_INSTALL_DEV" | sed "s%)$%,`expr $INSTALL_PART_NR - 1`)%" )
536
    GRUB_ROOT_PART=$( echo "$GRUB_INSTALL_DEV" | sed "s%)$%,`expr $INSTALL_PART_NR - 1`)%" )
542
 
537
 
543
 
538
 
544
    ### find active Windows partition
539
    ### find active Windows partition
545
    ### -----------------------------------------------------------
540
    ### -----------------------------------------------------------
546
    if [ ! $WIN_PART ]; then
541
    if [ ! $WIN_PART ]; then
547
        # try to find active Windows partition
542
        # try to find active Windows partition
548
        WIN_PART=$( fdisk -l 2>/dev/null | awk '{ if ($2 == "*" && $7 ~ "NTFS") print $1 }' | head -1 )
543
        WIN_PART=$( fdisk -l 2>/dev/null | awk '{ if ($2 == "*" && $7 ~ "NTFS") print $1 }' | head -1 )
549
    fi
544
    fi
550
 
545
 
551
    if [ $WIN_PART ]; then
546
    if [ $WIN_PART ]; then
552
        WIN_installed=true
547
        WIN_installed=true
553
        WIN_DISK=$( echo "$WIN_PART" | sed -e 's%\([sh]d[a-z]\)[0-9]*$%\1%' )
548
        WIN_DISK=$( echo "$WIN_PART" | sed -e 's%\([sh]d[a-z]\)[0-9]*$%\1%' )
554
        WIN_PART_NR=$( echo "$WIN_PART" | sed -e 's%.*/[sh]d[a-z]\([0-9]*\)$%\1%' )
549
        WIN_PART_NR=$( echo "$WIN_PART" | sed -e 's%.*/[sh]d[a-z]\([0-9]*\)$%\1%' )
555
        # convert dev syntax to grub syntax
550
        # convert dev syntax to grub syntax
556
        GRUB_WIN_DEV=$( grep $WIN_DISK $DEVICE_MAP | awk '{ print $1 }' )
551
        GRUB_WIN_DEV=$( grep $WIN_DISK $DEVICE_MAP | awk '{ print $1 }' )
557
        GRUB_WIN_PART=$( echo "$GRUB_WIN_DEV" | sed "s%)$%,`expr $WIN_PART_NR - 1`)%" )
552
        GRUB_WIN_PART=$( echo "$GRUB_WIN_DEV" | sed "s%)$%,`expr $WIN_PART_NR - 1`)%" )
558
 
553
 
559
        # $GRUB_WIN_PART should be something like (hd0,0)
554
        # $GRUB_WIN_PART should be something like (hd0,0)
560
        echo "Found active Windows partition ( $WIN_PART = $GRUB_WIN_PART )" 
555
        echo "Found active Windows partition ( $WIN_PART = $GRUB_WIN_PART )" 
561
        echo "Will add entry for Windows in GRUB."
556
        echo "Will add entry for Windows in GRUB."
562
        echo
557
        echo
563
    fi
558
    fi
564
 
559
 
565
 
560
 
566
    ### create grub.conf file
561
    ### create grub.conf file
567
    ### -----------------------------------------------------------
562
    ### -----------------------------------------------------------
568
    echo "Create grub.conf ..."
563
    echo "Create grub.conf ..."
569
 
564
 
570
    TITLE="Linux"
565
    TITLE="Linux"
571
    [ -e $NEW/etc/redhat-release ] && TITLE=$( cat $NEW/etc/redhat-release )
566
    [ -e $NEW/etc/redhat-release ] && TITLE=$( cat $NEW/etc/redhat-release )
572
 
567
 
573
    DEFAULT=0
568
    DEFAULT=0
574
    # set default=1, if smp kernel is running
569
    # set default=1, if smp kernel is running
575
    uname -r | grep -q smp
570
    uname -r | grep -q smp
576
    [ "$?" = "0" ] && DEFAULT=1
571
    [ "$?" = "0" ] && DEFAULT=1
577
 
572
 
578
    cat > $NEW/boot/grub/grub.conf <<EOF
573
    cat > $NEW/boot/grub/grub.conf <<EOF
579
# grub.conf generated by $SCRIPTNAME
574
# grub.conf generated by $SCRIPTNAME
580
default=$DEFAULT
575
default=$DEFAULT
581
timeout=10
576
timeout=10
582
splashimage=${GRUB_ROOT_PART}${INSTALL_BOOT_DIR}/grub/splash.xpm.gz
577
splashimage=${GRUB_ROOT_PART}${INSTALL_BOOT_DIR}/grub/splash.xpm.gz
583
#hiddenmenu
578
#hiddenmenu
584
EOF
579
EOF
585
 
580
 
586
    if [ $UP_installed ]; then
581
    if [ $UP_installed ]; then
587
        echo "Add entry for UP kernel into grub.conf"
582
        echo "Add entry for UP kernel into grub.conf"
588
        cat >> $NEW/boot/grub/grub.conf <<EOF
583
        cat >> $NEW/boot/grub/grub.conf <<EOF
589
title $TITLE (${KERNEL_VERSION})
584
title $TITLE (${KERNEL_VERSION})
590
        root $GRUB_ROOT_PART
585
        root $GRUB_ROOT_PART
591
        kernel ${INSTALL_BOOT_DIR}/vmlinuz-$KERNEL_VERSION ro root=$INSTALL_PART
586
        kernel ${INSTALL_BOOT_DIR}/vmlinuz-$KERNEL_VERSION ro root=$INSTALL_PART
592
        initrd ${INSTALL_BOOT_DIR}/initrd-$KERNEL_VERSION.img
587
        initrd ${INSTALL_BOOT_DIR}/initrd-$KERNEL_VERSION.img
593
EOF
588
EOF
594
    fi
589
    fi
595
 
590
 
596
    if [ $SMP_installed ]; then
591
    if [ $SMP_installed ]; then
597
        echo "Add entry for SMP kernel into grub.conf"
592
        echo "Add entry for SMP kernel into grub.conf"
598
        cat >> $NEW/boot/grub/grub.conf <<EOF
593
        cat >> $NEW/boot/grub/grub.conf <<EOF
599
title $TITLE (${KERNEL_VERSION}smp)
594
title $TITLE (${KERNEL_VERSION}smp)
600
        root $GRUB_ROOT_PART
595
        root $GRUB_ROOT_PART
601
        kernel ${INSTALL_BOOT_DIR}/vmlinuz-${KERNEL_VERSION}smp ro root=$INSTALL_PART
596
        kernel ${INSTALL_BOOT_DIR}/vmlinuz-${KERNEL_VERSION}smp ro root=$INSTALL_PART
602
        initrd ${INSTALL_BOOT_DIR}/initrd-${KERNEL_VERSION}smp.img
597
        initrd ${INSTALL_BOOT_DIR}/initrd-${KERNEL_VERSION}smp.img
603
EOF
598
EOF
604
    fi
599
    fi
605
 
600
 
606
    if [ $WIN_installed ]; then
601
    if [ $WIN_installed ]; then
607
        echo "Add entry for Windows into grub.conf"
602
        echo "Add entry for Windows into grub.conf"
608
        cat >> $NEW/boot/grub/grub.conf <<EOF
603
        cat >> $NEW/boot/grub/grub.conf <<EOF
609
title Windows
604
title Windows
610
        rootnoverify $GRUB_WIN_PART
605
        rootnoverify $GRUB_WIN_PART
611
        chainloader +1
606
        chainloader +1
612
EOF
607
EOF
613
    fi
608
    fi
614
 
609
 
615
    chmod 600 $NEW/boot/grub/grub.conf
610
    chmod 600 $NEW/boot/grub/grub.conf
616
    ln -s ../boot/grub/grub.conf $NEW/etc/grub.conf
611
    ln -s ../boot/grub/grub.conf $NEW/etc/grub.conf
617
    ln -s ./grub.conf $NEW/boot/grub/menu.lst
612
    ln -s ./grub.conf $NEW/boot/grub/menu.lst
618
    echo "done."; echo
613
    echo "done."; echo
619
 
614
 
620
 
615
 
621
    ### create /etc/sysconfig/grub file
616
    ### create /etc/sysconfig/grub file
622
    ### -----------------------------------------------------------
617
    ### -----------------------------------------------------------
623
    cat > $NEW/etc/sysconfig/grub <<EOF    
618
    cat > $NEW/etc/sysconfig/grub <<EOF    
624
boot=$INSTALL_DEV
619
boot=$INSTALL_DEV
625
forcelba=0
620
forcelba=0
626
EOF
621
EOF
627
 
622
 
628
 
623
 
629
fi
624
fi
630
 
625
 
631
 
626
 
632
### install kernel and other files into /boot
627
### install kernel and other files into /boot
633
### -----------------------------------------------------------
628
### -----------------------------------------------------------
634
echo "Install kernel(s) ..."
629
echo "Install kernel(s) ..."
635
 
630
 
636
[ -e /boot/vmlinuz ]      && BOOT_DIR=/boot
631
[ -e /boot/vmlinuz ]      && BOOT_DIR=/boot
637
[ -e /boot/boot/vmlinuz ] && BOOT_DIR=/boot/boot
632
[ -e /boot/boot/vmlinuz ] && BOOT_DIR=/boot/boot
638
 
633
 
639
if [ ! $BOOT_DIR ]; then
634
if [ ! $BOOT_DIR ]; then
640
    echo "ERROR: No kernel found - installation failed"; echo
635
    echo "ERROR: No kernel found - installation failed"; echo
641
    exit_now 1
636
    exit_now 1
642
fi
637
fi
643
 
638
 
644
cp -a $BOOT_DIR/vmlinuz            $NEW/boot/vmlinuz-${KERNEL_VERSION}
639
cp -a $BOOT_DIR/vmlinuz            $NEW/boot/vmlinuz-${KERNEL_VERSION}
645
cp -a $BOOT_DIR/vmlinuzs           $NEW/boot/vmlinuz-${KERNEL_VERSION}smp  2>/dev/null
640
cp -a $BOOT_DIR/vmlinuzs           $NEW/boot/vmlinuz-${KERNEL_VERSION}smp  2>/dev/null
646
cp -a $BOOT_DIR/System.map-*       $NEW/boot/
641
cp -a $BOOT_DIR/System.map-*       $NEW/boot/
647
cp -a $BOOT_DIR/config-*           $NEW/boot/
642
cp -a $BOOT_DIR/config-*           $NEW/boot/
648
cp -a $BOOT_DIR/symvers-*.gz       $NEW/boot/        2>/dev/null
643
cp -a $BOOT_DIR/symvers-*.gz       $NEW/boot/        2>/dev/null
649
cp -a $BOOT_DIR/grub/splash.xpm.gz $NEW/boot/grub/   2>/dev/null
644
cp -a $BOOT_DIR/grub/splash.xpm.gz $NEW/boot/grub/   2>/dev/null
650
cp -a $BOOT_DIR/message.ja         $NEW/boot/        2>/dev/null
645
cp -a $BOOT_DIR/message.ja         $NEW/boot/        2>/dev/null
651
cp -a $BOOT_DIR/message            $NEW/boot/        2>/dev/null
646
cp -a $BOOT_DIR/message            $NEW/boot/        2>/dev/null
652
 
647
 
653
echo "done."; echo
648
echo "done."; echo
654
 
649
 
655
 
650
 
656
### create /etc/sysconfig/kernel file
651
### create /etc/sysconfig/kernel file
657
### -----------------------------------------------------------
652
### -----------------------------------------------------------
658
cat > $NEW/etc/sysconfig/kernel <<EOF    
653
cat > $NEW/etc/sysconfig/kernel <<EOF    
659
# UPDATEDEFAULT specifies if new-kernel-pkg should make
654
# UPDATEDEFAULT specifies if new-kernel-pkg should make
660
# new kernels the default
655
# new kernels the default
661
UPDATEDEFAULT=yes
656
UPDATEDEFAULT=yes
662
 
657
 
663
# DEFAULTKERNEL specifies the default kernel package type
658
# DEFAULTKERNEL specifies the default kernel package type
664
DEFAULTKERNEL=kernel
659
DEFAULTKERNEL=kernel
665
EOF
660
EOF
666
 
661
 
667
 
662
 
668
### create /etc/fstab
663
### create /etc/fstab
669
### -----------------------------------------------------------
664
### -----------------------------------------------------------
670
cat > $NEW/etc/fstab <<EOF
665
cat > $NEW/etc/fstab <<EOF
671
$INSTALL_PART	/		$FS_TYPE		defaults	1 1
666
$INSTALL_PART	/		$FS_TYPE		defaults	1 1
672
EOF
667
EOF
673
 
668
 
674
if [ -z "$INSTALL_BOOT_DIR" ]; then
669
if [ -z "$INSTALL_BOOT_DIR" ]; then
675
   echo "$INSTALL_DEV	/boot		$FS_TYPE		defaults	1 2" >> $NEW/etc/fstab
670
   echo "$INSTALL_DEV	/boot		$FS_TYPE		defaults	1 2" >> $NEW/etc/fstab
676
fi
671
fi
677
 
672
 
678
cat >> $NEW/etc/fstab <<EOF
673
cat >> $NEW/etc/fstab <<EOF
679
devpts          /dev/pts        devpts          gid=5,mode=620  0 0
674
devpts          /dev/pts        devpts          gid=5,mode=620  0 0
680
tmpfs	        /dev/shm        tmpfs           defaults        0 0
675
tmpfs	        /dev/shm        tmpfs           defaults        0 0
681
proc	        /proc           proc            defaults        0 0
676
proc	        /proc           proc            defaults        0 0
682
sysfs		/sys            sysfs           defaults        0 0
677
sysfs		/sys            sysfs           defaults        0 0
683
EOF
678
EOF
684
 
679
 
685
if [ "$SWAP_PART" ]; then
680
if [ "$SWAP_PART" ]; then
686
    for SWAP_PARTITION in $SWAP_PART ; do
681
    for SWAP_PARTITION in $SWAP_PART ; do
687
        echo "$SWAP_PARTITION	swap		swap		defaults,pri=1	0 0" >> $NEW/etc/fstab
682
        echo "$SWAP_PARTITION	swap		swap		defaults,pri=1	0 0" >> $NEW/etc/fstab
688
    done
683
    done
689
fi
684
fi
690
 
685
 
691
 
686
 
692
### make initrd 
687
### make initrd 
693
### (needs $NEW/etc/fstab to find correct modules for root filesystem !!)
688
### (needs $NEW/etc/fstab to find correct modules for root filesystem !!)
694
### -----------------------------------------------------------
689
### -----------------------------------------------------------
695
echo "Create initrd(s) ..."
690
echo "Create initrd(s) ..."
696
# initrd should not be build on tmpfs (we take $NEW/tmp instead of /tmp)
691
# initrd should not be build on tmpfs (we take $NEW/tmp instead of /tmp)
697
sed -i "s|^TMPDIR=.*|TMPDIR=\"$NEW/tmp\"|" /usr/sbin/livecd-mkinitrd
692
sed -i "s|^TMPDIR=.*|TMPDIR=\"$NEW/tmp\"|" /usr/sbin/livecd-mkinitrd
698
 
693
 
699
if [ $UP_installed ]; then
694
if [ $UP_installed ]; then
700
    depmod -a ${KERNEL_VERSION}
695
    depmod -a ${KERNEL_VERSION}
701
    /usr/sbin/livecd-mkinitrd --fstab=$NEW/etc/fstab \
696
    /usr/sbin/livecd-mkinitrd --fstab=$NEW/etc/fstab \
702
                    $NEW/boot/initrd-${KERNEL_VERSION}.img ${KERNEL_VERSION}
697
                    $NEW/boot/initrd-${KERNEL_VERSION}.img ${KERNEL_VERSION}
703
    if [ ! -e $NEW/boot/initrd-${KERNEL_VERSION}.img ]; then
698
    if [ ! -e $NEW/boot/initrd-${KERNEL_VERSION}.img ]; then
704
        echo "ERROR: Failed to create $NEW/boot/initrd-${KERNEL_VERSION}.img"
699
        echo "ERROR: Failed to create $NEW/boot/initrd-${KERNEL_VERSION}.img"
705
        exit_now 1
700
        exit_now 1
706
    fi
701
    fi
707
fi
702
fi
708
if [ $SMP_installed ]; then
703
if [ $SMP_installed ]; then
709
    depmod -a ${KERNEL_VERSION}smp
704
    depmod -a ${KERNEL_VERSION}smp
710
    /usr/sbin/livecd-mkinitrd --fstab=$NEW/etc/fstab \
705
    /usr/sbin/livecd-mkinitrd --fstab=$NEW/etc/fstab \
711
                    $NEW/boot/initrd-${KERNEL_VERSION}smp.img ${KERNEL_VERSION}smp
706
                    $NEW/boot/initrd-${KERNEL_VERSION}smp.img ${KERNEL_VERSION}smp
712
    if [ ! -e $NEW/boot/initrd-${KERNEL_VERSION}smp.img ]; then
707
    if [ ! -e $NEW/boot/initrd-${KERNEL_VERSION}smp.img ]; then
713
        echo "ERROR: Failed to create $NEW/boot/initrd-${KERNEL_VERSION}smp.img"
708
        echo "ERROR: Failed to create $NEW/boot/initrd-${KERNEL_VERSION}smp.img"
714
        exit_now 1
709
        exit_now 1
715
    fi
710
    fi
716
fi
711
fi
717
echo "done."; echo
712
echo "done."; echo
718
 
713
 
719
 
714
 
720
### remove LiveCD init.d scripts
715
### remove LiveCD init.d scripts
721
### -----------------------------------------------------------
716
### -----------------------------------------------------------
722
for file in $LIVECD_INIT_SCRIPTS; do
717
for file in $LIVECD_INIT_SCRIPTS; do
723
    rm -f $NEW/etc/rc.d/init.d/$file
718
    rm -f $NEW/etc/rc.d/init.d/$file
724
    for n in 0 1 2 3 4 5 6; do
719
    for n in 0 1 2 3 4 5 6; do
725
	rm -f $NEW/etc/rc.d/rc${n}.d/*$file
720
	rm -f $NEW/etc/rc.d/rc${n}.d/*$file
726
    done
721
    done
727
done
722
done
728
 
723
 
729
 
724
 
730
### restore cronjobs
725
### restore cronjobs
731
### -----------------------------------------------------------
726
### -----------------------------------------------------------
732
mv $NEW/etc/cron_backup/sysstat       $NEW/etc/cron.d/ 2>/dev/null
727
mv $NEW/etc/cron_backup/sysstat       $NEW/etc/cron.d/ 2>/dev/null
733
mv $NEW/etc/cron_backup/cfengine      $NEW/etc/cron.d/ 2>/dev/null
728
mv $NEW/etc/cron_backup/cfengine      $NEW/etc/cron.d/ 2>/dev/null
734
mv $NEW/etc/cron_backup/psi-cronjobs  $NEW/etc/cron.d/ 2>/dev/null
729
mv $NEW/etc/cron_backup/psi-cronjobs  $NEW/etc/cron.d/ 2>/dev/null
735
mv $NEW/etc/cron_backup/00-makewhatis.cron.weekly $NEW/etc/cron.weekly/00-makewhatis.cron 2>/dev/null
730
mv $NEW/etc/cron_backup/00-makewhatis.cron.weekly $NEW/etc/cron.weekly/00-makewhatis.cron 2>/dev/null
736
mv $NEW/etc/cron_backup/*             $NEW/etc/cron.daily/ 2>/dev/null
731
mv $NEW/etc/cron_backup/*             $NEW/etc/cron.daily/ 2>/dev/null
737
 
732
 
738
 
733
 
739
### prepare chroot to $NEW
734
### prepare chroot to $NEW
740
### -----------------------------------------------------------
735
### -----------------------------------------------------------
741
mount --bind /dev $NEW/dev
736
mount --bind /dev $NEW/dev
742
mount --bind /sys $NEW/sys
737
mount --bind /sys $NEW/sys
743
mount -t proc proc $NEW/proc
738
mount -t proc proc $NEW/proc
744
 
739
 
745
 
740
 
746
### turn on kudzu again
741
### turn on kudzu again
747
### -----------------------------------------------------------
742
### -----------------------------------------------------------
748
chroot $NEW chkconfig kudzu on
743
chroot $NEW chkconfig kudzu on
749
 
744
 
750
 
745
 
751
### turn on check_update again (only at PSI)
746
### turn on check_update again (only at PSI)
752
### -----------------------------------------------------------
747
### -----------------------------------------------------------
753
chroot $NEW chkconfig check_update on 2>/dev/null
748
chroot $NEW chkconfig check_update on 2>/dev/null
754
 
749
 
755
 
750
 
756
### fix some services which were disabled 
751
### fix some services which were disabled 
757
### because of diskless NFS client
752
### because of diskless NFS client
758
### -----------------------------------------------------------
753
### -----------------------------------------------------------
759
if [ -e /$MOUNTDIR/service.on ]; then
754
if [ -e /$MOUNTDIR/service.on ]; then
760
    cat /$MOUNTDIR/service.on | while read $serv; do
755
    cat /$MOUNTDIR/service.on | while read $serv; do
761
        chroot $NEW chkconfig $serv on
756
        chroot $NEW chkconfig $serv on
762
    done
757
    done
763
fi
758
fi
764
 
759
 
765
 
760
 
766
### remove some files
761
### remove some files
767
### -----------------------------------------------------------
762
### -----------------------------------------------------------
768
rm -rf $NEW/usr/share/applications/livecd-install-gui.desktop
763
rm -rf $NEW/usr/share/applications/livecd-install-gui.desktop
769
rm -rf $NEW/usr/share/applications/save-localdata.desktop
764
rm -rf $NEW/usr/share/applications/save-localdata.desktop
770
 
765
 
771
 
766
 
772
### remove RPMs that can break future updates  
767
### remove RPMs that can break future updates  
773
### -----------------------------------------------------------
768
### -----------------------------------------------------------
774
if [ ! $NORPMREMOVE ]; then
769
if [ ! $NORPMREMOVE ]; then
775
    echo "Remove RPMs that may break future updates ..."
770
    echo "Remove RPMs that may break future updates ..."
776
    chroot $NEW rpm -qa 2>/dev/null > /tmp/rpmlist
771
    chroot $NEW rpm -qa 2>/dev/null > /tmp/rpmlist
777
 
772
 
778
    # Scientific Linux RPMs
773
    # Scientific Linux RPMs
779
    RPMSTOREMOVE="$RPMS_TO_REMOVE $RPMS_TO_REMOVE_SL"
774
    RPMSTOREMOVE="$RPMS_TO_REMOVE $RPMS_TO_REMOVE_SL"
780
 
775
 
781
    # PSI Scientific Linux RPMs
776
    # PSI Scientific Linux RPMs
782
    if [ -e /etc/sysconfig/psi ]; then
777
    if [ -e /etc/sysconfig/psi ]; then
783
        RPMSTOREMOVE="$RPMS_TO_REMOVE $RPMS_TO_REMOVE_PSI"
778
        RPMSTOREMOVE="$RPMS_TO_REMOVE $RPMS_TO_REMOVE_PSI"
784
    fi
779
    fi
785
 
780
 
786
    for rpm in $RPMSTOREMOVE; do
781
    for rpm in $RPMSTOREMOVE; do
787
        rpms_remove=$( cat /tmp/rpmlist | grep "^$rpm" )
782
        rpms_remove=$( cat /tmp/rpmlist | grep "^$rpm" )
788
        for rpm_remove in $rpms_remove; do        
783
        for rpm_remove in $rpms_remove; do        
789
            chroot $NEW rpm -e --nodeps $rpm_remove >/dev/null 2>&1
784
            chroot $NEW rpm -e --nodeps $rpm_remove >/dev/null 2>&1
790
            [ "$?" = "0" ] && echo " removing $rpm_remove"
785
            [ "$?" = "0" ] && echo " removing $rpm_remove"
791
        done
786
        done
792
    done
787
    done
793
    echo "done."; echo
788
    echo "done."; echo
794
fi
789
fi
795
 
790
 
796
 
791
 
797
### disable nvidia driver 
792
### disable nvidia driver 
798
### -----------------------------------------------------------
793
### -----------------------------------------------------------
799
# not in case of a PSI installation
794
# not in case of a PSI installation
800
if [ ! -e /etc/sysconfig/psi ]; then
795
if [ ! -e /etc/sysconfig/psi ]; then
801
    if [ -e $NEW/etc/X11/xorg.conf.nv_SAVED ]; then
796
    if [ -e $NEW/etc/X11/xorg.conf.nv_SAVED ]; then
802
        echo "Remove nvidia driver and correct xorg.conf ..."
797
        echo "Remove nvidia driver and correct xorg.conf ..."
803
        # correct xorg.conf
798
        # correct xorg.conf
804
        sed -i "s/#nv_SAVED //" $NEW/etc/X11/xorg.conf
799
        sed -i "s/#nv_SAVED //" $NEW/etc/X11/xorg.conf
805
        sed -i "/.*Driver.*nvidia.*/d" $NEW/etc/X11/xorg.conf
800
        sed -i "/.*Driver.*nvidia.*/d" $NEW/etc/X11/xorg.conf
806
        # disable nvidia libs (if not yet done by rpm -e)
801
        # disable nvidia libs (if not yet done by rpm -e)
807
        LIB=lib
802
        LIB=lib
808
        [ $( arch ) = "x86_64" ] && LIB=lib64
803
        [ $( arch ) = "x86_64" ] && LIB=lib64
809
        mv -f $NEW/usr/X11R6/$LIB/modules/extensions/xxx.libGLcore.a.saved_by_nvidia \
804
        mv -f $NEW/usr/X11R6/$LIB/modules/extensions/xxx.libGLcore.a.saved_by_nvidia \
810
              $NEW/usr/X11R6/$LIB/modules/extensions/libGLcore.a 2>/dev/null
805
              $NEW/usr/X11R6/$LIB/modules/extensions/libGLcore.a 2>/dev/null
811
        mv -f $NEW/usr/X11R6/$LIB/modules/extensions/xxx.libglx.a.saved_by_nvidia \
806
        mv -f $NEW/usr/X11R6/$LIB/modules/extensions/xxx.libglx.a.saved_by_nvidia \
812
              $NEW/usr/X11R6/$LIB/modules/extensions/libglx.a 2>/dev/null
807
              $NEW/usr/X11R6/$LIB/modules/extensions/libglx.a 2>/dev/null
813
        rm -f $NEW/usr/X11R6/$LIB/modules/extensions/libglx.so
808
        rm -f $NEW/usr/X11R6/$LIB/modules/extensions/libglx.so
814
        rm -f $NEW/usr/X11R6/$LIB/libGL.so*
809
        rm -f $NEW/usr/X11R6/$LIB/libGL.so*
815
        rm -f $NEW/usr/$LIB/libGLcore.so
810
        rm -f $NEW/usr/$LIB/libGLcore.so
816
        echo "done."; echo
811
        echo "done."; echo
817
    fi
812
    fi
818
fi
813
fi
819
 
814
 
820
 
815
 
821
### install grub for the 2. time, if it failed before 
816
### install grub for the 2. time, if it failed before 
822
### (happens on xfs filesystem)
817
### (happens on xfs filesystem)
823
### -----------------------------------------------------------
818
### -----------------------------------------------------------
824
if [ ! $NOGRUB ] && [ $GRUB_FAILED ]; then
819
if [ ! $NOGRUB ] && [ $GRUB_FAILED ]; then
825
 
820
 
826
    echo "Run grub-install for the 2. time ... "
821
    echo "Run grub-install for the 2. time ... "
827
    mkdir -p $NEW/boot/grub
822
    mkdir -p $NEW/boot/grub
828
    if [ $FLOPPY ]; then
823
    if [ $FLOPPY ]; then
829
        grub-install --root-directory=$NEW $MBR_DEV
824
        grub-install --root-directory=$NEW $MBR_DEV
830
    else
825
    else
831
        grub-install --no-floppy --root-directory=$NEW $MBR_DEV
826
        grub-install --no-floppy --root-directory=$NEW $MBR_DEV
832
    fi
827
    fi
833
    echo "done."; echo
828
    echo "done."; echo
834
 
829
 
835
fi
830
fi
836
 
831
 
837
### umount $INSTALL_PART
832
### umount $INSTALL_PART
838
### -----------------------------------------------------------
833
### -----------------------------------------------------------
839
umount $NEW/dev
834
umount $NEW/dev
840
umount $NEW/sys
835
umount $NEW/sys
841
umount $NEW/proc
836
umount $NEW/proc
842
UMOUNT_LIST=`df -l | grep "$NEW" | sed -e 's/  */ /g' | cut -d" " -f6 | sort -r`
837
UMOUNT_LIST=`df -l | grep "$NEW" | sed -e 's/  */ /g' | cut -d" " -f6 | sort -r`
843
umount $UMOUNT_LIST
838
umount $UMOUNT_LIST
844
 
839
 
845
 
840
 
846
### print summary
841
### print summary
847
### -----------------------------------------------------------
842
### -----------------------------------------------------------
848
echo                     "--------------------------------------------------------------"
843
echo                     "--------------------------------------------------------------"
849
echo                     "  LiveCD installed on partition $INSTALL_PART"
844
echo                     "  LiveCD installed on partition $INSTALL_PART"
850
[ "$SWAP_PART" ] && echo "  Partition(s) $SWAP_PART will be used as swap partition(s)"
845
[ "$SWAP_PART" ] && echo "  Partition(s) $SWAP_PART will be used as swap partition(s)"
851
echo
846
echo
852
[ ! $NOGRUB ]    && echo "  GRUB installed in Master Boot Record (MBR) of $MBR_DEV"
847
[ ! $NOGRUB ]    && echo "  GRUB installed in Master Boot Record (MBR) of $MBR_DEV"
853
[ ! $NOGRUB ]    && echo "  MBR saved as $MBR_FILENAME on $INSTALL_PART and in /tmp"
848
[ ! $NOGRUB ]    && echo "  MBR saved as $MBR_FILENAME on $INSTALL_PART and in /tmp"
854
[ ! $NOGRUB ]    && echo "  If you have to restore MBR, execute under Linux:"
849
[ ! $NOGRUB ]    && echo "  If you have to restore MBR, execute under Linux:"
855
[ ! $NOGRUB ]    && echo "  # dd if=$MBR_FILENAME of=$MBR_DEV bs=512 count=1"
850
[ ! $NOGRUB ]    && echo "  # dd if=$MBR_FILENAME of=$MBR_DEV bs=512 count=1"
856
echo 
851
echo 
857
[ $WIN_PART ]    && echo "  Entry created in grub.conf for Windows partition $WIN_PART"
852
[ $WIN_PART ]    && echo "  Entry created in grub.conf for Windows partition $WIN_PART"
858
echo                     "--------------------------------------------------------------"
853
echo                     "--------------------------------------------------------------"
859
echo                     "End of $SCRIPTNAME"
854
echo                     "End of $SCRIPTNAME"
860
echo
855
echo