diff options
Diffstat (limited to 'functions.sh')
-rwxr-xr-x | functions.sh | 503 |
1 files changed, 318 insertions, 185 deletions
diff --git a/functions.sh b/functions.sh index 677af95..78285bc 100755 --- a/functions.sh +++ b/functions.sh @@ -1,7 +1,7 @@ #!/usr/bin/bash -# Copyright (C) 2017-2018 Daniel Tartavel-jeannot <contact@librepc.com> -# Jean-Baptiste Biernacki <j.biernacki@free.fr> +# Copyright (C) 2017-2020 Daniel Tartavel-jeannot <contact@librepc.com> +# 2019-2020 Jean-Baptiste Biernacki <j.biernacki@free.fr> # Copyright (C) 2020 Neal Gompa <ngompa13@gmail.com> # # This program is free software; you can redistribute it and/or modify @@ -24,6 +24,19 @@ function timestamp() { date "+[%H:%M:%S]" } +function exit(){ + if [ 0 -ne ${#} ]; then + if [ 0 -ne ${1} ]; then + warning "unmounting all mounted files before exit" + unmountdevsysproc + unmountingPartitions + unloopingImage + fi + fi + + unset exit + exit $@ +} function WaitToContinue() { read -p "Break... Press [ENTER] to continue." GARBAGE @@ -46,8 +59,7 @@ function error() { } -function verify_disk_space() -{ +function verify_disk_space() { 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" @@ -62,8 +74,7 @@ function verify_disk_space() # creation of install path and copy of qemu ( installing it if not yet installed ) -function createchroot() -{ +function createchroot() { title "Making chroot" if ! [ -f /usr/share/distribution-gpg-keys/mageia/RPM-GPG-KEY-Mageia ]; then title "distribution-gpg-keys package not present : installing distribution-gpg-keys" @@ -85,6 +96,7 @@ function createchroot() fi fi # Starting qemu service if not started + info "check systemd-binfmt service : " /usr/bin/systemctl is-active systemd-binfmt.service if [ ${?} -ne 0 ]; then title "Starting systemd-binfmt.service" @@ -93,20 +105,19 @@ function createchroot() error "line ${LINENO} can't start qemu-user-static : exiting" exit ${ERR_1} fi - else - title "Restarting systemd-binfmt.service" - /usr/bin/systemctl restart systemd-binfmt.service - if [ ${?} -ne 0 ]; then - error "line ${LINENO} can't start qemu-user-static : exiting" - exit ${ERR_1} - fi +# else +# title "Restarting systemd-binfmt.service" +# /usr/bin/systemctl restart systemd-binfmt.service +# if [ ${?} -ne 0 ]; then +# error "line ${LINENO} can't start qemu-user-static : exiting" +# exit ${ERR_1} +# fi fi return 0 } # enabling extra Mageia repositories -function genusemirroroptions() -{ +function genusemirroroptions() { DNF_MIRROROPTS="--config=${DNF_CONFIGPATH} --forcearch=${ARM_VERSION} --nogpgcheck --releasever=${MAGEIA_VERSION}" if [ ! -z "${MIRROR}" ]; then @@ -133,8 +144,7 @@ function genusemirroroptions() } # enabling extra Mageia repositories -function enableextrarepos() -{ +function enableextrarepos() { extrasect_baseprefix="mageia" # if [ "${MAGEIA_VERSION}" = "cauldron" ]; then # extrasect_baseprefix="cauldron" @@ -173,8 +183,7 @@ function enableextrarepos() } # adding Mageia urpmi repositories -function addurpmimedia() -{ +function addurpmimedia() { title "Creating media ${MIRROR}" info "Removing old media" @@ -214,8 +223,7 @@ function addurpmimedia() return 0 } -function updateurpmmirror() -{ +function updateurpmmirror() { title "updating mirror" /sbin/urpmi.update -a --urpmi-root "${BUILD_PATH}" if [ ${?} -ne 0 ]; then @@ -225,8 +233,7 @@ function updateurpmmirror() return 0 } -function installbasesystem() -{ +function installbasesystem() { # Create Build path if ! [ -d "${BUILD_PATH}" ]; then warning "Build path ( ${BUILD_PATH} ) does not exist, do you want to create it ? [Y|n] " @@ -272,17 +279,16 @@ function installbasesystem() return 0 } -function installpkg() -{ +function installpkg() { if [ ${INSTALL_METHOD} = "urpmi" ]; then - /usr/sbin/urpmi --urpmi-root "$BUILD_PATH" --ignorearch --no-verify-rpm --auto --split-level 200 --split-length 200 $3 $1; + /usr/sbin/urpmi --urpmi-root "${BUILD_PATH}" --root "${BUILD_PATH}" --ignorearch --no-verify-rpm --auto --split-level 200 --split-length 200 $3 $1; else /usr/bin/dnf $2 --installroot="${BUILD_PATH}" ${DNF_MIRROROPTS} --assumeyes install $1; fi } -function preparechroot() -{ + +function preparechroot() { title "Preparing chrooting in ${BUILD_PATH}" info "making /etc/hostname" @@ -297,7 +303,7 @@ function preparechroot() fi info "configuring second_stage_install.sh for ${INSTALL_METHOD}" if [ ${INSTALL_METHOD} = "urpmi" ]; then - sed -i -e "s/<INSTALL_EXEC>/sbin\/urpmi --no-verify-rpm --auto/g" "${BUILD_PATH}/second_stage_install.sh" + sed -i -e "s/<INSTALL_EXEC>/sbin\/urpmi --no-verify-rpm --auto --split-length 0/g" "${BUILD_PATH}/second_stage_install.sh" else sed -i -e "s/<INSTALL_EXEC>/bin\/dnf --nogpgcheck --assumeyes install/g" "${BUILD_PATH}/second_stage_install.sh" fi @@ -329,32 +335,76 @@ function preparechroot() return 0 } - -function jumpchroot() -{ - title "chrooting to ${BUILD_PATH}" +function mountdevsysproc(){ info "mounting dev, sys, proc directories in chroot" /usr/bin/mount -B /dev "${BUILD_PATH}/dev" +# mkdir ${BUILD_PATH}/dev +# ln -s ${DEVICE} ${BUILD_PATH}/dev/loop0 +# if [ 1 -eq ${SEPARATE_BOOT_PARTITION} ]; then +# ln -s ${BOOTP} ${BUILD_PATH}/dev/loop0p1 +# ln -s ${ROOTP} ${BUILD_PATH}/dev/loop0p2 +# else +# ln -s ${ROOTP} ${BUILD_PATH}/dev/loop0p1 +# fi if [ ${?} -ne 0 ]; then error "line ${LINENO} error mounting ${BUILD_PATH}/dev : exiting" exit ${ERR_1} fi + MOUNTED_DEV=true /usr/bin/mount -B /sys "${BUILD_PATH}/sys" if [ ${?} -ne 0 ]; then error "line ${LINENO} error mounting ${BUILD_PATH}/sys : exiting" exit ${ERR_1} fi + MOUNTED_SYS=true /usr/bin/mount -B /proc "${BUILD_PATH}/proc" if [ ${?} -ne 0 ]; then error "line ${LINENO} error mounting ${BUILD_PATH}/proc : exiting" exit ${ERR_1} fi + MOUNTED_PROC=true + return 0 +} + +function unmountdevsysproc(){ + info "unmounting dev, sys, proc" +# LIST_MOUNTED=$(/usr/bin/mount -l | grep mageia4arm) + if [ ${MOUNTED_DEV:=false} = true ]; then + /usr/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 + fi + if [ ${MOUNTED_PROC:=false} = true ]; then + /usr/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 + fi + if [ ${MOUNTED_SYS:=false} = true ]; then + /usr/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 + fi + return 0 +} + +function jumpchroot() { + title "chrooting to ${BUILD_PATH}" + + mountdevsysproc + info "Copying resolv.conf" /usr/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" exit ${ERR_1} fi + info "chrooting to ${BUILD_PATH}" if [ "$OPT" = "chroot" ]; then info "/sbin/chroot ${BUILD_PATH}" @@ -374,28 +424,13 @@ function jumpchroot() fi fi - info "unmounting dev, sys, proc" - /usr/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 - /usr/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 - /usr/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 + unmountdevsysproc + return 0 } -function createImageWrap() -{ +function createImageWrap() { title "Wrap image creation" preImgCreation if [ ${?} -ne 0 ]; then @@ -403,18 +438,22 @@ function createImageWrap() exit ${ERR_1} fi createimage - if [ -z "${BOOTFS}" ]; then - BOOTFS="ext4" - fi + +# loopingImage + + partitionningimage + + BOOTFS=${BOOTFS:="ext4"} formatpartitions ${BOOTFS} ext4 + + loopingImage return 0 } - -function createimage() -{ - title " in ${IMAGE}" +function createimage() { + title "Createimage" + info "will be the file : ${INSTALL_PATH}/${IMAGE}" if [ -f "${INSTALL_PATH}/${IMAGE}" ]; then warning "Deleting previous image" /usr/bin/rm -f "${INSTALL_PATH}/${IMAGE}" @@ -424,81 +463,139 @@ function createimage() fi fi - warning "please wait until end of image creation" - /usr/bin/dd if=/dev/zero of="${INSTALL_PATH}/${IMAGE}" bs=1MB count=$(( ${IMAGE_SIZE} * 1024 )) status=progress +# warning "please wait until end of image creation" +# /usr/bin/dd if=/dev/zero of="${INSTALL_PATH}/${IMAGE}" bs=1MB count=$(( ${IMAGE_SIZE} * 1024 )) status=progress + /usr/bin/truncate -s ${IMAGE_SIZE}G "${INSTALL_PATH}/${IMAGE}" if [ ${?} -ne 0 ]; then error "line ${LINENO} can't make image at ${INSTALL_PATH}/${IMAGE} : exiting" exit ${ERR_1} fi + /usr/bin/chown ${USER}:${USER} "${INSTALL_PATH}/${IMAGE}" - loopingImage - - if [ ${?} -ne 0 ]; then - error "line ${LINENO} error in the process ${CONFIG_PATH}/specialFunctions.sh ." - exit ${ERR_1} - fi - - info "making partitions" - echo -e "${FDISK_SCRIPT}" | /sbin/fdisk ${DEVICE} + return 0 +} - #Activate 'pY' : /dev/loopXpY - partx -vu "${DEVICE}" - #Previous function give us a list of partition. It is easy to get it and define prior this list the partition. - #But... How to distinguish between the boot p1 and the root p2 if both are empty and ext4 ? ... - if [ 1 -eq ${SEPARATE_BOOT_PARTITION} ]; then - BOOTP="${DEVICE}p1" - ROOTP="${DEVICE}p2" +function partitionningimage() { + title "Partitionning image" + +# if [ "x" != "${FDISK_SCRIPT:="x"}" ]; then +# echo -e "${FDISK_SCRIPT}" | /sbin/fdisk ${DEVICE} +# el + if [ "x" != "${SFDISK_SCRIPT:="x"}" ]; then + HDD_INFO="$(echo -e "${SFDISK_SCRIPT}" | /usr/sbin/sfdisk "${INSTALL_PATH}/${IMAGE}")" + echo "${HDD_INFO}" + SECTOR_SIZE="$(echo "${HDD_INFO}" | grep -m1 "Units: sectors" | sed -e 's/^.* \([[:digit:]]\+\) bytes[[:space:]]*$/\1/')" + if [ 1 -eq ${SEPARATE_BOOT_PARTITION} ]; then + BOOT_P_INFO=$(echo "${HDD_INFO}" | grep -m1 -A3 "^Device" | grep "${IMAGE}1" | tr '*' ' ' | sed -e 's/[[:space:]]\+/ /g') + ROOT_P_INFO=$(echo "${HDD_INFO}" | grep -m1 -A3 "^Device" | grep "${IMAGE}2" | tr '*' ' ' | sed -e 's/[[:space:]]\+/ /g') + BOOT_OFFSET_S="$(echo "${BOOT_P_INFO}" | sed -e "s/^.*${IMAGE}[[:digit:]][[:space:]\*]\+//g" | cut -d ' ' -f 1)" + BOOT_NB_SECTORS=$(echo "${BOOT_P_INFO}" | sed -e "s/^.*${IMAGE}[[:digit:]][[:space:]\*]\+//g" | cut -d ' ' -f 3) + BOOT_SIZE_KB="$((${SECTOR_SIZE}*${BOOT_NB_SECTORS}/1024))" + BOOT_SIZE_B="$((${SECTOR_SIZE}*${BOOT_NB_SECTORS}))" + BOOT_OFFSET_KB="$((${SECTOR_SIZE}*${BOOT_OFFSET_S}/1024))" + info "Boot offset : ${BOOT_OFFSET_S}" + info "Boot offset (kB) : ${BOOT_OFFSET_KB}" + info "Boot sectors : ${BOOT_NB_SECTORS}" + info "Boot size (kB) : ${BOOT_SIZE_KB}" + info "Boot size (B) : ${BOOT_SIZE_B}" + else + ROOT_P_INFO=$(echo "${HDD_INFO}" | grep -m1 -A3 "^Device" | grep "${IMAGE}1") + fi + ROOT_OFFSET_S=$(echo "${ROOT_P_INFO}" | sed -e "s/^.*${IMAGE}[[:digit:]][[:space:]\*]\+//g" | cut -d ' ' -f 1) + ROOT_NB_SECTORS=$(echo "${ROOT_P_INFO}" | sed -e "s/^.*${IMAGE}[[:digit:]][[:space:]\*]\+//g" | cut -d ' ' -f 3) + ROOT_SIZE_KB="$((${SECTOR_SIZE}*${ROOT_NB_SECTORS}/1024))" + ROOT_OFFSET_B="$((${SECTOR_SIZE}*${ROOT_OFFSET_S}))" + + info "Root offset : ${ROOT_OFFSET_S}" + info "Root offset (B) : ${ROOT_OFFSET_B}" + info "Root sectors : ${ROOT_NB_SECTORS}" + info "Root size kB : ${ROOT_SIZE_KB}" else - ROOTP="${DEVICE}p1" + error "Error, no partitionning script found." fi + return 0 } - -function loopingImage() -{ +function loopingImage() { title "Looping image ..." # Mettre en place et contrôler des périphériques boucle. # -f, --find trouver le premier périphérique inutilisé # --show afficher le nom du périphérique après configuration (avec -f) - DEVICE=$(/sbin/losetup -f --show "${INSTALL_PATH}/${IMAGE}") +# DEVICE=$(/usr/sbin/losetup -f --show "${INSTALL_PATH}/${IMAGE}") + DEVICE=$(/usr/bin/udisksctl loop-setup -f ${INSTALL_PATH}/${IMAGE} | sed -e 's/^.*\/dev\//\/dev\//' -e 's/\.$//') + info "Image looped on ${DEVICE}" + + + #Previous function give us a list of partition. It is easy to get it and define prior this list the partition. + #But... How to distinguish between the boot p1 and the root p2 if both are empty and ext4 ? ... + if [ 1 -eq ${SEPARATE_BOOT_PARTITION} ]; then + BOOTP="${DEVICE}p1" + ROOTP="${DEVICE}p2" + +# BOOT_UUID=$(/usr/sbin/blkid -s UUID -o value UUID "${BOOTP}") + BOOT_UUID=$(/usr/bin/lsblk -n -o UUID "${BOOTP}") + info "Boot UUID: ${BOOT_UUID}" + else + ROOTP="${DEVICE}p1" + fi + +# ROOT_UUID=$(/usr/sbin/blkid -s UUID -o value UUID "${ROOTP}") + ROOT_UUID=$(/usr/bin/lsblk -n -o UUID "${ROOTP}") + info "Root UUID: ${ROOT_UUID}" + return 0 } -function formatpartitions() -{ +function formatpartitions() { info "Formatting partitions" if [ 1 -eq ${SEPARATE_BOOT_PARTITION} ]; then info "Boot : ${BOOTP} as ${1}" - "/sbin/mkfs.${1}" "${BOOTP}" + if [ "vfat" = ${1} ]; then + temporary=$(mktemp) + truncate -s ${BOOT_SIZE_B} ${temporary} + FSINFO=$(/usr/sbin/mkfs.vfat -v ${temporary} ) # $((${BOOT_SIZE_KB}))) + /usr/bin/dd seek=${BOOT_OFFSET_S} if=${temporary} of=${INSTALL_PATH}/${IMAGE} + BOOT_UUID=$(echo "${FSINFO}" | grep 'Volume ID is' | sed 's/Volume ID is \([[:alnum:]]*\),.*$/\1/') + info "Boot UUID = ${BOOT_UUID}" + rm -f ${temporary} + else + FSINFO=$(yes | /usr/sbin/mkfs.ext4 -E offset=${BOOT_OFFSET_B} ${INSTALL_PATH}/${IMAGE} $((${BOOT_SIZE_KB}))k) + BOOT_UUID=$(echo "${FSINFO}" | grep 'Filesystem UUID' | sed 's/Filesystem UUID: //') + fi +# "/sbin/mkfs.${1}" "${BOOTP}" if [ ${?} -ne 0 ]; then error "line ${LINENO} error formating ${BOOTP} : exiting" - /sbin/losetup -d "${DEVICE}" +# /usr/sbin/losetup -d "${DEVICE}" + udisksctl unmount -b ${BOOTP} exit ${ERR_1} fi - BOOT_UUID=$(blkid -s UUID -o value UUID "${BOOTP}") - info "Boot UUID: ${BOOT_UUID}" +# BOOT_UUID=$(/usr/sbin/blkid -s UUID -o value UUID "${BOOTP}") +# info "Boot UUID: ${BOOT_UUID}" fi info "Root : ${ROOTP} as ${2}" - "/sbin/mkfs.${2}" "${ROOTP}" +# "/sbin/mkfs.${2}" "${ROOTP}" + echo /usr/sbin/mkfs.ext4 -E offset=${ROOT_OFFSET_B} ${INSTALL_PATH}/${IMAGE} $((${ROOT_SIZE_KB}))k + FSINFO=$(yes | /usr/sbin/mkfs.ext4 -E offset=${ROOT_OFFSET_B} ${INSTALL_PATH}/${IMAGE} $((${ROOT_SIZE_KB}))k) if [ ${?} -ne 0 ]; then error "line ${LINENO} error formating ${ROOTP} : exiting" - /sbin/losetup -d "${DEVICE}" +# /usr/sbin/losetup -d "${DEVICE}" +# udisksctl unmount -b ${ROOTP} exit ${ERR_1} fi - ROOT_UUID=$(blkid -s UUID -o value UUID "${ROOTP}") + ROOT_UUID=$(echo "${FSINFO}" | grep 'Filesystem UUID' | sed 's/Filesystem UUID: //') +# ROOT_UUID=$(/usr/sbin/blkid -s UUID -o value UUID "${ROOTP}") info "Root UUID: ${ROOT_UUID}" return 0 } -function generateExtlinux() -{ +function generateExtlinux() { info "Generate extlinux if extlinux.conf exists." if [ -e "${CONFIG_PATH}/extlinux.conf" ]; then info "\tFound extlinux.conf" @@ -507,7 +604,7 @@ function generateExtlinux() /usr/bin/rm -rf "${BUILD_PATH}/boot/extlinux" mkdir -p "${BUILD_PATH}/boot/extlinux" fi - if [ ! -f "${BUILD_PATH}/boot/extlinux/extlinux.conf" ]; then +# if [ ! -f "${BUILD_PATH}/boot/extlinux/extlinux.conf" ]; then info "\tTuning extlinux.conf" cp "${CONFIG_PATH}/extlinux.conf" "${BUILD_PATH}/boot/extlinux/extlinux.conf" #In order to use the UUID, a initrd file is necessary. @@ -515,12 +612,11 @@ function generateExtlinux() sed -i -e "s/<BOOT_ARGS>/${BOOT_ARGS}/g" "${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" - fi +# fi fi } -function copyingsystem() -{ +function copyingsystem() { generateExtlinux info "Remove second_stage_install.sh" @@ -551,47 +647,40 @@ function copyingsystem() copyingcommon sync - warning "You can now burn the image ( ${INSTALL_PATH}/${IMAGE} ) on SD card" - info "pv \"${INSTALL_PATH}/${IMAGE}\" | dd of=/dev/mmcblk#" +# warning "You can now burn the image ( ${INSTALL_PATH}/${IMAGE} ) on SD card" +# info "pv \"${INSTALL_PATH}/${IMAGE}\" | dd of=/dev/mmcblk#" return 0 } -function mountPartitions(){ - info "mounting partitions, making mountpoint if necessary" +function mountPartitions() { + title "mounting partitions, making mountpoint if necessary" + ROOT=$(/usr/bin/udisksctl mount -b ${ROOTP} | sed -e 's/^.* at //' -e 's/\.$//' ) + if [ ${?} -ne 0 ]; then + error "line ${LINENO} error mounting ${ROOTP} : exiting" + exit ${ERR_1} + fi + MOUNTED_ROOT=true + info "Root partition mount in ${ROOT}" + BUILD_PATH=${ROOT} + if [ 1 -eq ${SEPARATE_BOOT_PARTITION} ]; then - if ! [ -d "${BOOT}" ]; then - /usr/bin/mkdir "${BOOT}" - if [ ${?} -ne 0 ]; then - error "line ${LINENO} error making directory ${BOOT} : exiting" - exit ${ERR_1} - fi - fi - /usr/bin/mount "${BOOTP}" "${BOOT}" + BOOT=$(/usr/bin/udisksctl mount -b ${BOOTP} | sed -e 's/^.* at //' -e 's/\.$//' ) if [ ${?} -ne 0 ]; then error "line ${LINENO} error mounting ${BOOTP} : exiting" exit ${ERR_1} fi - fi - - if ! [ -d "${ROOT}" ]; then - /usr/bin/mkdir "${ROOT}" - if [ ${?} -ne 0 ]; then - error "line ${LINENO} error making directory ${ROOT} : exiting" - exit ${ERR_1} - fi - fi - /usr/bin/mount "${ROOTP}" "${ROOT}" - if [ ${?} -ne 0 ]; then - error "line ${LINENO} error mounting ${ROOTP} : exiting" - exit ${ERR_1} + info "boot partition mount in ${BOOT}" + MOUNTED_BOOT=true + + mkdir -p "${BUILD_PATH}/boot/EFI" + /usr/bin/mount -B ${BOOT} "${BUILD_PATH}/boot/EFI" fi } -function unmountingPartitions() -{ +function unmountingPartitions() { title "Unmounting partitions..." # Syncing devices before unmounting @@ -600,79 +689,98 @@ function unmountingPartitions() if [ -z "${BOOTP}" ] && [ -z "${ROOTP}" ] ; then warning "Root partition and Boot partition not defined !" - for LOOP in $(losetup -l -O NAME,BACK-FILE -n | grep "${IMAGE}" | cut -d ' ' -f 1 ) ; do + for LOOP in $(/usr/sbin/losetup -l -O NAME,BACK-FILE -n | grep "${IMAGE}" | cut -d ' ' -f 1 ) ; do IFS=$'\n' - for PARTITION in $(mount -l | grep ${LOOP}); do + for PARTITION in $(/usr/bin/mount -l | grep ${LOOP}); do MOUNTPOINT=$(echo "$PARTITION" | cut -d ' ' -f 3) PARTITION=$(echo "$PARTITION" | cut -d ' ' -f 1) - info "unmount ${PARTITION} and remove ${MOUNTPOINT}" - /usr/bin/umount "${PARTITION}" - if [ ${?} -eq 0 ]; then - /usr/bin/rmdir "${MOUNTPOINT}" - else - error "line ${LINENO} error unmounting ${BOOT}..." + info "unmount ${PARTITION}" # and remove ${MOUNTPOINT}" + udisksctl unmount -b ${PARTITION} +# if [ ${?} -eq 0 ]; then +# /usr/bin/rmdir "${MOUNTPOINT}" +# else +# error "line ${LINENO} error unmounting ${BOOT}..." +# fi + if [ 0 -ne ${?} ]; then + error "line ${LINENO} error unmounting ${PARTITION}..." fi done unset IFS done else - if [ ! -z "${BOOTP}" ]; then - /usr/bin/umount "${BOOTP}" - if [ ${?} -eq 0 ]; then - /usr/bin/rmdir "${BOOT}" - else + if [ ${MOUNTED_BOOT:=false} = true ]; then + udisksctl unmount -b ${BOOTP} + if [ 0 -ne ${?} ]; then error "line ${LINENO} error unmounting ${BOOT}..." fi fi - /usr/bin/umount "${ROOTP}" - if [ ${?} -eq 0 ]; then - /usr/bin/rmdir "${ROOT}" - else - error "line ${LINENO} error unmounting ${ROOT}..." + if [ ${MOUNTED_ROOT:=false} = true ]; then + udisksctl unmount -b ${ROOTP} + if [ 0 -ne ${?} ]; then + error "line ${LINENO} error unmounting ${ROOT}..." + fi fi + +# if [ ! -z "${BOOTP}" ]; then +# udisksctl unmount -b ${BOOTP} +# if [ ${?} -eq 0 ]; then +# /usr/bin/rmdir "${BOOT}" +# else +# error "line ${LINENO} error unmounting ${BOOT}..." +# fi +# fi +# udisksctl unmount -b ${ROOTP} +# if [ ${?} -eq 0 ]; then +# /usr/bin/rmdir "${ROOT}" +# else +# error "line ${LINENO} error unmounting ${ROOT}..." +# fi fi return 0 } -function unloopingImage(){ +function unloopingImage() { title "Unlooping image..." # Syncing devices before unmounting /usr/bin/sync - - # [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}" - for PARTITION in ${LOOP}p* ; do - partx -dv "${PARTITION}" + + if [ "x" != "${DEVICE:="x"}" ]; then + /usr/bin/udisksctl loop-delete -b ${DEVICE} + else +# if [ 0 -ne ${?} ]; then + warning "Unloop failed, try to unmount all partitions from the image..." + info "Looped devices to unmount : $(/usr/sbin/losetup -l -O NAME,BACK-FILE -n | grep "${IMAGE}" | cut -d ' ' -f 1 ) " + + for LOOP in $(/usr/sbin/losetup -l -O NAME,BACK-FILE -n | grep "${IMAGE}" | cut -d ' ' -f 1 ) ; do + for PARTITION in ${LOOP}p* ; do + info "Unmount ${PARTITION}" + udisksctl unmount -b ${PARTITION} + done + info "Unloop ${LOOP}" + /usr/bin/udisksctl loop-delete -b ${LOOP} done -# losetup -d "${LOOP}" - kpartx -d "${INSTALL_PATH}/${IMAGE}" - done + fi return 0 } # Copying files common to all systems -function copyingcommon() -{ +function copyingcommon() { title "Copying common files and configuration" rsync -rlptDH "${SOURCE_PATH}/common/" "${ROOT}/" - rsync -rlptDH "${SOURCE_PATH}/tools/"*.sh "${ROOT}/usr/local/usr/bin/" - chown root:root "${ROOT}/usr/local/usr/bin/" + rsync -rlptDH "${SOURCE_PATH}/tools/"*.sh "${ROOT}/usr/local/bin/" + chown root:root "${ROOT}/usr/local/bin/" return 0 } -function mkfstab() -{ +function mkfstab() { title "making /etc/fstab" + # BUG : For installing kernel inside a chroot, the UUID of root partition is NOT found, Workaround to try : using ${ROOTP} instead. 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" + echo -e "proc\t/proc\tproc\tdefaults\t0\t0\nUUID=${BOOT_UUID}\t/boot/EFI\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 @@ -681,25 +789,26 @@ function mkfstab() # cleaning build space -function clean() -{ +function clean() { title "Cleaning" info "In case script failed or crash inside the chroot, need to unmount dev|sys|proc..." - /bin/umount -lf "${BUILD_PATH}/dev" - /bin/umount -lf "${BUILD_PATH}/sys" - /bin/umount -lf "${BUILD_PATH}/proc" +# udisksctl unmount -b ${PARTITION} +# /bin/umount -lf "${BUILD_PATH}/dev" +# /bin/umount -lf "${BUILD_PATH}/sys" +# /bin/umount -lf "${BUILD_PATH}/proc" + unmountdevsysproc unmountingPartitions unloopingImage # Removing old Build directory - if [ -d "${BUILD_PATH}" ]; then - info "Removing ${BUILD_PATH}" - /usr/bin/rm -Rf "${BUILD_PATH}" - else - warning "${BUILD_PATH} does not exists" - fi +# if [ -d "${BUILD_PATH}" ]; then +# info "Removing ${BUILD_PATH}" +# /usr/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}" @@ -712,8 +821,26 @@ function clean() } -function generateExtra() -{ +function check_extrapackage() { + for i in ${PACKAGE} ; do + /usr/bin/urpmq --urpmi-root "${BUILD_PATH}" --root "${BUILD_PATH}" --ignorearch --no-verify-rpm ${i} + if [ 0 -ne ${?} ]; then + warning "Package ${i} not found !" + else + PACKAGE_VALID+="${i} " + fi + done + return 0 +} + +function extrapackage() { + for i in ${PACKAGE_VALID} ; do + installpkg ${i} + done + return 0 +} + +function generateExtra() { #Set values by default to false. GEN_CHECKSUM=${GEN_CHECKSUM:="false"} GEN_GZ=${GEN_GZ:="false"} @@ -723,40 +850,46 @@ function generateExtra() md5sum "${INSTALL_PATH}/${IMAGE}" > "${INSTALL_PATH}/${IMAGE}.md5" sha512sum "${INSTALL_PATH}/${IMAGE}" > "${INSTALL_PATH}/${IMAGE}.sha512" sha384sum "${INSTALL_PATH}/${IMAGE}" > "${INSTALL_PATH}/${IMAGE}.sha3" + info "${INSTALL_PATH}/${IMAGE}.md5" + info "${INSTALL_PATH}/${IMAGE}.sha512" + info "${INSTALL_PATH}/${IMAGE}.sha3" fi if ${GEN_GZ} ; then title "Image compression" pv "${INSTALL_PATH}/${IMAGE}" | gzip -9 >"${INSTALL_PATH}/${IMAGE}.gz" fi if ${GEN_SIGN} ; then + title "Signing checksums" pushd "${INSTALL_PATH}" - gpg --sign ${IMAGE}.md5 - gpg --sign ${IMAGE}.sha512 - gpg --sign ${IMAGE}.sha384 + if [ -e "${INSTALL_PATH}/${IMAGE}.md5" ]; then + gpg --sign ${IMAGE}.md5 + fi + if [ -e "${INSTALL_PATH}/${IMAGE}.sha512" ]; then + gpg --sign ${IMAGE}.sha512 + fi + if [ -e "${INSTALL_PATH}/${IMAGE}.sha3" ]; then + gpg --sign ${IMAGE}.sha384 + fi popd fi } -function preImgCreation() -{ +function preImgCreation() { error "This function is called if no sourced file about fdisk was lauched." return 1 } -function postPrepareChroot() -{ +function postPrepareChroot() { error "This function is called if no sourced file is containing postPrepareChroot function." return 1 } -function bunrningBootloader() -{ +function bunrningBootloader() { error "This function is called if no sourced file is containing bunrningBootloader function." return 1 } -function copyingCustomSystem() -{ +function copyingCustomSystem() { error "This function is called if no sourced file is containing copyingCustomSystem function." return 1 } |