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