#!/bin/bash CHAPTER="$1" PACKAGE="$2" if ! grep -q "^${PACKAGE}," packages.csv; then printf "%b" " ${IRED}PACKAGE ${IYLW}${PACKAGE} ${IRED}DOES NOT EXIST!${RST}\n" exit 1 fi if [[ -f "${LFS}/sources/chapter${CHAPTER}/${PACKAGE}" ]]; then printf "%b" "${GRN}Package ${YLW}${PACKAGE} ${GRN}already built and installed${RST}\n" else grep -i "^${PACKAGE}," packages.csv | grep -i -v "\.patch;" | while read -r line; do VERSION="$(echo "${line}" | cut -d\, -f2)" URL="$(echo "${line}" | cut -d\, -f3 | sed "s/@/${VERSION}/g")" CACHEFILE="$(basename "${URL}")" DIRNAME="$(tar -tf "${CACHEFILE}" | sed -e 's@/.*@@' | uniq)" # Remove existing if exists rm -rf "${DIRNAME}" printf "%b" "${IBLU}Extracting ${YLW}${CACHEFILE}${RST}... " tar xf "${CACHEFILE}" > /dev/null 2>&1 & pid=$! spinner "$pid" "${SPINNER}" retval=$? if [[ "$retval" -ne 0 ]]; then printf "%b" "${GRN}Extraction " fail "FAILED!" return $retval else success "OK" fi pushd "${DIRNAME}" > /dev/null || return 1 printf "%b" " ${CYN}Compiling ${YLW}${PACKAGE}${RST}... " mkdir -p "${LFS}/sources/log/chapter${CHAPTER}/" # shellcheck source=/dev/null source "${LFS}/sources/chapter${CHAPTER}/${PACKAGE}.sh" 2>&1 > "${LFS}/sources/log/chapter${CHAPTER}/${PACKAGE}.log" 2>&1 & pid=$! spinner "$pid" "${SPINNER}" retval=$? if [[ "$retval" -ne 0 ]]; then fail "FAILED!" popd > /dev/null || return 1 return $retval else success "OK" touch "${LFS}"/sources/chapter"${CHAPTER}"/"${PACKAGE}" rm -rf "${LFS}"/sources/"${DIRNAME}" fi popd > /dev/null || return 1 done fi