diff options
author | William Harrington <kb0iic@berzerkula.org> | 2021-03-23 13:17:02 -0500 |
---|---|---|
committer | William Harrington <kb0iic@berzerkula.org> | 2021-03-23 13:17:02 -0500 |
commit | 66d4171655e0b93766c82f50ce06521f85b58222 (patch) | |
tree | 1b6d1cbcbc169e5cbb4e6ea6698ed91d82d7cc88 /packageinstall.sh | |
parent | 9d68d5da4115353816ab4f6b1c7a4f5db43576f9 (diff) | |
parent | 887bf450c01c511a3f6d048d3db78e8edfb21e8a (diff) |
Merge branch 'master' into chapter7
Diffstat (limited to 'packageinstall.sh')
-rw-r--r-- | packageinstall.sh | 38 |
1 files changed, 17 insertions, 21 deletions
diff --git a/packageinstall.sh b/packageinstall.sh index 3e899a1..a890ded 100644 --- a/packageinstall.sh +++ b/packageinstall.sh @@ -1,3 +1,5 @@ +#!/bin/bash + CHAPTER="$1" PACKAGE="$2" @@ -5,19 +7,18 @@ if [ -f "${LFS}/sources/chapter${CHAPTER}/${PACKAGE}" ]; then echo -e "${GRN}Package ${YLW}${PACKAGE} ${GRN}already built and installed for ${YLW}Chapter ${CHAPTER}.${RST}" else - grep -i "^${PACKAGE}" packages.csv | grep -i -v "\.patch;" | while read line; do - VERSION="$(echo $line | cut -d\, -f2)" - URL="$(echo $line | cut -d\, -f3 | sed "s/@/${VERSION}/g")" + 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="$(echo "${CACHEFILE}" | sed 's/\(.*\)\.tar\..*/\1/')" + #DIRNAME="$(echo "${CACHEFILE}" | sed 's/\(.*\)\.tar\..*/\1/')" + DIRNAME="$(tar -tf "${CACHEFILE}" | sed -e 's@/.*@@' | uniq)" - if [ -d "${DIRNAME}" ]; then - rm -rf ${DIRNAME} - fi - mkdir -p "${DIRNAME}" + # Remove existing if exists + rm -rf "${DIRNAME}" echo -ne "${IBLU}Extracting ${YLW}${CACHEFILE}... " - tar xf "${CACHEFILE}" -C "${DIRNAME}" >/dev/null 2>&1 & pid=$! + tar xf "${CACHEFILE}" > /dev/null 2>&1 & pid=$! spinner "$pid" retval=$? if [ "$retval" -ne 0 ]; then @@ -25,31 +26,26 @@ else return $retval fi - #TOPLEVELDIR = "tar -tf ${CACHEFILE} | sed -e 's@/.*@@' | uniq" - - pushd "${DIRNAME}" > /dev/null - if [ "$(ls -1A | wc -l)" == "1" ]; then - find */ -mindepth 1 -maxdepth 1 -exec mv -t ./ -- {} + - fi + pushd "${DIRNAME}" > /dev/null || return 1 echo -ne "\n${CYN}Compiling ${YLW}${PACKAGE}${RST}... " sleep 5 - mkdir -p "../log/chapter${CHAPTER}/" - source "../chapter${CHAPTER}/${PACKAGE}.sh" 2>&1 > "../log/chapter${CHAPTER}/${PACKAGE}.log" 2>&1 & pid=$! + mkdir -p "${LFS}/sources/log/chapter${CHAPTER}/" + source "${LFS}/sources/chapter${CHAPTER}/${PACKAGE}.sh" 2>&1 > "${LFS}/sources/log/chapter${CHAPTER}/${PACKAGE}.log" 2>&1 & pid=$! spinner "$pid" retval=$? if [ "$retval" -ne 0 ]; then echo -e "\n${GRN}Compiling ${YLW}${PACKAGE} ${RED}FAILED!${RST}" - popd > /dev/null + popd > /dev/null || return 1 return $retval else echo -e "\n${GRN}Done Compiling ${YLW}${PACKAGE}${RST}" - touch ${LFS}/sources/chapter${CHAPTER}/${PACKAGE} - rm -rf ${LFS}/sources/${DIRNAME} + touch "${LFS}"/sources/chapter"${CHAPTER}"/"${PACKAGE}" + rm -rf "${LFS}"/sources/"${DIRNAME}" fi - popd > /dev/null + popd > /dev/null || return 1 done fi |