2672 |
rexy |
1 |
#!/bin/bash
|
|
|
2 |
#
|
|
|
3 |
# Authors: Mageia Team
|
|
|
4 |
# Update for ALCASAR : Hamza ESSAYEGH (Querdos) - Rexy - Laurent Roux - Aurelien Dubois
|
|
|
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 ######
|
|
|
13 |
###############################################################################""
|
|
|
14 |
|
|
|
15 |
CURRENT_DIR="$(readlink -f "$(dirname $0)")"
|
|
|
16 |
LOG_FILE="$CURRENT_DIR/build-image.log"
|
|
|
17 |
|
|
|
18 |
# Mageia
|
|
|
19 |
MAGEIA_VERSION=`cat /etc/release|cut -c 16`
|
|
|
20 |
ARCH=`cat /etc/release|cut -c 33-38`
|
|
|
21 |
MAGEIA_NEW_DIR=/tmp/mageia_new
|
|
|
22 |
MAGEIA_OFFICIAL_DIR=/tmp/mageia_official
|
|
|
23 |
# ISO file
|
|
|
24 |
ISO_DIR="/var/iso"
|
|
|
25 |
ISO_IN="$ISO_DIR/Mageia-$MAGEIA_VERSION-$ARCH-DVD.iso"
|
|
|
26 |
|
|
|
27 |
# Drake installer
|
|
|
28 |
INSTALLER_DIR="${MAGEIA_NEW_DIR}/${ARCH}/install/alcasar"
|
|
|
29 |
AUTO_INSTALL_CFG="/var/iso/auto_inst.cfg.pl"
|
|
|
30 |
ADVERT_DIR="${MAGEIA_NEW_DIR}/${ARCH}/install/extra/advertising"
|
|
|
31 |
|
|
|
32 |
# Alcasar
|
|
|
33 |
ALCASAR_TAR="$1"
|
|
|
34 |
ALCASAR_EXTRACTED_DIR=$(echo $ALCASAR_TAR | rev | cut -d '.' -f 3- | rev)
|
|
|
35 |
|
|
|
36 |
# Mirrors
|
|
|
37 |
ISO_SUPPORT="http://ftp.free.fr/mirrors/mageia.org/iso/$MAGEIA_VERSION/Mageia-$MAGEIA_VERSION-$ARCH-DVD/Mageia-$MAGEIA_VERSION-$ARCH-DVD.iso"
|
|
|
38 |
ISO_MD5="http://ftp.free.fr/mirrors/mageia.org/iso/$MAGEIA_VERSION/Mageia-$MAGEIA_VERSION-$ARCH-DVD/Mageia-$MAGEIA_VERSION-$ARCH-DVD.iso.md5"
|
|
|
39 |
|
|
|
40 |
# RPMs
|
|
|
41 |
RPM_DIR="/root/rpms"
|
|
|
42 |
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-mageia-theme harddrake hdparm hexedit info iwlwifi-agn-ucode kernel-desktop-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"
|
|
|
43 |
|
|
|
44 |
#######################
|
|
|
45 |
###### Functions ######
|
|
|
46 |
################################################################################
|
|
|
47 |
# Print the given error message and exit 1
|
|
|
48 |
function errorExit()
|
|
|
49 |
{
|
|
|
50 |
tput bold
|
|
|
51 |
echo -e "ERROR : $1 \nAborting\n" >&2
|
|
|
52 |
echo "$1" > "$LOG_FILE"
|
|
|
53 |
tput sgr0
|
|
|
54 |
exit 1
|
|
|
55 |
}
|
|
|
56 |
#-------------------------------------------------------------------------------
|
|
|
57 |
# Print progress bar. $1 is a multiple of five
|
|
|
58 |
function printProgress()
|
|
|
59 |
{
|
|
|
60 |
local a
|
|
|
61 |
let "a = $1 / 5"
|
|
|
62 |
let "b = 25 - $a"
|
|
|
63 |
progressStr=$(printf "%${a}s")
|
|
|
64 |
progressStrBlanks=$(printf "%${b}s")
|
|
|
65 |
echo -en "Downloading...$1% [${progressStr// /#}${progressStrBlanks// / }]\r"
|
|
|
66 |
}
|
|
|
67 |
#-------------------------------------------------------------------------------
|
|
|
68 |
function printBold()
|
|
|
69 |
{
|
|
|
70 |
tput bold 2>/dev/null
|
|
|
71 |
echo $1
|
|
|
72 |
tput sgr0 2>/dev/null
|
|
|
73 |
}
|
|
|
74 |
#######################
|
|
|
75 |
###### Main ######
|
|
|
76 |
################################################################################
|
|
|
77 |
|
|
|
78 |
# Retrieve list of Alcasar dependencies
|
|
|
79 |
tar -xf /var/iso/$ALCASAR_TAR -C /tmp/ || errorExit "could not extract alcasar tar archive"
|
|
|
80 |
alcasarRpmList="$(grep -oP "(?<=PACKAGES=\").*?(?=\")" /tmp/$ALCASAR_EXTRACTED_DIR/scripts/alcasar-urpmi.sh)"
|
|
|
81 |
alcasarKernel="$(grep -oP "(?<=KERNEL=\").*?(?=\")" /tmp/$ALCASAR_EXTRACTED_DIR/scripts/alcasar-urpmi.sh)"
|
|
|
82 |
alcasarRpmList="$alcasarRpmList $alcasarKernel"
|
|
|
83 |
|
|
|
84 |
# Make clean rpm list
|
|
|
85 |
rpmList=$(echo $BASE_RPM_LIST $alcasarRpmList | sed "s/ /\n/g" | sort | uniq | sed "s/\n/ /g")
|
|
|
86 |
|
|
|
87 |
# Insert list into AUTO_INSTALL_CFG
|
|
|
88 |
formattedList=$(echo $rpmList | sed "s/[^ ]*/\'\0\'/g" | sed "s/ /,\n/g" | sed "/kernel-server/d")
|
|
|
89 |
cp "${AUTO_INSTALL_CFG}_template" "$AUTO_INSTALL_CFG" -f
|
|
|
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 |
|
|
|
95 |
echo "$fileTop" > "$AUTO_INSTALL_CFG"
|
|
|
96 |
echo "$formattedList" >> "$AUTO_INSTALL_CFG"
|
|
|
97 |
echo "$fileBottom" >> "$AUTO_INSTALL_CFG"
|
|
|
98 |
|
|
|
99 |
# Installing tools to create the iso
|
|
|
100 |
printBold "Installing necessary tools"
|
|
|
101 |
dnf install 'dnf-command(download)' -y >/dev/null || errorExit "could not install necessary packages"
|
|
|
102 |
dnf config-manager --set-enabled mageia-x86_64-nonfree updates-x86_64-nonfree >/dev/null || errorExit "could not install necessary packages"
|
|
|
103 |
dnf install -y lftp wget cdrkit-genisoimage rpmtools >/dev/null || errorExit "could not install necessary packages"
|
|
|
104 |
|
|
|
105 |
|
|
|
106 |
# Directories initialization
|
|
|
107 |
#-------------------------------------------------------------------------------
|
|
|
108 |
[[ ! -d "$RPM_DIR" ]] && mkdir -p "$RPM_DIR"
|
|
|
109 |
|
|
|
110 |
# Beggining work on the ISO
|
|
|
111 |
#-------------------------------------------------------------------------------
|
|
|
112 |
# Checking the optional Mageia image. If not present or does not match the
|
|
|
113 |
# docker's version, download it
|
|
|
114 |
if [[ ! -f "$ISO_IN" ]]; then
|
|
|
115 |
printBold "Downloading the Mageia iso"
|
|
|
116 |
cd $ISO_DIR || errorExit "could not cd to $ISO_DIR"
|
|
|
117 |
echo Installing lftp
|
|
|
118 |
lftpget -c $ISO_SUPPORT || ( cd "$CURRENT_DIR" && errorExit "could not download Mageia iso" )
|
|
|
119 |
cd $CURRENT_DIR
|
|
|
120 |
fi
|
|
|
121 |
|
|
|
122 |
# Mounting the image
|
|
|
123 |
printBold "Mounting the image"
|
|
|
124 |
[[ ! -d "$MAGEIA_OFFICIAL_DIR" ]] && mkdir -p "$MAGEIA_OFFICIAL_DIR"
|
|
|
125 |
mount -o ro,loop "$ISO_IN" "$MAGEIA_OFFICIAL_DIR" || errorExit "failed mounting $ISO_IN"
|
|
|
126 |
|
|
|
127 |
# Checking ARCHitecture
|
|
|
128 |
[[ -d ${MAGEIA_OFFICIAL_DIR}/x86_64 ]] && ARCH=x86_64 || ARCH=i586
|
|
|
129 |
|
|
|
130 |
# Creating new directory that will contains the "cleared" iso image
|
|
|
131 |
[[ -d ${MAGEIA_NEW_DIR} ]] && rm -rf ${MAGEIA_NEW_DIR}
|
|
|
132 |
mkdir ${MAGEIA_NEW_DIR}
|
|
|
133 |
|
|
|
134 |
# Copying main files except core and nonfree directories
|
|
|
135 |
echo "Extracting base image..."
|
|
|
136 |
cd $MAGEIA_OFFICIAL_DIR && \
|
|
|
137 |
tar cf - --exclude=${ARCH}/media . | (cd $MAGEIA_NEW_DIR && tar xf - ) && cd "${CURRENT_DIR}"
|
|
|
138 |
|
|
|
139 |
# Creating new directories core and nonfree and dir for alcasar stufs
|
|
|
140 |
mkdir -p ${MAGEIA_NEW_DIR}/${ARCH}/{media/{core,nonfree},install/alcasar}
|
|
|
141 |
|
|
|
142 |
# Adding Alcasar image advert to the installer
|
|
|
143 |
cp -f /var/iso/install_slideshow/* "$ADVERT_DIR"
|
|
|
144 |
|
|
|
145 |
# Retrieving core and nonfree dirs (official)
|
|
|
146 |
coreDir=${MAGEIA_OFFICIAL_DIR}/${ARCH}/media/core
|
|
|
147 |
nonFreeDir=${MAGEIA_OFFICIAL_DIR}/${ARCH}/media/nonfree
|
|
|
148 |
|
|
|
149 |
# Retrieving core and nonfree dirs (new)
|
|
|
150 |
coreDirNew=${MAGEIA_NEW_DIR}/${ARCH}/media/core/
|
|
|
151 |
nonFreeDirNew=${MAGEIA_NEW_DIR}/${ARCH}/media/nonfree
|
|
|
152 |
plopFilePath=${MAGEIA_NEW_DIR}/${ARCH}/media/plop.idx
|
|
|
153 |
|
|
|
154 |
# Initializing counts
|
|
|
155 |
count=0
|
|
|
156 |
|
|
|
157 |
# Getting list of rpms needed by Mageia
|
|
|
158 |
#mageiaRpms="$(cat $MINIMAL_rpmList)"
|
|
|
159 |
|
|
|
160 |
# Copying the RPM in core and nonfree and clearing the plop.idx file
|
|
|
161 |
echo "Copying RPMS in ISO ..."
|
|
|
162 |
echo /dev/null > ${plopFilePath}
|
|
|
163 |
|
|
|
164 |
installedList="$(dnf list installed | cut -d ' ' -f1 | rev | cut -d . -f2- | rev | tail -n +2 | tr '\n' ' ')"
|
|
|
165 |
nbInstalled=$(echo $installedList | wc -w)
|
|
|
166 |
rpmList="$installedList $BASE_RPM_LIST $alcasarRpmList"
|
|
|
167 |
total=`echo $rpmList | wc -w`
|
|
|
168 |
|
|
|
169 |
for rpm in ${rpmList}; do
|
|
|
170 |
let percent="${count} * 100 / ${total}"
|
|
|
171 |
if [[ $count -lt $nbInstalled ]] ; then
|
|
|
172 |
dnf reinstall -y --downloadonly --downloaddir $coreDirNew $rpm 1> /dev/null || errorExit "could not download $rpm"
|
|
|
173 |
else
|
|
|
174 |
dnf install -y --downloadonly --downloaddir $coreDirNew $rpm 1> /dev/null || errorExit "could not download $rpm"
|
|
|
175 |
fi
|
|
|
176 |
printProgress ${percent}
|
|
|
177 |
|
|
|
178 |
count=$(expr ${count} + 1)
|
|
|
179 |
done
|
|
|
180 |
|
|
|
181 |
# Sorting the plop file alphabetically
|
|
|
182 |
cat ${plopFilePath} | sort > /tmp/tmpFileMageia && mv /tmp/tmpFileMageia ${plopFilePath}
|
|
|
183 |
|
|
|
184 |
# Informations
|
|
|
185 |
printBold "$count RPMs copied"
|
|
|
186 |
|
|
|
187 |
# Downloading rpms needed by Alcasar
|
|
|
188 |
cd "$CURRENT_DIR"
|
|
|
189 |
printBold "Downloading Alcasar dependencies"
|
|
|
190 |
tar -xf /var/iso/$ALCASAR_TAR
|
|
|
191 |
|
|
|
192 |
# Copying the Alcasar tar to be put into the ISO
|
|
|
193 |
cp /var/iso/$ALCASAR_TAR $INSTALLER_DIR/
|
|
|
194 |
|
|
|
195 |
# Add automatic install options
|
|
|
196 |
mkdir -p $INSTALLER_DIR || errorExit "could not create directory $INSTALLER_DIR"
|
|
|
197 |
cp $AUTO_INSTALL_CFG $INSTALLER_DIR || errorExit "could not copy $AUTO_INSTALL_CFG to $INSTALLER_DIR"
|
|
|
198 |
|
|
|
199 |
# Generating media info for core
|
|
|
200 |
echo "Generating media_info for core..."
|
|
|
201 |
genhdlist2 ${coreDirNew} --allow-empty-media --quiet
|
|
|
202 |
|
|
|
203 |
echo "Generating media_info for nonfree..."
|
|
|
204 |
genhdlist2 ${nonFreeDirNew} --allow-empty-media --quiet
|
|
|
205 |
|
|
|
206 |
# Puting pubkeys in media_info
|
|
|
207 |
cp ${coreDir}/media_info/pubkey ${coreDirNew}/media_info/
|
|
|
208 |
cp ${nonFreeDir}/media_info/pubkey ${nonFreeDirNew}/media_info/
|
|
|
209 |
|
|
|
210 |
# Retrieving media.cfg & compssUsers.pl depending on the arch
|
|
|
211 |
mkdir ${MAGEIA_NEW_DIR}/${ARCH}/media/media_info
|
|
|
212 |
cp ${MAGEIA_OFFICIAL_DIR}/${ARCH}/media/media_info/compssUsers.pl ${MAGEIA_NEW_DIR}/${ARCH}/media/media_info/compssUsers.pl
|
|
|
213 |
cp ${MAGEIA_OFFICIAL_DIR}/${ARCH}/media/media_info/media.cfg ${MAGEIA_NEW_DIR}/${ARCH}/media/media_info/media.cfg
|
|
|
214 |
|
|
|
215 |
# Specify install configuration
|
|
|
216 |
sed -i -e 's*rdz*rdz kickstart=/tmp/media/x86_64/install/alcasar/auto_inst.cfg.pl*g' ${MAGEIA_NEW_DIR}/isolinux/isolinux.cfg
|
|
|
217 |
|
|
|
218 |
# Generating distr
|
|
|
219 |
echo "Generating mirror tree..."
|
|
|
220 |
gendistrib -s ${MAGEIA_NEW_DIR}/${ARCH}
|
|
|
221 |
|
|
|
222 |
# Creating the new iso file
|
|
|
223 |
echo "Creating the isofile..."
|
|
|
224 |
alcasarVersion=$(echo $ALCASAR_TAR | cut -d '-' -f2 | rev | cut -d '.' -f 3- | rev )
|
|
|
225 |
newIsoName=Mageia-$MAGEIA_VERSION-${ARCH}-Alcasar${alcasarVersion}.iso
|
|
|
226 |
cd ${MAGEIA_NEW_DIR} && genisoimage -quiet -o ${CURRENT_DIR}/${newIsoName} \
|
|
|
227 |
-b isolinux/isolinux.bin \
|
|
|
228 |
-c boot.catalog \
|
|
|
229 |
-no-emul-boot -boot-load-size 4 \
|
|
|
230 |
-boot-info-table -J -R -V "Mageia-$MAGEIA_VERSION Alcasar ${ARCH}" .
|
|
|
231 |
|
|
|
232 |
# Unmounting
|
|
|
233 |
echo "Umounting..."
|
|
|
234 |
umount ${MAGEIA_OFFICIAL_DIR} && rmdir ${MAGEIA_OFFICIAL_DIR}
|
|
|
235 |
|
|
|
236 |
# Removing temporary dir
|
|
|
237 |
rm -rf ${MAGEIA_NEW_DIR}
|
|
|
238 |
|
|
|
239 |
mv ${CURRENT_DIR}/${newIsoName} /var/iso/
|
|
|
240 |
|
|
|
241 |
# Finished
|
|
|
242 |
rm -f "$AUTO_INSTALL_CFG"
|
|
|
243 |
echo "Done."
|