mirror of
https://github.com/armbian/build.git
synced 2025-08-15 23:56:57 +02:00
122 lines
4.5 KiB
Bash
122 lines
4.5 KiB
Bash
# unmount_on_exit
|
|
#
|
|
unmount_on_exit() {
|
|
|
|
trap - INT TERM EXIT
|
|
local stacktrace="$(get_extension_hook_stracktrace "${BASH_SOURCE[*]}" "${BASH_LINENO[*]}")"
|
|
display_alert "unmount_on_exit() called!" "$stacktrace" "err"
|
|
if [[ "${ERROR_DEBUG_SHELL}" == "yes" ]]; then
|
|
ERROR_DEBUG_SHELL=no # dont do it twice
|
|
display_alert "MOUNT" "${MOUNT}" "err"
|
|
display_alert "SDCARD" "${SDCARD}" "err"
|
|
display_alert "ERROR_DEBUG_SHELL=yes, starting a shell." "ERROR_DEBUG_SHELL" "err"
|
|
bash < /dev/tty || true
|
|
fi
|
|
|
|
umount_chroot "${SDCARD}/"
|
|
mountpoint -q "${SRC}"/cache/toolchain && umount -l "${SRC}"/cache/toolchain
|
|
mountpoint -q "${SRC}"/cache/rootfs && umount -l "${SRC}"/cache/rootfs
|
|
umount -l "${SDCARD}"/tmp > /dev/null 2>&1
|
|
umount -l "${SDCARD}" > /dev/null 2>&1
|
|
umount -l "${MOUNT}"/boot > /dev/null 2>&1
|
|
umount -l "${MOUNT}" > /dev/null 2>&1
|
|
[[ $CRYPTROOT_ENABLE == yes ]] && cryptsetup luksClose "${ROOT_MAPPER}"
|
|
losetup -d "${LOOP}" > /dev/null 2>&1
|
|
rm -rf --one-file-system "${SDCARD}"
|
|
exit_with_error "debootstrap-ng was interrupted" || true # don't trigger again
|
|
|
|
}
|
|
|
|
# debootstrap_ng
|
|
#
|
|
debootstrap_ng() {
|
|
display_alert "Checking for rootfs cache" "$(echo "${BRANCH} ${BOARD} ${RELEASE} ${DESKTOP_APPGROUPS_SELECTED} ${DESKTOP_ENVIRONMENT} ${BUILD_MINIMAL}" | tr -s " ")" "info"
|
|
|
|
[[ $ROOTFS_TYPE != ext4 ]] && display_alert "Assuming $BOARD $BRANCH kernel supports $ROOTFS_TYPE" "" "wrn"
|
|
|
|
# trap to unmount stuff in case of error/manual interruption
|
|
trap unmount_on_exit INT TERM EXIT
|
|
|
|
# stage: clean and create directories
|
|
rm -rf $SDCARD $MOUNT
|
|
mkdir -p $SDCARD $MOUNT $DEST/images $SRC/cache/rootfs
|
|
|
|
# bind mount rootfs if defined
|
|
if [[ -d "${ARMBIAN_CACHE_ROOTFS_PATH}" ]]; then
|
|
mountpoint -q "${SRC}"/cache/rootfs && umount -l "${SRC}"/cache/toolchain
|
|
mount --bind "${ARMBIAN_CACHE_ROOTFS_PATH}" "${SRC}"/cache/rootfs
|
|
fi
|
|
|
|
# stage: verify tmpfs configuration and mount
|
|
# CLI needs ~1.5GiB, desktop - ~3.5GiB
|
|
# calculate and set tmpfs mount to use 9/10 of available RAM+SWAP
|
|
local phymem=$(((($(awk '/MemTotal/ {print $2}' /proc/meminfo) + $(awk '/SwapTotal/ {print $2}' /proc/meminfo))) / 1024 * 9 / 10)) # MiB
|
|
if [[ $BUILD_DESKTOP == yes ]]; then local tmpfs_max_size=3500; else local tmpfs_max_size=1500; fi # MiB
|
|
if [[ $FORCE_USE_RAMDISK == no ]]; then
|
|
local use_tmpfs=no
|
|
elif [[ $FORCE_USE_RAMDISK == yes || $phymem -gt $tmpfs_max_size ]]; then
|
|
local use_tmpfs=yes
|
|
fi
|
|
[[ -n $FORCE_TMPFS_SIZE ]] && phymem=$FORCE_TMPFS_SIZE
|
|
|
|
[[ $use_tmpfs == yes ]] && mount -t tmpfs -o size=${phymem}M tmpfs $SDCARD
|
|
|
|
# stage: prepare basic rootfs: unpack cache or create from scratch
|
|
create_rootfs_cache
|
|
|
|
call_extension_method "pre_install_distribution_specific" "config_pre_install_distribution_specific" << 'PRE_INSTALL_DISTRIBUTION_SPECIFIC'
|
|
*give config a chance to act before install_distribution_specific*
|
|
Called after `create_rootfs_cache` (_prepare basic rootfs: unpack cache or create from scratch_) but before `install_distribution_specific` (_install distribution and board specific applications_).
|
|
PRE_INSTALL_DISTRIBUTION_SPECIFIC
|
|
|
|
# stage: install kernel and u-boot packages
|
|
# install distribution and board specific applications
|
|
|
|
install_distribution_specific
|
|
install_common
|
|
|
|
# install locally built packages
|
|
[[ $EXTERNAL_NEW == compile ]] && chroot_installpackages_local
|
|
|
|
# install from apt.armbian.com
|
|
[[ $EXTERNAL_NEW == prebuilt ]] && chroot_installpackages "yes"
|
|
|
|
# stage: user customization script
|
|
# NOTE: installing too many packages may fill tmpfs mount
|
|
customize_image
|
|
|
|
# remove packages that are no longer needed. Since we have intrudoced uninstall feature, we might want to clean things that are no longer needed
|
|
display_alert "No longer needed packages" "purge" "info"
|
|
chroot $SDCARD /bin/bash -c "apt-get autoremove -y" > /dev/null 2>&1
|
|
|
|
# create list of all installed packages for debug purposes
|
|
chroot $SDCARD /bin/bash -c "dpkg -l | grep ^ii | awk '{ print \$2\",\"\$3 }'" > $DEST/${LOG_SUBPATH}/installed-packages-${RELEASE}$([[ ${BUILD_MINIMAL} == yes ]] &&
|
|
echo "-minimal")$([[ ${BUILD_DESKTOP} == yes ]] && echo "-desktop").list 2>&1
|
|
|
|
# clean up / prepare for making the image
|
|
umount_chroot "$SDCARD"
|
|
post_debootstrap_tweaks
|
|
|
|
if [[ $ROOTFS_TYPE == fel ]]; then
|
|
FEL_ROOTFS=$SDCARD/
|
|
display_alert "Starting FEL boot" "$BOARD" "info"
|
|
start_fel_boot
|
|
else
|
|
prepare_partitions
|
|
create_image
|
|
fi
|
|
|
|
# stage: unmount tmpfs
|
|
umount $SDCARD 2>&1
|
|
if [[ $use_tmpfs = yes ]]; then
|
|
while grep -qs "$SDCARD" /proc/mounts; do
|
|
umount $SDCARD
|
|
sleep 5
|
|
done
|
|
fi
|
|
rm -rf $SDCARD
|
|
|
|
# remove exit trap
|
|
trap - INT TERM EXIT
|
|
}
|