Subversion Repositories ALCASAR

Rev

Rev 2484 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2484 rexy 1
#!/bin/bash
2
#
3
# Authors: Mageia Team
4
# Update for ALCASAR : Hamza ESSAYEGH (Querdos) - Rexy - Laurent Roux
5
##
6
# Usage: $0 ARGS
7
#     --iso-file, -i      Mageia-xxx-xxxxxx-xxx.iso (mandatory)
8
#     --lang, -l          Language for installation (optional)
9
#                         Supported languages: fr;en
10
#
11
 
12
# Colors parameters
13
RED='\033[0;31m'
14
GREEN='\033[0;32m'
15
YELLOW='\033[0;33m'
16
NC='\033[0m'
17
 
18
function print_percentage() {
19
    local percent=$1
20
    if [ ${percent} -lt 5 ]; then
21
        echo -ne "Downloading... [                      ] ${percent}%\r"
22
    elif [ ${percent} -lt 10 ]; then
23
        echo -ne "Downloading... [ #                    ] ${percent}%\r"
24
    elif [  ${percent} -lt 15  ]; then
25
        echo -ne "Downloading... [ ##                   ] ${percent}%\r"
26
    elif [  ${percent} -lt 20  ]; then
27
        echo -ne "Downloading... [ ###                  ] ${percent}%\r"
28
    elif [  ${percent} -lt 25  ]; then
29
        echo -ne "Downloading... [ ####                 ] ${percent}%\r"
30
    elif [  ${percent} -lt 30  ]; then
31
        echo -ne "Downloading... [ #####                ] ${percent}%\r"
32
    elif [  ${percent} -lt 35  ]; then
33
        echo -ne "Downloading... [ ######               ] ${percent}%\r"
34
    elif [  ${percent} -lt 40  ]; then
35
        echo -ne "Downloading... [ #######              ] ${percent}%\r"
36
    elif [  ${percent} -lt 45  ]; then
37
        echo -ne "Downloading... [ ########             ] ${percent}%\r"
38
    elif [  ${percent} -lt 50  ]; then
39
        echo -ne "Downloading... [ #########            ] ${percent}%\r"
40
    elif [  ${percent} -lt 55  ]; then
41
        echo -ne "Downloading... [ ##########           ] ${percent}%\r"
42
    elif [  ${percent} -lt 60  ]; then
43
        echo -ne "Downloading... [ ###########          ] ${percent}%\r"
44
    elif [  ${percent} -lt 65  ]; then
45
        echo -ne "Downloading... [ ############         ] ${percent}%\r"
46
    elif [  ${percent} -lt 70  ]; then
47
        echo -ne "Downloading... [ #############        ] ${percent}%\r"
48
    elif [  ${percent} -lt 75  ]; then
49
        echo -ne "Downloading... [ ##############       ] ${percent}%\r"
50
    elif [  ${percent} -lt 80  ]; then
51
        echo -ne "Downloading... [ ###############      ] ${percent}%\r"
52
    elif [  ${percent} -lt 85  ]; then
53
        echo -ne "Downloading... [ ################     ] ${percent}%\r"
54
    elif [  ${percent} -lt 90  ]; then
55
        echo -ne "Downloading... [ #################    ] ${percent}%\r"
56
    elif [  ${percent} -lt 95  ]; then
57
        echo -ne "Downloading... [ ##################   ] ${percent}%\r"
58
    elif [  ${percent} -lt 100  ]; then
59
        echo -ne "Downloading... [ ###################  ] ${percent}%\r"
60
    elif [  ${percent} == 100  ]; then
61
        echo -ne "Downloading... [ #################### ] ${percent}%\r"
62
    fi
63
}
64
 
65
# Check if a given option is valid an set a global var with the option value
66
function optionIsValid() {
67
    # Retrieving option and its value
68
    local option=$1
69
    local value=$2
70
 
71
    # Available options (short and long)
72
    local isoFileOption="--iso-file -i"
73
    local langOption="--lang -l"
74
 
75
    # Iso file option ?
76
    for opt in ${isoFileOption}; do
77
        if [[ ${opt} = ${option} ]]; then
78
            isoFile=${value}
79
            return 0
80
        fi
81
    done
82
 
83
    # Language option ?
84
    for opt in ${langOption}; do
85
        if [[ ${opt} = ${option} ]]; then
86
            lang="-${value}"
87
            return 0
88
        fi
89
    done
90
 
91
    # Unknown option
92
    echo "Unknown option '${option}'. Aborting." && exit 1
93
}
94
 
95
# Check if needed packages are installed
96
function requiredPackagesInstalled() {
97
    # Checking mkisofs
98
    command -v genisoimage > /dev/null 2>&1 || \
99
        { echo "The package genisoimage is not installed." && \
100
            genisoimageNotInstalled=1; }
101
 
102
    # Checking genhdlist2
103
    command -v genhdlist2 > /dev/null 2>&1 || \
104
        { echo "The package genhdlist2 is not installed." && \
105
            genhdlist2NotInstalled=1; }
106
 
107
    # Checking gendistrib
108
    command -v gendistrib > /dev/null 2>&1 || \
109
        { echo "The package gendistrib is not installed (rpmtools)." && \
110
            gendistribNotInstalled=1; }
111
 
112
    # If one of the following, aborting
113
    [[ ${genisoimageNotInstalled} -eq 1 ]] || \
114
        [[ ${genhdlist2NotInstalled} -eq 1 ]] || \
115
        [[ ${gendistribNotInstalled} -eq 1 ]] && exit 1
116
}
117
 
118
# Check if a given language is supported by this script or not
119
function languageIsSupported() {
120
    local lang=$1
121
    local supportedLang="fr en"
122
 
123
    # Comparing with available langs
124
    for supLang in ${supportedLang}; do
125
        if [[ ${supLang} = ${lang} ]]; then
126
            return 0
127
        fi
128
    done
129
 
130
    # Language is not supported
131
    echo "Language '${lang}' is not supported. Aborting." && exit 1
132
}
133
 
134
# "Purify" the rpm name -> for the plop.idx file ("Mageia-5.1-x86_64 rpmname" for example)
135
function purifyRpmName() {
136
    local str=$1
137
    local arch=$2
138
    local len=${#str}
139
 
140
    p=`echo ${str} | grep -oP ".*\.mga6"`
141
    echo "Mageia-6-${arch} ${p}"
142
}
143
 
2525 rexy 144
#################################
145
#          BEGIN HERE           #
146
#################################
2484 rexy 147
# Checking arguments (rpm_list and iso file and eventually lang)
148
[[ ($# -lt 1) || ($# -gt 2) ]] && echo \
149
"Usage: $0 ARGS
150
    --iso-file, -i      Mageia-xxx-xxxxxx-xxx.iso (mandatory)
151
    --lang, -l          Language for installation (optional)
152
                        Supported languages: fr;en
153
" && exit 1
154
 
155
# Checking options
156
optionIsValid $1 $2
157
 
158
# Checking that mandatory option have been specified
159
[[ -z ${isoFile} ]] && { echo "Iso file option is mandatory. Aborting." && exit 1; }
160
 
161
# Checking validity of options
162
[[ -f ${isoFile} ]] || { echo "Invalid iso file. Aborting." && exit 1; }
163
 
164
# Checking that executed as root
165
[[ $(whoami) != "root" ]] && \
166
    { echo "This script must be executed with root privileges. Aborting." && exit 1; }
167
 
168
# Checking required packages
169
requiredPackagesInstalled
170
 
171
# Directories
172
actualDir=$(pwd)
173
RPMS_DIR=$(pwd)"/rpms"
174
[[ -d ${RPMS_DIR} ]] && rm -rf ${RPMS_DIR}
175
mkdir ${RPMS_DIR}
2525 rexy 176
# Retreiving rpm_lists
177
rpm_need_by_alcasar=`rpm -qa`
178
rpm_need_by_mageia=`cat minimal-rpm-list`
2484 rexy 179
 
180
# official and new dirs
181
mageiaNewDir=/tmp/mageia_new
182
mageiaOfficialDir=/tmp/mageia_official
183
 
184
 
185
 
186
# Mounting the image
187
echo "Mounting the image..."
188
[[ ! -d ${mageiaOfficialDir} ]] && mkdir ${mageiaOfficialDir}
189
mount -o ro,loop ${isoFile} ${mageiaOfficialDir} || { echo "Failed mounting '${isoFile}'. Aborting." && exit 1; }
190
 
191
# Checking architecture
192
[[ -d ${mageiaOfficialDir}/x86_64 ]] && arch=x86_64 || arch=i586
193
 
194
# Creating new directory that will contains the "cleared" iso image
195
[[ -d ${mageiaNewDir} ]] && rm -rf ${mageiaNewDir}
196
mkdir ${mageiaNewDir}
197
 
198
# Copying main files except core and nonfree directories
199
echo "Extracting base image..."
2525 rexy 200
cd $mageiaOfficialDir && \
2484 rexy 201
    tar cf - --exclude=${arch}/media . | (cd $mageiaNewDir && tar xf - ) && cd "${actualDir}"
202
 
203
# Creating new directories core and nonfree and dir for alcasar stufs
204
mkdir -p ${mageiaNewDir}/${arch}/{media/{core,nonfree},install/alcasar}
205
 
206
# Retrieving core and nonfree dirs (official)
207
coreDir=${mageiaOfficialDir}/${arch}/media/core
208
nonFreeDir=${mageiaOfficialDir}/${arch}/media/nonfree
209
 
210
# Retrieving core and nonfree dirs (new)
211
coreDirNew=${mageiaNewDir}/${arch}/media/core/
212
nonFreeDirNew=${mageiaNewDir}/${arch}/media/nonfree
213
plopFilePath=${mageiaNewDir}/${arch}/media/plop.idx
214
 
215
# Initializing counts
216
count=0
217
countCore=0
218
countNonFree=0
219
 
220
# Copying the RPM in core and nonfree and clearing the plop.idx file
221
echo "Copying RPMS in ISO ..."
222
> ${plopFilePath}
2525 rexy 223
total=`echo $rpm_need_by_mageia | wc -w`
224
# Selecting & copying of rpm need by Mageia
225
for rpm in ${rpm_need_by_mageia}; do
2484 rexy 226
        let percent="${count} * 100 / ${total}"
227
        print_percentage ${percent}
228
        # Retreiving output of ls in directories
229
        fileInCore=$(ls ${coreDir} | grep "^${rpm}")
230
        fileInNonFree=$(ls ${nonFreeDir} | grep "^${rpm}")
231
        # If present in core, copying in core_new
232
        if [[ ! -z ${fileInCore} ]]; then
233
                # Copying RPM
234
                cp "${coreDir}/${fileInCore}" ${coreDirNew}
235
                countCore=$(expr ${countCore} + 1)
2525 rexy 236
                # Updating the plop.idx
237
                purifyRpmName ${rpm} ${arch} >> ${plopFilePath}
238
        # if present in nonfree, copying in nonfree_new
239
        elif [[ ! -z ${fileInNonFree} ]]; then
2484 rexy 240
                # Copying RPM
241
                cp  "${nonFreeDir}/${fileInNonFree}" ${nonFreeDirNew}
242
                countNonFree=$(expr ${countNonFree} + 1)
2525 rexy 243
                # Updating the plop.idx
244
                purifyRpmName ${rpm} ${arch} >> ${plopFilePath}
245
        else
246
                echo "$rpm not found"
247
        fi
248
        count=$(expr ${count} + 1)
249
done
250
# Sorting the plop file alphabetically
251
cat ${plopFilePath} | sort > /tmp/tmpFileMageia && mv /tmp/tmpFileMageia ${plopFilePath}
252
# Informations
253
echo "$count RPMs copied (${countCore} from core and ${countNonFree} from nonfree)"
254
echo "Hit a Key to download complemmentary RPMs"
255
read a
256
 
257
count=0
258
total=`echo $rpm_need_by_alcasar | wc -w`
259
# Selecting & copying of rpm need by alcasar
260
for rpm in ${rpm_need_by_alcasar}; do
261
        let percent="${count} * 100 / ${total}"
262
        print_percentage ${percent}
263
        # Retreiving output of ls in directories
264
        fileInCore=$(ls ${coreDir} | grep "^${rpm}")
265
        fileInNonFree=$(ls ${nonFreeDir} | grep "^${rpm}")
266
        # we need to download icomplementary RPMS (that aren't in core nor in nonfree)
267
        if [ -z ${fileInCore} ] && [ -z ${fileInNonFree} ]; then
2484 rexy 268
                url=$(urpmq --ignorearch --sources ${rpm} | grep 'updates\|release' | uniq)
269
                wget -P "${RPMS_DIR}" "${url}" --quiet
270
                short_name=`rpm -q $rpm --qf "%{NAME}\n"`
271
        fi
272
        count=$(expr ${count} + 1)
273
done
2525 rexy 274
tar -cvf ${actualDir}/alcasar.tar.gz ${RPMS_DIR}/
275
cp ${actualDir}/alcasar.tar.gz ${mageiaNewDir}/${arch}/install/alcasar
2484 rexy 276
# Informations
2525 rexy 277
echo "$count complementary RPMs copied"
278
echo "Hit a Key to create the ISO file"
279
read a
2484 rexy 280
 
281
# Copying customized files
282
echo "Copying customized files..."
283
###   only if we want to change the normal install procedure ###
284
#cp ${actualDir}/config/first_login ${mageiaNewDir}/${arch}/install/alcasar
285
#cp ${actualDir}/config/auto_inst-${arch}${lang}.cfg.pl ${mageiaNewDir}/${arch}/install/alcasar/auto_inst-${arch}.cfg.pl
286
#cp -f ${actualDir}"/config/isolinux-x86_64.cfg" ${mageiaNewDir}/isolinux/isolinux.cfg
287
 
288
# Generating media info for core
289
echo "Generating media_info for core..."
290
genhdlist2 ${coreDirNew} --allow-empty-media --quiet
291
 
292
echo "Generating media_info for nonfree..."
293
genhdlist2 ${nonFreeDirNew} --allow-empty-media --quiet
294
 
295
# Puting pubkeys in media_info
296
cp ${coreDir}/media_info/pubkey ${coreDirNew}/media_info/
297
cp ${nonFreeDir}/media_info/pubkey ${nonFreeDirNew}/media_info/
298
 
299
# Retrieving media.cfg & compssUsers.pl depending on the arch
300
mkdir ${mageiaNewDir}/${arch}/media/media_info
301
cp ${mageiaOfficialDir}/${arch}/media/media_info/compssUsers.pl ${mageiaNewDir}/${arch}/media/media_info/compssUsers.pl
302
cp ${mageiaOfficialDir}/${arch}/media/media_info/media.cfg ${mageiaNewDir}/${arch}/media/media_info/media.cfg
303
 
304
# Generating distr
305
echo "Generating mirror tree..."
306
gendistrib -s ${mageiaNewDir}/${arch}
307
 
308
# Creating the new iso file
309
echo "Creating the isofile..."
310
newIsoName=Mageia-6-${arch}${lang}-Alcasar.iso
311
cd ${mageiaNewDir} && genisoimage -quiet -o ${actualDir}/${newIsoName} \
312
    -b isolinux/isolinux.bin \
313
    -c boot.catalog \
314
    -no-emul-boot -boot-load-size 4 \
315
    -boot-info-table -J -R -V "Mageia-6 Alcasar (${arch})" .
316
 
317
# Unmounting
318
echo "Umounting..."
319
umount ${mageiaOfficialDir} && rmdir ${mageiaOfficialDir}
320
 
321
# Removing temporary dir
322
rm -rf ${mageiaNewDir}
323
 
324
# Setting same permissions as the initial image
325
cd ${actualDir}
326
chmod --reference=${isoFile} ${newIsoName}
327
chown --reference=${isoFile} ${newIsoName}
328
 
329
# Finished
330
echo "Done."