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`
|
2944 |
rexy |
48 |
TMP_DIR=/var/tmp
|
|
|
49 |
MAGEIA_NEW_DIR=$TMP_DIR/mageia_new
|
|
|
50 |
MAGEIA_OFFICIAL_DIR=$TMP_DIR/mageia_official
|
|
|
51 |
MAGEIA_OFFICIAL_DIR_EFI=$TMP_DIR/mageia_official_efi
|
2941 |
rexy |
52 |
coreDir=${MAGEIA_OFFICIAL_DIR}/${ARCH}/media/core
|
|
|
53 |
nonFreeDir=${MAGEIA_OFFICIAL_DIR}/${ARCH}/media/nonfree
|
|
|
54 |
coreDirNew=${MAGEIA_NEW_DIR}/${ARCH}/media/core/
|
|
|
55 |
nonFreeDirNew=${MAGEIA_NEW_DIR}/${ARCH}/media/nonfree
|
|
|
56 |
|
|
|
57 |
# Drake installer
|
|
|
58 |
INSTALLER_DIR="${MAGEIA_NEW_DIR}/${ARCH}/install/alcasar"
|
|
|
59 |
EFI_GRUB_CFG="${MAGEIA_NEW_DIR}/boot/grub2/grub.cfg"
|
|
|
60 |
ADVERT_DIR="${MAGEIA_NEW_DIR}/${ARCH}/install/extra/advertising"
|
2944 |
rexy |
61 |
AUTO_INSTALL_CFG=$TMP_DIR/auto_inst.cfg.pl
|
2941 |
rexy |
62 |
|
|
|
63 |
# RPMs needed during an install stage
|
2944 |
rexy |
64 |
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 ldetect lftp lib64alsa-plugins lib64glib-networking-gnutls locales-en locales-fr lsof lvm2 mageia-theme-Default man-db 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 mandi mandi-ifw"
|
2941 |
rexy |
65 |
|
|
|
66 |
#######################
|
|
|
67 |
###### Main ######
|
|
|
68 |
################################################################################
|
|
|
69 |
|
|
|
70 |
# Some checks
|
|
|
71 |
[[ $(whoami) != 'root' ]] && errorExit 'Please run as root'
|
|
|
72 |
[[ $ISO_IN == "" ]] && errorExit "No Mageia iso file in $RESSOURCES"
|
|
|
73 |
[[ ! -f "$RESSOURCES/auto_inst.cfg.pl_template" ]] && errorExit "No auto_inst.cfg.pl_template file in $RESSOURCES"
|
|
|
74 |
[[ $ALCASAR_TARBALL == "" ]] && errorExit "No ALCASAR tarball file in $RESSOURCES"
|
2944 |
rexy |
75 |
|
|
|
76 |
for directory in $MAGEIA_NEW_DIR $MAGEIA_OFFICIAL_DIR $MAGEIA_OFFICIAL_DIR_EFI
|
2941 |
rexy |
77 |
do
|
|
|
78 |
[ -d $directory ] || mkdir -p $directory
|
|
|
79 |
done
|
|
|
80 |
printBold "Mageiar will be build with Mageia-$MAGEIA_VERSION-$ARCH and $ALCASAR_EXTRACTED_DIR"
|
|
|
81 |
|
2944 |
rexy |
82 |
# Retrieve list of installed RPM
|
|
|
83 |
ALCASAR_RPM_LIST="$(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' ' ')"
|
|
|
84 |
# agregate & clean rpm list
|
|
|
85 |
RPM_LIST=$(echo $BASE_RPM_LIST $ALCASAR_RPM_LIST | sed "s/ /\n/g" | sort | uniq | sed "s/\n/ /g")
|
2941 |
rexy |
86 |
|
|
|
87 |
# Insert list into AUTO_INSTALL_CFG
|
2944 |
rexy |
88 |
formattedList=$(echo $RPM_LIST | sed "s/[^ ]*/\'\0\'/g" | sed "s/ /,\n/g")
|
|
|
89 |
cp -f $RESSOURCES/auto_inst.cfg.pl_template $AUTO_INSTALL_CFG
|
2941 |
rexy |
90 |
insertLineNumber=$(grep -n "'default_packages' => " "$AUTO_INSTALL_CFG" | cut -d ':' -f1)
|
|
|
91 |
fileTop=$(head -n "+$insertLineNumber" "$AUTO_INSTALL_CFG")
|
|
|
92 |
fileBottom=$(tail -n "+$insertLineNumber" "$AUTO_INSTALL_CFG" | tail -n +2)
|
|
|
93 |
cat /dev/null > "$AUTO_INSTALL_CFG"
|
|
|
94 |
echo "$fileTop" > "$AUTO_INSTALL_CFG"
|
|
|
95 |
echo "$formattedList" >> "$AUTO_INSTALL_CFG"
|
|
|
96 |
echo "$fileBottom" >> "$AUTO_INSTALL_CFG"
|
|
|
97 |
|
2944 |
rexy |
98 |
# Installing tools to create the iso file
|
|
|
99 |
printBold "Installing ISO building tools"
|
2941 |
rexy |
100 |
dnf install 'dnf-command(download)' -y || errorExit "could not install necessary packages"
|
|
|
101 |
dnf install -y lftp wget cdrkit-genisoimage xorriso rpmtools syslinux || errorExit "could not install necessary packages"
|
|
|
102 |
|
|
|
103 |
# Mounting the ISO image
|
|
|
104 |
printBold "Mounting the image"
|
2944 |
rexy |
105 |
if [ `mount |grep $MAGEIA_OFFICIAL_DIR | wc -l` -eq 0 ]; then # if not already mounted
|
|
|
106 |
mount -o ro,loop $RESSOURCES/$ISO_IN $MAGEIA_OFFICIAL_DIR || errorExit "failed mounting $ISO_IN."
|
|
|
107 |
fi
|
2941 |
rexy |
108 |
sleep 1 # wait for mounting process
|
|
|
109 |
[ -d ${MAGEIA_OFFICIAL_DIR}/x86_64 ] || umount $MAGEIA_OFFICIAL_DIR || errorExit "The ISO file isn't in the target architecture ($ARCH)"
|
|
|
110 |
|
|
|
111 |
# Copying main files except core and nonfree directories
|
|
|
112 |
echo "Extracting base image..."
|
|
|
113 |
cd $MAGEIA_OFFICIAL_DIR && \
|
|
|
114 |
tar cf - --exclude=${ARCH}/media . | (cd $MAGEIA_NEW_DIR && tar xf - ) && cd "${CURRENT_DIR}"
|
|
|
115 |
|
|
|
116 |
# Creating new directories core and nonfree and dir for alcasar stufs
|
|
|
117 |
mkdir -p ${MAGEIA_NEW_DIR}/${ARCH}/{media/{core,nonfree},install/alcasar}
|
|
|
118 |
|
|
|
119 |
# Adding Alcasar image advert to the installer
|
2944 |
rexy |
120 |
cp -f $RESSOURCES/install_slideshow/* "$ADVERT_DIR" || errorExit "could not copy custom slideshow to $ADVERT_DIR"
|
2941 |
rexy |
121 |
|
|
|
122 |
# Create the installed RPM list excluding those brought with alcasar archive (they aren't in repository)
|
2944 |
rexy |
123 |
nbInstalled=$(echo $RPM_LIST | wc -w)
|
|
|
124 |
total=`echo $RPM_LIST | wc -w`
|
2941 |
rexy |
125 |
count=0
|
|
|
126 |
# Copying the RPM in core and clearing the plop.idx file
|
2944 |
rexy |
127 |
echo "Copying $total RPMS in ISO ..."
|
|
|
128 |
for rpm in ${RPM_LIST}; do
|
2941 |
rexy |
129 |
let percent="${count} * 100 / ${total}"
|
2944 |
rexy |
130 |
dnf download --downloaddir $coreDirNew $rpm 1> /dev/null || errorExit "could not download $rpm"
|
2941 |
rexy |
131 |
printProgress ${percent}
|
|
|
132 |
count=$(expr ${count} + 1)
|
|
|
133 |
done
|
|
|
134 |
printBold "$count RPMs copied"
|
|
|
135 |
|
2944 |
rexy |
136 |
# Copying the Alcasar tarball & automatic install option into the ISO
|
2941 |
rexy |
137 |
mkdir -p $INSTALLER_DIR || errorExit "could not create directory $INSTALLER_DIR"
|
2944 |
rexy |
138 |
cp $RESSOURCES/$ALCASAR_TARBALL $INSTALLER_DIR || errorExit "could not copy $RESSOURCES/$ALCASAR_TARBALL to $INSTALLER_DIR"
|
2941 |
rexy |
139 |
cp $AUTO_INSTALL_CFG $INSTALLER_DIR || errorExit "could not copy $AUTO_INSTALL_CFG to $INSTALLER_DIR"
|
|
|
140 |
|
|
|
141 |
# Generating media info for core
|
|
|
142 |
echo "Generating media_info for core..."
|
|
|
143 |
genhdlist2 ${coreDirNew} --allow-empty-media --quiet
|
|
|
144 |
echo "Generating media_info for nonfree..."
|
|
|
145 |
genhdlist2 ${nonFreeDirNew} --allow-empty-media --quiet
|
|
|
146 |
|
|
|
147 |
# Puting pubkeys in media_info
|
|
|
148 |
cp ${coreDir}/media_info/pubkey ${coreDirNew}/media_info/
|
|
|
149 |
cp ${nonFreeDir}/media_info/pubkey ${nonFreeDirNew}/media_info/
|
|
|
150 |
|
|
|
151 |
# Retrieving media.cfg & compssUsers.pl depending on the arch
|
|
|
152 |
mkdir ${MAGEIA_NEW_DIR}/${ARCH}/media/media_info
|
|
|
153 |
cp ${MAGEIA_OFFICIAL_DIR}/${ARCH}/media/media_info/compssUsers.pl ${MAGEIA_NEW_DIR}/${ARCH}/media/media_info/compssUsers.pl
|
|
|
154 |
cp ${MAGEIA_OFFICIAL_DIR}/${ARCH}/media/media_info/media.cfg ${MAGEIA_NEW_DIR}/${ARCH}/media/media_info/media.cfg
|
|
|
155 |
|
|
|
156 |
# Specify install configuration
|
|
|
157 |
#sed -i -e 's*rdz*rdz kickstart=/tmp/media/x86_64/install/alcasar/auto_inst.cfg.pl*g' ${MAGEIA_NEW_DIR}/isolinux/isolinux.cfg
|
|
|
158 |
sed -i -e 's*noiswmd*noiswmd kickstart=/tmp/media/x86_64/install/alcasar/auto_inst.cfg.pl*g' $EFI_GRUB_CFG
|
|
|
159 |
|
|
|
160 |
# Generating distr
|
|
|
161 |
echo "Generating mirror tree..."
|
|
|
162 |
gendistrib -s ${MAGEIA_NEW_DIR}/${ARCH}
|
|
|
163 |
|
|
|
164 |
# Creating the new iso file
|
|
|
165 |
echo "Creating the isofile..."
|
|
|
166 |
newIsoName=Mageia-$MAGEIA_VERSION-${ARCH}-Alcasar-$ALCASAR_VERSION.iso
|
|
|
167 |
|
|
|
168 |
# Generating the iso file
|
|
|
169 |
# Parameters for xorriso found using the following command on the original mageia iso
|
|
|
170 |
# xorriso -indev Mageia-7-x86_64.iso -report_el_torito as_mkisofs
|
|
|
171 |
cd ${MAGEIA_NEW_DIR} && xorriso -as mkisofs \
|
|
|
172 |
-V 'Mageia-7.1-x86_64' \
|
|
|
173 |
-partition_cyl_align off \
|
|
|
174 |
-partition_offset 0 \
|
|
|
175 |
--mbr-force-bootable \
|
|
|
176 |
-iso_mbr_part_type 0x00 \
|
2944 |
rexy |
177 |
-c 'boot.catalog' \
|
|
|
178 |
-b 'boot/grub2/eltorito.img' \
|
2941 |
rexy |
179 |
-no-emul-boot \
|
|
|
180 |
-boot-load-size 4 \
|
|
|
181 |
-boot-info-table \
|
|
|
182 |
--grub2-boot-info \
|
|
|
183 |
-eltorito-alt-boot \
|
|
|
184 |
-boot-load-size 8192 \
|
2944 |
rexy |
185 |
-o ${TMP_DIR}/${newIsoName} .
|
2941 |
rexy |
186 |
|
|
|
187 |
# Unmounting & Removing temporary dir
|
|
|
188 |
echo "Umounting..."
|
|
|
189 |
umount $MAGEIA_OFFICIAL_DIR
|
2944 |
rexy |
190 |
for directory in $MAGEIA_NEW_DIR $MAGEIA_OFFICIAL_DIR $MAGEIA_OFFICIAL_DIR_EFI
|
2941 |
rexy |
191 |
do
|
|
|
192 |
[ -d $directory ] && rm -rf $directory
|
|
|
193 |
done
|
|
|
194 |
rm -f "$AUTO_INSTALL_CFG"
|
|
|
195 |
echo "Done."
|