Subversion Repositories ALCASAR

Rev

Details | Last modification | View Log

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