2018-06-06 11:15:11 +02:00
#!/bin/bash
# Copyright (C) 2017-2018 Daniel Tartavel-jeannot <contact@librepc.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
2019-10-27 22:25:10 +01:00
#Change the local to the most global
2019-11-01 14:15:49 +01:00
export LC_ALL = C
2019-10-27 22:25:10 +01:00
2019-11-03 23:34:36 +01:00
function WaitToContinue( ) {
2019-10-27 16:08:49 +01:00
read -p "Break... Press [ENTER] to continue." GARBAGE
}
2018-06-06 11:15:11 +02:00
2019-11-03 23:34:36 +01:00
function title( ) {
2019-10-01 22:01:26 +02:00
echo -e " \e[1;32m ${ 1 } \e[0m "
2018-06-06 11:15:11 +02:00
}
2019-11-03 23:34:36 +01:00
function info( ) {
2019-10-01 22:01:26 +02:00
echo -e " \e[36m ${ 1 } \e[0m "
2018-06-06 11:15:11 +02:00
}
2019-11-03 23:34:36 +01:00
function warning( ) {
2019-10-01 22:01:26 +02:00
echo -e " \e[1;35m ${ 1 } \e[0m "
2018-06-06 11:15:11 +02:00
}
2019-11-03 23:34:36 +01:00
function error( ) {
2019-10-01 22:01:26 +02:00
echo -e " \e[1;31m ${ 1 } \e[0m "
2018-06-06 11:15:11 +02:00
}
2019-11-03 23:34:36 +01:00
function help( ) {
2019-10-01 22:01:26 +02:00
echo -e " ${ CMDNAME } [option] [size of image in Go] "
echo -e "Options:"
echo -e " --all create ready to burn image of Mageia ${ MAGEIA_VERSION } "
echo -e "--clean Clean all (suppress all) to make a new image"
echo -e "--size size of image default: 7Go"
echo -e " --build-path Path to the build directory of the image of Mageia ${ MAGEIA_VERSION } "
echo -e "--target target system (for now rpi, odroid)"
echo -e "--target-version version of the target (0, 1, 2, 3 for rpi, 3 or 4 for odroid)"
echo -e "--config Path to config files"
echo -e "--bootfs filesystem of boot partition (ext4 or vfat) default: ext4"
echo -e "--nonfree activate nonfree repos"
echo -e "--tainted activate tainted repos"
2019-11-03 23:34:36 +01:00
2019-10-01 22:01:26 +02:00
echo -e "\nBuild levels:"
echo -e "--create-chroot Create the chroot directory"
echo -e "--addmedia add mirrors"
echo -e "--update-mirror update urpmi database"
echo -e "--install-basesystem install base system"
echo -e "--chroot chroot to arm directory and launch packages installation"
echo -e " --create-image Create the image of Mageia ${ MAGEIA_VERSION } "
echo -e "\nFor image size, make sure it fit on physical support. (Default size is 7 Go)"
2018-06-06 11:15:11 +02:00
}
2019-10-27 18:42:51 +01:00
2019-11-03 23:34:36 +01:00
function verify_disk_space( )
2019-10-27 18:42:51 +01:00
{
2019-11-03 23:34:36 +01:00
title "Verifying if there is enough space on disk to make the image"
DISK_SPACE = $( /usr/bin/df -BG --output= avail " ${ INSTALL_PATH } " | sed '1d;s/[^0-9]//g' )
info " Free disk space: ${ DISK_SPACE } G "
if [ ${ DISK_SPACE } -lt ${ IMAGE_SIZE } ] ; then
warning "image size is greater than disk space"
info "correct the problem and relaunch the script with parameter --create-rpi-image"
info " ${ 0 } --size ${ IMAGE_SIZE } --create-rpi-image "
return 1
2019-10-01 22:01:26 +02:00
fi
2019-10-02 17:48:11 +02:00
return 0
2018-06-06 11:15:11 +02:00
}
2019-10-02 17:03:36 +02:00
2018-06-06 11:15:11 +02:00
# creation of install path and copy of qemu ( installing it if not yet installed )
function createchroot( )
{
2019-10-01 22:01:26 +02:00
title "Making chroot"
if ! [ -f /bin/qemu-arm-static ] ; then
title "Qemu package not present : installing qemu packages"
/sbin/urpmi --auto --no-recommends qemu-user-static
if [ ${ ? } -ne 0 ] ; then
error " line ${ LINENO } can't install qemu-user-static : exiting "
2019-10-02 17:03:36 +02:00
exit ${ ERR_1 }
2019-10-01 22:01:26 +02:00
fi
fi
# Starting qemu service if not started
/bin/systemctl is-active systemd-binfmt.service
if [ ${ ? } -ne 0 ] ; then
title "Starting systemd-binfmt.service"
/bin/systemctl start systemd-binfmt.service
if [ ${ ? } -ne 0 ] ; then
error " line ${ LINENO } can't start qemu-user-static : exiting "
2019-10-02 17:03:36 +02:00
exit ${ ERR_1 }
2019-10-01 22:01:26 +02:00
fi
fi
2019-10-02 17:48:11 +02:00
return 0
2018-06-06 11:15:11 +02:00
}
2019-10-02 17:03:36 +02:00
2018-12-07 20:38:32 +01:00
# adding Mageia repositories
2018-06-06 11:15:11 +02:00
function addmedia( )
{
2019-10-01 22:01:26 +02:00
title " Creating media ${ MIRROR } "
2019-10-27 22:25:10 +01:00
if [ ! -z " ${ MIRROR } " ] ; then
/sbin/urpmi.addmedia --urpmi-root " ${ BUILD_PATH } " --distrib " ${ MIRROR } "
else
info "MIRROR variable not set, using mirrorlist."
/sbin/urpmi.addmedia --urpmi-root " ${ BUILD_PATH } " --distrib --mirrorlist " http://mirrors.mageia.org/api/mageia. ${ MAGEIA_VERSION } . ${ ARM_VERSION } .list "
fi
2019-10-01 22:01:26 +02:00
err = ${ ? }
if [ ${ err } -ne 0 ] ; then
error " line ${ LINENO } error ${ err } - can't add medias from ${ MIRROR } : exiting "
2019-10-02 17:03:36 +02:00
exit ${ ERR_1 }
2019-10-01 22:01:26 +02:00
fi
if [ ${ NONFREE } -eq 1 ] ; then
title "activating non-free repos"
/sbin/urpmi.update --urpmi-root " ${ BUILD_PATH } " --no-ignore Nonfree\ Release Nonfree\ Updates
err = ${ ? }
if [ ${ err } -ne 0 ] ; then
error " line ${ LINENO } error ${ err } - can't activate medias nonfree : exiting "
2019-10-02 17:03:36 +02:00
exit ${ ERR_1 }
2019-10-01 22:01:26 +02:00
fi
fi
if [ ${ TAINTED } -eq 1 ] ; then
title "activating tainted repos"
/sbin/urpmi.update --urpmi-root " ${ BUILD_PATH } " --no-ignore Tainted\ Release Tainted\ Updates
err = ${ ? }
if [ ${ err } -ne 0 ] ; then
error " line ${ LINENO } error ${ err } - can't activate medias tainted : exiting "
2019-10-02 17:03:36 +02:00
exit ${ ERR_1 }
2019-10-01 22:01:26 +02:00
fi
fi
2019-10-02 17:48:11 +02:00
return 0
2018-06-06 11:15:11 +02:00
}
2019-10-02 17:03:36 +02:00
2018-06-06 11:15:11 +02:00
function updatemirror( )
{
2019-10-01 22:01:26 +02:00
title "updating mirror"
/sbin/urpmi.update -a --urpmi-root " ${ BUILD_PATH } "
if [ ${ ? } -ne 0 ] ; then
error " line ${ LINENO } can't update mirrors : exiting "
2019-10-02 17:03:36 +02:00
exit ${ ERR_1 }
2019-10-01 22:01:26 +02:00
fi
2019-10-02 17:48:11 +02:00
return 0
2018-06-06 11:15:11 +02:00
}
2019-10-02 17:03:36 +02:00
2018-06-06 11:15:11 +02:00
function installbasesystem( )
{
2019-10-01 22:01:26 +02:00
# Create Build path
if ! [ -d " ${ BUILD_PATH } " ] ; then
warning " Build path ( ${ BUILD_PATH } ) does not exist, do you want to create it ? [Y|n] "
read yn
if [ -z ${ yn } ] || [ ${ yn } = "Y" ] || [ ${ yn } = "y" ] ; then
title " Creating ${ BUILD_PATH } "
/bin/mkdir -p " ${ BUILD_PATH } /usr/bin " " ${ BUILD_PATH } /usr/lib/binfmt.d "
if [ ${ ? } -ne 0 ] ; then
error " line ${ LINENO } can't create ${ BUILD_PATH } : exiting "
2019-10-02 17:03:36 +02:00
exit ${ ERR_1 }
2019-10-01 22:01:26 +02:00
fi
else
2019-10-02 17:03:36 +02:00
exit ${ ERR_1 }
2019-10-01 22:01:26 +02:00
fi
else
info "Build path exists"
fi
2019-03-29 22:50:46 +01:00
2019-10-01 22:01:26 +02:00
title "installing basesystem"
2019-10-27 18:42:51 +01:00
/sbin/urpmi --urpmi-root " ${ BUILD_PATH } " --ignorearch --no-verify-rpm --auto --split-level 200 --split-length 0 shadow-utils basesystem-minimal
2019-10-01 22:01:26 +02:00
if [ ${ ? } -ne 0 ] ; then
error " line ${ LINENO } error installing shadow-utils or basesystem-minimal : exiting "
2019-10-02 17:03:36 +02:00
exit ${ ERR_1 }
2019-10-01 22:01:26 +02:00
fi
2019-10-27 18:42:51 +01:00
#/sbin/urpmi --urpmi-root "${BUILD_PATH}" --ignorearch --no-verify-rpm --auto --split-level 200 --split-length 0 basesystem-minimal
2019-10-01 22:01:26 +02:00
#if [ ${?} -ne 0 ]; then
# error "line ${LINENO} error installing basesystem-minimal : exiting"
2019-10-02 17:03:36 +02:00
# exit ${ERR_1}
2019-10-01 22:01:26 +02:00
#fi
2019-11-01 14:15:49 +01:00
/sbin/urpmi --urpmi-root " ${ BUILD_PATH } " --ignorearch --no-verify-rpm --auto --split-level 200 --split-length 0 urpmi locales u-boot
2019-10-01 22:01:26 +02:00
if [ ${ ? } -ne 0 ] ; then
error " line ${ LINENO } error installing urpmi or locales.fr : exiting "
2019-10-02 17:03:36 +02:00
exit ${ ERR_1 }
2019-10-01 22:01:26 +02:00
fi
2019-10-02 17:48:11 +02:00
return 0
2018-06-06 11:15:11 +02:00
}
2019-10-02 17:03:36 +02:00
2018-12-13 23:18:14 +01:00
function preparechroot( )
2018-06-06 11:15:11 +02:00
{
2019-10-01 22:01:26 +02:00
title " Preparing chrooting in ${ BUILD_PATH } "
#Copying qemu
/bin/cp /bin/qemu-arm-static " ${ BUILD_PATH } /usr/bin/ "
if [ ${ ? } -ne 0 ] ; then
error " line ${ LINENO } can't copy /bin/qemu-user-static to ${ BUILD_PATH } /usr/bin/ : exiting "
2019-10-02 17:03:36 +02:00
exit ${ ERR_1 }
2019-10-01 22:01:26 +02:00
fi
/bin/cp /usr/lib/binfmt.d/qemu-arm-static.conf " ${ BUILD_PATH } /usr/lib/binfmt.d "
if [ ${ ? } -ne 0 ] ; then
error " line ${ LINENO } can't copy /usr/lib/binfmt.d/qemu-arm-static.conf to ${ BUILD_PATH } /usr/lib/binfmt.d : exiting "
2019-10-02 17:03:36 +02:00
exit ${ ERR_1 }
2019-10-01 22:01:26 +02:00
fi
info "making /etc/hostname"
echo " ${ HOSTNAME } " > " ${ BUILD_PATH } /etc/hostname "
info " copying second stage script in ${ BUILD_PATH } "
#echo "/bin/cp ${CONFIG_PATH}/second_stage_install.sh ${BUILD_PATH}/"
cp --preserve= mode " ${ CONFIG_PATH } /second_stage_install.sh " " ${ BUILD_PATH } /second_stage_install.sh "
if [ ${ ? } -ne 0 ] ; then
error " line ${ LINENO } error copying ${ CONFIG_PATH } /second_stage_install.sh : exiting "
2019-10-02 17:03:36 +02:00
exit ${ ERR_1 }
2019-10-01 22:01:26 +02:00
fi
info "creation of user account"
2019-10-02 17:03:36 +02:00
echo -e " /bin/passwd << EOF\n ${ ROOT_PWD } \n ${ ROOT_PWD } \nEOF\n /sbin/useradd ${ ID_USER } \n /bin/passwd ${ ID_USER } << EOF\n ${ PASSWORD } \n ${ PASSWORD } \nEOF " >>" ${ BUILD_PATH } /second_stage_install.sh "
2019-10-01 22:01:26 +02:00
2019-10-27 16:08:49 +01:00
# info "Copying skel in root directory"
# /bin/rsync -rlptH "${BUILD_PATH}/etc/skel/" "${BUILD_PATH}/root/"
#This line break the default .bashrc file from the package "rootfiles" and the values as PATH (and /usr/sbin programs).
2019-10-01 22:01:26 +02:00
2019-10-02 17:03:36 +02:00
postPrepareChroot
if [ ${ ? } -ne 0 ] ; then
error " line ${ LINENO } error in postPrepareChroot function. "
exit ${ ERR_1 }
fi
2019-10-02 17:48:11 +02:00
return 0
2018-12-13 23:18:14 +01:00
}
2019-10-02 17:03:36 +02:00
2018-12-13 23:18:14 +01:00
function jumpchroot( )
{
2019-10-01 22:01:26 +02:00
title " chrooting to ${ BUILD_PATH } "
info "mounting dev, sys, proc directories in chroot"
/bin/mount -B /dev " ${ BUILD_PATH } /dev "
if [ ${ ? } -ne 0 ] ; then
error " line ${ LINENO } error mounting ${ BUILD_PATH } /dev : exiting "
2019-10-02 17:03:36 +02:00
exit ${ ERR_1 }
2019-10-01 22:01:26 +02:00
fi
/bin/mount -B /sys " ${ BUILD_PATH } /sys "
if [ ${ ? } -ne 0 ] ; then
error " line ${ LINENO } error mounting ${ BUILD_PATH } /sys : exiting "
2019-10-02 17:03:36 +02:00
exit ${ ERR_1 }
2019-10-01 22:01:26 +02:00
fi
/bin/mount -B /proc " ${ BUILD_PATH } /proc "
if [ ${ ? } -ne 0 ] ; then
error " line ${ LINENO } error mounting ${ BUILD_PATH } /proc : exiting "
2019-10-02 17:03:36 +02:00
exit ${ ERR_1 }
2019-10-01 22:01:26 +02:00
fi
info "Copying resolv.conf"
/bin/cp -v --preserve= mode /etc/resolv.conf " ${ BUILD_PATH } /etc/ "
if [ ${ ? } -ne 0 ] ; then
error " line ${ LINENO } error copying ${ BUILD_PATH } /etc/resolv.conf : exiting "
2019-10-02 17:03:36 +02:00
exit ${ ERR_1 }
2019-10-01 22:01:26 +02:00
fi
if [ " $OPT " = "chroot" ] ; then
/sbin/chroot " ${ BUILD_PATH } "
else
2019-11-03 23:34:36 +01:00
/sbin/chroot --userspec root:root " ${ BUILD_PATH } " /bin/bash -v -c 'sh /second_stage_install.sh 2>&1'
2019-10-01 22:01:26 +02:00
fi
RET = ${ ? }
if [ ${ RET } -ne 0 ] ; then
error " line ${ LINENO } Warning : chrooting to ${ BUILD_PATH } retrurn an error ${ RET } "
ERRORN = $(( ${ ERRORN } + 1 ))
fi
info "unmounting dev, sys, proc"
/bin/umount -lf " ${ BUILD_PATH } /dev "
if [ ${ ? } -ne 0 ] ; then
warning " line ${ LINENO } Warning : error unmounting ${ BUILD_PATH } /dev, continuing anyway "
ERRORN = $(( ${ ERRORN } + 1 ))
fi
/bin/umount -lf " ${ BUILD_PATH } /sys "
if [ ${ ? } -ne 0 ] ; then
warning " line ${ LINENO } Warning : error unmounting ${ BUILD_PATH } /sys, continuing anyway "
ERRORN = $(( ${ ERRORN } + 1 ))
fi
/bin/umount -lf " ${ BUILD_PATH } /proc "
if [ ${ ? } -ne 0 ] ; then
warning " line ${ LINENO } Warning : error unmounting ${ BUILD_PATH } /proc, continuing anyway "
ERRORN = $(( ${ ERRORN } + 1 ))
fi
2019-10-02 17:48:11 +02:00
return 0
2018-06-06 11:15:11 +02:00
}
2019-10-02 17:03:36 +02:00
function createImageWrap( )
2018-06-06 11:15:11 +02:00
{
2019-10-02 17:03:36 +02:00
title "Wrap image creation"
preImgCreation
if [ ${ ? } -ne 0 ] ; then
2019-10-02 18:36:06 +02:00
error " line ${ LINENO } error in the process ${ CONFIG_PATH } /specialFunctions.sh . "
2019-10-02 17:03:36 +02:00
exit ${ ERR_1 }
2019-10-01 22:01:26 +02:00
fi
createimage
2019-10-02 17:03:36 +02:00
if [ -z " ${ BOOTFS } " ] ; then
BOOTFS = "ext4"
2019-10-01 22:01:26 +02:00
fi
formatpartitions ${ BOOTFS } ext4
copyingsystem
2019-10-02 17:48:11 +02:00
return 0
2018-06-06 11:15:11 +02:00
}
2018-12-21 22:27:43 +01:00
2019-10-02 17:03:36 +02:00
2019-11-03 23:34:36 +01:00
function copyingsystem( )
2018-06-06 11:15:11 +02:00
{
2019-11-03 23:34:36 +01:00
mountImage
mkfstab
info "Generate extlinux if extlinux.conf exists."
if [ -e " ${ CONFIG_PATH } /extlinux.conf " ] ; then
info "\tFound extlinux.conf"
if [ ! -d " ${ BUILD_PATH } /boot/extlinux " ] ; then
info "making /boot/extlinux/extlinux.conf"
/bin/rm -rf " ${ BUILD_PATH } /boot/extlinux "
mkdir -p " ${ BUILD_PATH } /boot/extlinux "
fi
if [ ! -f " ${ BUILD_PATH } /boot/extlinux/extlinux.conf " ] ; then
info "\tTuning extlinux.conf"
sed -e s/\< UUID\> /${ ROOT_UUID } /g ${ CONFIG_PATH } /extlinux.conf >" ${ BUILD_PATH } /boot/extlinux/extlinux.conf "
KERNEL_ID = $( basename ${ BUILD_PATH } /usr/lib/linux-*)
sed -i -e s/\< FDTDIR\> /${ KERNEL_ID } /g " ${ BUILD_PATH } /boot/extlinux/extlinux.conf "
2019-10-01 22:01:26 +02:00
fi
fi
2019-11-03 23:34:36 +01:00
info "Remove second_stage_install.sh"
/bin/rm -f " ${ BUILD_PATH } /second_stage_install.sh "
if [ 1 -eq ${ SEPARATE_BOOT_PARTITION } ] ; then
ARM_BOOT = " ${ BUILD_PATH } /mnt/arm_boot "
if ! [ -d " ${ ARM_BOOT } " ] ; then
rm -rf " ${ ARM_BOOT } "
mkdir -p " ${ ARM_BOOT } "
fi
info "copying Mageia image to root partition"
/bin/rsync -rlptogDH --exclude " ${ ARM_BOOT } / " --exclude "qemu-arm-static*" " ${ BUILD_PATH } / " " ${ ROOT } / "
/bin/rsync -rlptogDH " ${ ARM_BOOT } / " " ${ BOOT } / "
/bin/rsync -rlptogDH " ${ BUILD_PATH } /boot/ " " ${ BOOT } / "
else
info "copying Mageia image to root partition"
/bin/rsync -rlptogDH --exclude "qemu-arm-static*" " ${ BUILD_PATH } / " " ${ ROOT } / "
2019-10-01 22:01:26 +02:00
fi
2019-10-02 17:48:11 +02:00
2019-11-03 23:34:36 +01:00
copyingCustomSystem
2019-10-02 18:36:06 +02:00
if [ ${ ? } -ne 0 ] ; then
error " line ${ LINENO } error in the process ${ CONFIG_PATH } /specialFunctions.sh . "
exit ${ ERR_1 }
2019-10-01 22:01:26 +02:00
fi
2019-11-03 23:34:36 +01:00
copyingcommon
# Syncing devices before unmounting
/usr/bin/sync
2019-10-08 16:13:45 +02:00
if [ 1 -eq ${ SEPARATE_BOOT_PARTITION } ] ; then
2019-11-03 23:34:36 +01:00
/usr/bin/umount " ${ BOOT } "
if [ ${ ? } -eq 0 ] ; then
/bin/rmdir " ${ BOOT } "
else
error " line ${ LINENO } error unmounting ${ BOOT } : exiting "
2019-10-08 16:13:45 +02:00
exit ${ ERR_1 }
fi
2019-11-03 23:34:36 +01:00
fi
/usr/bin/umount " ${ ROOT } "
if [ ${ ? } -eq 0 ] ; then
/bin/rmdir " ${ ROOT } "
else
error " line ${ LINENO } error unmounting ${ ROOT } : exiting "
exit ${ ERR_1 }
2019-10-01 22:01:26 +02:00
fi
2019-10-08 16:13:45 +02:00
2019-11-03 23:34:36 +01:00
/usr/sbin/partx -d " ${ DEVICE } "
2019-10-01 22:01:26 +02:00
if [ ${ ? } -ne 0 ] ; then
2019-11-03 23:34:36 +01:00
error " line ${ LINENO } warning : error unmounting ${ DEVICE } "
2019-10-02 17:03:36 +02:00
exit ${ ERR_1 }
2019-10-01 22:01:26 +02:00
fi
2019-10-08 16:13:45 +02:00
2019-11-03 23:34:36 +01:00
warning " You can now burn the image ( ${ INSTALL_PATH } / ${ IMAGE } ) on SD card "
2019-10-02 17:48:11 +02:00
return 0
2018-06-06 11:15:11 +02:00
}
2019-10-02 17:03:36 +02:00
2019-11-03 23:34:36 +01:00
function mountImage( ) {
2019-10-01 22:01:26 +02:00
info "mounting partitions, making mountpoint if necessary"
2019-10-08 16:13:45 +02:00
if [ 1 -eq ${ SEPARATE_BOOT_PARTITION } ] ; then
if ! [ -d " ${ BOOT } " ] ; then
/bin/mkdir " ${ BOOT } "
if [ ${ ? } -ne 0 ] ; then
error " line ${ LINENO } error making directory ${ BOOT } : exiting "
exit ${ ERR_1 }
fi
fi
/bin/mount " ${ BOOTP } " " ${ BOOT } "
2019-10-01 22:01:26 +02:00
if [ ${ ? } -ne 0 ] ; then
2019-10-08 16:13:45 +02:00
error " line ${ LINENO } error mounting ${ BOOTP } : exiting "
2019-10-02 17:03:36 +02:00
exit ${ ERR_1 }
2019-10-01 22:01:26 +02:00
fi
fi
2019-10-08 16:13:45 +02:00
2019-10-01 22:01:26 +02:00
if ! [ -d " ${ ROOT } " ] ; then
/bin/mkdir " ${ ROOT } "
if [ ${ ? } -ne 0 ] ; then
error " line ${ LINENO } error making directory ${ ROOT } : exiting "
2019-10-02 17:03:36 +02:00
exit ${ ERR_1 }
2019-10-01 22:01:26 +02:00
fi
fi
/bin/mount " ${ ROOTP } " " ${ ROOT } "
if [ ${ ? } -ne 0 ] ; then
error " line ${ LINENO } error mounting ${ ROOTP } : exiting "
2019-10-02 17:03:36 +02:00
exit ${ ERR_1 }
2019-10-01 22:01:26 +02:00
fi
2019-11-03 23:34:36 +01:00
}
# Copying files common to all systems
function copyingcommon( )
{
title "Copying common files and configuration"
rsync -rlptDH " ${ SOURCE_PATH } /common/ " " ${ ROOT } / "
rsync -rlptDH " ${ SOURCE_PATH } /tools/ " *.sh " ${ ROOT } /usr/local/bin/ "
chown root:root " ${ ROOT } /usr/local/bin/ "
return 0
}
2019-10-01 22:01:26 +02:00
2019-11-03 23:34:36 +01:00
function formatpartitions( )
{
info "Formatting partitions"
if [ 1 -eq ${ SEPARATE_BOOT_PARTITION } ] ; then
info " Boot : ${ BOOTP } as ${ 1 } "
" /sbin/mkfs. ${ 1 } " " ${ BOOTP } "
if [ ${ ? } -ne 0 ] ; then
error " line ${ LINENO } error formating ${ BOOTP } : exiting "
/sbin/losetup -d " ${ DEVICE } "
exit ${ ERR_1 }
fi
BOOT_UUID = $( blkid -s UUID -o value UUID " ${ BOOTP } " )
info " Boot UUID: ${ BOOT_UUID } "
fi
info " Root : ${ ROOTP } as ${ 2 } "
" /sbin/mkfs. ${ 2 } " " ${ ROOTP } "
if [ ${ ? } -ne 0 ] ; then
error " line ${ LINENO } error formating ${ ROOTP } : exiting "
/sbin/losetup -d " ${ DEVICE } "
exit ${ ERR_1 }
fi
ROOT_UUID = $( blkid -s UUID -o value UUID " ${ ROOTP } " )
info " Root UUID: ${ ROOT_UUID } "
return 0
}
function mkfstab( )
{
title "making /etc/fstab"
2019-10-02 17:48:11 +02:00
### BUG : /mnt/arm_boot is set to vfat for all plateforms, odroid configuration says ext4.
2019-10-02 18:36:06 +02:00
#echo -e "proc /proc proc defaults 0 0\nUUID=${BOOT_UUID} /mnt/arm_boot vfat defaults 0 0\nUUID=${ROOT_UUID} / ext4 defaults 0 0" > "${BUILD_PATH}/etc/fstab"
2019-10-08 16:13:45 +02:00
#echo -e "proc\t/proc\tproc\tdefaults\t0\t0\nUUID=${BOOT_UUID}\t/mnt/arm_boot\t${BOOTFS}\tdefaults\t0\t0\nUUID=${ROOT_UUID}\t/\text4\tdefaults\t0\t0" > "${BUILD_PATH}/etc/fstab"
if [ 1 -eq ${ SEPARATE_BOOT_PARTITION } ] ; then
echo -e " proc\t/proc\tproc\tdefaults\t0\t0\nUUID= ${ BOOT_UUID } \t/mnt/arm_boot\t ${ BOOTFS } \tdefaults\t0\t0\nUUID= ${ ROOT_UUID } \t/\text4\tdefaults\t0\t0 " > " ${ BUILD_PATH } /etc/fstab "
else
echo -e " proc\t/proc\tproc\tdefaults\t0\t0\nUUID= ${ ROOT_UUID } \t/\text4\tdefaults\t0\t0 " > " ${ BUILD_PATH } /etc/fstab "
fi
2019-11-03 23:34:36 +01:00
return 0
}
function createimage( )
{
title " in ${ IMAGE } "
if [ -f " ${ INSTALL_PATH } / ${ IMAGE } " ] ; then
warning "Deleting previous image"
/bin/rm -f " ${ INSTALL_PATH } / ${ IMAGE } "
if [ ${ ? } -ne 0 ] ; then
error " line ${ LINENO } error can't remove previous image at ${ INSTALL_PATH } / ${ IMAGE } : exiting "
exit ${ ERR_1 }
2019-10-06 13:23:56 +02:00
fi
2019-10-01 22:01:26 +02:00
fi
2019-11-03 23:34:36 +01:00
warning "please wait until end of image creation"
/bin/dd if = /dev/zero of = " ${ INSTALL_PATH } / ${ IMAGE } " bs = 1MB count = $(( ${ IMAGE_SIZE } * 1024 ))
if [ ${ ? } -ne 0 ] ; then
error " line ${ LINENO } can't make image at ${ INSTALL_PATH } / ${ IMAGE } : exiting "
exit ${ ERR_1 }
2019-10-08 16:13:45 +02:00
fi
2019-11-03 23:34:36 +01:00
DEVICE = $( /sbin/losetup -f --show " ${ INSTALL_PATH } / ${ IMAGE } " )
2019-10-06 13:23:56 +02:00
2019-11-03 23:34:36 +01:00
bunrningBootloader
2019-10-02 18:36:06 +02:00
if [ ${ ? } -ne 0 ] ; then
error " line ${ LINENO } error in the process ${ CONFIG_PATH } /specialFunctions.sh . "
exit ${ ERR_1 }
fi
2019-10-01 22:01:26 +02:00
2019-11-03 23:34:36 +01:00
info "making partitions"
echo -e " ${ FDISK_SCRIPT } " | /sbin/fdisk ${ DEVICE }
2019-10-01 22:01:26 +02:00
2019-11-03 23:34:36 +01:00
# Activate loop device
info " device to detach ${ DEVICE } "
/sbin/losetup -d " ${ DEVICE } "
DEVICE = $( /sbin/partx -va " ${ INSTALL_PATH } / ${ IMAGE } " | /bin/grep -m 1 -E -o '/dev/loop.?' )
info " New attached device ${ DEVICE } "
info "partitions list:"
info " $( /sbin/partx -v " ${ INSTALL_PATH } / ${ IMAGE } " ) "
2019-10-08 16:13:45 +02:00
if [ 1 -eq ${ SEPARATE_BOOT_PARTITION } ] ; then
2019-11-03 23:34:36 +01:00
BOOTP = " ${ DEVICE } p1 "
ROOTP = " ${ DEVICE } p2 "
2019-10-01 22:01:26 +02:00
else
2019-11-03 23:34:36 +01:00
ROOTP = " ${ DEVICE } p1 "
2019-10-01 22:01:26 +02:00
fi
2019-11-03 23:34:36 +01:00
return 0
}
2019-10-01 22:01:26 +02:00
2019-11-03 23:34:36 +01:00
function unmounting( )
{
title "Unmounting..."
2019-10-06 13:23:56 +02:00
2019-11-03 23:34:36 +01:00
# Unmounting /dev /proc /sys in chroot
if ! [ -z " $( mountpoint -qd " ${ BUILD_PATH } /dev " ) " ] ; then # mountpoint - see if a directory or file is a mountpoint ; -d Show the major/minor numbers of the device that is mounted on the given directory.
info " Unmounting ${ BUILD_PATH } /dev "
umount " ${ BUILD_PATH } /dev "
if ! [ ${ ? } -ne 0 ] ; then
error " line ${ LINENO } can't unmount ${ BUILD_PATH } /dev : exiting "
#exit ${ERR_1}
fi
fi
if ! [ -z " $( mountpoint -qd " ${ BUILD_PATH } /sys " ) " ] ; then
info " Unmounting ${ BUILD_PATH } /sys "
umount " ${ BUILD_PATH } /sys "
if ! [ ${ ? } -ne 0 ] ; then
error " line ${ LINENO } can't unmount ${ BUILD_PATH } /sys : exiting "
#exit ${ERR_1}
fi
fi
if ! [ -z " $( mountpoint -qd " ${ BUILD_PATH } /proc " ) " ] ; then
info " Unmounting ${ BUILD_PATH } /proc "
umount " ${ BUILD_PATH } /proc "
if ! [ ${ ? } -ne 0 ] ; then
error " line ${ LINENO } can't unmount ${ BUILD_PATH } /proc : exiting "
#exit ${ERR_1}
fi
fi
2019-10-06 13:23:56 +02:00
2019-11-03 23:34:36 +01:00
# [root@jabztop mageia4arm (master)]# losetup -l -O NAME,BACK-FILE -n
# /dev/loop0 /home/jibz/workspaces/mageia4arm/build/Mageia-7-bananaPro1.img (deleted)
info " Looped devices to unmount : $( losetup -l -O NAME,BACK-FILE -n | grep " ${ IMAGE } " | cut -d ' ' -f 1 ) "
for LOOP in $( losetup -l -O NAME,BACK-FILE -n | grep " ${ IMAGE } " | cut -d ' ' -f 1 ) ; do
info " removing ${ LOOP } "
losetup -d " ${ LOOP } "
done
2019-10-02 17:48:11 +02:00
return 0
2018-06-06 11:15:11 +02:00
}
2019-10-02 17:03:36 +02:00
2019-11-03 23:34:36 +01:00
# cleaning build space
function clean( )
2018-07-22 14:20:42 +02:00
{
2019-11-03 23:34:36 +01:00
title "Cleaning"
unmounting
# Removing old Build directory
if [ -d " ${ BUILD_PATH } " ] ; then
info " Removing ${ BUILD_PATH } "
/bin/rm -Rf " ${ BUILD_PATH } "
else
warning " ${ BUILD_PATH } does not exists "
fi
# removing old image
if [ -e " ${ INSTALL_PATH } / ${ IMAGE } " ] ; then
info " Removing ${ IMAGE } "
/bin/rm -f " ${ INSTALL_PATH } / ${ IMAGE } "
else
warning " ${ IMAGE } does not exists "
fi
# Removing boot and root directory
if [ -d " ${ BOOT } " ] ; then
info " Removing ${ BOOT } "
/bin/rm -rf " ${ BOOT } "
else
warning " ${ BOOT } does not exists "
fi
if [ -d " ${ ROOT } " ] ; then
info " Removing ${ ROOT } "
/bin/rm -rf " ${ ROOT } "
else
warning " ${ ROOT } does not exists "
fi
2019-10-02 17:48:11 +02:00
return 0
2018-07-22 14:20:42 +02:00
}
2019-10-02 17:03:36 +02:00
function preImgCreation( )
{
error "This function is called if no sourced file about fdisk was lauched."
return 1
}
function postPrepareChroot( )
{
2019-10-02 18:36:06 +02:00
error "This function is called if no sourced file is containing postPrepareChroot function."
return 1
}
function bunrningBootloader( )
{
error "This function is called if no sourced file is containing bunrningBootloader function."
2019-10-02 17:03:36 +02:00
return 1
}
2019-10-02 18:36:06 +02:00
function copyingCustomSystem( )
{
error "This function is called if no sourced file is containing bunrningBootloader function."
return 1
}
2019-10-02 17:48:11 +02:00
ERRORN = 0
2019-10-02 17:03:36 +02:00
ERR_1 = 1
ERR_DEFAULT_CONFIG = 2
ERR_NO_CONFIG_FILE = 3
2019-10-02 22:27:24 +02:00
ERR_NOT_ROOT = 4
ERR_DEPENDENCY_MISSING = 5
2019-10-02 17:03:36 +02:00
ERR_NO_SPACE = 6
ERR_7 = 7
ERR_8 = 8
ERR_9 = 9
2019-10-08 16:13:45 +02:00
SEPARATE_BOOT_PARTITION = 1
2019-10-02 17:03:36 +02:00
#######################
# PROGRAMM START HERE #
#######################
info ${ 0 }
2019-10-02 22:27:24 +02:00
#Check dependencies :
#if [ -e /usr/bin/qemu-arm-static ]; then
# error "qemu-user-static package is needed."
# exit ${ERR_DEPENDENCY_MISSING}
#fi
#if [ 0 -ne $(id -u) ]; then
# error "Script need to be run as root."
# exit ${ERR_NOT_ROOT}
#fi
2019-10-02 17:03:36 +02:00
SOURCE_PATH = " $( /bin/dirname " $( readlink -f " ${ 0 } " ) " ) "
INSTALL_PATH = " ${ SOURCE_PATH } /arm "
FILES_PATH = " ${ SOURCE_PATH } /files "
PLATFORMS_PATH = " ${ SOURCE_PATH } /platforms "
CMDNAME = $( /bin/basename " ${ 0 } " )
2019-10-01 22:01:26 +02:00
if [ ${# } = = 0 ] ; then
help
exit
2018-06-06 11:15:11 +02:00
fi
# parsing commandline
2019-10-01 22:01:26 +02:00
TEMP = $( getopt -o h,a --long all,help,clean,create-chroot,addmedia,create-image,,config:,target:,target-version:,chroot,bootfs:,install-basesystem,update-mirror,build-path:,size:,nonfree,tainted -n ${ CMDNAME } -- " ${ @ } " )
2019-10-02 17:03:36 +02:00
if [ ${ ? } -ne 0 ] ; then error " line ${ LINENO } Failed parsing options. " >& 2 ; exit ${ ERR_1 } ; fi
2019-10-01 22:01:26 +02:00
eval set -- " ${ TEMP } "
2018-06-06 11:15:11 +02:00
2019-10-01 22:01:26 +02:00
echo " ${ TEMP } "
2019-10-02 17:03:36 +02:00
# Note the quotes around `$TEMP': they are essential! Or not, $( ) do the same as ` `. But there are the ` ' used ?
while true; do
2019-10-01 22:01:26 +02:00
case " ${ 1 } " in
-h| --help)
help
exit 0
; ;
-a| --all)
OPT = "all"
shift 1
; ;
--clean)
OPT = "clean"
shift
; ;
--size)
IMAGE_SIZE_P = ${ 2 }
shift 2
; ;
--build-path)
2019-10-02 22:27:24 +02:00
INSTALL_PATH_P = $( readlink -f " ${ 2 } " )
2019-10-01 22:01:26 +02:00
shift 2
; ;
--chroot)
if [ -z ${ OPT } ] ; then
OPT = "chroot"
fi
shift
; ;
--create-chroot)
if [ -z ${ OPT } ] ; then
OPT = "createchroot"
fi
shift
; ;
--addmedia)
if [ -z ${ OPT } ] ; then
OPT = "addmedia"
fi
shift
; ;
--update-mirror)
if [ -z ${ OPT } ] ; then
OPT = "updatemirror"
fi
shift
; ;
--install-basesystem)
if [ -z ${ OPT } ] ; then
OPT = "installbasesystem"
fi
shift
; ;
--create-image)
if [ -z ${ OPT } ] ; then
CREATEIMAGE = true
OPT = "createimage"
fi
shift
; ;
--target)
TARGET_P = ${ 2 }
shift 2
; ;
--target-version)
TARGET_VERSION_P = ${ 2 }
shift 2
; ;
--config)
CONFIG_PATH = " ${ PLATFORMS_PATH } / ${ 2 } "
shift 2
; ;
--bootfs)
BOOTFS_P = ${ 2 }
shift 2
; ;
--nonfree)
NONFREE_P = 1
2019-10-02 22:27:24 +02:00
shift
2019-10-01 22:01:26 +02:00
; ;
--tainted)
TAINTED_P = 1
2019-10-02 22:27:24 +02:00
shift
2019-10-01 22:01:26 +02:00
; ;
--)
2018-06-06 11:15:11 +02:00
shift
break; ;
2019-10-01 22:01:26 +02:00
*)
error " Parameter ${ 1 } does not exists "
2019-10-02 17:03:36 +02:00
exit ${ ERR_1 } ; ;
2019-10-01 22:01:26 +02:00
esac
2018-06-06 11:15:11 +02:00
done
2018-06-09 16:15:50 +02:00
# path of config file
2019-10-01 22:01:26 +02:00
if ! [ -d " ${ CONFIG_PATH } " ] ; then
info " Config path does not exists, defaulting to ./platforms/ ${ TARGET } "
CONFIG_PATH = " ${ PLATFORMS_PATH } / ${ TARGET } "
2019-10-02 17:03:36 +02:00
warning "Do you want to create it and to copy the template file in? [Y|n] "
2019-09-29 06:50:44 +02:00
read yn
2019-10-01 22:01:26 +02:00
if [ -z ${ yn } ] || [ ${ yn } = "Y" ] || [ ${ yn } = "y" ] ; then
/usr/bin/mkdir " ${ CONFIG_PATH } / "
2019-10-02 17:03:36 +02:00
/usr/bin/cp --preserve= mode " ${ SOURCE_PATH } /mageia4arm.cfg.template " " ${ CONFIG_PATH } /mageia4arm.cfg "
2019-10-01 22:01:26 +02:00
warning " You need now to modify the config file ( ${ CONFIG_PATH } /mageia4arm.cfg) and relaunch the script "
2019-10-02 17:03:36 +02:00
exit ${ ERR_DEFAULT_CONFIG }
2019-09-29 06:50:44 +02:00
else
2019-10-02 22:27:24 +02:00
error "Error: Can't continue without config file, exiting"
2019-10-02 17:03:36 +02:00
exit ${ ERR_NO_CONFIG_FILE }
2019-09-29 06:50:44 +02:00
fi
2018-06-09 10:59:49 +02:00
fi
2018-06-06 11:15:11 +02:00
2019-10-02 17:03:36 +02:00
if [ -e " ${ CONFIG_PATH } /mageia4arm.cfg " ] ; then
info " using ${ CONFIG_PATH } /mageia4arm.cfg as config "
source " ${ CONFIG_PATH } /mageia4arm.cfg " #NOTE1 : Here is sourced a file with variables.
else
2019-10-02 22:27:24 +02:00
warning "Config file does not exists, do you want to copy template ? [Y|n] "
2019-10-02 17:03:36 +02:00
read yn
if [ -z ${ yn } ] || [ ${ yn } = "Y" ] || [ ${ yn } = "y" ] ; then
/usr/bin/cp --preserve= mode " ${ SOURCE_PATH } /mageia4arm.cfg.template " " ${ CONFIG_PATH } /mageia4arm.cfg "
warning " You need now to modify the config file ( ${ CONFIG_PATH } /mageia4arm.cfg) and relaunch the script "
exit ${ ERR_DEFAULT_CONFIG }
2019-10-01 22:01:26 +02:00
fi
2018-06-06 11:15:11 +02:00
fi
2018-07-17 11:18:06 +02:00
2019-10-01 22:01:26 +02:00
if ! [ -z " ${ IMAGE_SIZE_P } " ] ; then
IMAGE_SIZE = ${ IMAGE_SIZE_P }
2019-01-05 20:58:18 +01:00
fi
2019-10-01 22:01:26 +02:00
if ! [ -z " ${ INSTALL_PATH_P } " ] ; then
INSTALL_PATH = ${ INSTALL_PATH_P }
2019-01-05 20:58:18 +01:00
fi
2019-10-01 22:01:26 +02:00
if ! [ -z " ${ TARGET_P } " ] ; then
TARGET = ${ TARGET_P }
2019-01-05 20:58:18 +01:00
fi
2019-10-01 22:01:26 +02:00
if ! [ -z " ${ TARGET_VERSION_P } " ] ; then
TARGET_VERSION = ${ TARGET_VERSION_P }
2019-01-05 20:58:18 +01:00
fi
2019-10-01 22:01:26 +02:00
if ! [ -z " ${ BOOTFS_P } " ] ; then
BOOTFS = ${ BOOTFS_P }
2019-01-05 20:58:18 +01:00
fi
2019-10-01 22:01:26 +02:00
if ! [ -z " ${ NONFREE_P } " ] ; then
NONFREE = ${ NONFREE_P }
2019-10-02 22:27:24 +02:00
else
NONFREE = 0
2019-05-08 14:59:04 +02:00
fi
2019-10-01 22:01:26 +02:00
if ! [ -z " ${ TAINTED_P } " ] ; then
TAINTED = ${ TAINTED_P }
2019-10-02 22:27:24 +02:00
else
TAINTED = 0
2019-05-08 14:59:04 +02:00
fi
2019-10-01 22:01:26 +02:00
info "Option: " ${ OPT }
2019-01-05 20:58:18 +01:00
2019-10-01 22:01:26 +02:00
IMAGE = " Mageia- ${ MAGEIA_VERSION } - ${ TARGET } ${ TARGET_VERSION } .img "
2019-01-05 20:58:18 +01:00
BOOT = "/mnt/boot"
ROOT = "/mnt/root"
2019-10-06 13:23:56 +02:00
BUILD_PATH = " ${ INSTALL_PATH } /build- ${ TARGET } ${ TARGET_VERSION } "
2019-01-05 20:58:18 +01:00
ARM_VERSION = "armv7hl"
2019-10-02 17:03:36 +02:00
# Assigne a script for creating a particular target image (rpi, odroid, ...)
if [ -e " ${ CONFIG_PATH } /specialFunctions.sh " ] ; then
source " ${ CONFIG_PATH } /specialFunctions.sh "
fi
2018-07-17 11:18:06 +02:00
2019-10-01 22:01:26 +02:00
info " target : ${ TARGET } "
info " target_version : ${ TARGET_VERSION } "
info " source path: ${ SOURCE_PATH } "
info " Install path: ${ INSTALL_PATH } "
info " Build path: ${ BUILD_PATH } "
info " Commande : ${ CMDNAME } "
info " Firmware path : ${ FIRMWARE_PATH } "
info " Firmware dir : ${ FIRMWARE_DIR } "
2018-06-09 16:15:50 +02:00
2018-12-07 20:38:32 +01:00
# Defining default image size to 7 go
2019-10-06 13:23:56 +02:00
if [ [ " ${ IMAGE_SIZE } " -lt 2 ] ] || [ [ " ${ IMAGE_SIZE } " -gt 128 ] ] ; then
2019-10-01 22:01:26 +02:00
IMAGE_SIZE = 7
2018-06-06 11:15:11 +02:00
fi
2018-12-07 20:38:32 +01:00
# change dir to install path and create it if not existing
2019-10-01 22:01:26 +02:00
if [ " ${ OPT } " != "clean" ] ; then
info " cd ${ INSTALL_PATH } "
if ! [ -e " ${ INSTALL_PATH } " ] ; then
/bin/mkdir -p " ${ INSTALL_PATH } "
if [ -z ${ ? } ] ; then
error " line ${ LINENO } can't make directory ${ INSTALL_PATH } , exiting "
2019-10-02 17:03:36 +02:00
exit ${ ERR_1 }
2019-10-01 22:01:26 +02:00
fi
fi
cd " ${ INSTALL_PATH } "
if [ -z ${ ? } ] ; then
error " line ${ LINENO } can't change to directory ${ INSTALL_PATH } , exiting "
2019-10-02 17:03:36 +02:00
exit ${ ERR_1 }
2019-10-01 22:01:26 +02:00
fi
2018-06-06 11:15:11 +02:00
fi
2018-12-07 20:38:32 +01:00
#if no parameters then display help message
2019-10-01 22:01:26 +02:00
if [ -z ${ OPT } ] ; then
OPT = "--help"
2018-06-06 11:15:11 +02:00
fi
2019-10-02 18:36:06 +02:00
info " Image size is: ${ IMAGE_SIZE } GB "
2019-10-01 22:01:26 +02:00
case ${ OPT } in
"clean" )
clean
; ;
"all" )
verify_disk_space
2019-10-06 13:23:56 +02:00
if [ ${ ? } -ne 0 ] ; then
2019-10-01 22:01:26 +02:00
echo -e "Not enough space on disk\nDo you want to continue anyway ? [Y,n]"
read yn
if [ ${ yn } = "n" ] ; then
2019-10-02 17:03:36 +02:00
exit ${ ERR_NO_SPACE }
2019-10-01 22:01:26 +02:00
fi
fi
createchroot
addmedia
updatemirror
installbasesystem
2019-11-03 23:34:36 +01:00
mkfstab
2019-10-01 22:01:26 +02:00
preparechroot
jumpchroot
2019-10-02 17:03:36 +02:00
createImageWrap
2019-10-27 18:42:51 +01:00
unmounting
2019-10-01 22:01:26 +02:00
; ;
"createchroot" )
createchroot
; ;
"chroot" )
jumpchroot
; ;
"addmedia" )
addmedia
; ;
"updatemirror" )
updatemirror
; ;
"createimage" )
verify_disk_space
2019-10-06 13:23:56 +02:00
if [ ${ ? } -ne 0 ] ; then
2019-10-01 22:01:26 +02:00
warning "Not enough space on disk"
2019-10-02 17:03:36 +02:00
exit ${ ERR_NO_SPACE }
2019-10-01 22:01:26 +02:00
fi
2019-10-02 17:03:36 +02:00
createImageWrap
2019-10-01 22:01:26 +02:00
; ;
"installbasesystem" )
installbasesystem
; ;
2018-06-06 11:15:11 +02:00
esac
2018-07-26 07:37:59 +02:00
2018-12-07 20:38:32 +01:00
2019-10-06 13:23:56 +02:00
if [ ${ ERRORN } -ne 0 ] ; then
2019-10-01 22:01:26 +02:00
warning " Some errors occurs : ${ ERRORN } errors "
2018-08-04 00:14:36 +02:00
fi
2019-10-02 17:03:36 +02:00
exit ${ ERRORN }