| #!/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
|
| zmsg "Could Not Locate zbc file. exiting."
|
| return 2
|
| fi
|
| local pkg="$(basename ${file%-*})"
|
| zprint "Checking For: $pkg "
|
| ! 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
|
| }
|
| zbuild_extract() {
|
| tar -xf $ZPACK -C $ZTMP || { zmsg "Error Extracting package Tar. Exiting."; return 666; }
|
|
|
| zprint "::Locating Package::"
|
| pushd ${ZTMP}
|
| source "$ZPACKTMP/install.sh"
|
| zprint "::Found ${packagedir}::"
|
| popd
|
| ZSCRIPT=$(find "${ZPACKTMP}" -type f -name "*.zbc" | head -n 1)
|
| }
|
| #
|
| # 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}
|
| ZTARBASEDIR=${ZTARBASEDIR:-/usr/local/src}
|
| ZTAR=$1
|
| ZPACK=$(find $ZTARBASEDIR -type f -name "${ZTAR}.tar")
|
| let zerror=0
|
| export ZSRC
|
|
|
| if [[ -z $ZPACK ]]; then
|
| zmsg "Cannot Locate Package tar file. exiting."
|
| let zerror=666
|
| else
|
| zprint "Found ${ZPACK} in ${ZTARBASEDIR}"
|
| fi
|
|
|
| # Extract the Package Tar
|
| ZTMP=$ZBUILD/stage3
|
| ZPACKTMP=$ZTMP/$(basename ${ZPACK%.*})
|
| mkdir -pv $ZPACKTMP
|
| [ $zerror -eq 0 ] && zbuild_extract
|
| zcheck=$?
|
| [ $zcheck -eq 0 ] && zbuild_check $ZSCRIPT
|
| zcheck=$?
|
| [ $zcheck -eq 1 ] && zprint "$(basename ${ZSCRIPT}) Already Installed. Done."
|
| # Install Package
|
| if [[ $zcheck -eq 0 ]]; then
|
| stars
|
| zprint "Executing ${ZSCRIPT}"
|
| zbuild_wait 5
|
| zbuild_exec "${ZSCRIPT}" || zerror=$?
|
| /sbin/ldconfig
|
| 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
|