IMAGE_RELEASE=${FALSE}
+CHROOT_SCRIPT="/build/chroot.sh"
# Functions
umount "${chroot_dir}/run"
umount "${chroot_dir}/tmp"
}
+
+chroot_script_init(){
+ echo "#!/bin/bash" > "${IMAGE_MOUNT_DIR}${CHROOT_SCRIPT}"
+}
+
+chroot_script_add_cmd(){
+ local command
+ for command in "$@"
+ do
+ echo "${command}" >> "${IMAGE_MOUNT_DIR}${CHROOT_SCRIPT}"
+ done
+}
+
+
+chroot_script_exec() {
+ chmod +x "${IMAGE_MOUNT_DIR}${CHROOT_SCRIPT}"
+
+ chroot_wrapper ${IMAGE_MOUNT_DIR} "${CHROOT_SCRIPT}"
+}
clone_git_repos "${IMAGE_MOUNT_DIR}/build" ${GIT_REPOS}
+
#
## Prepare chrooting into the image.
#
-# Check if the network stack should be build.
-if [ "${USE_GIT_NETWORK_STACK}" == "True" ]; then
- BUILD_NETWORK_CMDS="cd network/ && ./autogen.sh && ./configure && make && make install"
-fi
-
-ENABLE_GETTY="/bin/systemctl enable getty@.service"
+chroot_script_init
-# Check if the arch uses grub
if [ "${HAVE_GRUB}" == "True" ]; then
- GENERATE_GRUB_CONF="grub-install --boot-directory=${IMAGE_MOUNT_DIR}/boot/ --modules="${FILESYSTEM} part_msdos" ${outlo} && \
- grub-mkconfig -o /boot/grub/grub.cfg"
+ chroot_script_add_cmd "grub-install --boot-directory=/boot/ ${outlo}" "grub-mkconfig -o /boot/grub/grub.cfg"
fi
-# Use systemd-nspawn to spawn a chroot environment and execute
-# commands inside it.
-#
-# The first command enables the terminal on TTY1.
-# The second command generates the configuration file for grub2.
+
+# ENABLE Serial Console
+chroot_script_add_cmd "/bin/systemctl enable getty@.service"
-systemd-nspawn -D ${IMAGE_MOUNT_DIR} --bind /dev --capability=CAP_SYS_ADMIN,CAP_SYS_RAWIO --bind /proc --bind /sys << END
- echo "Execute commands inside chroot"
- ${ENABLE_GETTY}
- ${GENERATE_GRUB_CONF}
- cd /build/ && ls
- ${BUILD_NETWORK_CMDS}
- echo "All commands executed"
-END
+# Check if the network stack should be build.
+if [ "${USE_GIT_NETWORK_STACK}" == "True" ]; then
+ chroot_script_add_cmd "cd /build/network" "./autogen.sh" "./configure" "make" "make install"
+fi
+chroot_script_exec
# Insert the UUID because grub-mkconfig often fails to