From 0b97320e000c47b97ffea872704dd82145df8bfc Mon Sep 17 00:00:00 2001 From: Aditya Date: Fri, 6 Jan 2023 11:16:03 +0530 Subject: [PATCH] Stop relying on SU --- scripts/main.sh | 91 ++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 74 insertions(+), 17 deletions(-) diff --git a/scripts/main.sh b/scripts/main.sh index 36b5ad0..64b3774 100644 --- a/scripts/main.sh +++ b/scripts/main.sh @@ -1,6 +1,7 @@ #!/bin/bash # Set SU +# ====== if [ $? -eq 1 ] then SU=doas @@ -8,6 +9,8 @@ else SU=sudo fi +# Exit on error +# ============= exit_status=0 function check_exit_code() { @@ -24,35 +27,89 @@ function stop_script() { exit 1 } + +# Chapter 2 +# ========= echo "Chapter 2" echo "Checking required packages" bash ./chapter2/2.2-version-check.sh -echo "Creating filesystem" -$SU bash ./chapter2/2.5-create-filesystem.sh - -echo "Mounting filesystem" -$SU bash ./chapter2/2.7-mount.sh - - -echo "Chapter 3" -echo "Downloading sources" -bash ./chapter3/3.1-sources.sh - - -echo "Chapter 4" -echo "Creating direcctories" -$SU bash ./chapter4/4.2-create-dir.sh - - +# Exit on error check_exit_code if [ $exit_status -ne 0 ] then stop_script "chapter2/2.2-version-check.sh" fi + # Set LFS variable +# ================ export LFS=/mnt/lfs echo "LFS is $LFS" +# Chapter 2.5 +# =========== +echo "Creating filesystem" +su -c "bash ./chapter2/2.5-create-filesystem.sh" + +# Exit on error +check_exit_code +if [ $exit_status -ne 0 ] +then + stop_script "chapter2/2.5-create-filesystem.sh" +fi + + +# Chapter 2.7 +# =========== +echo "Mounting filesystem" +su -c "bash ./chapter2/2.7-mount.sh" + +# Exit on error +check_exit_code +if [ $exit_status -ne 0 ] +then + stop_script "chapter2/2.7-mount.sh" +fi + + +# Chapter 3 +# ========= +echo "Chapter 3" +echo "Downloading sources" +bash ./chapter3/3.1-sources.sh + +# Exit on error +check_exit_code +if [ $exit_status -ne 0 ] +then + stop_script "chapter3/3.1-sources.sh" +fi + + +# Chapter 4 +# ========= +echo "Chapter 4" +echo "Creating direcctories" +su -c "bash ./chapter4/4.2-create-dir.sh" + +# Exit on error +check_exit_code +if [ $exit_status -ne 0 ] +then + stop_script "chapter4/4.2-create-dir.sh" +fi + + +# Chapter 4.3 +# =========== +echo "Adding LFS user" +su -c "bash ./chapter4/4.3-add-user.sh" + +# Exit on error +check_exit_code +if [ $exit_status -ne 0 ] +then + stop_script "chapter4/4.3-add-user.sh" +fi