Subversion Repositories ALCASAR

Rev

Rev 2878 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log

Rev Author Line No. Line
2672 rexy 1
#!/bin/bash
2
#
3
# Authors: Mageia Team
2921 rexy 4
# Update for ALCASAR : Hamza ESSAYEGH (Querdos) - Rexy - Laurent Roux - Aurelien Dubois - Pierre Rivault
2672 rexy 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
###### Variables ######
2878 rexy 13
################################################################################
2672 rexy 14
 
15
CURRENT_DIR="$(readlink -f "$(dirname $0)")"
16
LOG_FILE="$CURRENT_DIR/build-image.log"
17
 
18
# Mageia
2878 rexy 19
MAGEIA_VERSION=`cat /etc/release|cut -d" " -f3`
20
ARCH=`cat /etc/release|cut -d" " -f6`
2672 rexy 21
MAGEIA_NEW_DIR=/tmp/mageia_new
22
MAGEIA_OFFICIAL_DIR=/tmp/mageia_official
2921 rexy 23
MAGEIA_OFFICIAL_DIR_EFI=/tmp/mageia_official_efi
2672 rexy 24
# ISO file
25
ISO_DIR="/var/iso"
2860 rexy 26
ISO_IN="$ISO_DIR/Mageia-$MAGEIA_VERSION-$ARCH.iso"
2672 rexy 27
 
28
# Drake installer
29
INSTALLER_DIR="${MAGEIA_NEW_DIR}/${ARCH}/install/alcasar"
2860 rexy 30
EFI_GRUB_CFG="${MAGEIA_NEW_DIR}/boot/grub2/grub.cfg"
2672 rexy 31
AUTO_INSTALL_CFG="/var/iso/auto_inst.cfg.pl"
32
ADVERT_DIR="${MAGEIA_NEW_DIR}/${ARCH}/install/extra/advertising"
33
 
34
# Alcasar
35
ALCASAR_TAR="$1"
36
ALCASAR_EXTRACTED_DIR=$(echo $ALCASAR_TAR | rev | cut -d '.' -f 3- | rev)
37
 
38
# Mirrors
2860 rexy 39
ISO_SUPPORT="http://ftp.free.fr/mirrors/mageia.org/iso/$MAGEIA_VERSION/Mageia-$MAGEIA_VERSION-$ARCH/Mageia-$MAGEIA_VERSION-$ARCH.iso"
40
ISO_MD5="http://ftp.free.fr/mirrors/mageia.org/iso/$MAGEIA_VERSION/Mageia-$MAGEIA_VERSION-$ARCH/Mageia-$MAGEIA_VERSION-$ARCH.iso.md5"
2672 rexy 41
 
42
# RPMs
43
RPM_DIR="/root/rpms"
2878 rexy 44
BASE_RPM_LIST="acpi acpid alsa-utils aoss arp-scan basesystem bash-completion coreutils-doc cpupower curl dhcp-client dmraid dnf dnf-plugins-core dosfstools dracut drakx-net-text gpm grub2 grub2-efi grub2-mageia-theme harddrake hdparm hexedit info iwlwifi-agn-ucode kernel-server-latest kernel-firmware kernel-firmware-nonfree ldetect lftp lib64alsa-plugins lib64glib-networking-gnutls locales-en locales-fr lsof lvm2 mageia-theme-Default man-db mandi-ifw man-pages microcode microcode_ctl mtools ntfs-3g numlock os-prober p11-kit perl-Hal-Cdroms plymouth procmail python3 python3-dbus radeon-firmware ralink-firmware rtlwifi-firmware sharutils shorewall-ipv6 strace sysfsutils tmpwatch tree vim-minimal vnstat xdg-user-dirs-gtk sudo socat"
2672 rexy 45
 
46
#######################
47
###### Functions ######
48
################################################################################
49
# Print the given error message and exit 1
50
function errorExit()
51
{
52
    tput bold
53
    echo -e "ERROR : $1 \nAborting\n" >&2
54
    echo "$1" > "$LOG_FILE"
55
    tput sgr0
56
    exit 1
57
}
58
#-------------------------------------------------------------------------------
59
# Print progress bar. $1 is a multiple of five
60
function printProgress()
61
{
62
    local a
63
    let "a = $1 / 5"
64
    let "b = 25 - $a"
65
    progressStr=$(printf "%${a}s")
66
    progressStrBlanks=$(printf "%${b}s")
67
    echo -en "Downloading...$1% [${progressStr// /#}${progressStrBlanks// / }]\r"
68
}
69
#-------------------------------------------------------------------------------
70
function printBold()
71
{
72
    tput bold 2>/dev/null
73
    echo $1
74
    tput sgr0 2>/dev/null
75
}
76
#######################
77
######    Main    ######
78
################################################################################
79
 
80
# Retrieve list of Alcasar dependencies
81
tar -xf /var/iso/$ALCASAR_TAR -C /tmp/ || errorExit "could not extract alcasar tar archive"
82
alcasarRpmList="$(grep -oP "(?<=PACKAGES=\").*?(?=\")" /tmp/$ALCASAR_EXTRACTED_DIR/scripts/alcasar-urpmi.sh)"
83
alcasarKernel="$(grep -oP "(?<=KERNEL=\").*?(?=\")" /tmp/$ALCASAR_EXTRACTED_DIR/scripts/alcasar-urpmi.sh)"
84
alcasarRpmList="$alcasarRpmList $alcasarKernel"
85
 
86
# Make clean rpm list
87
rpmList=$(echo $BASE_RPM_LIST $alcasarRpmList | sed "s/ /\n/g" | sort | uniq | sed "s/\n/ /g")
88
 
89
# Insert list into AUTO_INSTALL_CFG
90
formattedList=$(echo $rpmList | sed "s/[^ ]*/\'\0\'/g" | sed "s/ /,\n/g" | sed "/kernel-server/d")
91
cp "${AUTO_INSTALL_CFG}_template" "$AUTO_INSTALL_CFG" -f
92
insertLineNumber=$(grep -n "'default_packages' => " "$AUTO_INSTALL_CFG" | cut -d ':' -f1)
93
fileTop=$(head -n "+$insertLineNumber" "$AUTO_INSTALL_CFG")
94
fileBottom=$(tail -n "+$insertLineNumber" "$AUTO_INSTALL_CFG" | tail -n +2)
95
cat /dev/null > "$AUTO_INSTALL_CFG"
96
 
97
echo "$fileTop" > "$AUTO_INSTALL_CFG"
98
echo "$formattedList" >> "$AUTO_INSTALL_CFG"
99
echo "$fileBottom" >> "$AUTO_INSTALL_CFG"
100
 
101
# Installing tools to create the iso
102
printBold "Installing necessary tools"
2750 rexy 103
dnf install 'dnf-command(download)' -y || errorExit "could not install necessary packages"
104
#dnf install 'dnf-command(config-manager)' -y || errorExit "could not install necessary packages"
105
dnf config-manager --set-enabled mageia-x86_64-nonfree updates-x86_64-nonfree  || errorExit "could not install necessary packages"
106
dnf install -y lftp wget cdrkit-genisoimage xorriso rpmtools syslinux || errorExit "could not install necessary packages"
2672 rexy 107
 
108
 
109
# Directories initialization
110
#-------------------------------------------------------------------------------
111
[[ ! -d "$RPM_DIR" ]] && mkdir -p "$RPM_DIR"
112
 
113
# Beggining work on the ISO
114
#-------------------------------------------------------------------------------
115
# Checking the optional Mageia image. If not present or does not match the
116
# docker's version, download it
117
if [[ ! -f "$ISO_IN" ]]; then
118
    printBold "Downloading the Mageia iso"
119
    cd $ISO_DIR || errorExit "could not cd to $ISO_DIR"
120
    echo Installing lftp
121
    lftpget -c $ISO_SUPPORT || ( cd "$CURRENT_DIR" && errorExit "could not download Mageia iso" )
122
    cd $CURRENT_DIR
123
fi
124
 
125
# Mounting the image
126
printBold "Mounting the image"
127
[[ ! -d "$MAGEIA_OFFICIAL_DIR" ]] && mkdir -p "$MAGEIA_OFFICIAL_DIR"
2750 rexy 128
mount -o ro,loop "$ISO_IN" "$MAGEIA_OFFICIAL_DIR" || (sleep 5 ; mount -o ro,loop "$ISO_IN" "$MAGEIA_OFFICIAL_DIR" || errorExit "failed mounting $ISO_IN. Running the script again might solve the issue.")
2672 rexy 129
 
130
# Checking ARCHitecture
131
[[ -d ${MAGEIA_OFFICIAL_DIR}/x86_64 ]] && ARCH=x86_64 || ARCH=i586
132
 
133
# Creating new directory that will contains the "cleared" iso image
134
[[ -d ${MAGEIA_NEW_DIR} ]] && rm -rf ${MAGEIA_NEW_DIR}
135
mkdir ${MAGEIA_NEW_DIR}
136
 
137
# Copying main files except core and nonfree directories
138
echo "Extracting base image..."
139
cd $MAGEIA_OFFICIAL_DIR && \
140
    tar cf - --exclude=${ARCH}/media . | (cd $MAGEIA_NEW_DIR && tar xf - ) && cd "${CURRENT_DIR}"
141
 
142
# Creating new directories core and nonfree and dir for alcasar stufs
143
mkdir -p ${MAGEIA_NEW_DIR}/${ARCH}/{media/{core,nonfree},install/alcasar}
144
 
145
# Adding Alcasar image advert to the installer
146
cp -f /var/iso/install_slideshow/* "$ADVERT_DIR"
147
 
148
# Retrieving core and nonfree dirs (official)
149
coreDir=${MAGEIA_OFFICIAL_DIR}/${ARCH}/media/core
150
nonFreeDir=${MAGEIA_OFFICIAL_DIR}/${ARCH}/media/nonfree
151
 
152
# Retrieving core and nonfree dirs (new)
153
coreDirNew=${MAGEIA_NEW_DIR}/${ARCH}/media/core/
154
nonFreeDirNew=${MAGEIA_NEW_DIR}/${ARCH}/media/nonfree
155
plopFilePath=${MAGEIA_NEW_DIR}/${ARCH}/media/plop.idx
156
 
157
# Initializing counts
158
count=0
159
 
160
# Getting list of rpms needed by Mageia
161
#mageiaRpms="$(cat $MINIMAL_rpmList)"
162
 
163
# Copying the RPM in core and nonfree and clearing the plop.idx file
164
echo "Copying RPMS in ISO ..."
165
echo /dev/null > ${plopFilePath}
166
 
2860 rexy 167
dnf upgrade -y
168
 
2672 rexy 169
installedList="$(dnf list installed | cut -d ' ' -f1 | rev | cut -d . -f2- | rev | tail -n +2 | tr '\n' ' ')"
170
nbInstalled=$(echo $installedList | wc -w)
171
rpmList="$installedList $BASE_RPM_LIST $alcasarRpmList"
172
total=`echo $rpmList | wc -w`
173
 
174
for rpm in ${rpmList}; do
175
	let percent="${count} * 100 / ${total}"
176
    if [[ $count -lt $nbInstalled ]] ; then
177
        dnf reinstall -y --downloadonly --downloaddir $coreDirNew $rpm 1> /dev/null || errorExit "could not download $rpm"
178
    else
179
        dnf install -y --downloadonly --downloaddir $coreDirNew $rpm 1> /dev/null || errorExit "could not download $rpm"
180
    fi
181
    printProgress ${percent}
182
 
183
	count=$(expr ${count} + 1)
184
done
185
 
186
# Sorting the plop file alphabetically
187
cat ${plopFilePath} | sort > /tmp/tmpFileMageia && mv /tmp/tmpFileMageia ${plopFilePath}
188
 
189
# Informations
190
printBold "$count RPMs copied"
191
 
192
# Downloading rpms needed by Alcasar
193
cd "$CURRENT_DIR"
194
printBold "Downloading Alcasar dependencies"
195
tar -xf /var/iso/$ALCASAR_TAR
196
 
197
# Copying the Alcasar tar to be put into the ISO
198
cp /var/iso/$ALCASAR_TAR $INSTALLER_DIR/
199
 
200
# Add automatic install options
201
mkdir -p $INSTALLER_DIR || errorExit "could not create directory $INSTALLER_DIR"
202
cp $AUTO_INSTALL_CFG $INSTALLER_DIR || errorExit "could not copy $AUTO_INSTALL_CFG to $INSTALLER_DIR"
203
 
204
# Generating media info for core
205
echo "Generating media_info for core..."
206
genhdlist2 ${coreDirNew} --allow-empty-media --quiet
207
 
208
echo "Generating media_info for nonfree..."
209
genhdlist2 ${nonFreeDirNew} --allow-empty-media --quiet
210
 
211
# Puting pubkeys in media_info
212
cp ${coreDir}/media_info/pubkey ${coreDirNew}/media_info/
213
cp ${nonFreeDir}/media_info/pubkey ${nonFreeDirNew}/media_info/
214
 
215
# Retrieving media.cfg & compssUsers.pl depending on the arch
216
mkdir ${MAGEIA_NEW_DIR}/${ARCH}/media/media_info
217
cp ${MAGEIA_OFFICIAL_DIR}/${ARCH}/media/media_info/compssUsers.pl ${MAGEIA_NEW_DIR}/${ARCH}/media/media_info/compssUsers.pl
218
cp ${MAGEIA_OFFICIAL_DIR}/${ARCH}/media/media_info/media.cfg ${MAGEIA_NEW_DIR}/${ARCH}/media/media_info/media.cfg
219
 
220
# Specify install configuration
2860 rexy 221
#sed -i -e 's*rdz*rdz kickstart=/tmp/media/x86_64/install/alcasar/auto_inst.cfg.pl*g'  ${MAGEIA_NEW_DIR}/isolinux/isolinux.cfg
2750 rexy 222
sed -i -e 's*noiswmd*noiswmd kickstart=/tmp/media/x86_64/install/alcasar/auto_inst.cfg.pl*g'  $EFI_GRUB_CFG 
2672 rexy 223
 
224
# Generating distr
225
echo "Generating mirror tree..."
226
gendistrib -s ${MAGEIA_NEW_DIR}/${ARCH}
227
 
228
# Creating the new iso file
229
echo "Creating the isofile..."
230
alcasarVersion=$(echo $ALCASAR_TAR | cut -d '-' -f2 | rev | cut -d '.' -f 3- | rev )
231
newIsoName=Mageia-$MAGEIA_VERSION-${ARCH}-Alcasar${alcasarVersion}.iso
2750 rexy 232
 
2921 rexy 233
# Generating the iso file
234
# Parameters for xorriso found using the following command on the original mageia iso
235
# xorriso -indev Mageia-7-x86_64.iso -report_el_torito as_mkisofs
236
cd ${MAGEIA_NEW_DIR} && xorriso -as mkisofs \
237
	-V 'Mageia-7.1-x86_64' \
238
	--grub2-mbr --interval:local_fs:0s-15s:zero_mbrpt:${ISO_IN} \
239
	-partition_cyl_align off \
240
	-partition_offset 0 \
241
	--mbr-force-bootable \
242
	-append_partition 2 0xef --interval:local_fs:8785156d-8793347d::${ISO_IN} \
243
	-iso_mbr_part_type 0x00 \
244
	-c '/boot.catalog' \
245
	-b '/boot/grub2/eltorito.img' \
246
	-no-emul-boot \
247
	-boot-load-size 4 \
248
	-boot-info-table \
249
	--grub2-boot-info \
250
	-eltorito-alt-boot \
251
	-e '--interval:appended_partition_2_start_2196289s_size_8192d:all::' \
252
	-no-emul-boot \
253
	-boot-load-size 8192 \
254
	-o ${CURRENT_DIR}/${newIsoName} .
2672 rexy 255
 
2860 rexy 256
 
2672 rexy 257
# Unmounting
258
echo "Umounting..."
259
umount ${MAGEIA_OFFICIAL_DIR} && rmdir ${MAGEIA_OFFICIAL_DIR}
260
 
261
# Removing temporary dir
262
rm -rf ${MAGEIA_NEW_DIR}
263
 
264
mv ${CURRENT_DIR}/${newIsoName} /var/iso/
265
 
266
# Finished
267
rm -f "$AUTO_INSTALL_CFG"
268
echo "Done."