]> git.ipfire.org Git - people/jschlag/ipfire-3.x-image.git/commitdiff
Improve how we execute commands in chroot master
authorJonatan Schlag <jonatan.schlag@ipfire.org>
Sun, 23 Jun 2019 14:25:53 +0000 (16:25 +0200)
committerJonatan Schlag <jonatan.schlag@ipfire.org>
Sun, 23 Jun 2019 14:25:53 +0000 (16:25 +0200)
Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org>
functions.sh
generate_image.sh

index f666c30234de85b33fcf4a944d1b14dbc52aad88..ad46a30ffd3e5295473d7c0a1aea6b85e66b6e80 100644 (file)
@@ -20,6 +20,7 @@ FALSE=1
 
 IMAGE_RELEASE=${FALSE}
 
+CHROOT_SCRIPT="/build/chroot.sh"
 
 
 # Functions
@@ -356,3 +357,22 @@ chroot_wrapper() {
        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}"
+}
index 88e4506d02895da7bdf61bef72be4e0f7ee8c11d..674cc2289204dde382f644e8a9b4e61c34440b8d 100755 (executable)
@@ -172,40 +172,29 @@ reset_root_password "${IMAGE_MOUNT_DIR}"
 
 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