Fix rootfs issue

This commit is contained in:
2025-04-29 00:01:36 -07:00
parent fcab0c9c55
commit cac89696cc
2 changed files with 139 additions and 213 deletions

346
build.sh
View File

@@ -1,211 +1,140 @@
#!/bin/bash -e #!/bin/bash -e
# shellcheck disable=SC2119 # shellcheck disable=SC2119
run_sub_stage() run_sub_stage() {
{
log "Begin ${SUB_STAGE_DIR}" log "Begin ${SUB_STAGE_DIR}"
pushd "${SUB_STAGE_DIR}" > /dev/null pushd "${SUB_STAGE_DIR}" >/dev/null
for i in {00..99}; do for i in {00..99}; do
if [ -f "${i}-debconf-${ARCH}" ]; then for DEBCONF_FILE in "${i}-debconf-${ARCH}" "${i}-debconf-arm-only" "${i}-debconf"; do
log "Begin ${SUB_STAGE_DIR}/${i}-debconf-${ARCH}" if [ -f "${SUB_STAGE_DIR}/${DEBCONF_FILE}" ]; then
on_chroot << EOF # 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 <<EOF
debconf-set-selections <<SELEOF debconf-set-selections <<SELEOF
$(cat "${i}-debconf-${ARCH}") $(cat "${SUB_STAGE_DIR}/${DEBCONF_FILE}")
SELEOF SELEOF
EOF EOF
log "End ${SUB_STAGE_DIR}/${i}-debconf-${ARCH}"
elif [ -f "${i}-debconf-arm-only" ] && [[ "${ARCH}" == "arm64" || "${ARCH}" == "armhf" ]]; then log "End ${SUB_STAGE_DIR}/${DEBCONF_FILE}"
log "Begin ${SUB_STAGE_DIR}/${i}-debconf-arm-only" fi
on_chroot << EOF done
debconf-set-selections <<SELEOF for PACKAGE_LIST in "${i}-packages-nr-${ARCH}" "${i}-packages-nr-arm-only" "${i}-packages-nr"; do
$(cat "${i}-debconf-arm-only") if [ -f "${SUB_STAGE_DIR}/${PACKAGE_LIST}" ]; then
SELEOF # Skip arm-only packages if not arm architecture
EOF if [[ "${PACKAGE_LIST}" == *"-nr-arm-only" ]] && [[ "${ARCH}" != "armhf" && "${ARCH}" != "arm64" ]]; then
log "End ${SUB_STAGE_DIR}/${i}-debconf-arm-only" continue
elif [ -f "${i}-debconf" ]; then fi
log "Begin ${SUB_STAGE_DIR}/${i}-debconf"
on_chroot << EOF log "Begin ${SUB_STAGE_DIR}/${PACKAGE_LIST}"
debconf-set-selections <<SELEOF
$(cat "${i}-debconf") PACKAGES="$(sed -f "${SCRIPT_DIR}/remove-comments.sed" <"${SUB_STAGE_DIR}/${PACKAGE_LIST}")"
SELEOF
EOF if [ -n "$PACKAGES" ]; then
log "End ${SUB_STAGE_DIR}/${i}-debconf" on_chroot <<EOF
fi
if [ -f "${i}-packages-nr-${ARCH}" ]; then
log "Begin ${SUB_STAGE_DIR}/${i}-packages-nr-${ARCH}"
PACKAGES="$(sed -f "${SCRIPT_DIR}/remove-comments.sed" < "${i}-packages-nr-${ARCH}")"
if [ -n "$PACKAGES" ]; then
on_chroot << EOF
apt-get -o Acquire::Retries=3 install --no-install-recommends -y $PACKAGES apt-get -o Acquire::Retries=3 install --no-install-recommends -y $PACKAGES
EOF EOF
fi
log "End ${SUB_STAGE_DIR}/${PACKAGE_LIST}"
fi fi
log "End ${SUB_STAGE_DIR}/${i}-packages-nr-${ARCH}" done
elif [ -f "${i}-packages-nr-arm-only" ] && [[ "${ARCH}" == "arm64" || "${ARCH}" == "armhf" ]]; then for PACKAGE_LIST in "${i}-packages-${ARCH}" "${i}-packages-arm-only" "${i}-packages"; do
log "Begin ${SUB_STAGE_DIR}/${i}-packages-nr-arm-only" if [ -f "${SUB_STAGE_DIR}/${PACKAGE_LIST}" ]; then
PACKAGES="$(sed -f "${SCRIPT_DIR}/remove-comments.sed" < "${i}-packages-nr-arm-only")" # Skip arm-only packages if not arm architecture
if [ -n "$PACKAGES" ]; then if [[ "${PACKAGE_LIST}" == *"-packages-arm-only" ]] && [[ "${ARCH}" != "armhf" && "${ARCH}" != "arm64" ]]; then
on_chroot << EOF continue
apt-get -o Acquire::Retries=3 install --no-install-recommends -y $PACKAGES fi
EOF
fi log "Begin ${SUB_STAGE_DIR}/${PACKAGE_LIST}"
log "End ${SUB_STAGE_DIR}/${i}-packages-nr-arm-only"
elif [ -f "${i}-packages-nr" ]; then PACKAGES="$(sed -f "${SCRIPT_DIR}/remove-comments.sed" <"${SUB_STAGE_DIR}/${PACKAGE_LIST}")"
log "Begin ${SUB_STAGE_DIR}/${i}-packages-nr"
PACKAGES="$(sed -f "${SCRIPT_DIR}/remove-comments.sed" < "${i}-packages-nr")" if [ -n "$PACKAGES" ]; then
if [ -n "$PACKAGES" ]; then on_chroot <<EOF
on_chroot << EOF
apt-get -o Acquire::Retries=3 install --no-install-recommends -y $PACKAGES
EOF
fi
log "End ${SUB_STAGE_DIR}/${i}-packages-nr"
fi
if [ -f "${i}-packages-${ARCH}" ]; then
log "Begin ${SUB_STAGE_DIR}/${i}-packages-${ARCH}"
PACKAGES="$(sed -f "${SCRIPT_DIR}/remove-comments.sed" < "${i}-packages-${ARCH}")"
if [ -n "$PACKAGES" ]; then
on_chroot << EOF
apt-get -o Acquire::Retries=3 install -y $PACKAGES apt-get -o Acquire::Retries=3 install -y $PACKAGES
EOF EOF
fi
log "End ${SUB_STAGE_DIR}/${PACKAGE_LIST}"
fi fi
log "End ${SUB_STAGE_DIR}/${i}-packages-${ARCH}" done
elif [ -f "${i}-packages-arm-only" ] && [[ "${ARCH}" == "arm64" || "${ARCH}" == "armhf" ]]; then for PATCH_DIR in "${i}-patches-${ARCH}" "${i}-patches-arm-only" "${i}-patches"; do
log "Begin ${SUB_STAGE_DIR}/${i}-packages-arm-only" if [ -d "${SUB_STAGE_DIR}/${PATCH_DIR}" ]; then
PACKAGES="$(sed -f "${SCRIPT_DIR}/remove-comments.sed" < "${i}-packages-arm-only")" # Check arm-only patches should only apply for armhf/arm64
if [ -n "$PACKAGES" ]; then if [[ "${PATCH_DIR}" == *"-patches-arm-only" ]] && [[ "${ARCH}" != "armhf" && "${ARCH}" != "arm64" ]]; then
on_chroot << EOF continue
apt-get -o Acquire::Retries=3 install -y $PACKAGES fi
EOF
log "Begin ${SUB_STAGE_DIR}/${PATCH_DIR}"
pushd "${STAGE_WORK_DIR}" >/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 fi
log "End ${SUB_STAGE_DIR}/${i}-packages-arm-only" done
elif [ -f "${i}-packages" ]; then for RUN_SCRIPT in "${i}-run-${ARCH}.sh" "${i}-run-arm-only.sh" "${i}-run.sh"; do
log "Begin ${SUB_STAGE_DIR}/${i}-packages" if [ -x "${SUB_STAGE_DIR}/${RUN_SCRIPT}" ]; then
PACKAGES="$(sed -f "${SCRIPT_DIR}/remove-comments.sed" < "${i}-packages")" # Skip arm-only if not arm
if [ -n "$PACKAGES" ]; then if [[ "${RUN_SCRIPT}" == *"-arm-only.sh" ]] && [[ "${ARCH}" != "armhf" && "${ARCH}" != "arm64" ]]; then
on_chroot << EOF continue
apt-get -o Acquire::Retries=3 install -y $PACKAGES fi
EOF
log "Begin ${SUB_STAGE_DIR}/${RUN_SCRIPT}"
"./${RUN_SCRIPT}"
log "End ${SUB_STAGE_DIR}/${RUN_SCRIPT}"
fi fi
log "End ${SUB_STAGE_DIR}/${i}-packages" done
fi for CHROOT_SCRIPT in "${i}-run-chroot-${ARCH}.sh" "${i}-run-chroot-arm-only.sh" "${i}-run-chroot.sh"; do
if [ -d "${i}-patches-${ARCH}" ]; then if [ -f "${SUB_STAGE_DIR}/${CHROOT_SCRIPT}" ]; then
log "Begin ${SUB_STAGE_DIR}/${i}-patches-${ARCH}" # Skip arm-only if not arm
pushd "${STAGE_WORK_DIR}" > /dev/null if [[ "${CHROOT_SCRIPT}" == *"-arm-only.sh" ]] && [[ "${ARCH}" != "armhf" && "${ARCH}" != "arm64" ]]; then
if [ "${CLEAN}" = "1" ]; then continue
rm -rf .pc fi
rm -rf ./*-pc
log "Begin ${SUB_STAGE_DIR}/${CHROOT_SCRIPT}"
on_chroot <"${SUB_STAGE_DIR}/${CHROOT_SCRIPT}"
log "End ${SUB_STAGE_DIR}/${CHROOT_SCRIPT}"
fi fi
QUILT_PATCHES="${SUB_STAGE_DIR}/${i}-patches-${ARCH}" done
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}" log "End ${SUB_STAGE_DIR}"
} }
run_stage() {
run_stage(){
log "Begin ${STAGE_DIR}" log "Begin ${STAGE_DIR}"
STAGE="$(basename "${STAGE_DIR}")" STAGE="$(basename "${STAGE_DIR}")"
pushd "${STAGE_DIR}" > /dev/null pushd "${STAGE_DIR}" >/dev/null
STAGE_WORK_DIR="${WORK_DIR}/${STAGE}" STAGE_WORK_DIR="${WORK_DIR}/${STAGE}"
ROOTFS_DIR="${STAGE_WORK_DIR}"/rootfs ROOTFS_DIR="${STAGE_WORK_DIR}"/rootfs
@@ -230,9 +159,9 @@ run_stage(){
fi fi
for SUB_STAGE_DIR in "${STAGE_DIR}"/*; do for SUB_STAGE_DIR in "${STAGE_DIR}"/*; do
if [ -d "${SUB_STAGE_DIR}" ]; then if [ -d "${SUB_STAGE_DIR}" ]; then
if [ ! -f "${SUB_STAGE_DIR}/SKIP" ] && [ ! -f "${SUB_STAGE_DIR}/SKIP_${ARCH}" ]; then if [ ! -f "${SUB_STAGE_DIR}/SKIP" ] && [ ! -f "${SUB_STAGE_DIR}/SKIP_${ARCH}" ]; then
run_sub_stage run_sub_stage
fi fi
fi fi
done done
fi fi
@@ -242,7 +171,7 @@ run_stage(){
PREV_STAGE="${STAGE}" PREV_STAGE="${STAGE}"
PREV_STAGE_DIR="${STAGE_DIR}" PREV_STAGE_DIR="${STAGE_DIR}"
PREV_ROOTFS_DIR="${ROOTFS_DIR}" PREV_ROOTFS_DIR="${ROOTFS_DIR}"
popd > /dev/null popd >/dev/null
log "End ${STAGE_DIR}" log "End ${STAGE_DIR}"
} }
@@ -281,16 +210,14 @@ if [ -f config ]; then
source config source config
fi fi
while getopts "c:" flag while getopts "c:" flag; do
do
case "$flag" in case "$flag" in
c) c)
EXTRA_CONFIG="$OPTARG" EXTRA_CONFIG="$OPTARG"
# shellcheck disable=SC1090 # shellcheck disable=SC1090
source "$EXTRA_CONFIG" source "$EXTRA_CONFIG"
;; ;;
*) *) ;;
;;
esac esac
done done
@@ -368,7 +295,6 @@ trap term EXIT INT TERM
dependencies_check "${BASE_DIR}/depends" dependencies_check "${BASE_DIR}/depends"
PAGESIZE=$(getconf PAGESIZE) PAGESIZE=$(getconf PAGESIZE)
if [ "$ARCH" == "armhf" ] && [ "$PAGESIZE" != "4096" ]; then if [ "$ARCH" == "armhf" ] && [ "$PAGESIZE" != "4096" ]; then
echo echo
@@ -396,12 +322,12 @@ if [[ ! "$FIRST_USER_NAME" =~ ^[a-z][-a-z0-9_]*$ ]]; then
exit 1 exit 1
fi 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}" echo "Could not reach APT_PROXY server: ${APT_PROXY}"
exit 1 exit 1
fi 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 echo "WPA_PASSWORD" must be between 8 and 63 characters
exit 1 exit 1
fi fi
@@ -435,16 +361,16 @@ for EXPORT_DIR in ${EXPORT_DIRS}; do
source "${EXPORT_DIR}/EXPORT_IMAGE" source "${EXPORT_DIR}/EXPORT_IMAGE"
EXPORT_ROOTFS_DIR=${WORK_DIR}/$(basename "${EXPORT_DIR}")/rootfs EXPORT_ROOTFS_DIR=${WORK_DIR}/$(basename "${EXPORT_DIR}")/rootfs
if [ -e "${EXPORT_DIR}/EXPORT_ISO" ]; then if [ -e "${EXPORT_DIR}/EXPORT_ISO" ]; then
# shellcheck source=/dev/null # shellcheck source=/dev/null
source "${EXPORT_DIR}/EXPORT_ISO" source "${EXPORT_DIR}/EXPORT_ISO"
STAGE_DIR="${BASE_DIR}/export-iso" STAGE_DIR="${BASE_DIR}/export-iso"
run_stage run_stage
elif [ -e "${EXPORT_DIR}/EXPORT_IMAGE" ]; then elif [ -e "${EXPORT_DIR}/EXPORT_IMAGE" ]; then
# shellcheck source=/dev/null # shellcheck source=/dev/null
source "${EXPORT_DIR}/EXPORT_IMAGE" source "${EXPORT_DIR}/EXPORT_IMAGE"
STAGE_DIR="${BASE_DIR}/export-image" STAGE_DIR="${BASE_DIR}/export-image"
run_stage run_stage
fi fi
if [ "${USE_QEMU}" != "1" ]; then if [ "${USE_QEMU}" != "1" ]; then
if [ -e "${EXPORT_DIR}/EXPORT_NOOBS" ]; then if [ -e "${EXPORT_DIR}/EXPORT_NOOBS" ]; then
# shellcheck source=/dev/null # shellcheck source=/dev/null

View File

@@ -70,14 +70,14 @@ else
fi fi
mkdosfs -n bootfs -F "$FAT_SIZE" -s 4 -v "$BOOT_DEV" > /dev/null 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 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 mount -v "$ROOT_DEV" "${ROOTFS_DIR}" -t ext4
mkdir -p "${ROOTFS_DIR}/boot/firmware" mkdir -p "${ROOTFS_DIR}/boot/firmware"
mount -v "$BOOT_DEV" "${ROOTFS_DIR}/boot/firmware" -t vfat mount -v "$BOOT_DEV" "${ROOTFS_DIR}/boot/firmware" -t vfat
mkdir -p "${ROOTFS_DIR}/recovery" #mkdir -p "${ROOTFS_DIR}/recovery"
mount -v "$RECOVERY_DEV" "${ROOTFS_DIR}/recovery" -t ext4 #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 -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/" rsync -rtx "${EXPORT_ROOTFS_DIR}/boot/firmware/" "${ROOTFS_DIR}/boot/firmware/"