From cac89696ccc3194f42c0e35cf8b7d1d217a2823b Mon Sep 17 00:00:00 2001 From: oxmc7769 Date: Tue, 29 Apr 2025 00:01:36 -0700 Subject: [PATCH] Fix rootfs issue --- build.sh | 346 ++++++++++++++++------------------------- export-image/prerun.sh | 6 +- 2 files changed, 139 insertions(+), 213 deletions(-) diff --git a/build.sh b/build.sh index 85a47a9..8128568 100755 --- a/build.sh +++ b/build.sh @@ -1,211 +1,140 @@ #!/bin/bash -e # shellcheck disable=SC2119 -run_sub_stage() -{ +run_sub_stage() { log "Begin ${SUB_STAGE_DIR}" - pushd "${SUB_STAGE_DIR}" > /dev/null + pushd "${SUB_STAGE_DIR}" >/dev/null for i in {00..99}; do - if [ -f "${i}-debconf-${ARCH}" ]; then - log "Begin ${SUB_STAGE_DIR}/${i}-debconf-${ARCH}" - on_chroot << EOF + for DEBCONF_FILE in "${i}-debconf-${ARCH}" "${i}-debconf-arm-only" "${i}-debconf"; do + if [ -f "${SUB_STAGE_DIR}/${DEBCONF_FILE}" ]; then + # Skip arm-only if not arm + if [[ "${DEBCONF_FILE}" == *"-debconf-arm-only" ]] && [[ "${ARCH}" != "armhf" && "${ARCH}" != "arm64" ]]; then + continue + fi + + log "Begin ${SUB_STAGE_DIR}/${DEBCONF_FILE}" + + on_chroot </dev/null + + if [ "${CLEAN}" = "1" ]; then + rm -rf .pc + rm -rf ./*-pc + fi + + QUILT_PATCHES="${SUB_STAGE_DIR}/${PATCH_DIR}" + SUB_STAGE_QUILT_PATCH_DIR="$(basename "$SUB_STAGE_DIR")-pc" + mkdir -p "$SUB_STAGE_QUILT_PATCH_DIR" + ln -snf "$SUB_STAGE_QUILT_PATCH_DIR" .pc + + quilt upgrade + + if [ -e "${SUB_STAGE_DIR}/${PATCH_DIR}/EDIT" ]; then + echo "Dropping into bash to edit patches..." + bash + fi + + RC=0 + quilt push -a || RC=$? + case "$RC" in + 0 | 2) ;; # 0 = success, 2 = "already applied" + *) false ;; + esac + + popd >/dev/null + log "End ${SUB_STAGE_DIR}/${PATCH_DIR}" fi - log "End ${SUB_STAGE_DIR}/${i}-packages-arm-only" - elif [ -f "${i}-packages" ]; then - log "Begin ${SUB_STAGE_DIR}/${i}-packages" - PACKAGES="$(sed -f "${SCRIPT_DIR}/remove-comments.sed" < "${i}-packages")" - if [ -n "$PACKAGES" ]; then - on_chroot << EOF -apt-get -o Acquire::Retries=3 install -y $PACKAGES -EOF + done + for RUN_SCRIPT in "${i}-run-${ARCH}.sh" "${i}-run-arm-only.sh" "${i}-run.sh"; do + if [ -x "${SUB_STAGE_DIR}/${RUN_SCRIPT}" ]; then + # Skip arm-only if not arm + if [[ "${RUN_SCRIPT}" == *"-arm-only.sh" ]] && [[ "${ARCH}" != "armhf" && "${ARCH}" != "arm64" ]]; then + continue + fi + + log "Begin ${SUB_STAGE_DIR}/${RUN_SCRIPT}" + "./${RUN_SCRIPT}" + log "End ${SUB_STAGE_DIR}/${RUN_SCRIPT}" fi - log "End ${SUB_STAGE_DIR}/${i}-packages" - fi - if [ -d "${i}-patches-${ARCH}" ]; then - log "Begin ${SUB_STAGE_DIR}/${i}-patches-${ARCH}" - pushd "${STAGE_WORK_DIR}" > /dev/null - if [ "${CLEAN}" = "1" ]; then - rm -rf .pc - rm -rf ./*-pc + done + for CHROOT_SCRIPT in "${i}-run-chroot-${ARCH}.sh" "${i}-run-chroot-arm-only.sh" "${i}-run-chroot.sh"; do + if [ -f "${SUB_STAGE_DIR}/${CHROOT_SCRIPT}" ]; then + # Skip arm-only if not arm + if [[ "${CHROOT_SCRIPT}" == *"-arm-only.sh" ]] && [[ "${ARCH}" != "armhf" && "${ARCH}" != "arm64" ]]; then + continue + fi + + log "Begin ${SUB_STAGE_DIR}/${CHROOT_SCRIPT}" + on_chroot <"${SUB_STAGE_DIR}/${CHROOT_SCRIPT}" + log "End ${SUB_STAGE_DIR}/${CHROOT_SCRIPT}" fi - QUILT_PATCHES="${SUB_STAGE_DIR}/${i}-patches-${ARCH}" - SUB_STAGE_QUILT_PATCH_DIR="$(basename "$SUB_STAGE_DIR")-pc" - mkdir -p "$SUB_STAGE_QUILT_PATCH_DIR" - ln -snf "$SUB_STAGE_QUILT_PATCH_DIR" .pc - quilt upgrade - if [ -e "${SUB_STAGE_DIR}/${i}-patches-${ARCH}/EDIT" ]; then - echo "Dropping into bash to edit patches..." - bash - fi - RC=0 - quilt push -a || RC=$? - case "$RC" in - 0|2) - ;; - *) - false - ;; - esac - popd > /dev/null - log "End ${SUB_STAGE_DIR}/${i}-patches-${ARCH}" - elif [ -d "${i}-patches-arm-only" ] && [[ "${ARCH}" == "arm64" || "${ARCH}" == "armhf" ]]; then - log "Begin ${SUB_STAGE_DIR}/${i}-patches-arm-only" - pushd "${STAGE_WORK_DIR}" > /dev/null - if [ "${CLEAN}" = "1" ]; then - rm -rf .pc - rm -rf ./*-pc - fi - QUILT_PATCHES="${SUB_STAGE_DIR}/${i}-patches-arm-only" - SUB_STAGE_QUILT_PATCH_DIR="$(basename "$SUB_STAGE_DIR")-pc" - mkdir -p "$SUB_STAGE_QUILT_PATCH_DIR" - ln -snf "$SUB_STAGE_QUILT_PATCH_DIR" .pc - quilt upgrade - if [ -e "${SUB_STAGE_DIR}/${i}-patches-arm-only/EDIT" ]; then - echo "Dropping into bash to edit patches..." - bash - fi - RC=0 - quilt push -a || RC=$? - case "$RC" in - 0|2) - ;; - *) - false - ;; - esac - popd > /dev/null - log "End ${SUB_STAGE_DIR}/${i}-patches-arm-only" - elif [ -d "${i}-patches" ]; then - log "Begin ${SUB_STAGE_DIR}/${i}-patches" - pushd "${STAGE_WORK_DIR}" > /dev/null - if [ "${CLEAN}" = "1" ]; then - rm -rf .pc - rm -rf ./*-pc - fi - QUILT_PATCHES="${SUB_STAGE_DIR}/${i}-patches" - SUB_STAGE_QUILT_PATCH_DIR="$(basename "$SUB_STAGE_DIR")-pc" - mkdir -p "$SUB_STAGE_QUILT_PATCH_DIR" - ln -snf "$SUB_STAGE_QUILT_PATCH_DIR" .pc - quilt upgrade - if [ -e "${SUB_STAGE_DIR}/${i}-patches/EDIT" ]; then - echo "Dropping into bash to edit patches..." - bash - fi - RC=0 - quilt push -a || RC=$? - case "$RC" in - 0|2) - ;; - *) - false - ;; - esac - popd > /dev/null - log "End ${SUB_STAGE_DIR}/${i}-patches" - fi - if [ -x ${i}-run-${ARCH}.sh ]; then - log "Begin ${SUB_STAGE_DIR}/${i}-run-${ARCH}.sh" - ./${i}-run-${ARCH}.sh - log "End ${SUB_STAGE_DIR}/${i}-run-${ARCH}.sh" - elif [ -x "${i}-run-arm-only.sh" ] && [[ "${ARCH}" == "arm64" || "${ARCH}" == "armhf" ]]; then - log "Begin ${SUB_STAGE_DIR}/${i}-run-arm-only.sh" - ./${i}-run-arm-only.sh - log "End ${SUB_STAGE_DIR}/${i}-run-arm-only.sh" - elif [ -x ${i}-run.sh ]; then - log "Begin ${SUB_STAGE_DIR}/${i}-run.sh" - ./${i}-run.sh - log "End ${SUB_STAGE_DIR}/${i}-run.sh" - fi - if [ -f ${i}-run-chroot-${ARCH}.sh ]; then - log "Begin ${SUB_STAGE_DIR}/${i}-run-chroot-${ARCH}.sh" - on_chroot < ${i}-run-chroot-${ARCH}.sh - log "End ${SUB_STAGE_DIR}/${i}-run-chroot-${ARCH}.sh" - elif [ -f "${i}-run-chroot-arm-only.sh" ] && [[ "${ARCH}" == "arm64" || "${ARCH}" == "armhf" ]]; then - log "Begin ${SUB_STAGE_DIR}/${i}-run-chroot-arm-only.sh" - on_chroot < ${i}-run-chroot-arm-only.sh - log "End ${SUB_STAGE_DIR}/${i}-run-chroot-arm-only.sh" - elif [ -f ${i}-run-chroot.sh ]; then - log "Begin ${SUB_STAGE_DIR}/${i}-run-chroot.sh" - on_chroot < ${i}-run-chroot.sh - log "End ${SUB_STAGE_DIR}/${i}-run-chroot.sh" - fi + done done - popd > /dev/null + popd >/dev/null log "End ${SUB_STAGE_DIR}" } - -run_stage(){ +run_stage() { log "Begin ${STAGE_DIR}" STAGE="$(basename "${STAGE_DIR}")" - pushd "${STAGE_DIR}" > /dev/null + pushd "${STAGE_DIR}" >/dev/null STAGE_WORK_DIR="${WORK_DIR}/${STAGE}" ROOTFS_DIR="${STAGE_WORK_DIR}"/rootfs @@ -230,9 +159,9 @@ run_stage(){ fi for SUB_STAGE_DIR in "${STAGE_DIR}"/*; do if [ -d "${SUB_STAGE_DIR}" ]; then - if [ ! -f "${SUB_STAGE_DIR}/SKIP" ] && [ ! -f "${SUB_STAGE_DIR}/SKIP_${ARCH}" ]; then - run_sub_stage - fi + if [ ! -f "${SUB_STAGE_DIR}/SKIP" ] && [ ! -f "${SUB_STAGE_DIR}/SKIP_${ARCH}" ]; then + run_sub_stage + fi fi done fi @@ -242,7 +171,7 @@ run_stage(){ PREV_STAGE="${STAGE}" PREV_STAGE_DIR="${STAGE_DIR}" PREV_ROOTFS_DIR="${ROOTFS_DIR}" - popd > /dev/null + popd >/dev/null log "End ${STAGE_DIR}" } @@ -281,16 +210,14 @@ if [ -f config ]; then source config fi -while getopts "c:" flag -do +while getopts "c:" flag; do case "$flag" in - c) - EXTRA_CONFIG="$OPTARG" - # shellcheck disable=SC1090 - source "$EXTRA_CONFIG" - ;; - *) - ;; + c) + EXTRA_CONFIG="$OPTARG" + # shellcheck disable=SC1090 + source "$EXTRA_CONFIG" + ;; + *) ;; esac done @@ -368,7 +295,6 @@ trap term EXIT INT TERM dependencies_check "${BASE_DIR}/depends" - PAGESIZE=$(getconf PAGESIZE) if [ "$ARCH" == "armhf" ] && [ "$PAGESIZE" != "4096" ]; then echo @@ -396,12 +322,12 @@ if [[ ! "$FIRST_USER_NAME" =~ ^[a-z][-a-z0-9_]*$ ]]; then exit 1 fi -if [[ -n "${APT_PROXY}" ]] && ! curl --silent "${APT_PROXY}" >/dev/null ; then +if [[ -n "${APT_PROXY}" ]] && ! curl --silent "${APT_PROXY}" >/dev/null; then echo "Could not reach APT_PROXY server: ${APT_PROXY}" exit 1 fi -if [[ -n "${WPA_PASSWORD}" && ${#WPA_PASSWORD} -lt 8 || ${#WPA_PASSWORD} -gt 63 ]] ; then +if [[ -n "${WPA_PASSWORD}" && ${#WPA_PASSWORD} -lt 8 || ${#WPA_PASSWORD} -gt 63 ]]; then echo "WPA_PASSWORD" must be between 8 and 63 characters exit 1 fi @@ -435,16 +361,16 @@ for EXPORT_DIR in ${EXPORT_DIRS}; do source "${EXPORT_DIR}/EXPORT_IMAGE" EXPORT_ROOTFS_DIR=${WORK_DIR}/$(basename "${EXPORT_DIR}")/rootfs if [ -e "${EXPORT_DIR}/EXPORT_ISO" ]; then - # shellcheck source=/dev/null - source "${EXPORT_DIR}/EXPORT_ISO" - STAGE_DIR="${BASE_DIR}/export-iso" - run_stage - elif [ -e "${EXPORT_DIR}/EXPORT_IMAGE" ]; then - # shellcheck source=/dev/null - source "${EXPORT_DIR}/EXPORT_IMAGE" - STAGE_DIR="${BASE_DIR}/export-image" - run_stage - fi + # shellcheck source=/dev/null + source "${EXPORT_DIR}/EXPORT_ISO" + STAGE_DIR="${BASE_DIR}/export-iso" + run_stage + elif [ -e "${EXPORT_DIR}/EXPORT_IMAGE" ]; then + # shellcheck source=/dev/null + source "${EXPORT_DIR}/EXPORT_IMAGE" + STAGE_DIR="${BASE_DIR}/export-image" + run_stage + fi if [ "${USE_QEMU}" != "1" ]; then if [ -e "${EXPORT_DIR}/EXPORT_NOOBS" ]; then # shellcheck source=/dev/null diff --git a/export-image/prerun.sh b/export-image/prerun.sh index 516b65d..e59e58d 100755 --- a/export-image/prerun.sh +++ b/export-image/prerun.sh @@ -70,14 +70,14 @@ else fi mkdosfs -n bootfs -F "$FAT_SIZE" -s 4 -v "$BOOT_DEV" > /dev/null -mkfs.ext4 -L rootfs -O "$ROOT_FEATURES" "$ROOT_DEV" > /dev/null mkfs.ext4 -L recovery -O "$ROOT_FEATURES" "$RECOVERY_DEV" > /dev/null +mkfs.ext4 -L rootfs -O "$ROOT_FEATURES" "$ROOT_DEV" > /dev/null mount -v "$ROOT_DEV" "${ROOTFS_DIR}" -t ext4 mkdir -p "${ROOTFS_DIR}/boot/firmware" mount -v "$BOOT_DEV" "${ROOTFS_DIR}/boot/firmware" -t vfat -mkdir -p "${ROOTFS_DIR}/recovery" -mount -v "$RECOVERY_DEV" "${ROOTFS_DIR}/recovery" -t ext4 +#mkdir -p "${ROOTFS_DIR}/recovery" +#mount -v "$RECOVERY_DEV" "${ROOTFS_DIR}/recovery" -t ext4 rsync -aHAXx --exclude /var/cache/apt/archives --exclude /boot/firmware "${EXPORT_ROOTFS_DIR}/" "${ROOTFS_DIR}/" rsync -rtx "${EXPORT_ROOTFS_DIR}/boot/firmware/" "${ROOTFS_DIR}/boot/firmware/"