Subversion Repositories ALCASAR

Rev

Go to most recent revision | 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
# 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
 
144
# Checking arguments (rpm_list and iso file and eventually lang)
145
[[ ($# -lt 1) || ($# -gt 2) ]] && echo \
146
"Usage: $0 ARGS
147
    --iso-file, -i      Mageia-xxx-xxxxxx-xxx.iso (mandatory)
148
    --lang, -l          Language for installation (optional)
149
                        Supported languages: fr;en
150
" && exit 1
151
 
152
# Checking options
153
optionIsValid $1 $2
154
 
155
# Checking that mandatory option have been specified
156
[[ -z ${isoFile} ]] && { echo "Iso file option is mandatory. Aborting." && exit 1; }
157
 
158
# Checking validity of options
159
[[ -f ${isoFile} ]] || { echo "Invalid iso file. Aborting." && exit 1; }
160
 
161
# Checking that executed as root
162
[[ $(whoami) != "root" ]] && \
163
    { echo "This script must be executed with root privileges. Aborting." && exit 1; }
164
 
165
# Checking required packages
166
requiredPackagesInstalled
167
 
168
# Directories
169
actualDir=$(pwd)
170
RPMS_DIR=$(pwd)"/rpms"
171
[[ -d ${RPMS_DIR} ]] && rm -rf ${RPMS_DIR}
172
mkdir ${RPMS_DIR}
173
# Retreiving rpm_list
174
rpm_needed=`rpm -qa`
175
 
176
# official and new dirs
177
mageiaNewDir=/tmp/mageia_new
178
mageiaOfficialDir=/tmp/mageia_official
179
 
180
 
181
 
182
# Mounting the image
183
echo "Mounting the image..."
184
[[ ! -d ${mageiaOfficialDir} ]] && mkdir ${mageiaOfficialDir}
185
mount -o ro,loop ${isoFile} ${mageiaOfficialDir} || { echo "Failed mounting '${isoFile}'. Aborting." && exit 1; }
186
 
187
# Checking architecture
188
[[ -d ${mageiaOfficialDir}/x86_64 ]] && arch=x86_64 || arch=i586
189
 
190
# Creating new directory that will contains the "cleared" iso image
191
[[ -d ${mageiaNewDir} ]] && rm -rf ${mageiaNewDir}
192
mkdir ${mageiaNewDir}
193
 
194
# Copying main files except core and nonfree directories
195
echo "Extracting base image..."
196
cd /tmp/mageia_official && \
197
    tar cf - --exclude=${arch}/media . | (cd $mageiaNewDir && tar xf - ) && cd "${actualDir}"
198
 
199
# Creating new directories core and nonfree and dir for alcasar stufs
200
mkdir -p ${mageiaNewDir}/${arch}/{media/{core,nonfree},install/alcasar}
201
 
202
# Retrieving core and nonfree dirs (official)
203
coreDir=${mageiaOfficialDir}/${arch}/media/core
204
nonFreeDir=${mageiaOfficialDir}/${arch}/media/nonfree
205
 
206
# Retrieving core and nonfree dirs (new)
207
coreDirNew=${mageiaNewDir}/${arch}/media/core/
208
nonFreeDirNew=${mageiaNewDir}/${arch}/media/nonfree
209
plopFilePath=${mageiaNewDir}/${arch}/media/plop.idx
210
 
211
# Initializing counts
212
count=0
213
countCore=0
214
countNonFree=0
215
 
216
# Copying the RPM in core and nonfree and clearing the plop.idx file
217
echo "Copying RPMS in ISO ..."
218
> ${plopFilePath}
219
total=`echo $rpm_needed | wc -w`
220
 
221
# Selecting rpm
222
for rpm in ${rpm_needed}; do
223
	let percent="${count} * 100 / ${total}"
224
	print_percentage ${percent}
225
	# Retreiving output of ls in directories
226
	fileInCore=$(ls ${coreDir} | grep "^${rpm}")
227
	fileInNonFree=$(ls ${nonFreeDir} | grep "^${rpm}")
228
	# If present in core, copying in core_new
229
	if [[ ! -z ${fileInCore} ]]; then
230
		# Copying RPM
231
		cp "${coreDir}/${fileInCore}" ${coreDirNew}
232
		countCore=$(expr ${countCore} + 1)
233
    # Updating the plop.idx
234
    purifyRpmName ${rpm} ${arch} >> ${plopFilePath}
235
  # If present in nonfree, copying in nonfree_new
236
	elif [[ ! -z ${fileInNonFree} ]]; then
237
		# Copying RPM
238
		cp  "${nonFreeDir}/${fileInNonFree}" ${nonFreeDirNew}
239
		countNonFree=$(expr ${countNonFree} + 1)
240
    # Updating the plop.idx
241
    purifyRpmName ${rpm} ${arch} >> ${plopFilePath}
242
	else
243
	# we need to download it and to copy on ALCASAR special RPM tarball
244
	# if RPM name is also in core/nonfree, we need to copying it in core/nonfree
245
	# be carefull with kernel (ISO must boot on the original one)
246
		url=$(urpmq --ignorearch --sources ${rpm} | grep 'updates\|release' | uniq)
247
		wget -P "${RPMS_DIR}" "${url}" --quiet
248
		short_name=`rpm -q $rpm --qf "%{NAME}\n"`
249
		# echo "$count - $countCore - $countNonFree : $rpm not in core/update - shortame = $short_name"
250
		#read a
251
		cp ${RPMS_DIR}/${rpm}.${arch}.rpm ${coreDirNew}
252
	fi
253
	count=$(expr ${count} + 1)
254
done
255
 
256
# Sorting the plop file alphabetically
257
cat ${plopFilePath} | sort > /tmp/tmpFileMageia && mv /tmp/tmpFileMageia ${plopFilePath}
258
 
259
# Informations
260
echo "${countCore} files kept from core"
261
echo "${countNonFree} files kept from nonfree"
262
 
263
# Copying customized files
264
echo "Copying customized files..."
265
tar -cvf ${actualDir}/alcasar.tar.gz ${RPMS_DIR}/
266
cp ${actualDir}/alcasar.tar.gz ${mageiaNewDir}/${arch}/install/alcasar
267
###   only if we want to change the normal install procedure ###
268
#cp ${actualDir}/config/first_login ${mageiaNewDir}/${arch}/install/alcasar
269
#cp ${actualDir}/config/auto_inst-${arch}${lang}.cfg.pl ${mageiaNewDir}/${arch}/install/alcasar/auto_inst-${arch}.cfg.pl
270
#cp -f ${actualDir}"/config/isolinux-x86_64.cfg" ${mageiaNewDir}/isolinux/isolinux.cfg
271
 
272
# Generating media info for core
273
echo "Generating media_info for core..."
274
genhdlist2 ${coreDirNew} --allow-empty-media --quiet
275
 
276
echo "Generating media_info for nonfree..."
277
genhdlist2 ${nonFreeDirNew} --allow-empty-media --quiet
278
 
279
# Puting pubkeys in media_info
280
cp ${coreDir}/media_info/pubkey ${coreDirNew}/media_info/
281
cp ${nonFreeDir}/media_info/pubkey ${nonFreeDirNew}/media_info/
282
 
283
# Retrieving media.cfg & compssUsers.pl depending on the arch
284
mkdir ${mageiaNewDir}/${arch}/media/media_info
285
cp ${mageiaOfficialDir}/${arch}/media/media_info/compssUsers.pl ${mageiaNewDir}/${arch}/media/media_info/compssUsers.pl
286
cp ${mageiaOfficialDir}/${arch}/media/media_info/media.cfg ${mageiaNewDir}/${arch}/media/media_info/media.cfg
287
 
288
# Generating distr
289
echo "Generating mirror tree..."
290
gendistrib -s ${mageiaNewDir}/${arch}
291
 
292
# Creating the new iso file
293
echo "Creating the isofile..."
294
newIsoName=Mageia-6-${arch}${lang}-Alcasar.iso
295
cd ${mageiaNewDir} && genisoimage -quiet -o ${actualDir}/${newIsoName} \
296
    -b isolinux/isolinux.bin \
297
    -c boot.catalog \
298
    -no-emul-boot -boot-load-size 4 \
299
    -boot-info-table -J -R -V "Mageia-6 Alcasar (${arch})" .
300
 
301
# Unmounting
302
echo "Umounting..."
303
umount ${mageiaOfficialDir} && rmdir ${mageiaOfficialDir}
304
 
305
# Removing temporary dir
306
rm -rf ${mageiaNewDir}
307
 
308
# Setting same permissions as the initial image
309
cd ${actualDir}
310
chmod --reference=${isoFile} ${newIsoName}
311
chown --reference=${isoFile} ${newIsoName}
312
 
313
# Finished
314
echo "Done."