diff options
-rwxr-xr-x | create_arm_image.sh | 32 | ||||
-rwxr-xr-x | functions.sh | 122 |
2 files changed, 78 insertions, 76 deletions
diff --git a/create_arm_image.sh b/create_arm_image.sh index cf50d82..75c7f7b 100755 --- a/create_arm_image.sh +++ b/create_arm_image.sh @@ -75,7 +75,7 @@ if [ 0 -ne $(echo "${CMD_LINE}" | grep -c '\-\-log') ]; then exit fi -info ${0} +print_info ${0} #Check dependencies : #if [ -e /usr/bin/qemu-arm-static ]; then @@ -240,7 +240,7 @@ done # path of config file if ! [ -d "${CONFIG_PATH}" ]; then - info " Config path does not exists, defaulting to ./platforms/${TARGET}" + print_info " Config path does not exists, defaulting to ./platforms/${TARGET}" CONFIG_PATH="${PLATFORMS_PATH}/${TARGET}" warning "Do you want to create it and to copy the template file in? [Y|n] " read yn @@ -256,7 +256,7 @@ if ! [ -d "${CONFIG_PATH}" ]; then fi if [ -e "${CONFIG_PATH}/mageia4arm.cfg" ]; then - info "using ${CONFIG_PATH}/mageia4arm.cfg as config" + print_info "using ${CONFIG_PATH}/mageia4arm.cfg as config" source "${CONFIG_PATH}/mageia4arm.cfg" #NOTE1 : Here is sourced a file with variables. else warning "Config file does not exists, do you want to copy template ? [Y|n] " @@ -285,7 +285,7 @@ DESKTOP_NAME="${DESKTOP:="noDE"}" IMAGE_BASE="Mageia-${MAGEIA_VERSION}-${TARGET}" IMAGE="${IMAGE_BASE}-${DESKTOP_NAME}.img" -info "Option: "${OPT} +print_info "Option: "${OPT} BUILD_PATH="${INSTALL_PATH}/build-${TARGET}${TARGET_VERSION}" @@ -296,19 +296,19 @@ if [ -e "${CONFIG_PATH}/specialFunctions.sh" ]; then source "${CONFIG_PATH}/specialFunctions.sh" fi -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}" -info "Installation method : ${INSTALL_METHOD}" +print_info "target : ${TARGET}" +print_info "target_version : ${TARGET_VERSION}" +print_info "source path: ${SOURCE_PATH}" +print_info "Install path: ${INSTALL_PATH}" +print_info "Build path: ${BUILD_PATH}" +print_info "Commande : ${CMDNAME}" +print_info "Firmware path : ${FIRMWARE_PATH}" +print_info "Firmware dir : ${FIRMWARE_DIR}" +print_info "Installation method : ${INSTALL_METHOD}" # change dir to install path and create it if not existing if [ "${OPT}" != "clean" ]; then - info "cd ${INSTALL_PATH}" + print_info "cd ${INSTALL_PATH}" if ! [ -e "${INSTALL_PATH}" ]; then /usr/bin/mkdir -p "${INSTALL_PATH}" if [ -z ${?} ]; then @@ -326,7 +326,7 @@ fi #if no parameters then display help message OPT=${OPT:="--help"} -info "Image size is: ${IMAGE_SIZE} GB" +print_info "Image size is: ${IMAGE_SIZE} GB" case ${OPT} in @@ -362,7 +362,7 @@ case ${OPT} in unloopingImage warning "You can now burn the image ( ${INSTALL_PATH}/${IMAGE} ) on SD card" - info "pv \"${INSTALL_PATH}/${IMAGE}\" | dd of=/dev/mmcblk#" + print_info "pv \"${INSTALL_PATH}/${IMAGE}\" | dd of=/dev/mmcblk#" generateExtra ;; "createchroot") diff --git a/functions.sh b/functions.sh index e0c33d0..92c86b8 100755 --- a/functions.sh +++ b/functions.sh @@ -46,7 +46,7 @@ function title() { echo -e "\e[1;32m$(timestamp) ${1}\e[0m" } -function info() { +function print_info() { echo -e "\e[36m$(timestamp) ${1}\e[0m" } @@ -62,11 +62,11 @@ function error() { 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" + print_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" + print_info "correct the problem and relaunch the script with parameter --create-rpi-image" + print_info "${0} --size ${IMAGE_SIZE} --create-rpi-image" return 1 fi return 0 @@ -96,7 +96,7 @@ function createchroot() { fi fi # Starting qemu service if not started - info "check systemd-binfmt service : " + print_info "check systemd-binfmt service : " /usr/bin/systemctl is-active systemd-binfmt.service if [ ${?} -ne 0 ]; then title "Starting systemd-binfmt.service" @@ -186,14 +186,14 @@ function enableextrarepos() { function addurpmimedia() { title "Creating media ${MIRROR}" - info "Removing old media" + print_info "Removing old media" /sbin/urpmi.removemedia --urpmi-root "${BUILD_PATH}" -a - info "Adding media" + print_info "Adding media" if [ ! -z "${MIRROR}" ] ; then /sbin/urpmi.addmedia --urpmi-root "${BUILD_PATH}" --ignorearch --distrib "${MIRROR}" else - info "MIRROR variable not set, using mirrorlist." + print_info "MIRROR variable not set, using mirrorlist." /sbin/urpmi.addmedia --urpmi-root "${BUILD_PATH}" --ignorearch --distrib --mirrorlist "http://mirrors.mageia.org/api/mageia.${MAGEIA_VERSION}.${ARM_VERSION}.list" fi @@ -249,11 +249,11 @@ function installbasesystem() { exit ${ERR_1} fi else - info "Build path exists" + print_info "Build path exists" fi # Workaround mga#26044. - info "Preparing root filesystem tree" + print_info "Preparing root filesystem tree" mkdir -p "${BUILD_PATH}/usr/bin" mkdir -p "${BUILD_PATH}/usr/sbin" mkdir -p "${BUILD_PATH}/usr/lib" @@ -291,28 +291,28 @@ function installpkg() { function preparechroot() { title "Preparing chrooting in ${BUILD_PATH}" - info "making /etc/hostname" + print_info "making /etc/hostname" echo "${HOSTNAME:="localhost.localdomain"}" > "${BUILD_PATH}/etc/hostname" - info "copying second stage script in ${BUILD_PATH}" + print_info "copying second stage script in ${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" exit ${ERR_1} fi - info "configuring second_stage_install.sh for ${INSTALL_METHOD}" + print_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 --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 - info "Preparation for setting root and user account" + print_info "Preparation for setting root and user account" if [ -n "${ROOT_PWD}" ]; then #If root password defined, it will be setted at the end of the chroot of the second_stage_install.sh script echo -e "/usr/bin/passwd << EOF\n${ROOT_PWD}\n${ROOT_PWD}\nEOF\n" >>"${BUILD_PATH}/second_stage_install.sh" else - info "No root password... One password will be set at the first login." + print_info "No root password... One password will be set at the first login." echo -e "/usr/bin/passwd -d root\n/usr/bin/passwd -e root\n" >>"${BUILD_PATH}/second_stage_install.sh" fi @@ -324,7 +324,7 @@ function preparechroot() { echo -e "/usr/bin/passwd -d ${ID_USER}\n" >>"${BUILD_PATH}/second_stage_install.sh" fi else - info "No user defined, no user account created." + print_info "No user defined, no user account created." fi postPrepareChroot @@ -336,7 +336,7 @@ function preparechroot() { } function mountdevsysproc(){ - info "mounting dev, sys, proc directories in chroot" + print_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 @@ -367,7 +367,7 @@ function mountdevsysproc(){ } function unmountdevsysproc(){ - info "unmounting dev, sys, proc" + print_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" @@ -398,16 +398,16 @@ function jumpchroot() { mountdevsysproc - info "Copying resolv.conf" + print_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}" + print_info "chrooting to ${BUILD_PATH}" if [ "$OPT" = "chroot" ]; then - info "/sbin/chroot ${BUILD_PATH}" + print_info "/sbin/chroot ${BUILD_PATH}" /sbin/chroot "${BUILD_PATH}" RET=${?} if [ ${RET} -ne 0 ]; then @@ -415,7 +415,7 @@ function jumpchroot() { ERRORN=$((${ERRORN}+1)) fi else - info "/sbin/chroot --userspec root:root ${BUILD_PATH} /usr/bin/bash -v -c 'bash /second_stage_install.sh 2>&1'" + print_info "/sbin/chroot --userspec root:root ${BUILD_PATH} /usr/bin/bash -v -c 'bash /second_stage_install.sh 2>&1'" /sbin/chroot --userspec root:root "${BUILD_PATH}" /usr/bin/bash -v -c 'bash /second_stage_install.sh 2>&1' RET=${?} if [ ${RET} -ne 0 ]; then @@ -453,7 +453,7 @@ function createImageWrap() { function createimage() { title "Createimage" - info "will be the file : ${INSTALL_PATH}/${IMAGE}" + print_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}" @@ -494,11 +494,11 @@ function partitionningimage() { 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}" + print_info "Boot offset : ${BOOT_OFFSET_S}" + print_info "Boot offset (kB) : ${BOOT_OFFSET_KB}" + print_info "Boot sectors : ${BOOT_NB_SECTORS}" + print_info "Boot size (kB) : ${BOOT_SIZE_KB}" + print_info "Boot size (B) : ${BOOT_SIZE_B}" else ROOT_P_INFO=$(echo "${HDD_INFO}" | grep -m1 -A3 "^Device" | grep "${IMAGE}1") fi @@ -507,10 +507,10 @@ function partitionningimage() { 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}" + print_info "Root offset : ${ROOT_OFFSET_S}" + print_info "Root offset (B) : ${ROOT_OFFSET_B}" + print_info "Root sectors : ${ROOT_NB_SECTORS}" + print_info "Root size kB : ${ROOT_SIZE_KB}" else error "Error, no partitionning script found." fi @@ -526,7 +526,7 @@ function loopingImage() { # --show afficher le nom du périphérique après configuration (avec -f) # 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}" + print_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. @@ -538,30 +538,30 @@ function loopingImage() { # 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}" + print_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}" + print_info "Root UUID: ${ROOT_UUID}" return 0 } function formatpartitions() { - info "Formatting partitions" + print_info "Formatting partitions" if [ 1 -eq ${SEPARATE_BOOT_PARTITION} ]; then - info "Boot : ${BOOTP} as ${1}" + print_info "Boot : ${BOOTP} as ${1}" 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}" + print_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) @@ -575,10 +575,10 @@ function formatpartitions() { exit ${ERR_1} fi # BOOT_UUID=$(/usr/sbin/blkid -s UUID -o value UUID "${BOOTP}") -# info "Boot UUID: ${BOOT_UUID}" +# print_info "Boot UUID: ${BOOT_UUID}" fi - info "Root : ${ROOTP} as ${2}" + print_info "Root : ${ROOTP} as ${2}" # "/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) @@ -590,22 +590,22 @@ function formatpartitions() { fi 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}" + print_info "Root UUID: ${ROOT_UUID}" return 0 } function generateExtlinux() { - info "Generate extlinux if extlinux.conf exists." + print_info "Generate extlinux if extlinux.conf exists." if [ -e "${CONFIG_PATH}/extlinux.conf" ]; then - info "\tFound extlinux.conf" + print_info "\tFound extlinux.conf" if [ ! -d "${BUILD_PATH}/boot/extlinux" ]; then - info "making /boot/extlinux/extlinux.conf" + print_info "making /boot/extlinux/extlinux.conf" /usr/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" + print_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. sed -i -e "s/<UUID>/${ROOT_UUID}/g" "${BUILD_PATH}/boot/extlinux/extlinux.conf" @@ -619,7 +619,7 @@ function generateExtlinux() { function copyingsystem() { generateExtlinux - info "Remove second_stage_install.sh" + print_info "Remove second_stage_install.sh" /usr/bin/rm -f "${BUILD_PATH}/second_stage_install.sh" ### BUG : rpi3b+64b is using a bootloader partition, in which only the bootloader lays. Here, everything is copying into. @@ -629,12 +629,12 @@ function copyingsystem() { rm -rf "${ARM_BOOT}" mkdir -p "${ARM_BOOT}" fi - info "copying Mageia image to root partition" + print_info "copying Mageia image to root partition" /usr/bin/rsync -rlptogDH --exclude "${ARM_BOOT}/" --exclude "qemu-arm-static*" "${BUILD_PATH}/" "${ROOT}/" /usr/bin/rsync -rlptogDH "${ARM_BOOT}/" "${BOOT}/" #/usr/bin/rsync -rlptogDH "${BUILD_PATH}/boot/" "${BOOT}/" else - info "copying Mageia image to root partition" + print_info "copying Mageia image to root partition" /usr/bin/rsync -rlptogDH --exclude "qemu-arm-static*" "${BUILD_PATH}/" "${ROOT}/" fi @@ -648,7 +648,7 @@ function copyingsystem() { sync # warning "You can now burn the image ( ${INSTALL_PATH}/${IMAGE} ) on SD card" -# info "pv \"${INSTALL_PATH}/${IMAGE}\" | dd of=/dev/mmcblk#" +# print_info "pv \"${INSTALL_PATH}/${IMAGE}\" | dd of=/dev/mmcblk#" return 0 } @@ -662,7 +662,7 @@ function mountPartitions() { exit ${ERR_1} fi MOUNTED_ROOT=true - info "Root partition mount in ${ROOT}" + print_info "Root partition mount in ${ROOT}" BUILD_PATH=${ROOT} if [ 1 -eq ${SEPARATE_BOOT_PARTITION} ]; then @@ -671,7 +671,7 @@ function mountPartitions() { error "line ${LINENO} error mounting ${BOOTP} : exiting" exit ${ERR_1} fi - info "boot partition mount in ${BOOT}" + print_info "boot partition mount in ${BOOT}" MOUNTED_BOOT=true mkdir -p "${BUILD_PATH}/boot/EFI" @@ -694,7 +694,7 @@ function unmountingPartitions() { 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}" + print_info "unmount ${PARTITION}" # and remove ${MOUNTPOINT}" udisksctl unmount -b ${PARTITION} # if [ ${?} -eq 0 ]; then # /usr/bin/rmdir "${MOUNTPOINT}" @@ -713,6 +713,8 @@ function unmountingPartitions() { if [ 0 -ne ${?} ]; then error "line ${LINENO} error unmounting ${BOOT}..." fi + sync + sleep 4s fi if [ ${MOUNTED_ROOT:=false} = true ]; then udisksctl unmount -b ${ROOTP} @@ -750,14 +752,14 @@ function unloopingImage() { 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 ) " + print_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}" + print_info "Unmount ${PARTITION}" udisksctl unmount -b ${PARTITION} done - info "Unloop ${LOOP}" + print_info "Unloop ${LOOP}" /usr/bin/udisksctl loop-delete -b ${LOOP} done fi @@ -792,7 +794,7 @@ function mkfstab() { function clean() { title "Cleaning" - info "In case script failed or crash inside the chroot, need to unmount dev|sys|proc..." + print_info "In case script failed or crash inside the chroot, need to unmount dev|sys|proc..." # TODO find what blocks the umount. unmountdevsysproc @@ -800,7 +802,7 @@ function clean() { unloopingImage # removing old image - info "Removing ${IMAGE_BASE}* files" + print_info "Removing ${IMAGE_BASE}* files" /usr/bin/rm -f "${INSTALL_PATH}/${IMAGE_BASE}*.img" /usr/bin/rm -f "${INSTALL_PATH}/${IMAGE_BASE}*.gz" /usr/bin/rm -f "${INSTALL_PATH}/${IMAGE_BASE}*.md5" @@ -841,9 +843,9 @@ 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" + print_info "${INSTALL_PATH}/${IMAGE}.md5" + print_info "${INSTALL_PATH}/${IMAGE}.sha512" + print_info "${INSTALL_PATH}/${IMAGE}.sha3" fi if ${GEN_GZ} ; then title "Image compression" |