diff --git a/configs/init-overlay b/configs/init-overlay new file mode 100755 index 0000000..ade31c8 --- /dev/null +++ b/configs/init-overlay @@ -0,0 +1,24 @@ +#!/bin/sh + +mkdir /run/overlay + +# Set up the overlay filesystem +mount -t tmpfs tmpfs /run/overlay +mkdir -p /run/overlay/upper +mkdir -p /run/overlay/work +mkdir -p /run/overlay/root + +mount -t overlay overlay -o lowerdir=/,upperdir=/run/overlay/upper,workdir=/run/overlay/work /run/overlay/root + +# Pivot the root filesystem to the overlay filesystem +pivot_root /run/overlay/root /run/overlay/root/mnt + +# Move the original mount points to their new locations +for i in dev proc sys run; do + mount --move /mnt/$i /$i +done + +# Clean up and switch to the new init +umount /mnt +exec chroot . /sbin/init dev/console 2>&1 + diff --git a/make.project/arm_chroot.sh b/make.project/arm_chroot.sh index 60fa169..eebbc51 100755 --- a/make.project/arm_chroot.sh +++ b/make.project/arm_chroot.sh @@ -1,4 +1,6 @@ #!/bin/bash +set -u + APPNAME="CHROOT VFS SETUP" T_SYSROOT=${dir_sysroot} set -a diff --git a/make.project/backup_create.sh b/make.project/backup_create.sh index dd5bb11..6940534 100755 --- a/make.project/backup_create.sh +++ b/make.project/backup_create.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash - +set -u # fix an issue with open files limit on some hosts ulimit -l unlimited diff --git a/make.project/backup_restore.sh b/make.project/backup_restore.sh index 079a9b6..7ba77bf 100755 --- a/make.project/backup_restore.sh +++ b/make.project/backup_restore.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash - +set -u # fix an issue with open files limit on some hosts ulimit -l unlimited diff --git a/make.project/build_stage1.sh b/make.project/build_stage1.sh index 3a2b824..df238d9 100755 --- a/make.project/build_stage1.sh +++ b/make.project/build_stage1.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +set -u # closely aligns with LFS Ch 5, 6 diff --git a/make.project/build_stage2.sh b/make.project/build_stage2.sh index f348fdd..8a7211a 100755 --- a/make.project/build_stage2.sh +++ b/make.project/build_stage2.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash - +set -u # closely aligns with LFS Ch 5, 6 # fix an issue with open files limit on some hosts diff --git a/make.project/build_stage3.sh b/make.project/build_stage3.sh index e3e916b..98b0357 100755 --- a/make.project/build_stage3.sh +++ b/make.project/build_stage3.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +set -u # fix an issue with open files limit on some hosts ulimit -l unlimited diff --git a/make.project/build_stage4.sh b/make.project/build_stage4.sh index 4c1f4a5..bb84abe 100755 --- a/make.project/build_stage4.sh +++ b/make.project/build_stage4.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +set -u # fix an issue with open files limit on some hosts ulimit -l unlimited diff --git a/make.project/build_stage5.sh b/make.project/build_stage5.sh index 01add3a..9e50566 100755 --- a/make.project/build_stage5.sh +++ b/make.project/build_stage5.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +set -u # fix an issue with open files limit on some hosts ulimit -l unlimited diff --git a/make.project/clean.sh b/make.project/clean.sh index fa8ccef..98e00f4 100755 --- a/make.project/clean.sh +++ b/make.project/clean.sh @@ -1,4 +1,6 @@ # clean the slate +set -u + echo echo "Deleting ${dir_stage}" rm -Rf ${dir_stage} diff --git a/make.project/dirs.sh b/make.project/dirs.sh index 61477ff..1982447 100755 --- a/make.project/dirs.sh +++ b/make.project/dirs.sh @@ -1,3 +1,7 @@ +#!/usr/bin/env bash + +set -u + function echofail() { echo $1 exit 1 diff --git a/make.project/disarm_chroot.sh b/make.project/disarm_chroot.sh index 60770f3..d592b4a 100755 --- a/make.project/disarm_chroot.sh +++ b/make.project/disarm_chroot.sh @@ -1,4 +1,6 @@ #!/bin/bash +set -u + APPNAME="CHROOT VKFS SETUP" # ISO 8601 variation diff --git a/make.project/download_patches.sh b/make.project/download_patches.sh index f521a79..a798722 100755 --- a/make.project/download_patches.sh +++ b/make.project/download_patches.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +set -u function echofail() { echo "FAILED: $1" diff --git a/make.project/download_sources.sh b/make.project/download_sources.sh index 9485b73..7e66bde 100755 --- a/make.project/download_sources.sh +++ b/make.project/download_sources.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +set -u function echofail() { echo "FAILED: $1" diff --git a/make.project/enter_chroot.sh b/make.project/enter_chroot.sh index 4c7a726..cbc5998 100755 --- a/make.project/enter_chroot.sh +++ b/make.project/enter_chroot.sh @@ -1,4 +1,7 @@ #!/bin/bash +set -u + + APPNAME="CHROOT VFS SETUP" T_SYSROOT=${dir_sysroot} diff --git a/make.project/install_rex.sh b/make.project/install_rex.sh index 9a99b41..b167363 100755 --- a/make.project/install_rex.sh +++ b/make.project/install_rex.sh @@ -1,3 +1,6 @@ +#!/usr/bin/env bash + +set -u function echofail() { echo "Failed: $1" diff --git a/make.project/livecd.sh b/make.project/livecd.sh index 1550485..8e369e6 100755 --- a/make.project/livecd.sh +++ b/make.project/livecd.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash - +set -u # fix an issue with open files limit on some hosts ulimit -l unlimited diff --git a/make.project/master.sh b/make.project/master.sh index 65b3899..115a6eb 100755 --- a/make.project/master.sh +++ b/make.project/master.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +set -u # fix an issue with open files limit on some hosts ulimit -l unlimited diff --git a/make.project/purge_artifacts.sh b/make.project/purge_artifacts.sh index a457a0f..cb16a55 100755 --- a/make.project/purge_artifacts.sh +++ b/make.project/purge_artifacts.sh @@ -1,3 +1,7 @@ +#!/usr/bin/env bash + +set -u + echo echo "Recreating ${dir_artifacts}" rm -Rf ${dir_artifacts} diff --git a/rex.project/x86_64/components/livecd/asciidoc.bash b/rex.project/x86_64/components/livecd/asciidoc.bash index bb0d7b9..d37bb53 100755 --- a/rex.project/x86_64/components/livecd/asciidoc.bash +++ b/rex.project/x86_64/components/livecd/asciidoc.bash @@ -4,6 +4,7 @@ # make variables persist in subprocesses for logging function set -a +set -u # ---------------------------------------------------------------------- # Configuration: diff --git a/rex.project/x86_64/components/livecd/dracut.bash b/rex.project/x86_64/components/livecd/dracut.bash index 6208d30..137173b 100755 --- a/rex.project/x86_64/components/livecd/dracut.bash +++ b/rex.project/x86_64/components/livecd/dracut.bash @@ -4,7 +4,7 @@ # make variables persist in subprocesses for logging function set -a - +set -u # ---------------------------------------------------------------------- # Configuration: # ---------------------------------------------------------------------- diff --git a/rex.project/x86_64/components/livecd/libxml2.bash b/rex.project/x86_64/components/livecd/libxml2.bash index 5b287fe..89f6994 100755 --- a/rex.project/x86_64/components/livecd/libxml2.bash +++ b/rex.project/x86_64/components/livecd/libxml2.bash @@ -4,6 +4,7 @@ # make variables persist in subprocesses for logging function set -a +set -u # ---------------------------------------------------------------------- # Configuration: diff --git a/rex.project/x86_64/components/livecd/libxslt.bash b/rex.project/x86_64/components/livecd/libxslt.bash index 49105db..4530a71 100755 --- a/rex.project/x86_64/components/livecd/libxslt.bash +++ b/rex.project/x86_64/components/livecd/libxslt.bash @@ -4,6 +4,7 @@ # make variables persist in subprocesses for logging function set -a +set -u # ---------------------------------------------------------------------- # Configuration: diff --git a/rex.project/x86_64/components/livecd/livecd.bash b/rex.project/x86_64/components/livecd/livecd.bash index 19a1805..f72a9f8 100755 --- a/rex.project/x86_64/components/livecd/livecd.bash +++ b/rex.project/x86_64/components/livecd/livecd.bash @@ -4,6 +4,7 @@ # make variables persist in subprocesses for logging function set -a +set -u APPNAME="livecd" diff --git a/rex.project/x86_64/components/stage1/binutils.bash b/rex.project/x86_64/components/stage1/binutils.bash index dbb1eea..3a907fe 100755 --- a/rex.project/x86_64/components/stage1/binutils.bash +++ b/rex.project/x86_64/components/stage1/binutils.bash @@ -4,6 +4,7 @@ # make variables persist in subprocesses for logging function set -a +set -u # ---------------------------------------------------------------------- # Configuration: @@ -326,6 +327,9 @@ mode_install_pass2() { rm -v ${T_SYSROOT}/usr/lib/lib{bfd,ctf,ctf-nobfd,opcodes}.{a,la} assert_zero $? + rm -v rm -fv /usr/share/man/man1/{gprofng,gp-*}.1 + assert_zero $? + logprint "Install operation complete." } diff --git a/rex.project/x86_64/components/stage1/check_dependencies.bash b/rex.project/x86_64/components/stage1/check_dependencies.bash index 32ce616..95f5b6b 100755 --- a/rex.project/x86_64/components/stage1/check_dependencies.bash +++ b/rex.project/x86_64/components/stage1/check_dependencies.bash @@ -1,5 +1,7 @@ #!/bin/bash # Simple script to list version numbers of critical development tools +set -u + export LC_ALL=C echo diff --git a/rex.project/x86_64/components/stage1/create_sysroot_dirs.bash b/rex.project/x86_64/components/stage1/create_sysroot_dirs.bash index 0470f2c..7abf068 100755 --- a/rex.project/x86_64/components/stage1/create_sysroot_dirs.bash +++ b/rex.project/x86_64/components/stage1/create_sysroot_dirs.bash @@ -1,4 +1,5 @@ #!/usr/bin/env bash +set -u mkdir -pv ${dir_sysroot}/{etc,var} ${dir_sysroot}/usr/{bin,lib,sbin} || echofail "Creating sysroot directories..." diff --git a/rex.project/x86_64/components/stage1/gcc.bash b/rex.project/x86_64/components/stage1/gcc.bash index f177a04..ff5bff4 100755 --- a/rex.project/x86_64/components/stage1/gcc.bash +++ b/rex.project/x86_64/components/stage1/gcc.bash @@ -4,6 +4,7 @@ # make variables persist in subprocesses for logging function set -a +set -u # ---------------------------------------------------------------------- # Configuration: diff --git a/rex.project/x86_64/components/stage1/glibc.bash b/rex.project/x86_64/components/stage1/glibc.bash index 88c82b6..b95b628 100755 --- a/rex.project/x86_64/components/stage1/glibc.bash +++ b/rex.project/x86_64/components/stage1/glibc.bash @@ -4,6 +4,7 @@ # make variables persist in subprocesses for logging function set -a +set -u # ---------------------------------------------------------------------- # Configuration: diff --git a/rex.project/x86_64/components/stage1/linux.bash b/rex.project/x86_64/components/stage1/linux.bash index 85c9787..7097cb1 100755 --- a/rex.project/x86_64/components/stage1/linux.bash +++ b/rex.project/x86_64/components/stage1/linux.bash @@ -4,6 +4,7 @@ # make variables persist in subprocesses for logging function set -a +set -u # ---------------------------------------------------------------------- # Configuration: diff --git a/rex.project/x86_64/components/stage2/bash.bash b/rex.project/x86_64/components/stage2/bash.bash index 16a70ab..4774c9d 100755 --- a/rex.project/x86_64/components/stage2/bash.bash +++ b/rex.project/x86_64/components/stage2/bash.bash @@ -4,6 +4,7 @@ # make variables persist in subprocesses for logging function set -a +set -u # ---------------------------------------------------------------------- # Configuration: diff --git a/rex.project/x86_64/components/stage2/coreutils.bash b/rex.project/x86_64/components/stage2/coreutils.bash index 62fb3b1..d02b164 100755 --- a/rex.project/x86_64/components/stage2/coreutils.bash +++ b/rex.project/x86_64/components/stage2/coreutils.bash @@ -4,6 +4,7 @@ # make variables persist in subprocesses for logging function set -a +set -u # ---------------------------------------------------------------------- # Configuration: diff --git a/rex.project/x86_64/components/stage2/diffutils.bash b/rex.project/x86_64/components/stage2/diffutils.bash index 9227868..97f0e3e 100755 --- a/rex.project/x86_64/components/stage2/diffutils.bash +++ b/rex.project/x86_64/components/stage2/diffutils.bash @@ -4,6 +4,7 @@ # make variables persist in subprocesses for logging function set -a +set -u # ---------------------------------------------------------------------- # Configuration: diff --git a/rex.project/x86_64/components/stage2/file.bash b/rex.project/x86_64/components/stage2/file.bash index fe971b1..ce579bb 100755 --- a/rex.project/x86_64/components/stage2/file.bash +++ b/rex.project/x86_64/components/stage2/file.bash @@ -4,6 +4,7 @@ # make variables persist in subprocesses for logging function set -a +set -u # ---------------------------------------------------------------------- # Configuration: diff --git a/rex.project/x86_64/components/stage2/findutils.bash b/rex.project/x86_64/components/stage2/findutils.bash index ed43616..d651870 100755 --- a/rex.project/x86_64/components/stage2/findutils.bash +++ b/rex.project/x86_64/components/stage2/findutils.bash @@ -4,6 +4,7 @@ # make variables persist in subprocesses for logging function set -a +set -u # ---------------------------------------------------------------------- # Configuration: diff --git a/rex.project/x86_64/components/stage2/fix_chroot_perms.bash b/rex.project/x86_64/components/stage2/fix_chroot_perms.bash index ef56c13..6b8b9c5 100755 --- a/rex.project/x86_64/components/stage2/fix_chroot_perms.bash +++ b/rex.project/x86_64/components/stage2/fix_chroot_perms.bash @@ -3,6 +3,7 @@ # print to stdout, print to log # the path where logs are written to # note: LOGS_ROOT is sourced from environment +set -u APPNAME="FIX_CHROOT_PERMS" diff --git a/rex.project/x86_64/components/stage2/gawk.bash b/rex.project/x86_64/components/stage2/gawk.bash index 58bcd68..883bada 100755 --- a/rex.project/x86_64/components/stage2/gawk.bash +++ b/rex.project/x86_64/components/stage2/gawk.bash @@ -4,7 +4,7 @@ # make variables persist in subprocesses for logging function set -a - +set -u # ---------------------------------------------------------------------- # Configuration: # ---------------------------------------------------------------------- diff --git a/rex.project/x86_64/components/stage2/grep.bash b/rex.project/x86_64/components/stage2/grep.bash index a252b73..de34445 100755 --- a/rex.project/x86_64/components/stage2/grep.bash +++ b/rex.project/x86_64/components/stage2/grep.bash @@ -4,6 +4,7 @@ # make variables persist in subprocesses for logging function set -a +set -u # ---------------------------------------------------------------------- # Configuration: diff --git a/rex.project/x86_64/components/stage2/gzip.bash b/rex.project/x86_64/components/stage2/gzip.bash index d5f320e..b99468a 100755 --- a/rex.project/x86_64/components/stage2/gzip.bash +++ b/rex.project/x86_64/components/stage2/gzip.bash @@ -4,6 +4,7 @@ # make variables persist in subprocesses for logging function set -a +set -u # ---------------------------------------------------------------------- # Configuration: diff --git a/rex.project/x86_64/components/stage2/m4.bash b/rex.project/x86_64/components/stage2/m4.bash index 242e5ba..66469f0 100755 --- a/rex.project/x86_64/components/stage2/m4.bash +++ b/rex.project/x86_64/components/stage2/m4.bash @@ -4,6 +4,7 @@ # make variables persist in subprocesses for logging function set -a +set -u # ---------------------------------------------------------------------- # Configuration: diff --git a/rex.project/x86_64/components/stage2/make.bash b/rex.project/x86_64/components/stage2/make.bash index c448110..ff27e5d 100755 --- a/rex.project/x86_64/components/stage2/make.bash +++ b/rex.project/x86_64/components/stage2/make.bash @@ -4,6 +4,7 @@ # make variables persist in subprocesses for logging function set -a +set -u # ---------------------------------------------------------------------- # Configuration: diff --git a/rex.project/x86_64/components/stage2/ncurses.bash b/rex.project/x86_64/components/stage2/ncurses.bash index 4edc566..641f4f3 100755 --- a/rex.project/x86_64/components/stage2/ncurses.bash +++ b/rex.project/x86_64/components/stage2/ncurses.bash @@ -4,6 +4,7 @@ # make variables persist in subprocesses for logging function set -a +set -u # ---------------------------------------------------------------------- # Configuration: diff --git a/rex.project/x86_64/components/stage2/patch.bash b/rex.project/x86_64/components/stage2/patch.bash index 90d2942..568f0f0 100755 --- a/rex.project/x86_64/components/stage2/patch.bash +++ b/rex.project/x86_64/components/stage2/patch.bash @@ -4,6 +4,7 @@ # make variables persist in subprocesses for logging function set -a +set -u # ---------------------------------------------------------------------- # Configuration: diff --git a/rex.project/x86_64/components/stage2/populate_ug.bash b/rex.project/x86_64/components/stage2/populate_ug.bash index 5a6298a..4c38006 100755 --- a/rex.project/x86_64/components/stage2/populate_ug.bash +++ b/rex.project/x86_64/components/stage2/populate_ug.bash @@ -3,6 +3,7 @@ # print to stdout, print to log # the path where logs are written to # note: LOGS_ROOT is sourced from environment +set -u APPNAME="CHROOT PASSWD GROUPS" diff --git a/rex.project/x86_64/components/stage2/prepare_vkfs.bash b/rex.project/x86_64/components/stage2/prepare_vkfs.bash index af04b51..85419c9 100755 --- a/rex.project/x86_64/components/stage2/prepare_vkfs.bash +++ b/rex.project/x86_64/components/stage2/prepare_vkfs.bash @@ -3,6 +3,7 @@ # print to stdout, print to log # the path where logs are written to # note: LOGS_ROOT is sourced from environment +set -u APPNAME="CHROOT VFS SETUP" diff --git a/rex.project/x86_64/components/stage2/sed.bash b/rex.project/x86_64/components/stage2/sed.bash index c16b299..557e15c 100755 --- a/rex.project/x86_64/components/stage2/sed.bash +++ b/rex.project/x86_64/components/stage2/sed.bash @@ -4,6 +4,7 @@ # make variables persist in subprocesses for logging function set -a +set -u # ---------------------------------------------------------------------- # Configuration: diff --git a/rex.project/x86_64/components/stage2/tar.bash b/rex.project/x86_64/components/stage2/tar.bash index 61e14a7..e269225 100755 --- a/rex.project/x86_64/components/stage2/tar.bash +++ b/rex.project/x86_64/components/stage2/tar.bash @@ -4,6 +4,7 @@ # make variables persist in subprocesses for logging function set -a +set -u # ---------------------------------------------------------------------- # Configuration: diff --git a/rex.project/x86_64/components/stage2/xz.bash b/rex.project/x86_64/components/stage2/xz.bash index 60bb4d1..7418f2d 100755 --- a/rex.project/x86_64/components/stage2/xz.bash +++ b/rex.project/x86_64/components/stage2/xz.bash @@ -4,6 +4,7 @@ # make variables persist in subprocesses for logging function set -a +set -u # ---------------------------------------------------------------------- # Configuration: diff --git a/rex.project/x86_64/components/stage3/bison.bash b/rex.project/x86_64/components/stage3/bison.bash index 5f9ddde..32d4736 100755 --- a/rex.project/x86_64/components/stage3/bison.bash +++ b/rex.project/x86_64/components/stage3/bison.bash @@ -4,6 +4,7 @@ # make variables persist in subprocesses for logging function set -a +set -u # ---------------------------------------------------------------------- # Configuration: diff --git a/rex.project/x86_64/components/stage3/clean-temp.bash b/rex.project/x86_64/components/stage3/clean-temp.bash index 806b0be..ca41429 100755 --- a/rex.project/x86_64/components/stage3/clean-temp.bash +++ b/rex.project/x86_64/components/stage3/clean-temp.bash @@ -3,6 +3,7 @@ # print to stdout, print to log # the path where logs are written to # note: LOGS_ROOT is sourced from environment +set -u APPNAME="Cleaning up the Temporary System" diff --git a/rex.project/x86_64/components/stage5/squashfs-tools.bash b/rex.project/x86_64/components/stage5/squashfs-tools.bash new file mode 100755 index 0000000..7393cbb --- /dev/null +++ b/rex.project/x86_64/components/stage5/squashfs-tools.bash @@ -0,0 +1,219 @@ +#!/bin/bash +# desc: +# stages, builds, installs + +# make variables persist in subprocesses for logging function +set -a + +# ---------------------------------------------------------------------- +# Configuration: +# ---------------------------------------------------------------------- +# the name of this application +APPNAME="squashfs" + +# the version of this application +VERSION="4.6.1" + +# ---------------------------------------------------------------------- +# Variables and functions sourced from Environment: +# ---------------------------------------------------------------------- +# assert_zero() +# Checks if $1 is 0. If non-0 value, halts the execution of the script. +# +# LOGS_ROOT +# The parent directory where logs from this project will go. +# +# TEMP_STAGE_DIR +# The parent directory of where source archives are extracted to. + +# register mode selections +ARGUMENT_LIST=( + "stage" + "build" + "install" + "all" + "help" +) + +# modes to associate with switches +# assumes you want nothing done unless you ask for it. +MODE_STAGE=false +MODE_BUILD=false +MODE_INSTALL=false +MODE_ALL=false +MODE_HELP=false + +# the file to log to +LOGFILE="${APPNAME}.log" + +# ISO 8601 variation +TIMESTAMP="$(date +%Y-%m-%d_%H:%M:%S)" + +# the path where logs are written to +# note: LOGS_ROOT is sourced from environment +LOG_DIR="${LOGS_ROOT}/${APPNAME}-${TIMESTAMP}" + +mkdir -p ${TEMP_STAGE_DIR} +# the path where the source will be located when complete +# note: TEMP_STAGE_DIR is sourced from environment +T_SOURCE_DIR="${TEMP_STAGE_DIR}/${APPNAME}" + +# read defined arguments +opts=$(getopt \ + --longoptions "$(printf "%s," "${ARGUMENT_LIST[@]}")" \ + --name "$APPNAME" \ + --options "" \ + -- "$@" +) + +# process supplied arguments into flags that enable execution modes +eval set --$opts +while [[ $# -gt 0 ]]; do + case "$1" in + --stage) + MODE_STAGE=true + shift 1 + ;; + --build) + MODE_BUILD=true + shift 1 + ;; + --install) + MODE_INSTALL=true + shift 1 + ;; + --all) + MODE_ALL=true + shift 1 + ;; + --help) + MODE_HELP=true + shift 1 + ;; + *) + break + ;; + esac +done + +# print to stdout, print to log +logprint() { + mkdir -p "${LOG_DIR}" + echo "[$(date +%Y-%m-%d_%H:%M:%S)] [${APPNAME}] $1" \ + | tee -a "${LOG_DIR}/${LOGFILE}" +} + +# Tell the user we're alive... +logprint "Initializing the ${APPNAME} utility..." + +# when the stage mode is enabled, this will execute +mode_stage() { + logprint "Starting stage of ${APPNAME}..." + + logprint "Removing any pre-existing staging for ${APPNAME}." + rm -Rf "${T_SOURCE_DIR}"* + + logprint "Extracting ${APPNAME}-${VERSION} source archive to ${TEMP_STAGE_DIR}" + echo "${SOURCES_DIR}/${APPNAME}${VERSION}.tar."* -C "${TEMP_STAGE_DIR}" + tar xf "${SOURCES_DIR}/${APPNAME}${VERSION}.tar."* -C "${TEMP_STAGE_DIR}" + assert_zero $? + + # conditionally rename if it needs it + stat "${T_SOURCE_DIR}"* && mv "${T_SOURCE_DIR}"* "${T_SOURCE_DIR}" + + logprint "Staging operation complete." +} + +# when the build_pass1 mode is enabled, this will execute +mode_build() { + + # patch, configure and build + logprint "Starting build of ${APPNAME}..." + + logprint "Entering build dir." + pushd "${T_SOURCE_DIR}" + assert_zero $? + + pushd squashfs-tools + assert_zero $? + + logprint "Compiling..." + make + assert_zero $? + + logprint "Build operation complete." +} + +mode_install() { + logprint "Starting install of ${APPNAME}..." + pushd "${T_SOURCE_DIR}" + assert_zero $? + + pushd squashfs-tools + assert_zero $? + + # fixing nonsense + #sed -i 's/ECHO=$(which echo)/ECHO="echo"/' ../generate-manpages/functions.sh + #assert_zero $? + + #sed -i '4,8s/^/#/' ../generate-manpages/functions.sh + #assert_zero $? + + sed -i 's|INSTALL_DIR = $(INSTALL_PREFIX)/bin|INSTALL_DIR = /usr/sbin|' Makefile + assert_zero $? + + logprint "Installing..." + make install + assert_zero $? + + logprint "Install operation complete." +} + + +mode_help() { + echo "${APPNAME} [ --stage ] [ --build_temp ] [ --install_temp ] [ --all_temp ] [ --help ]" + exit 1 +} + +if [ "$MODE_ALL" = "true" ]; then + MODE_STAGE=true + MODE_BUILD=true + MODE_INSTALL=true +fi + +# if no options were selected, then show help and exit +if \ + [ "$MODE_HELP" != "true" ] && \ + [ "$MODE_STAGE" != "true" ] && \ + [ "$MODE_BUILD" != "true" ] && \ + [ "$MODE_INSTALL" != "true" ] +then + logprint "No option selected during execution." + mode_help +fi + +# if help was supplied at all, show help and exit +if [ "$MODE_HELP" = "true" ]; then + logprint "Help option selected. Printing options and exiting." + mode_help +fi + +if [ "$MODE_STAGE" = "true" ]; then + logprint "Staging option selected." + mode_stage + assert_zero $? +fi + +if [ "$MODE_BUILD" = "true" ]; then + logprint "Build of ${APPNAME} selected." + mode_build + assert_zero $? +fi + +if [ "$MODE_INSTALL" = "true" ]; then + logprint "Install of ${APPNAME} selected." + mode_install + assert_zero $? +fi + +logprint "Execution of ${APPNAME} completed." diff --git a/rex.project/x86_64/components/stage5/which.bash b/rex.project/x86_64/components/stage5/which.bash new file mode 100755 index 0000000..d5d25a8 --- /dev/null +++ b/rex.project/x86_64/components/stage5/which.bash @@ -0,0 +1,205 @@ +#!/bin/bash +# desc: +# stages, builds, installs + +# make variables persist in subprocesses for logging function +set -a + +# ---------------------------------------------------------------------- +# Configuration: +# ---------------------------------------------------------------------- +# the name of this application +APPNAME="which" + +# the version of this application +VERSION="2.21" + +# ---------------------------------------------------------------------- +# Variables and functions sourced from Environment: +# ---------------------------------------------------------------------- +# assert_zero() +# Checks if $1 is 0. If non-0 value, halts the execution of the script. +# +# LOGS_ROOT +# The parent directory where logs from this project will go. +# +# TEMP_STAGE_DIR +# The parent directory of where source archives are extracted to. + +# register mode selections +ARGUMENT_LIST=( + "stage" + "build" + "install" + "all" + "help" +) + +# modes to associate with switches +# assumes you want nothing done unless you ask for it. +MODE_STAGE=false +MODE_BUILD=false +MODE_INSTALL=false +MODE_ALL=false +MODE_HELP=false + +# the file to log to +LOGFILE="${APPNAME}.log" + +# ISO 8601 variation +TIMESTAMP="$(date +%Y-%m-%d_%H:%M:%S)" + +# the path where logs are written to +# note: LOGS_ROOT is sourced from environment +LOG_DIR="${LOGS_ROOT}/${APPNAME}-${TIMESTAMP}" + +# the path where the source will be located when complete +# note: TEMP_STAGE_DIR is sourced from environment +T_SOURCE_DIR="${TEMP_STAGE_DIR}/${APPNAME}" + +# read defined arguments +opts=$(getopt \ + --longoptions "$(printf "%s," "${ARGUMENT_LIST[@]}")" \ + --name "$APPNAME" \ + --options "" \ + -- "$@" +) + +# process supplied arguments into flags that enable execution modes +eval set --$opts +while [[ $# -gt 0 ]]; do + case "$1" in + --stage) + MODE_STAGE=true + shift 1 + ;; + --build) + MODE_BUILD=true + shift 1 + ;; + --install) + MODE_INSTALL=true + shift 1 + ;; + --all) + MODE_ALL=true + shift 1 + ;; + --help) + MODE_HELP=true + shift 1 + ;; + *) + break + ;; + esac +done + +# print to stdout, print to log +logprint() { + mkdir -p "${LOG_DIR}" + echo "[$(date +%Y-%m-%d_%H:%M:%S)] [${APPNAME}] $1" \ + | tee -a "${LOG_DIR}/${LOGFILE}" +} + +# Tell the user we're alive... +logprint "Initializing the ${APPNAME} utility..." + +# when the stage mode is enabled, this will execute +mode_stage() { + logprint "Starting stage of ${APPNAME}..." + + logprint "Removing any pre-existing staging for ${APPNAME}." + rm -Rf "${T_SOURCE_DIR}"* + + logprint "Extracting ${APPNAME}-${VERSION} source archive to ${TEMP_STAGE_DIR}" + tar xf "${SOURCES_DIR}/${APPNAME}-${VERSION}.tar."* -C "${TEMP_STAGE_DIR}" + assert_zero $? + + # conditionally rename if it needs it + stat "${T_SOURCE_DIR}-"* && mv "${T_SOURCE_DIR}-"* "${T_SOURCE_DIR}" + + logprint "Staging operation complete." +} + +# when the build_pass1 mode is enabled, this will execute +mode_build() { + + # patch, configure and build + logprint "Starting build of ${APPNAME}..." + + logprint "Entering build dir." + pushd "${T_SOURCE_DIR}" + assert_zero $? + + logprint "Configuring ${APPNAME}..." + ./configure --prefix=/usr + assert_zero $? + + logprint "Compiling..." + make + assert_zero $? + + logprint "Build operation complete." +} + +mode_install() { + logprint "Starting install of ${APPNAME}..." + pushd "${T_SOURCE_DIR}" + assert_zero $? + + logprint "Installing..." + make install + assert_zero $? + + logprint "Install operation complete." +} + + +mode_help() { + echo "${APPNAME} [ --stage ] [ --build_temp ] [ --install_temp ] [ --all_temp ] [ --help ]" + exit 1 +} + +if [ "$MODE_ALL" = "true" ]; then + MODE_STAGE=true + MODE_BUILD=true + MODE_INSTALL=true +fi + +# if no options were selected, then show help and exit +if \ + [ "$MODE_HELP" != "true" ] && \ + [ "$MODE_STAGE" != "true" ] && \ + [ "$MODE_BUILD" != "true" ] && \ + [ "$MODE_INSTALL" != "true" ] +then + logprint "No option selected during execution." + mode_help +fi + +# if help was supplied at all, show help and exit +if [ "$MODE_HELP" = "true" ]; then + logprint "Help option selected. Printing options and exiting." + mode_help +fi + +if [ "$MODE_STAGE" = "true" ]; then + logprint "Staging option selected." + mode_stage + assert_zero $? +fi + +if [ "$MODE_BUILD" = "true" ]; then + logprint "Build of ${APPNAME} selected." + mode_build + assert_zero $? +fi + +if [ "$MODE_INSTALL" = "true" ]; then + logprint "Install of ${APPNAME} selected." + mode_install + assert_zero $? +fi + +logprint "Execution of ${APPNAME} completed." diff --git a/rex.project/x86_64/environments/livecd.env.bash b/rex.project/x86_64/environments/livecd.env.bash new file mode 100755 index 0000000..ddc4699 --- /dev/null +++ b/rex.project/x86_64/environments/livecd.env.bash @@ -0,0 +1,75 @@ +set -a + +source ./project_config.sh + +TERM=xterm-256color +COLORTERM=truecolor +LC_ALL=C + +function echofail() { + echo + echo "FAILED: $1" + echo + exit 1 +} + +# keeps talking about T_SYSROOT as $LFS +# wants $LFS path to be a mount +# needs to be set for any user including root + +#2.6 +# sourced from project_config +T_SYSROOT=${dir_sysroot} +LFS=${T_SYSROOT} + +rex_dir="/rex_embedded" + + +# 4.3 we skip user and group creation, it's expected to be done before +# you start if you want a different user than you're running as +# == after that, configure the rex unit for dir creation to use that user + +if [ "$(id -u)" -ne 0 ]; then + echo "Not running as root." +fi + +# 4.4 + +# The set +h command turns off bash's hash function, which affects caching of paths for executables +set +h + +# ensures newly created files and directories are only writable by their owner, but are readable and executable by anyone +umask 022 + +# sets a comptabile machine name description for use when building crosstools that isn't going to be what the host system is using +# $LFS_TGT is what LFS uses for this +T_TRIPLET=x86_64-dhl-linux-gnu + +# prevents some configure scripts from looking in the wrong place for config.site +CONFIG_SITE=${T_SYSROOT}/usr/share/config.site + +# 4.5 +MAKEFLAGS="-j$(nproc)" + +# where the cross-compiler gets installed ($LFS/tools) +CROSSTOOLS_DIR=${T_SYSROOT}/xtools +TEMP_STAGE_DIR=${T_SYSROOT}/source_stage +# from project_config +SOURCES_DIR=${dir_sources} +PATCHES_DIR=${dir_patches} +LOGS_ROOT=${dir_logs}/apps/stage2 +CONFIGS_DIR=${dir_configs} + +# fail the unit in the event of a non-zero value passed +# used primarily to check exit codes on previous commands +# also a great convenient place to add in a "press any key to continue" +assert_zero() { + if [[ "$1" -eq 0 ]]; then + return + else + exit $1 + fi +} + +ARCHLIB_DIR=${T_SYSROOT}/lib64 +PATH=${CROSSTOOLS_DIR}/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin