plumbing 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/bin/echo run this from "make root"
  2. # Plumbing to download files
  3. [ -z "$ROOT" ] && echo "no" && exit 1
  4. mkdir -p "${DOWNLOAD:=$PWD/root_download}" || exit 1
  5. ### Functions to download, extract, and clean up after source packages.
  6. # Usage: download HASH URL
  7. # Grabs source from URL confirming SHA1 hash (Basically "wget $2")
  8. # If extracted source is in $DOWNLOAD (no version) build will use that instead
  9. download() {
  10. FILE="$(basename "$2")"
  11. [ -d "$DOWNLOAD/${FILE/-*/}" ] && echo "$FILE" local && return 0
  12. X=0; while true; do
  13. [ "$(sha1sum < "$DOWNLOAD/$FILE" 2>/dev/null)" == "$1 -" ] &&
  14. echo "$FILE" confirmed && break
  15. rm -f $DOWNLOAD/${FILE/-[0-9]*/}-[0-9]* || exit 1
  16. [ $X -eq 0 ] && X=1 || exit 1
  17. wget "$2" -O "$DOWNLOAD/$FILE"
  18. done
  19. }
  20. # Usage: setupfor PACKAGE
  21. # Extracts source tarball (or snapshot a repo) to create disposable build dir.
  22. # Basically "tar xvzCf $MYBUILD $DOWNLOAD/$1.tar.gz && cd $NEWDIR"
  23. setupfor() {
  24. PACKAGE="$(basename "$1")"
  25. announce "$PACKAGE" && cd "$MYBUILD" && rm -rf "$PACKAGE" || exit 1
  26. if [ -d "$DOWNLOAD/$PACKAGE" ]; then
  27. cp -la "$DOWNLOAD/$PACKAGE/." "$PACKAGE" && cd "$PACKAGE" || exit 1
  28. else
  29. tar xvaf "$DOWNLOAD/$PACKAGE"-*.t* && cd "$PACKAGE"-* || exit 1
  30. fi
  31. }
  32. # Usage: cleanup
  33. # Delete setupfor's dir, exiting if build failed (basically "rm -rf $PACKAGE")
  34. cleanup() {
  35. [ $? -ne 0 ] && exit 1
  36. [ -z "$PACKAGE" ] && exit 1
  37. [ ! -z "$NO_CLEANUP" ] && return
  38. cd .. && rm -rf "$PACKAGE"* || exit 1
  39. }