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/>.
|
|
|
|
|
|
|
|
|
|
|
|
function title()
|
|
|
|
{
|
|
|
|
echo -e "\e[1;32m$1\e[0m"
|
|
|
|
}
|
|
|
|
|
|
|
|
function info()
|
|
|
|
{
|
|
|
|
echo -e "\e[36m$1\e[0m"
|
|
|
|
}
|
|
|
|
|
|
|
|
function warning()
|
|
|
|
{
|
|
|
|
echo -e "\e[1;35m$1\e[0m"
|
|
|
|
}
|
|
|
|
|
|
|
|
function error()
|
|
|
|
{
|
|
|
|
echo -e "\e[1;31m$1\e[0m"
|
|
|
|
}
|
|
|
|
|
2018-07-21 12:15:40 +02:00
|
|
|
SOURCE_PATH="$(/bin/dirname "$(readlink -f "$0")")"
|
2018-07-16 09:58:28 +02:00
|
|
|
INSTALL_PATH="$SOURCE_PATH/arm"
|
2018-06-09 10:59:49 +02:00
|
|
|
FILES_PATH="$SOURCE_PATH/files"
|
2018-07-19 22:00:59 +02:00
|
|
|
CMDNAME=$(/bin/basename -z "$0")
|
2018-06-06 11:15:11 +02:00
|
|
|
|
|
|
|
#while read -r;do
|
|
|
|
# for MAGEIA_VERSION in $REPLY
|
|
|
|
# do
|
|
|
|
# if [ $MAGEIA_VERSION <= 5 ];then
|
|
|
|
# echo 'Mageia version >= 6 is needed'
|
|
|
|
# exit
|
|
|
|
# fi
|
|
|
|
# break
|
|
|
|
# done
|
|
|
|
#done < /etc/version
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function help()
|
|
|
|
{
|
|
|
|
echo "$CMDNAME [option] [size of image in Go]"
|
|
|
|
echo "Options:"
|
|
|
|
echo "--all create ready to burn image of Mageia $MAGEIA_VERSION"
|
2018-10-14 21:08:55 +02:00
|
|
|
echo "--clean Clean all (suppress all) to make a new image"
|
2018-06-06 11:15:11 +02:00
|
|
|
echo "--size size of image default: 7Go"
|
|
|
|
echo "--create-chroot Create the chroot directory"
|
|
|
|
echo "--addmedia add mirrors"
|
|
|
|
echo "--update-mirror update urpmi database"
|
|
|
|
echo "--install-basesystem install base system"
|
|
|
|
echo "--chroot chroot to arm directory and launch packages installation"
|
|
|
|
echo "--create-image Create the image of Mageia $MAGEIA_VERSION"
|
|
|
|
echo "--build-path Path to the build directory of the image of Mageia $MAGEIA_VERSION"
|
2018-12-13 23:18:14 +01:00
|
|
|
echo "--target target system (for now rpi, odroid)"
|
2019-01-05 20:58:18 +01:00
|
|
|
echo "--target-version version of the taget (0, 1, 2, 3 for rpi, xu3 or xu4 for odroid)"
|
2018-06-09 10:59:49 +02:00
|
|
|
echo "--config Path to config files"
|
2018-06-06 11:15:11 +02:00
|
|
|
echo "--bootfs filesystem of boot partition (ext4 or vfat) default: etx4"
|
2018-07-19 22:00:59 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-12-07 20:38:32 +01:00
|
|
|
# cleaning build space
|
2018-06-06 11:15:11 +02:00
|
|
|
function clean()
|
|
|
|
{
|
2018-12-21 22:27:43 +01:00
|
|
|
# Unmounting /dev /proc /sys in chroot
|
2018-06-06 11:15:11 +02:00
|
|
|
title "Cleaning"
|
2018-07-19 22:00:59 +02:00
|
|
|
if ! [ -z "$(mountpoint -qd "$BUILD_PATH/dev")" ];then
|
2018-06-06 11:15:11 +02:00
|
|
|
info "Unmounting $BUILD_PATH/dev"
|
2018-07-19 22:00:59 +02:00
|
|
|
umount "$BUILD_PATH/dev"
|
2018-06-06 11:15:11 +02:00
|
|
|
if ! [ $? -ne 0 ];then
|
|
|
|
error "line $LINENO can't unmount $BUILD_PATH/dev : exiting"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
2018-07-19 22:00:59 +02:00
|
|
|
if ! [ -z "$(mountpoint -qd "$BUILD_PATH/sys")" ];then
|
2018-06-06 11:15:11 +02:00
|
|
|
info "Unmounting $BUILD_PATH/sys"
|
2018-07-19 22:00:59 +02:00
|
|
|
umount "$BUILD_PATH/sys"
|
2018-06-06 11:15:11 +02:00
|
|
|
if ! [ $? -ne 0 ];then
|
|
|
|
error "line $LINENO can't unmount $BUILD_PATH/sys : exiting"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
2018-07-19 22:00:59 +02:00
|
|
|
if ! [ -z "$(mountpoint -qd "$BUILD_PATH/proc")" ];then
|
2018-06-06 11:15:11 +02:00
|
|
|
info "Unmounting $BUILD_PATH/proc"
|
2018-07-19 22:00:59 +02:00
|
|
|
umount "$BUILD_PATH/proc"
|
2018-06-06 11:15:11 +02:00
|
|
|
if ! [ $? -ne 0 ];then
|
|
|
|
error "line $LINENO can't unmount $BUILD_PATH/proc : exiting"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
2018-12-07 20:38:32 +01:00
|
|
|
# Removing old Build directory
|
2018-06-06 11:15:11 +02:00
|
|
|
if [ -d "$BUILD_PATH" ];then
|
|
|
|
info "Removing $BUILD_PATH"
|
2018-07-19 22:00:59 +02:00
|
|
|
/bin/rm -Rf "$BUILD_PATH"
|
2018-06-06 11:15:11 +02:00
|
|
|
else
|
|
|
|
warning "$BUILD_PATH does not exists"
|
|
|
|
fi
|
2018-12-07 20:38:32 +01:00
|
|
|
# removing old image
|
2018-06-06 11:15:11 +02:00
|
|
|
if [ -e "$IMAGE" ];then
|
2018-07-19 22:00:59 +02:00
|
|
|
info "Removing $IMAGE"
|
|
|
|
/bin/rm -f "$INSTALL_PATH/$IMAGE"
|
2018-06-06 11:15:11 +02:00
|
|
|
else
|
|
|
|
warning "$IMAGE does not exists"
|
|
|
|
fi
|
2018-12-07 20:38:32 +01:00
|
|
|
# removing loop devices
|
2018-07-19 22:00:59 +02:00
|
|
|
for LOOP in $(ls /dev/loop*[0-9]p1)
|
2018-07-18 00:48:15 +02:00
|
|
|
do
|
|
|
|
X=${LOOP:0:10}
|
2018-07-19 22:00:59 +02:00
|
|
|
if [ -e "$X" ];then
|
2018-07-18 00:48:15 +02:00
|
|
|
info "removing $X"
|
2018-07-19 22:00:59 +02:00
|
|
|
partx -d "$X"
|
2018-07-18 00:48:15 +02:00
|
|
|
fi
|
|
|
|
done
|
2018-12-07 20:38:32 +01:00
|
|
|
# Removing boot and root directory
|
2018-06-06 11:15:11 +02:00
|
|
|
if [ -d "$BOOT" ];then
|
|
|
|
info "Removing $BOOT"
|
2018-07-19 22:00:59 +02:00
|
|
|
/bin/rmdir "$BOOT"
|
2018-06-06 11:15:11 +02:00
|
|
|
else
|
|
|
|
warning "$BOOT does not exists"
|
|
|
|
fi
|
|
|
|
if [ -d "$ROOT" ];then
|
|
|
|
info "Removing $ROOT"
|
2018-07-19 22:00:59 +02:00
|
|
|
/bin/rmdir "$ROOT"
|
2018-06-06 11:15:11 +02:00
|
|
|
else
|
|
|
|
warning "$ROOT does not exists"
|
|
|
|
fi
|
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
|
|
|
# creation of install path and copy of qemu ( installing it if not yet installed )
|
|
|
|
|
|
|
|
function createchroot()
|
|
|
|
{
|
2018-07-18 00:48:15 +02:00
|
|
|
title "Making chroot"
|
2018-06-06 11:15:11 +02:00
|
|
|
if ! [ -f /bin/qemu-arm-static ]; then
|
|
|
|
title "Qemu package not present : installing qemu packages"
|
|
|
|
/sbin/urpmi --auto --no-recommends qemu-user-static
|
|
|
|
if ! [ $? -eq 0 ];then
|
|
|
|
error "line $LINENO can't install qemu-user-static : exiting"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
2018-12-07 20:38:32 +01:00
|
|
|
# Starting qemu service if not started
|
2018-06-06 11:15:11 +02:00
|
|
|
/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"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2018-12-07 20:38:32 +01:00
|
|
|
# Create Build path
|
2018-10-14 21:08:55 +02:00
|
|
|
if ! [ -d "$BUILD_PATH" ];then
|
2018-12-21 22:27:43 +01:00
|
|
|
warning "Build path ( $BUILD_PATH ) does not exists, do you want i create it ? [Y|n] "
|
2018-10-14 21:08:55 +02:00
|
|
|
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"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
exit 1
|
|
|
|
fi
|
2018-12-21 22:27:43 +01:00
|
|
|
else
|
2018-12-07 20:38:32 +01:00
|
|
|
info "Build path exists"
|
|
|
|
fi
|
2018-12-21 22:27:43 +01:00
|
|
|
#Copying qemu
|
2018-07-19 22:00:59 +02:00
|
|
|
/bin/cp /bin/qemu-arm-static "$BUILD_PATH/usr/bin/"
|
2018-06-06 11:15:11 +02:00
|
|
|
if [ $? -ne 0 ];then
|
|
|
|
error "line $LINENO can't copy /bin/qemu-user-static to $BUILD_PATH/usr/bin/ : exiting"
|
|
|
|
exit 1
|
|
|
|
fi
|
2018-07-19 22:00:59 +02:00
|
|
|
/bin/cp /usr/lib/binfmt.d/qemu-arm-static.conf "$BUILD_PATH/usr/lib/binfmt.d"
|
2018-06-06 11:15:11 +02:00
|
|
|
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"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2018-12-07 20:38:32 +01:00
|
|
|
# adding Mageia repositories
|
2018-06-06 11:15:11 +02:00
|
|
|
function addmedia()
|
|
|
|
{
|
|
|
|
title "Creating media $MIRROR"
|
2018-07-19 22:00:59 +02:00
|
|
|
/sbin/urpmi.addmedia --urpmi-root "$BUILD_PATH" --distrib "$MIRROR"
|
2018-06-06 11:15:11 +02:00
|
|
|
err=$?
|
|
|
|
if [ $err -ne 0 ];then
|
|
|
|
error "line $LINENO error $err - can't add medias from $MIRROR : exiting"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
title "activating non-free and tainted"
|
2018-07-19 22:00:59 +02:00
|
|
|
/sbin/urpmi.update --urpmi-root "$BUILD_PATH" --no-ignore Nonfree\ Release Nonfree\ Updates Tainted\ Release Tainted\ Updates
|
2018-06-06 11:15:11 +02:00
|
|
|
err=$?
|
|
|
|
if [ $err -ne 0 ];then
|
|
|
|
error "line $LINENO error $err - can't activate medias : exiting"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function updatemirror()
|
|
|
|
{
|
|
|
|
title "updating mirror"
|
2018-09-14 19:40:13 +02:00
|
|
|
/sbin/urpmi.update -a --urpmi-root "$BUILD_PATH"
|
2018-06-06 11:15:11 +02:00
|
|
|
if [ $? -ne 0 ];then
|
|
|
|
error "line $LINENO can't update mirrors : exiting"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function installbasesystem()
|
|
|
|
{
|
|
|
|
title "installing basesystem"
|
|
|
|
/sbin/urpmi --urpmi-root "$BUILD_PATH" --ignorearch --no-verify-rpm --auto --split-level 200 --split-length 200 shadow-utils basesystem-minimal
|
|
|
|
if [ $? -ne 0 ];then
|
|
|
|
error "line $LINENO error installing shadow-utils or basesystem-minimal : exiting"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
#/sbin/urpmi --urpmi-root "$BUILD_PATH" --ignorearch --no-verify-rpm --auto --split-level 200 --split-length 200 basesystem-minimal
|
|
|
|
#if [ $? -ne 0 ];then
|
|
|
|
# error "line $LINENO error installing basesystem-minimal : exiting"
|
|
|
|
# exit 1
|
|
|
|
#fi
|
2018-12-07 20:38:32 +01:00
|
|
|
/sbin/urpmi --urpmi-root "$BUILD_PATH" --ignorearch --no-verify-rpm --auto --split-level 200 --split-length 200 urpmi locales-fr systemd u-boot
|
2018-06-06 11:15:11 +02:00
|
|
|
if [ $? -ne 0 ];then
|
|
|
|
error "line $LINENO error installing urpmi or locales.fr : exiting"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2018-12-13 23:18:14 +01:00
|
|
|
function preparechroot()
|
2018-06-06 11:15:11 +02:00
|
|
|
{
|
|
|
|
title "Preparing chrooting in $BUILD_PATH"
|
|
|
|
info "making /etc/hostname"
|
2018-07-19 22:00:59 +02:00
|
|
|
echo "$HOSTNAME" > "$BUILD_PATH/etc/hostname"
|
2018-06-06 11:15:11 +02:00
|
|
|
|
|
|
|
info "copying second stage script in $BUILD_PATH"
|
2018-07-16 09:58:28 +02:00
|
|
|
echo "/bin/cp $SOURCE_PATH/$CONFIG_PATH/second_stage_install.sh $BUILD_PATH/"
|
|
|
|
cp "$SOURCE_PATH/$CONFIG_PATH/second_stage_install.sh" "$BUILD_PATH/second_stage_install.sh"
|
2018-06-06 11:15:11 +02:00
|
|
|
if [ $? -ne 0 ];then
|
2018-07-16 09:58:28 +02:00
|
|
|
error "line $LINENO error copying $SOURCE_PATH/$CONFIG_PATH/second_stage_install.sh : exiting"
|
2018-06-06 11:15:11 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
2018-08-03 23:30:15 +02:00
|
|
|
|
2018-06-06 11:15:11 +02:00
|
|
|
info "creation of user account"
|
|
|
|
echo "/bin/passwd << EOF
|
|
|
|
$ROOT_PWD
|
|
|
|
$ROOT_PWD
|
|
|
|
EOF
|
2018-07-19 22:00:59 +02:00
|
|
|
/sbin/useradd $ID_USER
|
|
|
|
/bin/passwd $ID_USER << EOF
|
|
|
|
$PASSWORD
|
|
|
|
$PASSWORD
|
2018-06-06 11:15:11 +02:00
|
|
|
EOF" >>"$BUILD_PATH/second_stage_install.sh"
|
2018-12-21 22:27:43 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2018-06-06 11:15:11 +02:00
|
|
|
info "Copying skel in root directory"
|
|
|
|
/bin/rsync -a /etc/skel/ "$BUILD_PATH/root/"
|
2018-12-21 22:27:43 +01:00
|
|
|
|
|
|
|
|
2018-08-03 23:30:15 +02:00
|
|
|
case $TARGET in
|
2019-01-05 20:58:18 +01:00
|
|
|
odroid)
|
2018-12-21 22:27:43 +01:00
|
|
|
#TEMPORARY CODE
|
2018-09-14 19:40:13 +02:00
|
|
|
#copying kernel odroid not existing in mageia repos
|
2019-01-05 20:58:18 +01:00
|
|
|
info "copying kernel-odroid and u-boot rpms in $BUILD_PATH/root"
|
2018-09-14 19:40:13 +02:00
|
|
|
echo "/bin/cp $SOURCE_PATH/$CONFIG_PATH/kernel-odroid-4.14.y-1.armv7hl.rpm $BUILD_PATH/root/"
|
|
|
|
/usr/bin/cp "$SOURCE_PATH/$CONFIG_PATH/kernel-odroid-4.14.y-1.armv7hl.rpm" "$BUILD_PATH/root/"
|
2019-01-05 20:58:18 +01:00
|
|
|
echo "/bin/cp $SOURCE_PATH/$CONFIG_PATH/u-boot-20180507-3.mga7.armv7hl.rpm $BUILD_PATH/root/"
|
|
|
|
/usr/bin/cp "$SOURCE_PATH/$CONFIG_PATH/u-boot-20180507-3.mga7.armv7hl.rpm" "$BUILD_PATH/root/"
|
2018-08-03 23:30:15 +02:00
|
|
|
if [ $? -ne 0 ];then
|
|
|
|
error "line $LINENO error copying $SOURCE_PATH/$CONFIG_PATH/kernel-odroid-4.14.y-1.armv7hl.rpm : exiting"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
rpi)
|
|
|
|
;;
|
|
|
|
esac
|
2018-12-13 23:18:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function jumpchroot()
|
|
|
|
{
|
2018-06-06 11:15:11 +02:00
|
|
|
title "chrooting to $BUILD_PATH"
|
2018-12-13 23:18:14 +01:00
|
|
|
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"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
/bin/mount -B /sys "$BUILD_PATH/sys"
|
|
|
|
if [ $? -ne 0 ];then
|
|
|
|
error "line $LINENO error mounting $BUILD_PATH/sys : exiting"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
/bin/mount -B /proc "$BUILD_PATH/proc"
|
|
|
|
if [ $? -ne 0 ];then
|
|
|
|
error "line $LINENO error mounting $BUILD_PATH/proc : exiting"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
info "Copying resolv.conf"
|
|
|
|
/bin/cp -a /etc/resolv.conf "$BUILD_PATH/etc/"
|
|
|
|
if [ $? -ne 0 ];then
|
|
|
|
error "line $LINENO error copying $BUILD_PATH/etc/resolv.conf : exiting"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
if [ "$OPT" = "chroot" ];then
|
|
|
|
/sbin/chroot "$BUILD_PATH"
|
|
|
|
else
|
|
|
|
/sbin/chroot --userspec root:root "$BUILD_PATH" /bin/bash -v -c 'sh /second_stage_install.sh'
|
|
|
|
fi
|
2018-07-16 09:58:28 +02:00
|
|
|
RET=$?
|
|
|
|
if [ $RET -ne 0 ];then
|
2018-07-26 07:37:59 +02:00
|
|
|
error "line $LINENO Warning : chrooting to $BUILD_PATH retrurn an error $RET"
|
|
|
|
ERRORN=$((ERRORN++))
|
2018-06-06 11:15:11 +02:00
|
|
|
fi
|
|
|
|
info "unmounting dev, sys, proc"
|
2018-12-13 23:18:14 +01:00
|
|
|
/bin/umount -lf "$BUILD_PATH/dev"
|
2018-06-06 11:15:11 +02:00
|
|
|
if [ $? -ne 0 ];then
|
|
|
|
warning "line $LINENO Warning : error unmounting $BUILD_PATH/dev, continuing anyway"
|
2018-07-26 07:37:59 +02:00
|
|
|
ERRORN=$((ERRORN++))
|
2018-06-06 11:15:11 +02:00
|
|
|
fi
|
2018-12-13 23:18:14 +01:00
|
|
|
/bin/umount -lf "$BUILD_PATH/sys"
|
2018-06-06 11:15:11 +02:00
|
|
|
if [ $? -ne 0 ];then
|
|
|
|
warning "line $LINENO Warning : error unmounting $BUILD_PATH/sys, continuing anyway"
|
2018-07-26 07:37:59 +02:00
|
|
|
ERRORN=$((ERRORN++))
|
2018-06-06 11:15:11 +02:00
|
|
|
fi
|
2018-12-13 23:18:14 +01:00
|
|
|
/bin/umount -lf "$BUILD_PATH/proc"
|
2018-06-06 11:15:11 +02:00
|
|
|
if [ $? -ne 0 ];then
|
|
|
|
warning "line $LINENO Warning : error unmounting $BUILD_PATH/proc, continuing anyway"
|
2018-07-26 07:37:59 +02:00
|
|
|
ERRORN=$((ERRORN++))
|
2018-06-06 11:15:11 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function verify_disk_space()
|
|
|
|
{
|
2018-07-18 00:48:15 +02:00
|
|
|
title "Verifying if there is enough space on disk to make the image"
|
2018-07-19 22:00:59 +02:00
|
|
|
DISK_SPACE=$(/usr/bin/df -BG --output=avail "$INSTALL_PATH" | sed '1d;s/[^0-9]//g')
|
2018-06-06 11:15:11 +02:00
|
|
|
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
|
|
|
|
fi
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
function createxu3image()
|
|
|
|
{
|
2018-09-14 19:40:13 +02:00
|
|
|
title "Creating Odroid XU3-XU4 image"
|
2018-06-06 11:15:11 +02:00
|
|
|
createimage
|
2018-07-19 22:00:59 +02:00
|
|
|
if [ -z "$BOOTFS" ];then
|
2018-06-06 11:15:11 +02:00
|
|
|
BOOTFS="ext4"
|
|
|
|
fi
|
2018-07-19 22:00:59 +02:00
|
|
|
formatpartitions "$BOOTFS" ext4
|
2018-06-06 11:15:11 +02:00
|
|
|
copyingsystem
|
|
|
|
}
|
2018-12-21 22:27:43 +01:00
|
|
|
|
|
|
|
|
2018-06-06 11:15:11 +02:00
|
|
|
function createrpiimage()
|
|
|
|
{
|
|
|
|
title "Creating Pi image"
|
2018-12-21 22:27:43 +01:00
|
|
|
|
2018-07-19 22:00:59 +02:00
|
|
|
if ! [ -d "$FIRMWARE_PATH/$FIRMWARE_DIR" ];then # the firmware directory does not exists
|
|
|
|
echo "$(ls *.zip| wc -l)"
|
|
|
|
if [ "$(ls *.zip| wc -l)" -eq 0 ];then # the firmware archive does not exists
|
2018-06-06 11:15:11 +02:00
|
|
|
warning "The raspberry pi firmware need to be downloaded"
|
|
|
|
info "Downloading FIRMWARE_FILENAME"
|
|
|
|
wget $FIRMWARE_DOWNLOAD_URL
|
|
|
|
if [ $? -ne 0 ];then
|
|
|
|
error "line $LINENO error downloading raspberry firmware at $FIRMWARE_DOWNLOAD_URL :exiting"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
info "extracting firmware"
|
|
|
|
unzip -d "$FIRMWARE_PATH" *.zip
|
|
|
|
if [ $? -ne 0 ];then
|
|
|
|
error "line $LINENO error unzipping $FIRMWARE_PATH : exiting"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
2018-12-21 22:27:43 +01:00
|
|
|
|
2018-06-06 11:15:11 +02:00
|
|
|
title "Making raspberry pi image"
|
|
|
|
|
|
|
|
createimage
|
|
|
|
if [ -z $BOOTFS ];then
|
|
|
|
BOOTFS="vfat"
|
|
|
|
fi
|
|
|
|
formatpartitions $BOOTFS ext4
|
|
|
|
copyingsystem
|
2018-12-21 22:27:43 +01:00
|
|
|
|
2018-06-06 11:15:11 +02:00
|
|
|
}
|
2018-12-21 22:27:43 +01:00
|
|
|
|
2018-06-06 11:15:11 +02:00
|
|
|
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 1
|
|
|
|
fi
|
|
|
|
fi
|
2018-12-21 22:27:43 +01:00
|
|
|
|
2018-06-06 11:15:11 +02: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 1
|
|
|
|
fi
|
2018-07-19 22:00:59 +02:00
|
|
|
DEVICE=$(/sbin/losetup -f --show "$INSTALL_PATH/$IMAGE")
|
2019-01-05 20:58:18 +01:00
|
|
|
if [ $TARGET = "odroid" ];then
|
|
|
|
info "installing blobs"
|
|
|
|
pushd "$SOURCE_PATH/$CONFIG_PATH/sd_fuse"
|
|
|
|
if [ $? -ne 0 ];then
|
|
|
|
error "line $LINENO error directory $SOURCE_PATH/$CONFIG_PATH/sd_fuse does not exists : exiting"
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
./sd_fusing.sh "$DEVICE"
|
|
|
|
fi
|
|
|
|
pushd
|
|
|
|
fi
|
|
|
|
|
|
|
|
info "making partitions"
|
2018-07-19 22:00:59 +02:00
|
|
|
/sbin/fdisk "$DEVICE" << EOF
|
2018-06-06 11:15:11 +02:00
|
|
|
n
|
|
|
|
p
|
|
|
|
1
|
|
|
|
|
2018-07-21 09:17:52 +02:00
|
|
|
+128M
|
2018-06-06 11:15:11 +02:00
|
|
|
t
|
|
|
|
c
|
|
|
|
n
|
|
|
|
p
|
|
|
|
2
|
|
|
|
|
|
|
|
|
2018-12-21 22:27:43 +01:00
|
|
|
a
|
|
|
|
1
|
|
|
|
a
|
|
|
|
2
|
2018-06-06 11:15:11 +02:00
|
|
|
w
|
|
|
|
EOF
|
2018-12-21 22:27:43 +01:00
|
|
|
|
2018-12-07 20:38:32 +01:00
|
|
|
# Activate loop device
|
2018-07-19 22:00:59 +02:00
|
|
|
/sbin/losetup -d "$DEVICE"
|
|
|
|
DEVICE=$(/sbin/partx -va "$INSTALL_PATH/$IMAGE" | /bin/grep -m 1 -E -o '/dev/loop.?')
|
2018-06-06 11:15:11 +02:00
|
|
|
info "device $DEVICE"
|
|
|
|
info "partitions list:"
|
2018-07-19 22:00:59 +02:00
|
|
|
info "$(/sbin/partx -v "$INSTALL_PATH/$IMAGE")"
|
2018-07-22 14:20:42 +02:00
|
|
|
BOOTP="${DEVICE}p1"
|
|
|
|
ROOTP="${DEVICE}p2"
|
2018-06-06 11:15:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
formatpartitions()
|
|
|
|
{
|
|
|
|
info "Formatting partitions"
|
2018-07-22 14:20:42 +02:00
|
|
|
info "Boot : $BOOTP as $1"
|
2018-07-19 22:00:59 +02:00
|
|
|
"/sbin/mkfs.$1" "$BOOTP"
|
2018-06-06 11:15:11 +02:00
|
|
|
if [ $? -ne 0 ];then
|
|
|
|
error "line $LINENO error formating $BOOTP : exiting"
|
2018-07-19 22:00:59 +02:00
|
|
|
/sbin/losetup -d "$DEVICE"
|
2018-06-06 11:15:11 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
2018-07-22 14:20:42 +02:00
|
|
|
info "Root : $ROOTP as $2"
|
2018-07-19 22:00:59 +02:00
|
|
|
"/sbin/mkfs.$2" "$ROOTP"
|
2018-06-06 11:15:11 +02:00
|
|
|
if [ $? -ne 0 ];then
|
|
|
|
error "line $LINENO error formating $ROOTP : exiting"
|
2018-07-19 22:00:59 +02:00
|
|
|
/sbin/losetup -d "$DEVICE"
|
2018-06-06 11:15:11 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
2018-07-22 14:20:42 +02:00
|
|
|
BOOT_UUID=$(blkid -s UUID -o value UUID "$BOOTP")
|
2018-07-22 12:59:26 +02:00
|
|
|
info "Boot UUID: $BOOT_UUID"
|
2018-07-22 14:20:42 +02:00
|
|
|
ROOT_UUID=$(blkid -s UUID -o value UUID "$ROOTP")
|
2018-07-22 12:59:26 +02:00
|
|
|
info "Root UUID: $ROOT_UUID"
|
2018-06-06 11:15:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
copyingsystem()
|
|
|
|
{
|
2018-12-21 22:27:43 +01:00
|
|
|
info "mounting partitions, making mountpoint if necessary"
|
2018-06-06 11:15:11 +02:00
|
|
|
if ! [ -d "$BOOT" ];then
|
|
|
|
/bin/mkdir "$BOOT"
|
|
|
|
if [ $? -ne 0 ];then
|
|
|
|
error "line $LINENO error making directory $BOOT : exiting"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
if ! [ -d "$ROOT" ];then
|
|
|
|
/bin/mkdir "$ROOT"
|
|
|
|
if [ $? -ne 0 ];then
|
|
|
|
error "line $LINENO error making directory $ROOT : exiting"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
/bin/mount "$BOOTP" "$BOOT"
|
|
|
|
if [ $? -ne 0 ];then
|
|
|
|
error "line $LINENO error mounting $BOOTP : exiting"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
/bin/mount "$ROOTP" "$ROOT"
|
|
|
|
if [ $? -ne 0 ];then
|
|
|
|
error "line $LINENO error mounting $ROOTP : exiting"
|
|
|
|
exit 1
|
|
|
|
fi
|
2018-07-22 18:46:29 +02:00
|
|
|
|
2018-06-06 11:15:11 +02:00
|
|
|
info "making /etc/fstab"
|
|
|
|
echo "proc /proc proc defaults 0 0
|
2019-01-05 20:58:18 +01:00
|
|
|
UUID=$BOOT_UUID /mnt/arm_boot vfat defaults 0 0
|
2018-07-26 07:37:59 +02:00
|
|
|
UUID=$ROOT_UUID / ext4 defaults 0 0" > "$BUILD_PATH"/etc/fstab
|
2018-07-22 18:46:29 +02:00
|
|
|
|
2018-12-28 09:42:54 +01:00
|
|
|
info "making /boot/extlinux/extlinux.conf"
|
|
|
|
mkdir -p "$BUILD_PATH/boot/extlinux"
|
2019-01-05 20:58:18 +01:00
|
|
|
sed 212!!;n**ù**:;ncq -e s/\<UUID\>/$ROOT_UUID/g $SOURCE_PATH/$CONFIG_PATH/extlinux.conf >"$BUILD_PATH/boot/extlinux/extlinux.conf"
|
2018-12-28 09:42:54 +01:00
|
|
|
KERNEL_ID=`basename $BUILD_PATH/usr/lib/linux-*`
|
|
|
|
sed -i -e s/\<FDTDIR\>/$KERNEL_ID/g "$BUILD_PATH/boot/extlinux/extlinux.conf"
|
2018-12-21 22:27:43 +01:00
|
|
|
|
2018-06-06 11:15:11 +02:00
|
|
|
case $TARGET in
|
|
|
|
rpi)
|
2018-12-21 22:27:43 +01:00
|
|
|
|
|
|
|
info "copying 10-vchiq-permissions.rules"
|
2018-10-12 08:55:19 +02:00
|
|
|
cp "$SOURCE_PATH/$CONFIG_PATH/10-vchiq-permissions.rules" "$BUILD_PATH/etc/udev/rules.d/"
|
2018-12-21 22:27:43 +01:00
|
|
|
info "Making /etc/modules"
|
2018-06-06 11:15:11 +02:00
|
|
|
echo "vchiq
|
|
|
|
snd_bcm2835
|
|
|
|
vc4
|
2018-07-20 22:42:54 +02:00
|
|
|
brcmfmac" >> "$BUILD_PATH"/etc/modules
|
2018-06-06 11:15:11 +02:00
|
|
|
|
2019-01-05 20:58:18 +01:00
|
|
|
ARM_BOOT="$BUILD_PATH/mnt/arm_boot"
|
|
|
|
if ! [ -d "$ARM_BOOT" ];then
|
|
|
|
mkdir -p "$ARM_BOOT"
|
2018-12-21 22:27:43 +01:00
|
|
|
fi
|
2018-06-06 11:15:11 +02:00
|
|
|
info "copying modprobe.conf"
|
2018-07-19 22:00:59 +02:00
|
|
|
/bin/cp -a "$SOURCE_PATH/$CONFIG_PATH/modprobe.conf" "$BUILD_PATH/etc/"
|
|
|
|
chown root:root "$BUILD_PATH/etc/modprobe.conf"
|
2018-12-21 22:27:43 +01:00
|
|
|
|
|
|
|
info "copying firmware, overlays in rpi boot partition"
|
|
|
|
# cp -a "$BUILD_PATH/usr/lib/linux-"* "$BOOT/dtb"
|
2019-01-05 20:58:18 +01:00
|
|
|
cp -av "$FIRMWARE_PATH/$FIRMWARE_DIR/boot/start"* "$ARM_BOOT/"
|
|
|
|
cp -av "$FIRMWARE_PATH/$FIRMWARE_DIR/boot/fixup"* "$ARM_BOOT/"
|
|
|
|
cp -av "$FIRMWARE_PATH/$FIRMWARE_DIR/boot/bootcode.bin"* "$ARM_BOOT/"
|
|
|
|
cp -av "$FIRMWARE_PATH/$FIRMWARE_DIR/boot/overlays" "$ARM_BOOT/"
|
2018-12-21 22:27:43 +01:00
|
|
|
|
2019-01-05 20:58:18 +01:00
|
|
|
info "copying u-boot binary to $ARM_BOOT"
|
2018-12-13 23:18:14 +01:00
|
|
|
case $TARGET_VERSION in
|
|
|
|
2)
|
|
|
|
info "copying u-boot for $TARGET 2"
|
2019-01-05 20:58:18 +01:00
|
|
|
cp "$BUILD_PATH/usr/lib/u-boot/rpi_2/u-boot.bin" "$ARM_BOOT/kernel7"
|
2018-12-13 23:18:14 +01:00
|
|
|
;;
|
|
|
|
0)
|
|
|
|
info "copying u-boot for $TARGET 0"
|
2019-01-05 20:58:18 +01:00
|
|
|
cp "$BUILD_PATH/usr/lib/u-boot/rpi_0_w/u-boot.bin" "$ARM_BOOT/kernel7"
|
2018-12-13 23:18:14 +01:00
|
|
|
;;
|
|
|
|
1)
|
|
|
|
info "copying u-boot for $TARGET 1"
|
2019-01-05 20:58:18 +01:00
|
|
|
cp "$BUILD_PATH/usr/lib/u-boot/rpi/u-boot.bin" "$ARM_BOOT/kernel7"
|
2018-12-13 23:18:14 +01:00
|
|
|
;;
|
|
|
|
3_32)
|
|
|
|
info "copying u-boot for $TARGET 3 32 bits"
|
2019-01-05 20:58:18 +01:00
|
|
|
cp "$BUILD_PATH/usr/lib/u-boot/rpi_3_32b/u-boot.bin" "$ARM_BOOT/kernel7"
|
2018-12-13 23:18:14 +01:00
|
|
|
;;
|
2018-12-23 11:37:13 +01:00
|
|
|
3+)
|
|
|
|
info "copying u-boot for $TARGET 3b+ 32 bits"
|
2019-01-05 20:58:18 +01:00
|
|
|
cp "$BUILD_PATH/usr/lib/u-boot/rpi_3_32b/u-boot.bin" "$ARM_BOOT/kernel7"
|
2018-12-23 11:37:13 +01:00
|
|
|
;;
|
2018-12-13 23:18:14 +01:00
|
|
|
esac
|
2018-12-21 22:27:43 +01:00
|
|
|
|
|
|
|
# info "copying raspberry optionals files in opt"
|
2018-12-07 20:38:32 +01:00
|
|
|
# /bin/rsync -rlptDH "$FIRMWARE_PATH/$FIRMWARE_DIR/opt/" "$BUILD_PATH/opt/"
|
2018-12-21 22:27:43 +01:00
|
|
|
|
2018-12-07 20:38:32 +01:00
|
|
|
info "copying wifi firmware file missing in kernel-firmware-nonfree"
|
|
|
|
if ! [ -d "$ROOT/usr/lib/firmware/brcm/" ];then
|
|
|
|
/bin/mkdir -p "$ROOT/usr/lib/firmware/brcm/"
|
|
|
|
fi
|
2018-12-23 11:37:13 +01:00
|
|
|
if ! [ -f "$ROOT/usr/lib/firmware/brcm/brcmfmac434"* ];then
|
|
|
|
/bin/cp "$SOURCE_PATH/$CONFIG_PATH/brcmfmac434"* "$ROOT/usr/lib/firmware/brcm/"
|
2018-12-21 22:27:43 +01:00
|
|
|
if [ $? -ne 0 ];then
|
|
|
|
error "line $LINENO error copying wifi firmware in $ROOTP/usr/lib/firmware/brcm/ : exiting"
|
|
|
|
exit 1
|
|
|
|
fi
|
2018-06-06 11:15:11 +02:00
|
|
|
fi
|
2018-12-28 09:42:54 +01:00
|
|
|
|
|
|
|
info "copying Mageia image to root partition"
|
2019-01-05 20:58:18 +01:00
|
|
|
/bin/rsync -a --exclude "$ARM_BOOT/" --exclude "qemu-arm-static*" "$BUILD_PATH/" "$ROOT/"
|
|
|
|
/bin/rsync -a "$ARM_BOOT/" "$BOOT/"
|
2018-06-06 11:15:11 +02:00
|
|
|
;;
|
2018-12-28 09:42:54 +01:00
|
|
|
odroid)
|
|
|
|
ODROID_BOOT="$BUILD_PATH/mnt/odroid_boot"
|
|
|
|
if ! [ -d "$ODROID_BOOT" ];then
|
|
|
|
mkdir -p "$ODROID_BOOT"
|
|
|
|
fi
|
2019-01-05 20:58:18 +01:00
|
|
|
case $TARGET_VERSION in
|
|
|
|
xu4)
|
|
|
|
info "copying u-boot for $TARGET $TARGET_VERSION"
|
|
|
|
cp "$BUILD_PATH/usr/lib/u-boot/$TARGET-$TARGET_VERSION/u-boot.bin" "$ARM_BOOT/"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
# temporary code waiting inclusion of xu4 in Mageia kernel and u-boot
|
|
|
|
|
2018-12-28 09:42:54 +01:00
|
|
|
info "Copying extlinux.conf on $ODROID_BOOT"
|
|
|
|
cp -R "$BUILD_PATH/boot/extlinux" "$ODROID_BOOT/"
|
|
|
|
info "copying Mageia image to root partition"
|
|
|
|
/bin/rsync -a --exclude "$ODROID_BOOT/" --exclude "qemu-arm-static*" "$BUILD_PATH/" "$ROOT/"
|
|
|
|
/bin/rsync -a "$ODROID_BOOT/" "$BOOT/"
|
2018-06-06 11:15:11 +02:00
|
|
|
;;
|
2018-07-17 11:18:06 +02:00
|
|
|
esac
|
2018-12-21 22:27:43 +01:00
|
|
|
|
2019-01-05 20:58:18 +01:00
|
|
|
# info "copying tools in /usr/local/bin/"
|
|
|
|
# /bin/cp -a "$SOURCE_PATH/tools/" "$BUILD_PATH/usr/local/bin/"
|
|
|
|
# if ! [ $? -eq 0 ];then
|
|
|
|
# error "line $LINENO error copying tools"
|
|
|
|
# ERRORN=$((ERRORN++))
|
|
|
|
# fi
|
2018-12-21 22:27:43 +01:00
|
|
|
# /bin/mkdir "$ROOT/boot"
|
2018-07-26 07:37:59 +02:00
|
|
|
|
2018-07-22 14:20:42 +02:00
|
|
|
copyingcommon
|
2018-12-07 20:38:32 +01:00
|
|
|
# Syncing devices before unmounting
|
2018-07-17 11:18:06 +02:00
|
|
|
/usr/bin/sync
|
|
|
|
/usr/bin/umount "$BOOT" "$ROOT"
|
2018-06-06 11:15:11 +02:00
|
|
|
if [ $? -eq 0 ];then
|
|
|
|
/bin/rmdir "$BOOT" "$ROOT"
|
|
|
|
else
|
|
|
|
error "line $LINENO error unmounting $ROOT or $BOOT : exiting"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2018-07-17 11:18:06 +02:00
|
|
|
/usr/sbin/partx -d "$DEVICE"
|
2018-06-06 11:15:11 +02:00
|
|
|
if [ $? -ne 0 ];then
|
|
|
|
error "line $LINENO warning : error unmounting $DEVICE "
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
warning "You can now burn the image ( $IMAGE ) on SD card"
|
|
|
|
}
|
|
|
|
|
2018-07-22 14:20:42 +02:00
|
|
|
# Copying files common to all systems
|
|
|
|
copyingcommon()
|
|
|
|
{
|
2018-07-22 18:46:29 +02:00
|
|
|
title "Copying common files and configuration"
|
2018-07-22 14:20:42 +02:00
|
|
|
rsync -aP "$SOURCE_PATH/common/" "$ROOT/"
|
2019-01-05 20:58:18 +01:00
|
|
|
rsync -aP "$SOURCE_PATH/tools/"*.sh "$ROOT/usr/local/bin/"
|
2018-12-16 14:21:26 +01:00
|
|
|
chown root:root "$ROOT/usr/local/bin/"
|
2018-07-22 14:20:42 +02:00
|
|
|
}
|
|
|
|
|
2018-06-06 11:15:11 +02:00
|
|
|
if [ $# == 0 ];then
|
|
|
|
help
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
# parsing commandline
|
2018-12-13 23:18:14 +01: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: -n $CMDNAME -- "$@")
|
2018-06-06 11:15:11 +02:00
|
|
|
if [ $? -ne 0 ] ; then error "line $LINENO Failed parsing options." >&2 ; exit 1 ; fi
|
|
|
|
eval set -- "$TEMP"
|
|
|
|
|
|
|
|
echo "$TEMP"
|
2018-09-14 19:40:13 +02:00
|
|
|
# Note the quotes around `$TEMP': they are essential!
|
2018-06-06 11:15:11 +02:00
|
|
|
while true;
|
|
|
|
do
|
|
|
|
case "$1" in
|
|
|
|
-h|--help)
|
|
|
|
help
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
-a|--all)
|
|
|
|
OPT="all"
|
|
|
|
shift 1
|
|
|
|
;;
|
|
|
|
--clean)
|
2018-07-16 09:58:28 +02:00
|
|
|
OPT="clean"
|
2018-06-06 11:15:11 +02:00
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--size)
|
2019-01-05 20:58:18 +01:00
|
|
|
IMAGE_SIZE_P=$2
|
2018-06-06 11:15:11 +02:00
|
|
|
shift 2
|
|
|
|
;;
|
|
|
|
--build-path)
|
2019-01-05 20:58:18 +01:00
|
|
|
INSTALL_PATH_P="$2"
|
2018-06-06 11:15:11 +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
|
|
|
|
;;
|
2018-12-13 23:18:14 +01:00
|
|
|
--target)
|
2019-01-05 20:58:18 +01:00
|
|
|
TARGET_P=$2
|
2018-12-13 23:18:14 +01:00
|
|
|
shift 2
|
|
|
|
;;
|
|
|
|
--target-version)
|
2019-01-05 20:58:18 +01:00
|
|
|
TARGET_VERSION_P=$2
|
2018-06-09 10:59:49 +02:00
|
|
|
shift 2
|
2018-06-06 11:15:11 +02:00
|
|
|
;;
|
|
|
|
--config)
|
2018-07-19 22:00:59 +02:00
|
|
|
CONFIG_PATH="$2"
|
2018-06-06 11:15:11 +02:00
|
|
|
shift 2
|
|
|
|
;;
|
|
|
|
--bootfs)
|
2019-01-05 20:58:18 +01:00
|
|
|
BOOTFS_P=$2
|
2018-06-06 11:15:11 +02:00
|
|
|
shift 2
|
|
|
|
;;
|
|
|
|
--)
|
|
|
|
shift
|
|
|
|
break;;
|
2018-10-14 21:08:55 +02:00
|
|
|
*)
|
|
|
|
error "Parameter $1 does not exists "
|
|
|
|
exit 1;;
|
2018-06-06 11:15:11 +02:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
|
2018-06-09 16:15:50 +02:00
|
|
|
# path of config file
|
2018-07-19 22:00:59 +02:00
|
|
|
if ! [ -d "$SOURCE_PATH/$CONFIG_PATH" ];then
|
2018-12-07 20:38:32 +01:00
|
|
|
info " Config path does not exists, defaulting to ./$TARGET"
|
2019-01-05 20:58:18 +01:00
|
|
|
CONFIG_PATH="$TARGET"
|
2018-06-09 10:59:49 +02:00
|
|
|
fi
|
2018-06-06 11:15:11 +02:00
|
|
|
|
2018-07-16 09:58:28 +02:00
|
|
|
if [ -d "$SOURCE_PATH/$CONFIG_PATH" ];then
|
2018-07-21 13:02:00 +02:00
|
|
|
if [ -e "$SOURCE_PATH/$CONFIG_PATH/mageia4arm.cfg" ];then
|
|
|
|
info "using $SOURCE_PATH/$CONFIG_PATH/mageia4arm.cfg as config"
|
|
|
|
. "$SOURCE_PATH/$CONFIG_PATH/mageia4arm.cfg"
|
2018-06-06 11:15:11 +02:00
|
|
|
else
|
2018-06-09 10:59:49 +02:00
|
|
|
warning "Config file does not exists, do you want i copy template ? [Y|n] "
|
|
|
|
read yn
|
2018-06-09 16:15:50 +02:00
|
|
|
if [ -z $yn ] || [ $yn = "Y" ] || [ $yn = "y" ];then
|
2018-07-21 13:02:00 +02:00
|
|
|
/usr/bin/cp "$SOURCE_PATH/mageia4arm.cfg.template" "$SOURCE_PATH/$CONFIG_PATH/mageia4arm.cfg"
|
2018-08-04 00:14:36 +02:00
|
|
|
warning "You need now to modify the config file ($SOURCE_PATH/$CONFIG_PATH/mageia4arm.cfg) and relaunch the script"
|
2018-10-14 21:08:55 +02:00
|
|
|
exit 2
|
2018-06-06 11:15:11 +02:00
|
|
|
fi
|
2018-06-09 10:59:49 +02:00
|
|
|
fi
|
|
|
|
else
|
|
|
|
warning "Config directory does not exists, do you want i make it and copy the template file in? [Y|n] "
|
|
|
|
read yn
|
2018-07-19 22:00:59 +02:00
|
|
|
if [ -z $yn ] || [ $yn = "Y" ] || [ $yn = "y" ];then
|
|
|
|
/usr/bin/mkdir "$SOURCE_PATH/$CONFIG_PATH/"
|
2018-07-21 13:02:00 +02:00
|
|
|
/usr/bin/cp "$SOURCE_PATH/config.template" "$SOURCE_PATH/$CONFIG_PATH/mageia4arm.cfg"
|
|
|
|
warning "You need now to modify the config file ($SOURCE_PATH/$CONFIG_PATH/mageia4arm.cfg) and relaunch the script"
|
2018-10-14 21:08:55 +02:00
|
|
|
exit 2
|
2018-06-06 11:15:11 +02:00
|
|
|
fi
|
|
|
|
fi
|
2018-07-17 11:18:06 +02:00
|
|
|
|
2019-01-05 20:58:18 +01:00
|
|
|
if ! [ -z "$IMAGE_SIZE_P" ];then
|
|
|
|
IMAGE_SIZE=$IMAGE_SIZE_P
|
|
|
|
fi
|
|
|
|
if ! [ -z "$INSTALL_PATH_P" ];then
|
|
|
|
INSTALL_PATH=$INSTALL_PATH_P
|
|
|
|
fi
|
|
|
|
if ! [ -z "$TARGET_P" ];then
|
|
|
|
TARGET=$TARGET_P
|
|
|
|
fi
|
|
|
|
if ! [ -z "$TARGET_VERSION_P" ];then
|
|
|
|
TARGET_VERSION=$TARGET_VERSION_P
|
|
|
|
fi
|
|
|
|
if ! [ -z "$BOOTFS_P" ];then
|
|
|
|
BOOTFS=$BOOTFS_P
|
|
|
|
fi
|
|
|
|
info "Option: "$OPT
|
|
|
|
|
|
|
|
IMAGE="Mageia-${MAGEIA_VERSION}-$TARGET$TARGET_VERSION.img"
|
|
|
|
BOOT="/mnt/boot"
|
|
|
|
ROOT="/mnt/root"
|
|
|
|
BUILD_PATH="$INSTALL_PATH/build"
|
|
|
|
ARM_VERSION="armv7hl"
|
|
|
|
|
2018-12-26 14:44:37 +01:00
|
|
|
# assign function for building image of TARGET ( rpi, odroid )
|
2018-07-17 11:18:06 +02:00
|
|
|
case $TARGET in
|
2018-12-13 23:18:14 +01:00
|
|
|
odroid)
|
2018-07-17 11:18:06 +02:00
|
|
|
CREATEIMG="createxu3image"
|
|
|
|
;;
|
|
|
|
rpi)
|
|
|
|
CREATEIMG="createrpiimage"
|
|
|
|
;;
|
|
|
|
*)
|
2018-12-21 22:27:43 +01:00
|
|
|
error "No Target : $TARGET"
|
2018-07-17 11:18:06 +02:00
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2018-12-21 22:27:43 +01:00
|
|
|
info "target : $TARGET"
|
2019-01-05 20:58:18 +01:00
|
|
|
info "target_version : $TARGET_VERSION"
|
2018-06-06 11:15:11 +02:00
|
|
|
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
|
2018-06-06 11:15:11 +02:00
|
|
|
if [[ "$IMAGE_SIZE" -lt 7 ]] || [[ "$IMAGE_SIZE" -gt 128 ]];then
|
|
|
|
IMAGE_SIZE=7
|
|
|
|
fi
|
|
|
|
|
2018-12-07 20:38:32 +01:00
|
|
|
# change dir to install path and create it if not existing
|
2018-06-06 11:15:11 +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"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
cd "$INSTALL_PATH"
|
|
|
|
if [ -z $? ];then
|
|
|
|
error "line $LINENO can't change to directory $INSTALL_PATH , exiting"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2018-12-07 20:38:32 +01:00
|
|
|
#if no parameters then display help message
|
2018-06-06 11:15:11 +02:00
|
|
|
if [ -z $OPT ];then
|
|
|
|
OPT="--help"
|
|
|
|
fi
|
|
|
|
|
|
|
|
info "Image size is: $IMAGE_SIZE Go"
|
|
|
|
|
|
|
|
case $OPT in
|
|
|
|
clean)
|
|
|
|
clean
|
|
|
|
;;
|
|
|
|
all)
|
|
|
|
verify_disk_space
|
|
|
|
if [ $? -eq 1 ];then
|
2018-07-19 22:00:59 +02:00
|
|
|
echo -e "Not enough space on disk\nDo you want to continue anyway ? [Y,n]"
|
2018-06-09 16:15:50 +02:00
|
|
|
read yn
|
|
|
|
if [ $yn = "n" ];then
|
2018-06-06 11:15:11 +02:00
|
|
|
exit 6
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
createchroot
|
|
|
|
addmedia
|
|
|
|
updatemirror
|
|
|
|
installbasesystem
|
2018-12-13 23:18:14 +01:00
|
|
|
preparechroot
|
2018-06-06 11:15:11 +02:00
|
|
|
jumpchroot
|
2018-07-18 00:48:15 +02:00
|
|
|
$CREATEIMG
|
2018-06-06 11:15:11 +02:00
|
|
|
;;
|
|
|
|
createchroot)
|
|
|
|
createchroot
|
|
|
|
;;
|
|
|
|
chroot)
|
|
|
|
jumpchroot
|
|
|
|
;;
|
|
|
|
addmedia)
|
|
|
|
addmedia
|
|
|
|
;;
|
|
|
|
updatemirror)
|
|
|
|
updatemirror
|
|
|
|
;;
|
|
|
|
createimage)
|
|
|
|
verify_disk_space
|
|
|
|
if [ $? -eq 1 ];then
|
|
|
|
warning "Not enough space on disk"
|
|
|
|
exit 6
|
|
|
|
fi
|
|
|
|
$CREATEIMG
|
|
|
|
;;
|
|
|
|
installbasesystem)
|
|
|
|
installbasesystem
|
|
|
|
;;
|
|
|
|
esac
|
2018-07-26 07:37:59 +02:00
|
|
|
|
2018-12-07 20:38:32 +01:00
|
|
|
|
2018-08-04 00:14:36 +02:00
|
|
|
if ! [ -z $ERRORN ];then
|
|
|
|
warning "Some errors occurs : $ERRORN errors"
|
|
|
|
fi
|