1
0

preparation modification structurelles

This commit is contained in:
Jybz 2019-11-03 22:34:36 +00:00
parent ec26c7845e
commit 013c1e174f

View File

@ -16,40 +16,29 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#Change the local to the most global
# export LC_ALL=C.UTF-8
export LC_ALL=C
function WaitToContinue()
{
function WaitToContinue() {
read -p "Break... Press [ENTER] to continue." GARBAGE
}
function title()
{
function title() {
echo -e "\e[1;32m${1}\e[0m"
}
function info()
{
function info() {
echo -e "\e[36m${1}\e[0m"
}
function warning()
{
function warning() {
echo -e "\e[1;35m${1}\e[0m"
}
function error()
{
function error() {
echo -e "\e[1;31m${1}\e[0m"
}
function help()
{
function help() {
echo -e "${CMDNAME} [option] [size of image in Go]"
echo -e "Options:"
echo -e "--all create ready to burn image of Mageia ${MAGEIA_VERSION}"
@ -62,6 +51,7 @@ function help()
echo -e "--bootfs filesystem of boot partition (ext4 or vfat) default: ext4"
echo -e "--nonfree activate nonfree repos"
echo -e "--tainted activate tainted repos"
echo -e "\nBuild levels:"
echo -e "--create-chroot Create the chroot directory"
echo -e "--addmedia add mirrors"
@ -73,101 +63,17 @@ function help()
echo -e "\nFor image size, make sure it fit on physical support. (Default size is 7 Go)"
}
function unmounting()
function verify_disk_space()
{
title "Unmounting..."
# Unmounting /dev /proc /sys in chroot
if ! [ -z "$(mountpoint -qd "${BUILD_PATH}/dev")" ]; then # mountpoint - see if a directory or file is a mountpoint ; -d Show the major/minor numbers of the device that is mounted on the given directory.
info "Unmounting ${BUILD_PATH}/dev"
umount "${BUILD_PATH}/dev"
if ! [ ${?} -ne 0 ]; then
error "line ${LINENO} can't unmount ${BUILD_PATH}/dev : exiting"
#exit ${ERR_1}
fi
fi
if ! [ -z "$(mountpoint -qd "${BUILD_PATH}/sys")" ]; then
info "Unmounting ${BUILD_PATH}/sys"
umount "${BUILD_PATH}/sys"
if ! [ ${?} -ne 0 ]; then
error "line ${LINENO} can't unmount ${BUILD_PATH}/sys : exiting"
#exit ${ERR_1}
fi
fi
if ! [ -z "$(mountpoint -qd "${BUILD_PATH}/proc")" ]; then
info "Unmounting ${BUILD_PATH}/proc"
umount "${BUILD_PATH}/proc"
if ! [ ${?} -ne 0 ]; then
error "line ${LINENO} can't unmount ${BUILD_PATH}/proc : exiting"
#exit ${ERR_1}
fi
fi
# [root@jabztop mageia4arm (master)]# losetup -l -O NAME,BACK-FILE -n
# /dev/loop0 /home/jibz/workspaces/mageia4arm/build/Mageia-7-bananaPro1.img (deleted)
# # removing loop devices
# for LOOP in $(ls /dev/loop*[0-9]p1); do
# X=${LOOP:0:10}
# if [ -e "${X}" ]; then
# info "removing ${X}"
# partx -d "${X}" # Tell the kernel about the presence and numbering of partitions.
# fi
# done
# info "Supposed image name : ${IMAGE}"
# info "Looped devices : $(losetup -l -O NAME,BACK-FILE -n)"
# info "Looped devices with this image : $(losetup -l -O NAME,BACK-FILE -n | grep "${IMAGE}" )"
info "Looped devices to unmount : $(losetup -l -O NAME,BACK-FILE -n | grep "${IMAGE}" | cut -d ' ' -f 1 ) "
# removing loop devices
# for LOOP in $(losetup -l -O NAME -n); do
# info "removing ${LOOP}"
# losetup -d "${LOOP}" # Tell the kernel about the presence and numbering of partitions.
# done
for LOOP in $(losetup -l -O NAME,BACK-FILE -n | grep "${IMAGE}" | cut -d ' ' -f 1 ) ; do
info "removing ${LOOP}"
losetup -d "${LOOP}"
done
return 0
}
# cleaning build space
function clean()
{
title "Cleaning"
unmounting
# Removing old Build directory
if [ -d "${BUILD_PATH}" ]; then
info "Removing ${BUILD_PATH}"
/bin/rm -Rf "${BUILD_PATH}"
else
warning "${BUILD_PATH} does not exists"
fi
# removing old image
if [ -e "${INSTALL_PATH}/${IMAGE}" ]; then
info "Removing ${IMAGE}"
/bin/rm -f "${INSTALL_PATH}/${IMAGE}"
else
warning "${IMAGE} does not exists"
fi
# Removing boot and root directory
if [ -d "${BOOT}" ]; then
info "Removing ${BOOT}"
/bin/rm -rf "${BOOT}"
else
warning "${BOOT} does not exists"
fi
if [ -d "${ROOT}" ]; then
info "Removing ${ROOT}"
/bin/rm -rf "${ROOT}"
else
warning "${ROOT} does not exists"
title "Verifying if there is enough space on disk to make the image"
DISK_SPACE=$(/usr/bin/df -BG --output=avail "${INSTALL_PATH}" | sed '1d;s/[^0-9]//g')
info "Free disk space: ${DISK_SPACE}G"
if [ ${DISK_SPACE} -lt ${IMAGE_SIZE} ]; then
warning "image size is greater than disk space"
info "correct the problem and relaunch the script with parameter --create-rpi-image"
info "${0} --size ${IMAGE_SIZE} --create-rpi-image"
return 1
fi
return 0
}
@ -363,7 +269,7 @@ function jumpchroot()
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'
/sbin/chroot --userspec root:root "${BUILD_PATH}" /bin/bash -v -c 'sh /second_stage_install.sh 2>&1'
fi
RET=${?}
if [ ${RET} -ne 0 ]; then
@ -390,21 +296,6 @@ function jumpchroot()
}
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"
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 createImageWrap()
{
title "Wrap image creation"
@ -423,7 +314,173 @@ function createImageWrap()
}
createimage()
function copyingsystem()
{
mountImage
mkfstab
info "Generate extlinux if extlinux.conf exists."
if [ -e "${CONFIG_PATH}/extlinux.conf" ]; then
info "\tFound extlinux.conf"
if [ ! -d "${BUILD_PATH}/boot/extlinux" ]; then
info "making /boot/extlinux/extlinux.conf"
/bin/rm -rf "${BUILD_PATH}/boot/extlinux"
mkdir -p "${BUILD_PATH}/boot/extlinux"
fi
if [ ! -f "${BUILD_PATH}/boot/extlinux/extlinux.conf" ]; then
info "\tTuning extlinux.conf"
sed -e s/\<UUID\>/${ROOT_UUID}/g ${CONFIG_PATH}/extlinux.conf >"${BUILD_PATH}/boot/extlinux/extlinux.conf"
KERNEL_ID=$(basename ${BUILD_PATH}/usr/lib/linux-*)
sed -i -e s/\<FDTDIR\>/${KERNEL_ID}/g "${BUILD_PATH}/boot/extlinux/extlinux.conf"
fi
fi
info "Remove second_stage_install.sh"
/bin/rm -f "${BUILD_PATH}/second_stage_install.sh"
if [ 1 -eq ${SEPARATE_BOOT_PARTITION} ]; then
ARM_BOOT="${BUILD_PATH}/mnt/arm_boot"
if ! [ -d "${ARM_BOOT}" ]; then
rm -rf "${ARM_BOOT}"
mkdir -p "${ARM_BOOT}"
fi
info "copying Mageia image to root partition"
/bin/rsync -rlptogDH --exclude "${ARM_BOOT}/" --exclude "qemu-arm-static*" "${BUILD_PATH}/" "${ROOT}/"
/bin/rsync -rlptogDH "${ARM_BOOT}/" "${BOOT}/"
/bin/rsync -rlptogDH "${BUILD_PATH}/boot/" "${BOOT}/"
else
info "copying Mageia image to root partition"
/bin/rsync -rlptogDH --exclude "qemu-arm-static*" "${BUILD_PATH}/" "${ROOT}/"
fi
copyingCustomSystem
if [ ${?} -ne 0 ]; then
error "line ${LINENO} error in the process ${CONFIG_PATH}/specialFunctions.sh ."
exit ${ERR_1}
fi
copyingcommon
# Syncing devices before unmounting
/usr/bin/sync
if [ 1 -eq ${SEPARATE_BOOT_PARTITION} ]; then
/usr/bin/umount "${BOOT}"
if [ ${?} -eq 0 ]; then
/bin/rmdir "${BOOT}"
else
error "line ${LINENO} error unmounting ${BOOT}: exiting"
exit ${ERR_1}
fi
fi
/usr/bin/umount "${ROOT}"
if [ ${?} -eq 0 ]; then
/bin/rmdir "${ROOT}"
else
error "line ${LINENO} error unmounting ${ROOT}: exiting"
exit ${ERR_1}
fi
/usr/sbin/partx -d "${DEVICE}"
if [ ${?} -ne 0 ]; then
error "line ${LINENO} warning : error unmounting ${DEVICE} "
exit ${ERR_1}
fi
warning "You can now burn the image ( ${INSTALL_PATH}/${IMAGE} ) on SD card"
return 0
}
function mountImage(){
info "mounting partitions, making mountpoint if necessary"
if [ 1 -eq ${SEPARATE_BOOT_PARTITION} ]; then
if ! [ -d "${BOOT}" ]; then
/bin/mkdir "${BOOT}"
if [ ${?} -ne 0 ]; then
error "line ${LINENO} error making directory ${BOOT} : exiting"
exit ${ERR_1}
fi
fi
/bin/mount "${BOOTP}" "${BOOT}"
if [ ${?} -ne 0 ]; then
error "line ${LINENO} error mounting ${BOOTP} : exiting"
exit ${ERR_1}
fi
fi
if ! [ -d "${ROOT}" ]; then
/bin/mkdir "${ROOT}"
if [ ${?} -ne 0 ]; then
error "line ${LINENO} error making directory ${ROOT} : exiting"
exit ${ERR_1}
fi
fi
/bin/mount "${ROOTP}" "${ROOT}"
if [ ${?} -ne 0 ]; then
error "line ${LINENO} error mounting ${ROOTP} : exiting"
exit ${ERR_1}
fi
}
# Copying files common to all systems
function copyingcommon()
{
title "Copying common files and configuration"
rsync -rlptDH "${SOURCE_PATH}/common/" "${ROOT}/"
rsync -rlptDH "${SOURCE_PATH}/tools/"*.sh "${ROOT}/usr/local/bin/"
chown root:root "${ROOT}/usr/local/bin/"
return 0
}
function formatpartitions()
{
info "Formatting partitions"
if [ 1 -eq ${SEPARATE_BOOT_PARTITION} ]; then
info "Boot : ${BOOTP} as ${1}"
"/sbin/mkfs.${1}" "${BOOTP}"
if [ ${?} -ne 0 ]; then
error "line ${LINENO} error formating ${BOOTP} : exiting"
/sbin/losetup -d "${DEVICE}"
exit ${ERR_1}
fi
BOOT_UUID=$(blkid -s UUID -o value UUID "${BOOTP}")
info "Boot UUID: ${BOOT_UUID}"
fi
info "Root : ${ROOTP} as ${2}"
"/sbin/mkfs.${2}" "${ROOTP}"
if [ ${?} -ne 0 ]; then
error "line ${LINENO} error formating ${ROOTP} : exiting"
/sbin/losetup -d "${DEVICE}"
exit ${ERR_1}
fi
ROOT_UUID=$(blkid -s UUID -o value UUID "${ROOTP}")
info "Root UUID: ${ROOT_UUID}"
return 0
}
function mkfstab()
{
title "making /etc/fstab"
### BUG : /mnt/arm_boot is set to vfat for all plateforms, odroid configuration says ext4.
#echo -e "proc /proc proc defaults 0 0\nUUID=${BOOT_UUID} /mnt/arm_boot vfat defaults 0 0\nUUID=${ROOT_UUID} / ext4 defaults 0 0" > "${BUILD_PATH}/etc/fstab"
#echo -e "proc\t/proc\tproc\tdefaults\t0\t0\nUUID=${BOOT_UUID}\t/mnt/arm_boot\t${BOOTFS}\tdefaults\t0\t0\nUUID=${ROOT_UUID}\t/\text4\tdefaults\t0\t0" > "${BUILD_PATH}/etc/fstab"
if [ 1 -eq ${SEPARATE_BOOT_PARTITION} ]; then
echo -e "proc\t/proc\tproc\tdefaults\t0\t0\nUUID=${BOOT_UUID}\t/mnt/arm_boot\t${BOOTFS}\tdefaults\t0\t0\nUUID=${ROOT_UUID}\t/\text4\tdefaults\t0\t0" > "${BUILD_PATH}/etc/fstab"
else
echo -e "proc\t/proc\tproc\tdefaults\t0\t0\nUUID=${ROOT_UUID}\t/\text4\tdefaults\t0\t0" > "${BUILD_PATH}/etc/fstab"
fi
return 0
}
function createimage()
{
title " in ${IMAGE}"
if [ -f "${INSTALL_PATH}/${IMAGE}" ]; then
@ -469,175 +526,84 @@ createimage()
}
formatpartitions()
function unmounting()
{
info "Formatting partitions"
if [ 1 -eq ${SEPARATE_BOOT_PARTITION} ]; then
info "Boot : ${BOOTP} as ${1}"
"/sbin/mkfs.${1}" "${BOOTP}"
if [ ${?} -ne 0 ]; then
error "line ${LINENO} error formating ${BOOTP} : exiting"
/sbin/losetup -d "${DEVICE}"
exit ${ERR_1}
title "Unmounting..."
# Unmounting /dev /proc /sys in chroot
if ! [ -z "$(mountpoint -qd "${BUILD_PATH}/dev")" ]; then # mountpoint - see if a directory or file is a mountpoint ; -d Show the major/minor numbers of the device that is mounted on the given directory.
info "Unmounting ${BUILD_PATH}/dev"
umount "${BUILD_PATH}/dev"
if ! [ ${?} -ne 0 ]; then
error "line ${LINENO} can't unmount ${BUILD_PATH}/dev : exiting"
#exit ${ERR_1}
fi
fi
if ! [ -z "$(mountpoint -qd "${BUILD_PATH}/sys")" ]; then
info "Unmounting ${BUILD_PATH}/sys"
umount "${BUILD_PATH}/sys"
if ! [ ${?} -ne 0 ]; then
error "line ${LINENO} can't unmount ${BUILD_PATH}/sys : exiting"
#exit ${ERR_1}
fi
fi
if ! [ -z "$(mountpoint -qd "${BUILD_PATH}/proc")" ]; then
info "Unmounting ${BUILD_PATH}/proc"
umount "${BUILD_PATH}/proc"
if ! [ ${?} -ne 0 ]; then
error "line ${LINENO} can't unmount ${BUILD_PATH}/proc : exiting"
#exit ${ERR_1}
fi
BOOT_UUID=$(blkid -s UUID -o value UUID "${BOOTP}")
info "Boot UUID: ${BOOT_UUID}"
fi
info "Root : ${ROOTP} as ${2}"
"/sbin/mkfs.${2}" "${ROOTP}"
if [ ${?} -ne 0 ]; then
error "line ${LINENO} error formating ${ROOTP} : exiting"
/sbin/losetup -d "${DEVICE}"
exit ${ERR_1}
fi
ROOT_UUID=$(blkid -s UUID -o value UUID "${ROOTP}")
info "Root UUID: ${ROOT_UUID}"
# [root@jabztop mageia4arm (master)]# losetup -l -O NAME,BACK-FILE -n
# /dev/loop0 /home/jibz/workspaces/mageia4arm/build/Mageia-7-bananaPro1.img (deleted)
info "Looped devices to unmount : $(losetup -l -O NAME,BACK-FILE -n | grep "${IMAGE}" | cut -d ' ' -f 1 ) "
for LOOP in $(losetup -l -O NAME,BACK-FILE -n | grep "${IMAGE}" | cut -d ' ' -f 1 ) ; do
info "removing ${LOOP}"
losetup -d "${LOOP}"
done
return 0
}
copyingsystem()
# cleaning build space
function clean()
{
info "mounting partitions, making mountpoint if necessary"
title "Cleaning"
if [ 1 -eq ${SEPARATE_BOOT_PARTITION} ]; then
if ! [ -d "${BOOT}" ]; then
/bin/mkdir "${BOOT}"
if [ ${?} -ne 0 ]; then
error "line ${LINENO} error making directory ${BOOT} : exiting"
exit ${ERR_1}
fi
fi
/bin/mount "${BOOTP}" "${BOOT}"
if [ ${?} -ne 0 ]; then
error "line ${LINENO} error mounting ${BOOTP} : exiting"
exit ${ERR_1}
fi
fi
unmounting
if ! [ -d "${ROOT}" ]; then
/bin/mkdir "${ROOT}"
if [ ${?} -ne 0 ]; then
error "line ${LINENO} error making directory ${ROOT} : exiting"
exit ${ERR_1}
fi
fi
/bin/mount "${ROOTP}" "${ROOT}"
if [ ${?} -ne 0 ]; then
error "line ${LINENO} error mounting ${ROOTP} : exiting"
exit ${ERR_1}
fi
info "making /etc/fstab"
### BUG : /mnt/arm_boot is set to vfat for all plateforms, odroid configuration says ext4.
#echo -e "proc /proc proc defaults 0 0\nUUID=${BOOT_UUID} /mnt/arm_boot vfat defaults 0 0\nUUID=${ROOT_UUID} / ext4 defaults 0 0" > "${BUILD_PATH}/etc/fstab"
#echo -e "proc\t/proc\tproc\tdefaults\t0\t0\nUUID=${BOOT_UUID}\t/mnt/arm_boot\t${BOOTFS}\tdefaults\t0\t0\nUUID=${ROOT_UUID}\t/\text4\tdefaults\t0\t0" > "${BUILD_PATH}/etc/fstab"
if [ 1 -eq ${SEPARATE_BOOT_PARTITION} ]; then
echo -e "proc\t/proc\tproc\tdefaults\t0\t0\nUUID=${BOOT_UUID}\t/mnt/arm_boot\t${BOOTFS}\tdefaults\t0\t0\nUUID=${ROOT_UUID}\t/\text4\tdefaults\t0\t0" > "${BUILD_PATH}/etc/fstab"
# Removing old Build directory
if [ -d "${BUILD_PATH}" ]; then
info "Removing ${BUILD_PATH}"
/bin/rm -Rf "${BUILD_PATH}"
else
echo -e "proc\t/proc\tproc\tdefaults\t0\t0\nUUID=${ROOT_UUID}\t/\text4\tdefaults\t0\t0" > "${BUILD_PATH}/etc/fstab"
warning "${BUILD_PATH} does not exists"
fi
if [ -e "${CONFIG_PATH}/extlinux.conf" ]; then
info "\tFound extlinux.conf"
if [ ! -d "${BUILD_PATH}/boot/extlinux" ]; then
info "making /boot/extlinux/extlinux.conf"
/bin/rm -rf "${BUILD_PATH}/boot/extlinux"
mkdir -p "${BUILD_PATH}/boot/extlinux"
fi
if [ ! -f "${BUILD_PATH}/boot/extlinux/extlinux.conf" ]; then
info "\tTuning extlinux.conf"
sed -e s/\<UUID\>/${ROOT_UUID}/g ${CONFIG_PATH}/extlinux.conf >"${BUILD_PATH}/boot/extlinux/extlinux.conf"
KERNEL_ID=$(basename ${BUILD_PATH}/usr/lib/linux-*)
sed -i -e s/\<FDTDIR\>/${KERNEL_ID}/g "${BUILD_PATH}/boot/extlinux/extlinux.conf"
fi
fi
info "Remove second_stage_install.sh"
/bin/rm -f "${BUILD_PATH}/second_stage_install.sh"
if [ 1 -eq ${SEPARATE_BOOT_PARTITION} ]; then
ARM_BOOT="${BUILD_PATH}/mnt/arm_boot"
if ! [ -d "${ARM_BOOT}" ]; then
rm -rf "${ARM_BOOT}"
mkdir -p "${ARM_BOOT}"
fi
info "copying Mageia image to root partition"
/bin/rsync -rlptogDH --exclude "${ARM_BOOT}/" --exclude "qemu-arm-static*" "${BUILD_PATH}/" "${ROOT}/"
/bin/rsync -rlptogDH "${ARM_BOOT}/" "${BOOT}/"
/bin/rsync -rlptogDH "${BUILD_PATH}/boot/" "${BOOT}/"
# removing old image
if [ -e "${INSTALL_PATH}/${IMAGE}" ]; then
info "Removing ${IMAGE}"
/bin/rm -f "${INSTALL_PATH}/${IMAGE}"
else
info "copying Mageia image to root partition"
/bin/rsync -rlptogDH --exclude "qemu-arm-static*" "${BUILD_PATH}/" "${ROOT}/"
warning "${IMAGE} does not exists"
fi
copyingCustomSystem
if [ ${?} -ne 0 ]; then
error "line ${LINENO} error in the process ${CONFIG_PATH}/specialFunctions.sh ."
exit ${ERR_1}
fi
# info "copying tools in /usr/local/bin/"
# /bin/cp -v --preserve=mode "${SOURCE_PATH}/tools/" "${BUILD_PATH}/usr/local/bin/"
# if ! [ ${?} -eq 0 ]; then
# error "line ${LINENO} error copying tools"
# ERRORN=$((${ERRORN}+1))
# fi
# /bin/mkdir "${ROOT}/boot"
copyingcommon
# Syncing devices before unmounting
/usr/bin/sync
# warning "Inspect files and press a touch to continue."
# read -n1 GARBAGE
if [ 1 -eq ${SEPARATE_BOOT_PARTITION} ]; then
/usr/bin/umount "${BOOT}"
if [ ${?} -eq 0 ]; then
/bin/rmdir "${BOOT}"
# Removing boot and root directory
if [ -d "${BOOT}" ]; then
info "Removing ${BOOT}"
/bin/rm -rf "${BOOT}"
else
error "line ${LINENO} error unmounting ${BOOT}: exiting"
exit ${ERR_1}
warning "${BOOT} does not exists"
fi
fi
/usr/bin/umount "${ROOT}"
if [ ${?} -eq 0 ]; then
/bin/rmdir "${ROOT}"
if [ -d "${ROOT}" ]; then
info "Removing ${ROOT}"
/bin/rm -rf "${ROOT}"
else
error "line ${LINENO} error unmounting ${ROOT}: exiting"
exit ${ERR_1}
warning "${ROOT} does not exists"
fi
/usr/sbin/partx -d "${DEVICE}"
if [ ${?} -ne 0 ]; then
error "line ${LINENO} warning : error unmounting ${DEVICE} "
exit ${ERR_1}
fi
#Add : seems that there is still the looped device attached.
#warning "try to detach looped device"
#Previous device
#info "${DEVICE}"
#Retrieve the new device number :
#DEVICE=$(/sbin/losetup -f --show "${INSTALL_PATH}/${IMAGE}")
#info "device to detach ${DEVICE}"
#/sbin/losetup -d "${DEVICE}"
warning "You can now burn the image ( ${INSTALL_PATH}/${IMAGE} ) on SD card"
return 0
}
# Copying files common to all systems
copyingcommon()
{
title "Copying common files and configuration"
rsync -rlptDH "${SOURCE_PATH}/common/" "${ROOT}/"
rsync -rlptDH "${SOURCE_PATH}/tools/"*.sh "${ROOT}/usr/local/bin/"
chown root:root "${ROOT}/usr/local/bin/"
return 0
}
@ -936,6 +902,7 @@ case ${OPT} in
addmedia
updatemirror
installbasesystem
mkfstab
preparechroot
jumpchroot
createImageWrap