| #!/bin/bash
|
| ZBefore=`date +%s`
|
| zzreset="\033[0m"
|
| zzwhite="\033[1;37m"
|
| zzred="\033[1;31m"
|
| zzpurple="\033[1;35m"
|
| SET_PASSWORD=0
|
| set +h
|
| umask 022
|
| LC_ALL=POSIX
|
|
|
| zprint() { echo -e "${zzwhite} *** $* *** ${zzreset}"; }
|
| zmsg() { echo -e "${zzred} *** $* *** ${zzreset}"; }
|
| stars() { echo -e "${zzpurple} $(printf '%.0s*' {1..100}) ${zzreset}"; }
|
|
|
| print_formatted_duration() {
|
| duration=$1
|
| hour=$((duration / 3600))
|
| mins=$(( (duration % 3600) / 60 ))
|
| sec=$((duration % 60))
|
| zprint $(printf "%02d Hours, %02d Minutes and %02d Seconds \n" ${hour} ${mins} ${sec})
|
| }
|
|
|
| zbuild_check() {
|
| local file="$1"
|
| if [[ -f ${ZBUILD}/${file} ]]; then
|
| return 0
|
| else
|
| stars
|
| zprint "Error: Missing $file ... Exiting"
|
| return 1
|
| fi
|
| }
|
|
|
| zbuild_wait() {
|
| local wait=${1:-5}
|
| zmsg "Waiting $wait seconds or Press [SPACE] to continue..."
|
| read -t $wait -n 1 key
|
| if [[ $key == " " ]]; then
|
| zmsg "Skipped wait."
|
| else
|
| zmsg "Continuing..."
|
| fi
|
| }
|
| zbuild_exec() {
|
| local file="$1"
|
| case "$file" in
|
| *.zbc)
|
| ${ZBUILD}/zbuild "${ZBUILD}/$file" || { echo "Error: $file - Exiting: $?"; return 1; }
|
| ;;
|
| *.sh)
|
| "${ZBUILD}/$file" || { echo "Error: $file - Exiting: $?"; return 1; }
|
| ;;
|
| *)
|
| zmsg "Invalid File Found in Stream"
|
| return 666
|
| ;;
|
| esac
|
| }
|
| check_chroot() {
|
| IS_CHROOT=0
|
| if [[ ! /proc/1/root/. -ef / ]]; then
|
| zmsg "Inside chroot"
|
| ZBUILD=${ZBUILD:-/zbuild}
|
| ZSRC=${ZSRC:-/sources}
|
| IS_CHROOT=1
|
| else
|
| zmsg "Outside chroot"
|
| source $(pwd)/stage0/0-environment.sh || { zmsg "Error Getting Environment"; exit 1; }
|
| fi
|
| }
|
|
|
| check_chroot
|
| case "$1" in
|
| "1")
|
| zprint "Stage 1 Section 1 Build"
|
| [[ $IS_CHROOT -eq 0 ]] && {
|
| stage_build=$(printf "%s " stage1/{100..121}-*.zbc)
|
| }
|
| ;;
|
| "2")
|
| zprint "Stage 1 Section 2 Build"
|
| [[ $IS_CHROOT -eq 1 ]] && {
|
| stage_build=$(printf "%s " stage1/{200..208}-*)
|
| }
|
| ;;
|
| "3")
|
| zprint "Stage 2 Base System"
|
| [[ $IS_CHROOT -eq 1 ]] && {
|
| ZBUILD_PASSWORD="${2:-lfsroot}"
|
| SET_PASSWORD=1
|
| stage_build=$(printf "%s " stage2/{001..079}-*.zbc)
|
| }
|
| ;;
|
| "4")
|
| zprint "Stage 2 Configuration"
|
| [[ $IS_CHROOT -eq 1 ]] && {
|
| stage_build=$(printf "%s " stage2/{100..107}-*.sh)
|
| }
|
| ;;
|
| "5")
|
| zprint "Stage 2 Extra Packages"
|
| [[ $IS_CHROOT -eq 1 ]] && {
|
| stage_build=$(printf "%s " stage2/{110..119}-*.zbc)
|
| }
|
| ;;
|
| "6")
|
| zprint "Stage 3 Finalize and Reboot"
|
| [[ $IS_CHROOT -eq 1 ]] && {
|
| stage_build=$(printf "%s " stage2/{200..201}-*.zbc)
|
| }
|
| ;;
|
| *)
|
| zprint "Usage: $0 1 - Primary Build Not in Chroot"
|
| zprint " The Following Options Require chroot "
|
| zprint " $0 2 - Extra Temporary Packages"
|
| zprint " $0 3 {password} - Main Build System"
|
| zprint " $0 4 - Finalize Scripts"
|
| zprint " $0 5 - Extra Packages"
|
| zprint " $0 6 - Kernel and Grub Setup"
|
| esac
|
|
|
| for script in ${stage_build[@]}; do
|
| stars
|
| zprint "Executing ${script}"
|
| zbuild_check "${script}" || break
|
| zbuild_wait 5
|
| zbuild_exec "${script}"
|
| stars
|
| done
|
|
|
| [[ $SET_PASSWORD -eq 1 ]] && echo "${ZBUILD_PASSWORD}" | passwd --stdin root
|
| ZAfter=`date +%s`
|
| let duration=ZAfter-ZBefore
|
| print_formatted_duration $duration
|