0,0 → 1,314 |
#!/bin/bash |
# |
# Authors: Mageia Team |
# Update for ALCASAR : Hamza ESSAYEGH (Querdos) - Rexy - Laurent Roux |
## |
# Usage: $0 ARGS |
# --iso-file, -i Mageia-xxx-xxxxxx-xxx.iso (mandatory) |
# --lang, -l Language for installation (optional) |
# Supported languages: fr;en |
# |
|
# Colors parameters |
RED='\033[0;31m' |
GREEN='\033[0;32m' |
YELLOW='\033[0;33m' |
NC='\033[0m' |
|
function print_percentage() { |
local percent=$1 |
if [ ${percent} -lt 5 ]; then |
echo -ne "Downloading... [ ] ${percent}%\r" |
elif [ ${percent} -lt 10 ]; then |
echo -ne "Downloading... [ # ] ${percent}%\r" |
elif [ ${percent} -lt 15 ]; then |
echo -ne "Downloading... [ ## ] ${percent}%\r" |
elif [ ${percent} -lt 20 ]; then |
echo -ne "Downloading... [ ### ] ${percent}%\r" |
elif [ ${percent} -lt 25 ]; then |
echo -ne "Downloading... [ #### ] ${percent}%\r" |
elif [ ${percent} -lt 30 ]; then |
echo -ne "Downloading... [ ##### ] ${percent}%\r" |
elif [ ${percent} -lt 35 ]; then |
echo -ne "Downloading... [ ###### ] ${percent}%\r" |
elif [ ${percent} -lt 40 ]; then |
echo -ne "Downloading... [ ####### ] ${percent}%\r" |
elif [ ${percent} -lt 45 ]; then |
echo -ne "Downloading... [ ######## ] ${percent}%\r" |
elif [ ${percent} -lt 50 ]; then |
echo -ne "Downloading... [ ######### ] ${percent}%\r" |
elif [ ${percent} -lt 55 ]; then |
echo -ne "Downloading... [ ########## ] ${percent}%\r" |
elif [ ${percent} -lt 60 ]; then |
echo -ne "Downloading... [ ########### ] ${percent}%\r" |
elif [ ${percent} -lt 65 ]; then |
echo -ne "Downloading... [ ############ ] ${percent}%\r" |
elif [ ${percent} -lt 70 ]; then |
echo -ne "Downloading... [ ############# ] ${percent}%\r" |
elif [ ${percent} -lt 75 ]; then |
echo -ne "Downloading... [ ############## ] ${percent}%\r" |
elif [ ${percent} -lt 80 ]; then |
echo -ne "Downloading... [ ############### ] ${percent}%\r" |
elif [ ${percent} -lt 85 ]; then |
echo -ne "Downloading... [ ################ ] ${percent}%\r" |
elif [ ${percent} -lt 90 ]; then |
echo -ne "Downloading... [ ################# ] ${percent}%\r" |
elif [ ${percent} -lt 95 ]; then |
echo -ne "Downloading... [ ################## ] ${percent}%\r" |
elif [ ${percent} -lt 100 ]; then |
echo -ne "Downloading... [ ################### ] ${percent}%\r" |
elif [ ${percent} == 100 ]; then |
echo -ne "Downloading... [ #################### ] ${percent}%\r" |
fi |
} |
|
# Check if a given option is valid an set a global var with the option value |
function optionIsValid() { |
# Retrieving option and its value |
local option=$1 |
local value=$2 |
|
# Available options (short and long) |
local isoFileOption="--iso-file -i" |
local langOption="--lang -l" |
|
# Iso file option ? |
for opt in ${isoFileOption}; do |
if [[ ${opt} = ${option} ]]; then |
isoFile=${value} |
return 0 |
fi |
done |
|
# Language option ? |
for opt in ${langOption}; do |
if [[ ${opt} = ${option} ]]; then |
lang="-${value}" |
return 0 |
fi |
done |
|
# Unknown option |
echo "Unknown option '${option}'. Aborting." && exit 1 |
} |
|
# Check if needed packages are installed |
function requiredPackagesInstalled() { |
# Checking mkisofs |
command -v genisoimage > /dev/null 2>&1 || \ |
{ echo "The package genisoimage is not installed." && \ |
genisoimageNotInstalled=1; } |
|
# Checking genhdlist2 |
command -v genhdlist2 > /dev/null 2>&1 || \ |
{ echo "The package genhdlist2 is not installed." && \ |
genhdlist2NotInstalled=1; } |
|
# Checking gendistrib |
command -v gendistrib > /dev/null 2>&1 || \ |
{ echo "The package gendistrib is not installed (rpmtools)." && \ |
gendistribNotInstalled=1; } |
|
# If one of the following, aborting |
[[ ${genisoimageNotInstalled} -eq 1 ]] || \ |
[[ ${genhdlist2NotInstalled} -eq 1 ]] || \ |
[[ ${gendistribNotInstalled} -eq 1 ]] && exit 1 |
} |
|
# Check if a given language is supported by this script or not |
function languageIsSupported() { |
local lang=$1 |
local supportedLang="fr en" |
|
# Comparing with available langs |
for supLang in ${supportedLang}; do |
if [[ ${supLang} = ${lang} ]]; then |
return 0 |
fi |
done |
|
# Language is not supported |
echo "Language '${lang}' is not supported. Aborting." && exit 1 |
} |
|
# "Purify" the rpm name -> for the plop.idx file ("Mageia-5.1-x86_64 rpmname" for example) |
function purifyRpmName() { |
local str=$1 |
local arch=$2 |
local len=${#str} |
|
p=`echo ${str} | grep -oP ".*\.mga6"` |
echo "Mageia-6-${arch} ${p}" |
} |
|
# Checking arguments (rpm_list and iso file and eventually lang) |
[[ ($# -lt 1) || ($# -gt 2) ]] && echo \ |
"Usage: $0 ARGS |
--iso-file, -i Mageia-xxx-xxxxxx-xxx.iso (mandatory) |
--lang, -l Language for installation (optional) |
Supported languages: fr;en |
" && exit 1 |
|
# Checking options |
optionIsValid $1 $2 |
|
# Checking that mandatory option have been specified |
[[ -z ${isoFile} ]] && { echo "Iso file option is mandatory. Aborting." && exit 1; } |
|
# Checking validity of options |
[[ -f ${isoFile} ]] || { echo "Invalid iso file. Aborting." && exit 1; } |
|
# Checking that executed as root |
[[ $(whoami) != "root" ]] && \ |
{ echo "This script must be executed with root privileges. Aborting." && exit 1; } |
|
# Checking required packages |
requiredPackagesInstalled |
|
# Directories |
actualDir=$(pwd) |
RPMS_DIR=$(pwd)"/rpms" |
[[ -d ${RPMS_DIR} ]] && rm -rf ${RPMS_DIR} |
mkdir ${RPMS_DIR} |
# Retreiving rpm_list |
rpm_needed=`rpm -qa` |
|
# official and new dirs |
mageiaNewDir=/tmp/mageia_new |
mageiaOfficialDir=/tmp/mageia_official |
|
|
|
# Mounting the image |
echo "Mounting the image..." |
[[ ! -d ${mageiaOfficialDir} ]] && mkdir ${mageiaOfficialDir} |
mount -o ro,loop ${isoFile} ${mageiaOfficialDir} || { echo "Failed mounting '${isoFile}'. Aborting." && exit 1; } |
|
# Checking architecture |
[[ -d ${mageiaOfficialDir}/x86_64 ]] && arch=x86_64 || arch=i586 |
|
# Creating new directory that will contains the "cleared" iso image |
[[ -d ${mageiaNewDir} ]] && rm -rf ${mageiaNewDir} |
mkdir ${mageiaNewDir} |
|
# Copying main files except core and nonfree directories |
echo "Extracting base image..." |
cd /tmp/mageia_official && \ |
tar cf - --exclude=${arch}/media . | (cd $mageiaNewDir && tar xf - ) && cd "${actualDir}" |
|
# Creating new directories core and nonfree and dir for alcasar stufs |
mkdir -p ${mageiaNewDir}/${arch}/{media/{core,nonfree},install/alcasar} |
|
# Retrieving core and nonfree dirs (official) |
coreDir=${mageiaOfficialDir}/${arch}/media/core |
nonFreeDir=${mageiaOfficialDir}/${arch}/media/nonfree |
|
# Retrieving core and nonfree dirs (new) |
coreDirNew=${mageiaNewDir}/${arch}/media/core/ |
nonFreeDirNew=${mageiaNewDir}/${arch}/media/nonfree |
plopFilePath=${mageiaNewDir}/${arch}/media/plop.idx |
|
# Initializing counts |
count=0 |
countCore=0 |
countNonFree=0 |
|
# Copying the RPM in core and nonfree and clearing the plop.idx file |
echo "Copying RPMS in ISO ..." |
> ${plopFilePath} |
total=`echo $rpm_needed | wc -w` |
|
# Selecting rpm |
for rpm in ${rpm_needed}; do |
let percent="${count} * 100 / ${total}" |
print_percentage ${percent} |
# Retreiving output of ls in directories |
fileInCore=$(ls ${coreDir} | grep "^${rpm}") |
fileInNonFree=$(ls ${nonFreeDir} | grep "^${rpm}") |
# If present in core, copying in core_new |
if [[ ! -z ${fileInCore} ]]; then |
# Copying RPM |
cp "${coreDir}/${fileInCore}" ${coreDirNew} |
countCore=$(expr ${countCore} + 1) |
# Updating the plop.idx |
purifyRpmName ${rpm} ${arch} >> ${plopFilePath} |
# If present in nonfree, copying in nonfree_new |
elif [[ ! -z ${fileInNonFree} ]]; then |
# Copying RPM |
cp "${nonFreeDir}/${fileInNonFree}" ${nonFreeDirNew} |
countNonFree=$(expr ${countNonFree} + 1) |
# Updating the plop.idx |
purifyRpmName ${rpm} ${arch} >> ${plopFilePath} |
else |
# we need to download it and to copy on ALCASAR special RPM tarball |
# if RPM name is also in core/nonfree, we need to copying it in core/nonfree |
# be carefull with kernel (ISO must boot on the original one) |
url=$(urpmq --ignorearch --sources ${rpm} | grep 'updates\|release' | uniq) |
wget -P "${RPMS_DIR}" "${url}" --quiet |
short_name=`rpm -q $rpm --qf "%{NAME}\n"` |
# echo "$count - $countCore - $countNonFree : $rpm not in core/update - shortame = $short_name" |
#read a |
cp ${RPMS_DIR}/${rpm}.${arch}.rpm ${coreDirNew} |
fi |
count=$(expr ${count} + 1) |
done |
|
# Sorting the plop file alphabetically |
cat ${plopFilePath} | sort > /tmp/tmpFileMageia && mv /tmp/tmpFileMageia ${plopFilePath} |
|
# Informations |
echo "${countCore} files kept from core" |
echo "${countNonFree} files kept from nonfree" |
|
# Copying customized files |
echo "Copying customized files..." |
tar -cvf ${actualDir}/alcasar.tar.gz ${RPMS_DIR}/ |
cp ${actualDir}/alcasar.tar.gz ${mageiaNewDir}/${arch}/install/alcasar |
### only if we want to change the normal install procedure ### |
#cp ${actualDir}/config/first_login ${mageiaNewDir}/${arch}/install/alcasar |
#cp ${actualDir}/config/auto_inst-${arch}${lang}.cfg.pl ${mageiaNewDir}/${arch}/install/alcasar/auto_inst-${arch}.cfg.pl |
#cp -f ${actualDir}"/config/isolinux-x86_64.cfg" ${mageiaNewDir}/isolinux/isolinux.cfg |
|
# Generating media info for core |
echo "Generating media_info for core..." |
genhdlist2 ${coreDirNew} --allow-empty-media --quiet |
|
echo "Generating media_info for nonfree..." |
genhdlist2 ${nonFreeDirNew} --allow-empty-media --quiet |
|
# Puting pubkeys in media_info |
cp ${coreDir}/media_info/pubkey ${coreDirNew}/media_info/ |
cp ${nonFreeDir}/media_info/pubkey ${nonFreeDirNew}/media_info/ |
|
# Retrieving media.cfg & compssUsers.pl depending on the arch |
mkdir ${mageiaNewDir}/${arch}/media/media_info |
cp ${mageiaOfficialDir}/${arch}/media/media_info/compssUsers.pl ${mageiaNewDir}/${arch}/media/media_info/compssUsers.pl |
cp ${mageiaOfficialDir}/${arch}/media/media_info/media.cfg ${mageiaNewDir}/${arch}/media/media_info/media.cfg |
|
# Generating distr |
echo "Generating mirror tree..." |
gendistrib -s ${mageiaNewDir}/${arch} |
|
# Creating the new iso file |
echo "Creating the isofile..." |
newIsoName=Mageia-6-${arch}${lang}-Alcasar.iso |
cd ${mageiaNewDir} && genisoimage -quiet -o ${actualDir}/${newIsoName} \ |
-b isolinux/isolinux.bin \ |
-c boot.catalog \ |
-no-emul-boot -boot-load-size 4 \ |
-boot-info-table -J -R -V "Mageia-6 Alcasar (${arch})" . |
|
# Unmounting |
echo "Umounting..." |
umount ${mageiaOfficialDir} && rmdir ${mageiaOfficialDir} |
|
# Removing temporary dir |
rm -rf ${mageiaNewDir} |
|
# Setting same permissions as the initial image |
cd ${actualDir} |
chmod --reference=${isoFile} ${newIsoName} |
chown --reference=${isoFile} ${newIsoName} |
|
# Finished |
echo "Done." |
Property changes: |
Added: svn:eol-style |
+native |
\ No newline at end of property |
Added: svn:executable |
+* |
\ No newline at end of property |