2941 |
rexy |
1 |
#!/bin/bash
|
|
|
2 |
#
|
|
|
3 |
# Build Mageiar (Mageia + ALCASAR) ISO file
|
|
|
4 |
# Authors: Hamza ESSAYEGH (Querdos) - Rexy - Laurent Roux - Aurelien Dubois - Pierre Rivault
|
|
|
5 |
#
|
|
|
6 |
####################################
|
|
|
7 |
###### Variables & functions ######
|
|
|
8 |
################################################################################
|
|
|
9 |
|
|
|
10 |
CURRENT_DIR="$(readlink -f "$(dirname $0)")"
|
|
|
11 |
LOG_FILE="$CURRENT_DIR/build-image.log"
|
|
|
12 |
RESSOURCES="$CURRENT_DIR/ressources"
|
|
|
13 |
|
|
|
14 |
# Print the given error message and exit 1
|
|
|
15 |
function errorExit()
|
|
|
16 |
{
|
|
|
17 |
tput bold
|
|
|
18 |
echo -e "ERROR : $1 \nAborting\n" >&2
|
|
|
19 |
echo "$1" > "$LOG_FILE"
|
|
|
20 |
tput sgr0
|
|
|
21 |
exit 1
|
|
|
22 |
}
|
|
|
23 |
#-------------------------------------------------------------------------------
|
|
|
24 |
# Print progress bar. $1 is a multiple of five
|
|
|
25 |
function printProgress()
|
|
|
26 |
{
|
|
|
27 |
local a
|
|
|
28 |
let "a = $1 / 5"
|
|
|
29 |
let "b = 25 - $a"
|
|
|
30 |
progressStr=$(printf "%${a}s")
|
|
|
31 |
progressStrBlanks=$(printf "%${b}s")
|
|
|
32 |
echo -en "Downloading...$1% [${progressStr// /#}${progressStrBlanks// / }]\r"
|
|
|
33 |
}
|
|
|
34 |
#-------------------------------------------------------------------------------
|
|
|
35 |
function printBold()
|
|
|
36 |
{
|
|
|
37 |
tput bold 2>/dev/null
|
|
|
38 |
echo $1
|
|
|
39 |
tput sgr0 2>/dev/null
|
|
|
40 |
}
|
|
|
41 |
|
|
|
42 |
ISO_IN=`ls $RESSOURCES | grep '^Mageia.*iso'`
|
|
|
43 |
MAGEIA_VERSION=`echo $ISO_IN|cut -d"-" -f2`
|
|
|
44 |
ARCH=`echo $ISO_IN |cut -d"-" -f3|cut -d"." -f1`
|
|
|
45 |
ALCASAR_TARBALL=`ls $RESSOURCES| grep '^alcasar.*gz'`
|
|
|
46 |
ALCASAR_EXTRACTED_DIR=$(echo $ALCASAR_TARBALL | rev | cut -d '.' -f 3- | rev)
|
|
|
47 |
ALCASAR_VERSION=`echo $ALCASAR_EXTRACTED_DIR | cut -d"-" -f2`
|
|
|
48 |
MAGEIA_NEW_DIR=/var/tmp/mageia_new
|
|
|
49 |
MAGEIA_OFFICIAL_DIR=/var/tmp/mageia_official
|
|
|
50 |
MAGEIA_OFFICIAL_DIR_EFI=/var/tmp/mageia_official_efi
|
|
|
51 |
coreDir=${MAGEIA_OFFICIAL_DIR}/${ARCH}/media/core
|
|
|
52 |
nonFreeDir=${MAGEIA_OFFICIAL_DIR}/${ARCH}/media/nonfree
|
|
|
53 |
coreDirNew=${MAGEIA_NEW_DIR}/${ARCH}/media/core/
|
|
|
54 |
nonFreeDirNew=${MAGEIA_NEW_DIR}/${ARCH}/media/nonfree
|
|
|
55 |
plopFilePath=${MAGEIA_NEW_DIR}/${ARCH}/media/plop.idx
|
|
|
56 |
ISO_OUT=/var/tmp/iso
|
|
|
57 |
RPM_DIR=/var/tmp/rpms
|
|
|
58 |
|
|
|
59 |
|
|
|
60 |
# Drake installer
|
|
|
61 |
INSTALLER_DIR="${MAGEIA_NEW_DIR}/${ARCH}/install/alcasar"
|
|
|
62 |
EFI_GRUB_CFG="${MAGEIA_NEW_DIR}/boot/grub2/grub.cfg"
|
|
|
63 |
ADVERT_DIR="${MAGEIA_NEW_DIR}/${ARCH}/install/extra/advertising"
|
|
|
64 |
AUTO_INSTALL_CFG="${ISO_OUT}/auto_inst.cfg.pl"
|
|
|
65 |
|
|
|
66 |
# RPMs needed during an install stage
|
|
|
67 |
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 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"
|
|
|
68 |
|
|
|
69 |
#######################
|
|
|
70 |
###### Main ######
|
|
|
71 |
################################################################################
|
|
|
72 |
|
|
|
73 |
# Some checks
|
|
|
74 |
[[ $(whoami) != 'root' ]] && errorExit 'Please run as root'
|
|
|
75 |
[[ $ISO_IN == "" ]] && errorExit "No Mageia iso file in $RESSOURCES"
|
|
|
76 |
[[ ! -f "$RESSOURCES/auto_inst.cfg.pl_template" ]] && errorExit "No auto_inst.cfg.pl_template file in $RESSOURCES"
|
|
|
77 |
[[ $ALCASAR_TARBALL == "" ]] && errorExit "No ALCASAR tarball file in $RESSOURCES"
|
|
|
78 |
for directory in $MAGEIA_NEW_DIR $MAGEIA_OFFICIAL_DIR $MAGEIA_OFFICIAL_DIR_EFI $ISO_OUT $RPM_DIR
|
|
|
79 |
do
|
|
|
80 |
[ -d $directory ] || mkdir -p $directory
|
|
|
81 |
done
|
|
|
82 |
printBold "Mageiar will be build with Mageia-$MAGEIA_VERSION-$ARCH and $ALCASAR_EXTRACTED_DIR"
|
|
|
83 |
|
|
|
84 |
# Retrieve list of Alcasar dependencies
|
|
|
85 |
tar -xf $RESSOURCES/$ALCASAR_TARBALL -C /tmp/ || errorExit "could not extract alcasar tar archive"
|
|
|
86 |
alcasarRpmList="$(grep -oP "(?<=PACKAGES=\").*?(?=\")" /tmp/$ALCASAR_EXTRACTED_DIR/scripts/alcasar-rpm.sh)"
|
|
|
87 |
alcasarKernel="$(grep -oP "(?<=KERNEL=\").*?(?=\")" /tmp/$ALCASAR_EXTRACTED_DIR/scripts/alcasar-rpm.sh)"
|
|
|
88 |
alcasarRpmList="$alcasarRpmList $alcasarKernel"
|
|
|
89 |
|
|
|
90 |
# Make clean rpm list
|
|
|
91 |
rpmList=$(echo $BASE_RPM_LIST $alcasarRpmList | sed "s/ /\n/g" | sort | uniq | sed "s/\n/ /g")
|
|
|
92 |
|
|
|
93 |
# Insert list into AUTO_INSTALL_CFG
|
|
|
94 |
formattedList=$(echo $rpmList | sed "s/[^ ]*/\'\0\'/g" | sed "s/ /,\n/g" | sed "/kernel-server/d")
|
|
|
95 |
cp $RESSOURCES/auto_inst.cfg.pl_template $AUTO_INSTALL_CFG -f
|
|
|
96 |
insertLineNumber=$(grep -n "'default_packages' => " "$AUTO_INSTALL_CFG" | cut -d ':' -f1)
|
|
|
97 |
fileTop=$(head -n "+$insertLineNumber" "$AUTO_INSTALL_CFG")
|
|
|
98 |
fileBottom=$(tail -n "+$insertLineNumber" "$AUTO_INSTALL_CFG" | tail -n +2)
|
|
|
99 |
cat /dev/null > "$AUTO_INSTALL_CFG"
|
|
|
100 |
echo "$fileTop" > "$AUTO_INSTALL_CFG"
|
|
|
101 |
echo "$formattedList" >> "$AUTO_INSTALL_CFG"
|
|
|
102 |
echo "$fileBottom" >> "$AUTO_INSTALL_CFG"
|
|
|
103 |
|
|
|
104 |
# Installing tools to create the iso
|
|
|
105 |
printBold "Installing necessary tools"
|
|
|
106 |
dnf install 'dnf-command(download)' -y || errorExit "could not install necessary packages"
|
|
|
107 |
#dnf install 'dnf-command(config-manager)' -y || errorExit "could not install necessary packages"
|
|
|
108 |
#dnf config-manager --set-enabled mageia-x86_64-nonfree updates-x86_64-nonfree || errorExit "could not install necessary packages"
|
|
|
109 |
dnf install -y lftp wget cdrkit-genisoimage xorriso rpmtools syslinux || errorExit "could not install necessary packages"
|
|
|
110 |
|
|
|
111 |
# Mounting the ISO image
|
|
|
112 |
printBold "Mounting the image"
|
|
|
113 |
mount -o ro,loop $RESSOURCES/$ISO_IN $MAGEIA_OFFICIAL_DIR || errorExit "failed mounting $ISO_IN."
|
|
|
114 |
sleep 1 # wait for mounting process
|
|
|
115 |
[ -d ${MAGEIA_OFFICIAL_DIR}/x86_64 ] || umount $MAGEIA_OFFICIAL_DIR || errorExit "The ISO file isn't in the target architecture ($ARCH)"
|
|
|
116 |
|
|
|
117 |
# Copying main files except core and nonfree directories
|
|
|
118 |
echo "Extracting base image..."
|
|
|
119 |
cd $MAGEIA_OFFICIAL_DIR && \
|
|
|
120 |
tar cf - --exclude=${ARCH}/media . | (cd $MAGEIA_NEW_DIR && tar xf - ) && cd "${CURRENT_DIR}"
|
|
|
121 |
|
|
|
122 |
# Creating new directories core and nonfree and dir for alcasar stufs
|
|
|
123 |
mkdir -p ${MAGEIA_NEW_DIR}/${ARCH}/{media/{core,nonfree},install/alcasar}
|
|
|
124 |
|
|
|
125 |
# Adding Alcasar image advert to the installer
|
|
|
126 |
cp -f $RESSOURCES/install_slideshow/* "$ADVERT_DIR"
|
|
|
127 |
|
|
|
128 |
# Create the installed RPM list excluding those brought with alcasar archive (they aren't in repository)
|
|
|
129 |
installedList="$(dnf list installed | cut -d ' ' -f1 | rev | cut -d . -f2- | rev | grep -Ev 'coova-chilli|gammu|lib64gammu8|ipt-netflow|nfdump|wkhtmltopdf' | tail -n +2 | tr '\n' ' ')"
|
|
|
130 |
nbInstalled=$(echo $installedList | wc -w)
|
|
|
131 |
rpmList="$installedList $BASE_RPM_LIST"
|
|
|
132 |
total=`echo $rpmList | wc -w`
|
|
|
133 |
count=0
|
|
|
134 |
# Copying the RPM in core and clearing the plop.idx file
|
|
|
135 |
echo "Copying RPMS in ISO ..."
|
|
|
136 |
echo /dev/null > ${plopFilePath}
|
|
|
137 |
for rpm in ${rpmList}; do
|
|
|
138 |
let percent="${count} * 100 / ${total}"
|
|
|
139 |
if [[ $count -lt $nbInstalled ]] ; then
|
|
|
140 |
dnf download -y --downloadonly --downloaddir $coreDirNew $rpm 1> /dev/null || errorExit "could not download $rpm"
|
|
|
141 |
else
|
|
|
142 |
dnf install -y --downloadonly --downloaddir $coreDirNew $rpm 1> /dev/null || errorExit "could not download $rpm"
|
|
|
143 |
fi
|
|
|
144 |
printProgress ${percent}
|
|
|
145 |
count=$(expr ${count} + 1)
|
|
|
146 |
done
|
|
|
147 |
echo "STOP"; exit 1
|
|
|
148 |
|
|
|
149 |
# Sorting the plop file alphabetically
|
|
|
150 |
cat ${plopFilePath} | sort > /tmp/tmpFileMageia && mv /tmp/tmpFileMageia ${plopFilePath}
|
|
|
151 |
|
|
|
152 |
# Informations
|
|
|
153 |
printBold "$count RPMs copied"
|
|
|
154 |
|
|
|
155 |
# Downloading rpms needed by Alcasar
|
|
|
156 |
cd "$CURRENT_DIR"
|
|
|
157 |
printBold "Downloading Alcasar dependencies"
|
|
|
158 |
tar -xf /var/iso/$ALCASAR_TARBALL
|
|
|
159 |
|
|
|
160 |
# Copying the Alcasar tar to be put into the ISO
|
|
|
161 |
cp /var/iso/$ALCASAR_TARBALL $INSTALLER_DIR/
|
|
|
162 |
|
|
|
163 |
# Add automatic install options
|
|
|
164 |
mkdir -p $INSTALLER_DIR || errorExit "could not create directory $INSTALLER_DIR"
|
|
|
165 |
cp $AUTO_INSTALL_CFG $INSTALLER_DIR || errorExit "could not copy $AUTO_INSTALL_CFG to $INSTALLER_DIR"
|
|
|
166 |
|
|
|
167 |
# Generating media info for core
|
|
|
168 |
echo "Generating media_info for core..."
|
|
|
169 |
genhdlist2 ${coreDirNew} --allow-empty-media --quiet
|
|
|
170 |
|
|
|
171 |
echo "Generating media_info for nonfree..."
|
|
|
172 |
genhdlist2 ${nonFreeDirNew} --allow-empty-media --quiet
|
|
|
173 |
|
|
|
174 |
# Puting pubkeys in media_info
|
|
|
175 |
cp ${coreDir}/media_info/pubkey ${coreDirNew}/media_info/
|
|
|
176 |
cp ${nonFreeDir}/media_info/pubkey ${nonFreeDirNew}/media_info/
|
|
|
177 |
|
|
|
178 |
# Retrieving media.cfg & compssUsers.pl depending on the arch
|
|
|
179 |
mkdir ${MAGEIA_NEW_DIR}/${ARCH}/media/media_info
|
|
|
180 |
cp ${MAGEIA_OFFICIAL_DIR}/${ARCH}/media/media_info/compssUsers.pl ${MAGEIA_NEW_DIR}/${ARCH}/media/media_info/compssUsers.pl
|
|
|
181 |
cp ${MAGEIA_OFFICIAL_DIR}/${ARCH}/media/media_info/media.cfg ${MAGEIA_NEW_DIR}/${ARCH}/media/media_info/media.cfg
|
|
|
182 |
|
|
|
183 |
# Specify install configuration
|
|
|
184 |
#sed -i -e 's*rdz*rdz kickstart=/tmp/media/x86_64/install/alcasar/auto_inst.cfg.pl*g' ${MAGEIA_NEW_DIR}/isolinux/isolinux.cfg
|
|
|
185 |
sed -i -e 's*noiswmd*noiswmd kickstart=/tmp/media/x86_64/install/alcasar/auto_inst.cfg.pl*g' $EFI_GRUB_CFG
|
|
|
186 |
|
|
|
187 |
# Generating distr
|
|
|
188 |
echo "Generating mirror tree..."
|
|
|
189 |
gendistrib -s ${MAGEIA_NEW_DIR}/${ARCH}
|
|
|
190 |
|
|
|
191 |
# Creating the new iso file
|
|
|
192 |
echo "Creating the isofile..."
|
|
|
193 |
newIsoName=Mageia-$MAGEIA_VERSION-${ARCH}-Alcasar-$ALCASAR_VERSION.iso
|
|
|
194 |
|
|
|
195 |
# Generating the iso file
|
|
|
196 |
# Parameters for xorriso found using the following command on the original mageia iso
|
|
|
197 |
# xorriso -indev Mageia-7-x86_64.iso -report_el_torito as_mkisofs
|
|
|
198 |
cd ${MAGEIA_NEW_DIR} && xorriso -as mkisofs \
|
|
|
199 |
-V 'Mageia-7.1-x86_64' \
|
|
|
200 |
--grub2-mbr --interval:local_fs:0s-15s:zero_mbrpt:${ISO_IN} \
|
|
|
201 |
-partition_cyl_align off \
|
|
|
202 |
-partition_offset 0 \
|
|
|
203 |
--mbr-force-bootable \
|
|
|
204 |
-append_partition 2 0xef --interval:local_fs:8785156d-8793347d::${ISO_IN} \
|
|
|
205 |
-iso_mbr_part_type 0x00 \
|
|
|
206 |
-c '/boot.catalog' \
|
|
|
207 |
-b '/boot/grub2/eltorito.img' \
|
|
|
208 |
-no-emul-boot \
|
|
|
209 |
-boot-load-size 4 \
|
|
|
210 |
-boot-info-table \
|
|
|
211 |
--grub2-boot-info \
|
|
|
212 |
-eltorito-alt-boot \
|
|
|
213 |
-e '--interval:appended_partition_2_start_2196289s_size_8192d:all::' \
|
|
|
214 |
-no-emul-boot \
|
|
|
215 |
-boot-load-size 8192 \
|
|
|
216 |
-o ${CURRENT_DIR}/${newIsoName} .
|
|
|
217 |
|
|
|
218 |
|
|
|
219 |
# Unmounting & Removing temporary dir
|
|
|
220 |
echo "Umounting..."
|
|
|
221 |
umount $MAGEIA_OFFICIAL_DIR
|
|
|
222 |
for directory in $MAGEIA_NEW_DIR $MAGEIA_OFFICIAL_DIR $MAGEIA_OFFICIAL_DIR_EFI $ISO_OUT $RPM_DIR
|
|
|
223 |
do
|
|
|
224 |
[ -d $directory ] && rm -rf $directory
|
|
|
225 |
done
|
|
|
226 |
|
|
|
227 |
mv ${CURRENT_DIR}/${newIsoName} /var/iso/
|
|
|
228 |
|
|
|
229 |
# Finished
|
|
|
230 |
rm -f "$AUTO_INSTALL_CFG"
|
|
|
231 |
echo "Done."
|