1
0

fonctionnalisation - première etape

Première etape de fonctionnalisation des fonctions dépendentes des plateformes
This commit is contained in:
Jybz 2019-10-02 15:03:36 +00:00
parent 584c02c3c5
commit ad4968f29d

View File

@ -21,43 +21,24 @@ function title()
echo -e "\e[1;32m${1}\e[0m" echo -e "\e[1;32m${1}\e[0m"
} }
function info() function info()
{ {
echo -e "\e[36m${1}\e[0m" echo -e "\e[36m${1}\e[0m"
} }
function warning() function warning()
{ {
echo -e "\e[1;35m${1}\e[0m" echo -e "\e[1;35m${1}\e[0m"
} }
function error() function error()
{ {
echo -e "\e[1;31m${1}\e[0m" echo -e "\e[1;31m${1}\e[0m"
} }
info ${0}
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}")
#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() function help()
{ {
@ -95,7 +76,7 @@ function clean()
umount "${BUILD_PATH}/dev" umount "${BUILD_PATH}/dev"
if ! [ ${?} -ne 0 ]; then if ! [ ${?} -ne 0 ]; then
error "line ${LINENO} can't unmount ${BUILD_PATH}/dev : exiting" error "line ${LINENO} can't unmount ${BUILD_PATH}/dev : exiting"
#exit 1 #exit ${ERR_1}
fi fi
fi fi
if ! [ -z "$(mountpoint -qd "${BUILD_PATH}/sys")" ]; then if ! [ -z "$(mountpoint -qd "${BUILD_PATH}/sys")" ]; then
@ -103,7 +84,7 @@ function clean()
umount "${BUILD_PATH}/sys" umount "${BUILD_PATH}/sys"
if ! [ ${?} -ne 0 ]; then if ! [ ${?} -ne 0 ]; then
error "line ${LINENO} can't unmount ${BUILD_PATH}/sys : exiting" error "line ${LINENO} can't unmount ${BUILD_PATH}/sys : exiting"
#exit 1 #exit ${ERR_1}
fi fi
fi fi
if ! [ -z "$(mountpoint -qd "${BUILD_PATH}/proc")" ]; then if ! [ -z "$(mountpoint -qd "${BUILD_PATH}/proc")" ]; then
@ -111,7 +92,7 @@ function clean()
umount "${BUILD_PATH}/proc" umount "${BUILD_PATH}/proc"
if ! [ ${?} -ne 0 ]; then if ! [ ${?} -ne 0 ]; then
error "line ${LINENO} can't unmount ${BUILD_PATH}/proc : exiting" error "line ${LINENO} can't unmount ${BUILD_PATH}/proc : exiting"
#exit 1 #exit ${ERR_1}
fi fi
fi fi
# Removing old Build directory # Removing old Build directory
@ -152,6 +133,7 @@ function clean()
exit 0 exit 0
} }
# creation of install path and copy of qemu ( installing it if not yet installed ) # creation of install path and copy of qemu ( installing it if not yet installed )
function createchroot() function createchroot()
{ {
@ -161,7 +143,7 @@ function createchroot()
/sbin/urpmi --auto --no-recommends qemu-user-static /sbin/urpmi --auto --no-recommends qemu-user-static
if [ ${?} -ne 0 ]; then if [ ${?} -ne 0 ]; then
error "line ${LINENO} can't install qemu-user-static : exiting" error "line ${LINENO} can't install qemu-user-static : exiting"
exit 1 exit ${ERR_1}
fi fi
fi fi
# Starting qemu service if not started # Starting qemu service if not started
@ -171,13 +153,14 @@ function createchroot()
/bin/systemctl start systemd-binfmt.service /bin/systemctl start systemd-binfmt.service
if [ ${?} -ne 0 ]; then if [ ${?} -ne 0 ]; then
error "line ${LINENO} can't start qemu-user-static : exiting" error "line ${LINENO} can't start qemu-user-static : exiting"
exit 1 exit ${ERR_1}
fi fi
fi fi
} }
# adding Mageia repositories # adding Mageia repositories
function addmedia() function addmedia()
{ {
@ -186,7 +169,7 @@ function addmedia()
err=${?} err=${?}
if [ ${err} -ne 0 ]; then if [ ${err} -ne 0 ]; then
error "line ${LINENO} error ${err} - can't add medias from ${MIRROR} : exiting" error "line ${LINENO} error ${err} - can't add medias from ${MIRROR} : exiting"
exit 1 exit ${ERR_1}
fi fi
if [ ${NONFREE} -eq 1 ]; then if [ ${NONFREE} -eq 1 ]; then
title "activating non-free repos" title "activating non-free repos"
@ -194,7 +177,7 @@ function addmedia()
err=${?} err=${?}
if [ ${err} -ne 0 ]; then if [ ${err} -ne 0 ]; then
error "line ${LINENO} error ${err} - can't activate medias nonfree : exiting" error "line ${LINENO} error ${err} - can't activate medias nonfree : exiting"
exit 1 exit ${ERR_1}
fi fi
fi fi
if [ ${TAINTED} -eq 1 ]; then if [ ${TAINTED} -eq 1 ]; then
@ -203,21 +186,23 @@ function addmedia()
err=${?} err=${?}
if [ ${err} -ne 0 ]; then if [ ${err} -ne 0 ]; then
error "line ${LINENO} error ${err} - can't activate medias tainted : exiting" error "line ${LINENO} error ${err} - can't activate medias tainted : exiting"
exit 1 exit ${ERR_1}
fi fi
fi fi
} }
function updatemirror() function updatemirror()
{ {
title "updating mirror" title "updating mirror"
/sbin/urpmi.update -a --urpmi-root "${BUILD_PATH}" /sbin/urpmi.update -a --urpmi-root "${BUILD_PATH}"
if [ ${?} -ne 0 ]; then if [ ${?} -ne 0 ]; then
error "line ${LINENO} can't update mirrors : exiting" error "line ${LINENO} can't update mirrors : exiting"
exit 1 exit ${ERR_1}
fi fi
} }
function installbasesystem() function installbasesystem()
{ {
# Create Build path # Create Build path
@ -229,10 +214,10 @@ function installbasesystem()
/bin/mkdir -p "${BUILD_PATH}/usr/bin" "${BUILD_PATH}/usr/lib/binfmt.d" /bin/mkdir -p "${BUILD_PATH}/usr/bin" "${BUILD_PATH}/usr/lib/binfmt.d"
if [ ${?} -ne 0 ]; then if [ ${?} -ne 0 ]; then
error "line ${LINENO} can't create ${BUILD_PATH} : exiting" error "line ${LINENO} can't create ${BUILD_PATH} : exiting"
exit 1 exit ${ERR_1}
fi fi
else else
exit 1 exit ${ERR_1}
fi fi
else else
info "Build path exists" info "Build path exists"
@ -242,20 +227,21 @@ function installbasesystem()
/sbin/urpmi --urpmi-root "${BUILD_PATH}" --ignorearch --no-verify-rpm --auto --split-level 200 --split-length 200 shadow-utils basesystem-minimal /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 if [ ${?} -ne 0 ]; then
error "line ${LINENO} error installing shadow-utils or basesystem-minimal : exiting" error "line ${LINENO} error installing shadow-utils or basesystem-minimal : exiting"
exit 1 exit ${ERR_1}
fi fi
#/sbin/urpmi --urpmi-root "${BUILD_PATH}" --ignorearch --no-verify-rpm --auto --split-level 200 --split-length 200 basesystem-minimal #/sbin/urpmi --urpmi-root "${BUILD_PATH}" --ignorearch --no-verify-rpm --auto --split-level 200 --split-length 200 basesystem-minimal
#if [ ${?} -ne 0 ]; then #if [ ${?} -ne 0 ]; then
# error "line ${LINENO} error installing basesystem-minimal : exiting" # error "line ${LINENO} error installing basesystem-minimal : exiting"
# exit 1 # exit ${ERR_1}
#fi #fi
/sbin/urpmi --urpmi-root "${BUILD_PATH}" --ignorearch --no-verify-rpm --auto --split-level 200 --split-length 200 urpmi locales-fr systemd u-boot /sbin/urpmi --urpmi-root "${BUILD_PATH}" --ignorearch --no-verify-rpm --auto --split-level 200 --split-length 200 urpmi locales-fr systemd u-boot
if [ ${?} -ne 0 ]; then if [ ${?} -ne 0 ]; then
error "line ${LINENO} error installing urpmi or locales.fr : exiting" error "line ${LINENO} error installing urpmi or locales.fr : exiting"
exit 1 exit ${ERR_1}
fi fi
} }
function preparechroot() function preparechroot()
{ {
title "Preparing chrooting in ${BUILD_PATH}" title "Preparing chrooting in ${BUILD_PATH}"
@ -265,12 +251,12 @@ function preparechroot()
/bin/cp /bin/qemu-arm-static "${BUILD_PATH}/usr/bin/" /bin/cp /bin/qemu-arm-static "${BUILD_PATH}/usr/bin/"
if [ ${?} -ne 0 ]; then if [ ${?} -ne 0 ]; then
error "line ${LINENO} can't copy /bin/qemu-user-static to ${BUILD_PATH}/usr/bin/ : exiting" error "line ${LINENO} can't copy /bin/qemu-user-static to ${BUILD_PATH}/usr/bin/ : exiting"
exit 1 exit ${ERR_1}
fi fi
/bin/cp /usr/lib/binfmt.d/qemu-arm-static.conf "${BUILD_PATH}/usr/lib/binfmt.d" /bin/cp /usr/lib/binfmt.d/qemu-arm-static.conf "${BUILD_PATH}/usr/lib/binfmt.d"
if [ ${?} -ne 0 ]; then 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" error "line ${LINENO} can't copy /usr/lib/binfmt.d/qemu-arm-static.conf to ${BUILD_PATH}/usr/lib/binfmt.d : exiting"
exit 1 exit ${ERR_1}
fi fi
@ -282,48 +268,23 @@ function preparechroot()
cp --preserve=mode "${CONFIG_PATH}/second_stage_install.sh" "${BUILD_PATH}/second_stage_install.sh" cp --preserve=mode "${CONFIG_PATH}/second_stage_install.sh" "${BUILD_PATH}/second_stage_install.sh"
if [ ${?} -ne 0 ]; then if [ ${?} -ne 0 ]; then
error "line ${LINENO} error copying ${CONFIG_PATH}/second_stage_install.sh : exiting" error "line ${LINENO} error copying ${CONFIG_PATH}/second_stage_install.sh : exiting"
exit 1 exit ${ERR_1}
fi fi
info "creation of user account" info "creation of user account"
echo "/bin/passwd << EOF 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"
${ROOT_PWD}
${ROOT_PWD}
EOF
/sbin/useradd ${ID_USER}
/bin/passwd ${ID_USER} << EOF
${PASSWORD}
${PASSWORD}
EOF" >>"${BUILD_PATH}/second_stage_install.sh"
info "Copying skel in root directory" info "Copying skel in root directory"
/bin/rsync -rlptH /etc/skel/ "${BUILD_PATH}/root/" /bin/rsync -rlptH /etc/skel/ "${BUILD_PATH}/root/"
postPrepareChroot
case ${TARGET} in
"bananaPro")
#TODO Complete here for Banana Pro.
;;
"odroid")
#TEMPORARY CODE
#copying kernel odroid not existing in mageia repos
info "copying kernel-odroid and u-boot rpms in ${BUILD_PATH}/root"
#echo "/bin/cp ${CONFIG_PATH}/kernel-odroid-4.14.y-1.armv7hl.rpm ${BUILD_PATH}/root/"
/usr/bin/cp --preserve=mode "${CONFIG_PATH}/kernel-odroid-4.14.y-1.armv7hl.rpm" "${BUILD_PATH}/root/"
#echo "/bin/cp ${CONFIG_PATH}/u-boot-20180507-3.mga7.armv7hl.rpm ${BUILD_PATH}/root/"
/usr/bin/cp --preserve=mode "${CONFIG_PATH}/u-boot-20180507-3.mga7.armv7hl.rpm" "${BUILD_PATH}/root/"
if [ ${?} -ne 0 ]; then if [ ${?} -ne 0 ]; then
error "line ${LINENO} error copying ${CONFIG_PATH}/kernel-odroid-4.14.y-1.armv7hl.rpm : exiting" error "line ${LINENO} error in postPrepareChroot function."
exit 1 exit ${ERR_1}
fi fi
;;
"rpi")
;;
esac
} }
function jumpchroot() function jumpchroot()
{ {
title "chrooting to ${BUILD_PATH}" title "chrooting to ${BUILD_PATH}"
@ -331,23 +292,23 @@ function jumpchroot()
/bin/mount -B /dev "${BUILD_PATH}/dev" /bin/mount -B /dev "${BUILD_PATH}/dev"
if [ ${?} -ne 0 ]; then if [ ${?} -ne 0 ]; then
error "line ${LINENO} error mounting ${BUILD_PATH}/dev : exiting" error "line ${LINENO} error mounting ${BUILD_PATH}/dev : exiting"
exit 1 exit ${ERR_1}
fi fi
/bin/mount -B /sys "${BUILD_PATH}/sys" /bin/mount -B /sys "${BUILD_PATH}/sys"
if [ ${?} -ne 0 ]; then if [ ${?} -ne 0 ]; then
error "line ${LINENO} error mounting ${BUILD_PATH}/sys : exiting" error "line ${LINENO} error mounting ${BUILD_PATH}/sys : exiting"
exit 1 exit ${ERR_1}
fi fi
/bin/mount -B /proc "${BUILD_PATH}/proc" /bin/mount -B /proc "${BUILD_PATH}/proc"
if [ ${?} -ne 0 ]; then if [ ${?} -ne 0 ]; then
error "line ${LINENO} error mounting ${BUILD_PATH}/proc : exiting" error "line ${LINENO} error mounting ${BUILD_PATH}/proc : exiting"
exit 1 exit ${ERR_1}
fi fi
info "Copying resolv.conf" info "Copying resolv.conf"
/bin/cp -v --preserve=mode /etc/resolv.conf "${BUILD_PATH}/etc/" /bin/cp -v --preserve=mode /etc/resolv.conf "${BUILD_PATH}/etc/"
if [ ${?} -ne 0 ]; then if [ ${?} -ne 0 ]; then
error "line ${LINENO} error copying ${BUILD_PATH}/etc/resolv.conf : exiting" error "line ${LINENO} error copying ${BUILD_PATH}/etc/resolv.conf : exiting"
exit 1 exit ${ERR_1}
fi fi
if [ "$OPT" = "chroot" ]; then if [ "$OPT" = "chroot" ]; then
/sbin/chroot "${BUILD_PATH}" /sbin/chroot "${BUILD_PATH}"
@ -377,6 +338,7 @@ function jumpchroot()
fi fi
} }
function verify_disk_space() function verify_disk_space()
{ {
title "Verifying if there is enough space on disk to make the image" title "Verifying if there is enough space on disk to make the image"
@ -391,63 +353,24 @@ function verify_disk_space()
return 0 return 0
} }
function createxu3image()
function createImageWrap()
{ {
title "Creating Odroid XU3-XU4 image" title "Wrap image creation"
preImgCreation
if [ ${?} -ne 0 ]; then
error "line ${LINENO} error in the process ${CONFIG_PATH}/createImage.sh ."
exit ${ERR_1}
fi
createimage createimage
if [ -z "${BOOTFS}" ]; then if [ -z "${BOOTFS}" ]; then
BOOTFS="ext4" BOOTFS="ext4"
fi fi
formatpartitions "${BOOTFS}" ext4
copyingsystem
}
function createbproimage()
{
#TODO
# title "Creating Banana Pro image"
# createimage
# if [ -z "${BOOTFS}" ]; then
# BOOTFS="ext4"
# fi
# formatpartitions "${BOOTFS}" ext4
# copyingsystem
}
function createrpiimage()
{
title "Creating Pi image"
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
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
title "Making raspberry pi image"
createimage
if [ -z ${BOOTFS} ]; then
BOOTFS="vfat"
fi
formatpartitions ${BOOTFS} ext4 formatpartitions ${BOOTFS} ext4
copyingsystem copyingsystem
} }
createimage() createimage()
{ {
title " in ${IMAGE}" title " in ${IMAGE}"
@ -456,7 +379,7 @@ createimage()
/bin/rm -f "${INSTALL_PATH}/${IMAGE}" /bin/rm -f "${INSTALL_PATH}/${IMAGE}"
if [ ${?} -ne 0 ]; then if [ ${?} -ne 0 ]; then
error "line ${LINENO} error can't remove previous image at ${INSTALL_PATH}/${IMAGE} : exiting" error "line ${LINENO} error can't remove previous image at ${INSTALL_PATH}/${IMAGE} : exiting"
exit 1 exit ${ERR_1}
fi fi
fi fi
@ -464,7 +387,7 @@ createimage()
/bin/dd if=/dev/zero of="${INSTALL_PATH}/${IMAGE}" bs=1MB count=$(( ${IMAGE_SIZE} * 1024 )) /bin/dd if=/dev/zero of="${INSTALL_PATH}/${IMAGE}" bs=1MB count=$(( ${IMAGE_SIZE} * 1024 ))
if [ ${?} -ne 0 ]; then if [ ${?} -ne 0 ]; then
error "line ${LINENO} can't make image at ${INSTALL_PATH}/${IMAGE} : exiting" error "line ${LINENO} can't make image at ${INSTALL_PATH}/${IMAGE} : exiting"
exit 1 exit ${ERR_1}
fi fi
DEVICE=$(/sbin/losetup -f --show "${INSTALL_PATH}/${IMAGE}") DEVICE=$(/sbin/losetup -f --show "${INSTALL_PATH}/${IMAGE}")
if [ ${TARGET} = "odroid" ]; then if [ ${TARGET} = "odroid" ]; then
@ -472,7 +395,7 @@ createimage()
pushd "${CONFIG_PATH}/sd_fuse" pushd "${CONFIG_PATH}/sd_fuse"
if [ ${?} -ne 0 ]; then if [ ${?} -ne 0 ]; then
error "line ${LINENO} error directory ${CONFIG_PATH}/sd_fuse does not exists : exiting" error "line ${LINENO} error directory ${CONFIG_PATH}/sd_fuse does not exists : exiting"
exit 1 exit ${ERR_1}
else else
./sd_fusing.sh "${DEVICE}" ./sd_fusing.sh "${DEVICE}"
fi fi
@ -480,25 +403,7 @@ createimage()
fi fi
info "making partitions" info "making partitions"
/sbin/fdisk "${DEVICE}" << EOF echo -e "${FDISK_SCRIPT}" | /sbin/fdisk ${DEVICE}
n
p
1
+128M
t
c
n
p
2
a
1
a
2
w
EOF
# Activate loop device # Activate loop device
/sbin/losetup -d "${DEVICE}" /sbin/losetup -d "${DEVICE}"
@ -510,6 +415,7 @@ EOF
ROOTP="${DEVICE}p2" ROOTP="${DEVICE}p2"
} }
formatpartitions() formatpartitions()
{ {
info "Formatting partitions" info "Formatting partitions"
@ -518,14 +424,14 @@ formatpartitions()
if [ ${?} -ne 0 ]; then if [ ${?} -ne 0 ]; then
error "line ${LINENO} error formating ${BOOTP} : exiting" error "line ${LINENO} error formating ${BOOTP} : exiting"
/sbin/losetup -d "${DEVICE}" /sbin/losetup -d "${DEVICE}"
exit 1 exit ${ERR_1}
fi fi
info "Root : ${ROOTP} as ${2}" info "Root : ${ROOTP} as ${2}"
"/sbin/mkfs.${2}" "${ROOTP}" "/sbin/mkfs.${2}" "${ROOTP}"
if [ ${?} -ne 0 ]; then if [ ${?} -ne 0 ]; then
error "line ${LINENO} error formating ${ROOTP} : exiting" error "line ${LINENO} error formating ${ROOTP} : exiting"
/sbin/losetup -d "${DEVICE}" /sbin/losetup -d "${DEVICE}"
exit 1 exit ${ERR_1}
fi fi
BOOT_UUID=$(blkid -s UUID -o value UUID "${BOOTP}") BOOT_UUID=$(blkid -s UUID -o value UUID "${BOOTP}")
info "Boot UUID: ${BOOT_UUID}" info "Boot UUID: ${BOOT_UUID}"
@ -533,6 +439,7 @@ formatpartitions()
info "Root UUID: ${ROOT_UUID}" info "Root UUID: ${ROOT_UUID}"
} }
copyingsystem() copyingsystem()
{ {
info "mounting partitions, making mountpoint if necessary" info "mounting partitions, making mountpoint if necessary"
@ -540,25 +447,25 @@ copyingsystem()
/bin/mkdir "${BOOT}" /bin/mkdir "${BOOT}"
if [ ${?} -ne 0 ]; then if [ ${?} -ne 0 ]; then
error "line ${LINENO} error making directory ${BOOT} : exiting" error "line ${LINENO} error making directory ${BOOT} : exiting"
exit 1 exit ${ERR_1}
fi fi
fi fi
if ! [ -d "${ROOT}" ]; then if ! [ -d "${ROOT}" ]; then
/bin/mkdir "${ROOT}" /bin/mkdir "${ROOT}"
if [ ${?} -ne 0 ]; then if [ ${?} -ne 0 ]; then
error "line ${LINENO} error making directory ${ROOT} : exiting" error "line ${LINENO} error making directory ${ROOT} : exiting"
exit 1 exit ${ERR_1}
fi fi
fi fi
/bin/mount "${BOOTP}" "${BOOT}" /bin/mount "${BOOTP}" "${BOOT}"
if [ ${?} -ne 0 ]; then if [ ${?} -ne 0 ]; then
error "line ${LINENO} error mounting ${BOOTP} : exiting" error "line ${LINENO} error mounting ${BOOTP} : exiting"
exit 1 exit ${ERR_1}
fi fi
/bin/mount "${ROOTP}" "${ROOT}" /bin/mount "${ROOTP}" "${ROOT}"
if [ ${?} -ne 0 ]; then if [ ${?} -ne 0 ]; then
error "line ${LINENO} error mounting ${ROOTP} : exiting" error "line ${LINENO} error mounting ${ROOTP} : exiting"
exit 1 exit ${ERR_1}
fi fi
info "making /etc/fstab" info "making /etc/fstab"
@ -630,7 +537,7 @@ copyingsystem()
/bin/cp --preserve=mode "${CONFIG_PATH}/brcmfmac434"* "${ROOT}/usr/lib/firmware/brcm/" /bin/cp --preserve=mode "${CONFIG_PATH}/brcmfmac434"* "${ROOT}/usr/lib/firmware/brcm/"
if [ ${?} -ne 0 ]; then if [ ${?} -ne 0 ]; then
error "line ${LINENO} error copying wifi firmware in ${ROOTP}/usr/lib/firmware/brcm/ : exiting" error "line ${LINENO} error copying wifi firmware in ${ROOTP}/usr/lib/firmware/brcm/ : exiting"
exit 1 exit ${ERR_1}
fi fi
fi fi
@ -680,17 +587,18 @@ copyingsystem()
/bin/rmdir "${BOOT}" "${ROOT}" /bin/rmdir "${BOOT}" "${ROOT}"
else else
error "line ${LINENO} error unmounting ${ROOT} or ${BOOT} : exiting" error "line ${LINENO} error unmounting ${ROOT} or ${BOOT} : exiting"
exit 1 exit ${ERR_1}
fi fi
/usr/sbin/partx -d "${DEVICE}" /usr/sbin/partx -d "${DEVICE}"
if [ ${?} -ne 0 ]; then if [ ${?} -ne 0 ]; then
error "line ${LINENO} warning : error unmounting ${DEVICE} " error "line ${LINENO} warning : error unmounting ${DEVICE} "
exit 1 exit ${ERR_1}
fi fi
warning "You can now burn the image ( ${INSTALL_PATH}/${IMAGE} ) on SD card" warning "You can now burn the image ( ${INSTALL_PATH}/${IMAGE} ) on SD card"
} }
# Copying files common to all systems # Copying files common to all systems
copyingcommon() copyingcommon()
{ {
@ -700,6 +608,56 @@ copyingcommon()
chown root:root "${ROOT}/usr/local/bin/" chown root:root "${ROOT}/usr/local/bin/"
} }
function preImgCreation()
{
error "This function is called if no sourced file about fdisk was lauched."
return 1
}
function postPrepareChroot()
{
error "This function is called if no sourced file contain postPrepareChroot function."
return 1
}
ERR_1=1
ERR_DEFAULT_CONFIG=2
ERR_NO_CONFIG_FILE=3
ERR_4=4
ERR_5=5
ERR_NO_SPACE=6
ERR_7=7
ERR_8=8
ERR_9=9
#######################
# PROGRAMM START HERE #
#######################
info ${0}
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}")
#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
if [ ${#} == 0 ]; then if [ ${#} == 0 ]; then
help help
exit exit
@ -708,13 +666,12 @@ fi
# parsing commandline # parsing commandline
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} -- "${@}") 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} -- "${@}")
if [ ${?} -ne 0 ] ; then error "line ${LINENO} Failed parsing options." >&2 ; exit 1 ; fi if [ ${?} -ne 0 ] ; then error "line ${LINENO} Failed parsing options." >&2 ; exit ${ERR_1} ; fi
eval set -- "${TEMP}" eval set -- "${TEMP}"
echo "${TEMP}" echo "${TEMP}"
# Note the quotes around `$TEMP': they are essential! Or not, $( ) do the same as ` ` # Note the quotes around `$TEMP': they are essential! Or not, $( ) do the same as ` `. But there are the ` ' used ?
while true; while true; do
do
case "${1}" in case "${1}" in
-h|--help) -h|--help)
help help
@ -800,7 +757,7 @@ do
break;; break;;
*) *)
error "Parameter ${1} does not exists " error "Parameter ${1} does not exists "
exit 1;; exit ${ERR_1};;
esac esac
done done
@ -809,34 +766,34 @@ done
if ! [ -d "${CONFIG_PATH}" ]; then if ! [ -d "${CONFIG_PATH}" ]; then
info " Config path does not exists, defaulting to ./platforms/${TARGET}" info " Config path does not exists, defaulting to ./platforms/${TARGET}"
CONFIG_PATH="${PLATFORMS_PATH}/${TARGET}" CONFIG_PATH="${PLATFORMS_PATH}/${TARGET}"
warning "Do you want i make it and copy the template file in? [Y|n] " warning "Do you want to create it and to copy the template file in? [Y|n] "
read yn read yn
if [ -z ${yn} ] || [ ${yn} = "Y" ] || [ ${yn} = "y" ]; then if [ -z ${yn} ] || [ ${yn} = "Y" ] || [ ${yn} = "y" ]; then
/usr/bin/mkdir "${CONFIG_PATH}/" /usr/bin/mkdir "${CONFIG_PATH}/"
/usr/bin/cp --preserve=mode "${SOURCE_PATH}/config.template" "${CONFIG_PATH}/mageia4arm.cfg" /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" warning "You need now to modify the config file (${CONFIG_PATH}/mageia4arm.cfg) and relaunch the script"
exit 2 exit ${ERR_DEFAULT_CONFIG}
else else
error( "Error: Can't continue without config file, exiting" ) error( "Error: Can't continue without config file, exiting" )
exit 3 exit ${ERR_NO_CONFIG_FILE}
fi fi
fi fi
if [ -e "${CONFIG_PATH}/mageia4arm.cfg" ]; then if [ -e "${CONFIG_PATH}/mageia4arm.cfg" ]; then
info "using ${CONFIG_PATH}/mageia4arm.cfg as config" info "using ${CONFIG_PATH}/mageia4arm.cfg as config"
source "${CONFIG_PATH}/mageia4arm.cfg" #NOTE1 : Here is sourced a file with variables. source "${CONFIG_PATH}/mageia4arm.cfg" #NOTE1 : Here is sourced a file with variables.
else else
warning "Config file does not exists, do you want i copy template ? [Y|n] " warning "Config file does not exists, do you want i copy template ? [Y|n] "
read yn read yn
if [ -z ${yn} ] || [ ${yn} = "Y" ] || [ ${yn} = "y" ]; then if [ -z ${yn} ] || [ ${yn} = "Y" ] || [ ${yn} = "y" ]; then
/usr/bin/cp --preserve=mode "${SOURCE_PATH}/mageia4arm.cfg.template" "${CONFIG_PATH}/mageia4arm.cfg" /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" warning "You need now to modify the config file (${CONFIG_PATH}/mageia4arm.cfg) and relaunch the script"
exit 2 exit ${ERR_DEFAULT_CONFIG}
fi fi
fi
else # What are this "else fi" related to ?
fi fi
# else # What are this "else fi" related to ?
#
# fi
if ! [ -z "${IMAGE_SIZE_P}" ]; then if ! [ -z "${IMAGE_SIZE_P}" ]; then
IMAGE_SIZE=${IMAGE_SIZE_P} IMAGE_SIZE=${IMAGE_SIZE_P}
@ -869,24 +826,29 @@ BUILD_PATH="${INSTALL_PATH}/build"
ARM_VERSION="armv7hl" ARM_VERSION="armv7hl"
# assign function for building image of TARGET ( rpi, odroid ) # assign function for building image of TARGET ( rpi, odroid )
case ${TARGET} in #NOTE2 : Why isn't it inside the sourced file ? Inside the .cfg ? It will make the code more flexible. # case ${TARGET} in #NOTE2 : Why isn't it inside the sourced file ? Inside the .cfg ? It will make the code more flexible.
"bananaPro") # "bananaPro")
CREATEIMG="createbproimage" # CREATEIMG="createbproimage"
;; # ;;
#
# "odroid")
# CREATEIMG="createxu3image"
# ;;
#
# "rpi")
# CREATEIMG="createrpiimage"
# ;;
#
# *)
# error "No Target : ${TARGET}"
# exit ${ERR_1}
# ;;
# esac
"odroid") # Assigne a script for creating a particular target image (rpi, odroid, ...)
CREATEIMG="createxu3image" if [ -e "${CONFIG_PATH}/specialFunctions.sh" ]; then
;; source "${CONFIG_PATH}/specialFunctions.sh"
fi
"rpi")
CREATEIMG="createrpiimage"
;;
*)
error "No Target : ${TARGET}"
exit 1
;;
esac
info "target : ${TARGET}" info "target : ${TARGET}"
info "target_version : ${TARGET_VERSION}" info "target_version : ${TARGET_VERSION}"
@ -909,13 +871,13 @@ if [ "${OPT}" != "clean" ]; then
/bin/mkdir -p "${INSTALL_PATH}" /bin/mkdir -p "${INSTALL_PATH}"
if [ -z ${?} ]; then if [ -z ${?} ]; then
error "line ${LINENO} can't make directory ${INSTALL_PATH} , exiting" error "line ${LINENO} can't make directory ${INSTALL_PATH} , exiting"
exit 1 exit ${ERR_1}
fi fi
fi fi
cd "${INSTALL_PATH}" cd "${INSTALL_PATH}"
if [ -z ${?} ]; then if [ -z ${?} ]; then
error "line ${LINENO} can't change to directory ${INSTALL_PATH} , exiting" error "line ${LINENO} can't change to directory ${INSTALL_PATH} , exiting"
exit 1 exit ${ERR_1}
fi fi
fi fi
@ -936,7 +898,7 @@ case ${OPT} in
echo -e "Not enough space on disk\nDo you want to continue anyway ? [Y,n]" echo -e "Not enough space on disk\nDo you want to continue anyway ? [Y,n]"
read yn read yn
if [ ${yn} = "n" ]; then if [ ${yn} = "n" ]; then
exit 6 exit ${ERR_NO_SPACE}
fi fi
fi fi
createchroot createchroot
@ -945,7 +907,8 @@ case ${OPT} in
installbasesystem installbasesystem
preparechroot preparechroot
jumpchroot jumpchroot
${CREATEIMG} # ${CREATEIMG}
createImageWrap
;; ;;
"createchroot") "createchroot")
createchroot createchroot
@ -963,9 +926,10 @@ case ${OPT} in
verify_disk_space verify_disk_space
if [ ${?} -eq 1 ]; then if [ ${?} -eq 1 ]; then
warning "Not enough space on disk" warning "Not enough space on disk"
exit 6 exit ${ERR_NO_SPACE}
fi fi
${CREATEIMG} # ${CREATEIMG}
createImageWrap
;; ;;
"installbasesystem") "installbasesystem")
installbasesystem installbasesystem
@ -976,3 +940,5 @@ esac
if ! [ -z ${ERRORN} ]; then if ! [ -z ${ERRORN} ]; then
warning "Some errors occurs : ${ERRORN} errors" warning "Some errors occurs : ${ERRORN} errors"
fi fi
exit ${ERRORN}