diff --git a/Makefile b/Makefile index f34ee00..f59b164 100644 --- a/Makefile +++ b/Makefile @@ -42,12 +42,33 @@ build_stage1: build_stage2: sudo /usr/bin/env -i bash -c ". ./project_config.sh && ${dir_make}/build_stage2.sh" +arm_chroot: + sudo /usr/bin/env -i bash -c ". ./project_config.sh && ${dir_make}/arm_chroot.sh" + +disarm_chroot: + sudo /usr/bin/env -i bash -c ". ./project_config.sh && ${dir_make}/disarm_chroot.sh" + +enter_chroot: + sudo /usr/bin/env -i bash -c ". ./project_config.sh && ${dir_make}/enter_chroot.sh" + +#embeds and kicks off rex +#build_stage3: +# sudo /usr/bin/env -i bash -c ". ./project_config.sh && ${dir_make}/build_stage3.sh" + # example: # make dirs # make install_rex # make download_sources # make download_patches # make build_stage1 +# make build_stage2 +# make arm_chroot +# make enter_chroot + +# Remember, before you make clean or make purge_artifacts you MUST run +# make disarm_chroot beforehand or you could cause irreversible damage +# to your system. It is recommended that these operations only be +# performed on a VM, and the host distribution is only tested on Fedora. # end dependency loading block endif diff --git a/make.project/arm_chroot.sh b/make.project/arm_chroot.sh new file mode 100755 index 0000000..6a79875 --- /dev/null +++ b/make.project/arm_chroot.sh @@ -0,0 +1,62 @@ +#!/bin/bash +APPNAME="CHROOT VFS SETUP" +T_SYSROOT=${dir_sysroot} + +assert_zero() { + if [[ "$1" -eq 0 ]]; then + return + else + exit $1 + fi +} + +# ISO 8601 variation +TIMESTAMP="$(date +%Y-%m-%d_%H:%M:%S)" + +LOG_DIR="${dir_logs}/${APPNAME}-${TIMESTAMP}" + +# the file to log to +LOGFILE="${APPNAME}.log" + +logprint() { + mkdir -p "${LOG_DIR}" + echo "[$(date +%Y-%m-%d_%H:%M:%S)] [${APPNAME}] $1" \ + | tee -a "${LOG_DIR}/${LOGFILE}" +} + +is_mounted() { + findmnt $1 &> /dev/null + if [ $? != 0 ]; then + /usr/bin/false + else + logprint "Already mounted, skipping." + /usr/bin/true + fi +} + +logprint "CHROOT VFS SETUP" + +mkdir -pv ${T_SYSROOT}/{dev,proc,sys,run} +assert_zero $? + +logprint "Bind mounting /dev from host to chroot sysroot..." +is_mounted ${T_SYSROOT}/dev || mount -v --bind /dev ${T_SYSROOT}/dev +assert_zero $? + +logprint "Bind mounting /dev/pts from host to chroot sysroot..." +is_mounted ${T_SYSROOT}/dev/pts || mount -v --bind /dev/pts ${T_SYSROOT}/dev/pts +assert_zero $? + +logprint "mounting proc filesystem from to chroot sysroot..." +is_mounted ${T_SYSROOT}/proc || mount -v -t proc proc ${T_SYSROOT}/proc +assert_zero $? + +# not a symlink on ubuntu +if [ -h ${T_SYSROOT}/dev/shm ]; then + mkdir -vp ${T_SYSROOT}/$(readlink ${T_SYSROOT})/dev/shm + assert_zero $? +else + mount -t tmpfs -o nosuid,nodev tmpfs ${T_SYSROOT}/dev/shm +fi + + diff --git a/make.project/disarm_chroot.sh b/make.project/disarm_chroot.sh new file mode 100755 index 0000000..a928315 --- /dev/null +++ b/make.project/disarm_chroot.sh @@ -0,0 +1,54 @@ +#!/bin/bash +APPNAME="CHROOT VKFS SETUP" + +# ISO 8601 variation +TIMESTAMP="$(date +%Y-%m-%d_%H:%M:%S)" +T_SYSROOT=${dir_sysroot} +LOG_DIR="${dir_logs}/${APPNAME}-${TIMESTAMP}" + +# the file to log to +LOGFILE="${APPNAME}.log" + +assert_zero() { + if [[ "$1" -eq 0 ]]; then + return + else + exit $1 + fi +} + +logprint() { + mkdir -p "${LOG_DIR}" + echo "[$(date +%Y-%m-%d_%H:%M:%S)] [${APPNAME}] $1" \ + | tee -a "${LOG_DIR}/${LOGFILE}" +} + +is_mounted() { + findmnt $1 &> /dev/null + if [ $? != 0 ]; then + logprint "Not mounted, skipping." + /usr/bin/false + else + /usr/bin/true + fi +} + +logprint "Unmounting CHROOT VFKS mounts" + +logprint "Unmounting ${T_SYSROOT}/dev" +is_mounted ${T_SYSROOT}/dev && umount -l ${T_SYSROOT}/dev + +logprint "Unmounting ${T_SYSROOT}/dev/pts" +is_mounted ${T_SYSROOT}/dev/pts && umount -l ${T_SYSROOT}/dev/pts + +logprint "Unmounting ${T_SYSROOT}/proc" +is_mounted ${T_SYSROOT}/proc && umount -l ${T_SYSROOT}/proc + +# not a symlink on ubuntu +logprint "Unmounting ${T_SYSROOT}/dev/shm" +ismounted ${T_SYSROOT}/dev/shm && umount -l {${T_SYSROOT}/dev/shm + +echo +logprint "You can now safely delete the chroot." +echo + diff --git a/make.project/enter_chroot.sh b/make.project/enter_chroot.sh new file mode 100755 index 0000000..f634980 --- /dev/null +++ b/make.project/enter_chroot.sh @@ -0,0 +1,32 @@ +#!/bin/bash +APPNAME="CHROOT VFS SETUP" +T_SYSROOT=${dir_sysroot} + +assert_zero() { + if [[ "$1" -eq 0 ]]; then + return + else + exit $1 + fi +} + +# ISO 8601 variation +TIMESTAMP="$(date +%Y-%m-%d_%H:%M:%S)" + +LOG_DIR="${dir_logs}/${APPNAME}-${TIMESTAMP}" + +# the file to log to +LOGFILE="${APPNAME}.log" + +logprint() { + mkdir -p "${LOG_DIR}" + echo "[$(date +%Y-%m-%d_%H:%M:%S)] [${APPNAME}] $1" \ + | tee -a "${LOG_DIR}/${LOGFILE}" +} + +/usr/sbin/chroot "${T_SYSROOT}" /usr/bin/env -i \ + HOME=/root \ + TERM="$TERM" \ + PS1='\n(dark horse linux) [ \u @ \H ] << \w >>\n\n[- ' \ + PATH=/usr/bin:/usr/sbin \ + /bin/bash --login diff --git a/project_config.sh b/project_config.sh index 6784e19..cd9e8f0 100755 --- a/project_config.sh +++ b/project_config.sh @@ -17,7 +17,6 @@ echo "Loading project_config.sh...." # this is where the directory for foster is located. serves as the # parent directory for most other directories project_root="$(dirname $(readlink -f "${BASH_SOURCE[0]}"))" - # the project files for the make system that is used to orchestrate the # build steps dir_make=${project_root}/make.project