| #!/bin/bash
|
| set +h
|
| umask 022
|
|
|
| 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 ${file} ]]; then
|
| return 2
|
| fi
|
| local pkg="$(basename ${file%.*})"
|
| ! grep -q "$pkg" "$ZBUILD/zpackage.db"
|
| return $?
|
| # found = 1
|
| # not found = 0
|
| }
|
|
|
| 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 "$file" || { echo "Error: $file - Exiting: $?"; return 1; }
|
| ;;
|
| *.sh)
|
| "$file" || { echo "Error: $file - Exiting: $?"; return 1; }
|
| ;;
|
| *)
|
| zmsg "Invalid File Found in Stream"
|
| return 666
|
| ;;
|
| esac
|
| }
|
| #
|
| # Start of Package Builder
|
| #
|
| ZBefore=`date +%s`
|
| zzreset="\033[0m"
|
| zzwhite="\033[1;37m"
|
| zzred="\033[1;31m"
|
| zzpurple="\033[1;35m"
|
| ZSRC=${ZSRC:-/sources}
|
| ZBUILD=${ZBUILD:-/zbuild}
|
| ZPACK=$1
|
| zerror=0
|
|
|
| if [[ -z $ZPACK ]]; then
|
| zmsg "A package tar file is required. exiting."
|
| exit 1
|
| fi
|
|
|
| # Extract the Package Tar
|
| ZTMP=$ZBUILD/stage3
|
| ZPACKTMP=$ZTMP/$(basename {ZPACK%.*})
|
|
|
| echo ":::: This should be created:: ${ZPACKTMP}"
|
| tar -xf $ZPACK -C $ZTMP || { zmsg "Error Extracting package Tar. Exiting."; exit 1; }
|
|
|
| if ! [[ -d $ZPACKTMP ]]; then
|
| zmsg "pack Directory Not Found. Exiting."
|
| exit 1
|
| else
|
| pushd ${ZTMP}
|
| source "$ZPACKTMP/install.sh"
|
| echo "Found ${packagedir}"
|
| popd
|
| fi
|
|
|
| if [[ -n "$packagedir" ]] && ([[ -z "$zcheck" ]] || [[ "$zcheck" == "0" ]]); then
|
| stars
|
| script=$(find "${ZPACKTMP}" -type f -name "*.zbc" | head -n 1)
|
| if [[ -z ${script} ]]; then
|
| zmsg "Could Not Locate zbc file. exiting."
|
| exit 1
|
| else
|
| zprint "Executing ${script}"
|
| zbuild_check "${script}"
|
| zcheck=$?
|
| if [[ $zcheck -eq 2 ]]; then
|
| zmsg "Error Missing ${script}. Exiting."
|
| break
|
| elif [[ $zcheck -eq 1 ]]; then
|
| zprint "$(basename ${script}) Already Installed. Continuing."
|
| continue
|
| fi
|
| zbuild_wait 5
|
| zbuild_exec "${script}" || zerror=$?
|
| /sbin/ldconfig
|
| fi
|
| fi
|
|
|
| if [[ $zerror -ne 0 ]]; then
|
| zmsg "An Error Occured in zbuild_exec. exiting."
|
| fi
|
|
|
| ZAfter=`date +%s`
|
| let duration=ZAfter-ZBefore
|
| print_formatted_duration $duration
|