• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2# Download and extract Jinja2
3# Homepage:
4# http://jinja.pocoo.org/
5# Installation instructions:
6# http://jinja.pocoo.org/docs/intro/#from-the-tarball-release
7# Download page:
8# https://pypi.python.org/pypi/Jinja2
9PACKAGE='Jinja2'
10VERSION='2.7.1'
11PACKAGE_DIR='jinja2'
12
13CHROMIUM_FILES="README.chromium OWNERS get_jinja2.sh"
14EXTRA_FILES='LICENSE AUTHORS'
15REMOVE_FILES='testsuite'
16
17SRC_URL='https://pypi.python.org/packages/source/'
18SRC_URL+="${PACKAGE:0:1}/$PACKAGE/$PACKAGE-$VERSION.tar.gz"
19FILENAME="$(basename $SRC_URL)"
20MD5_FILENAME="$FILENAME.md5"
21SHA512_FILENAME="$FILENAME.sha512"
22CHROMIUM_FILES+=" $MD5_FILENAME $SHA512_FILENAME"
23
24BUILD_DIR="$PACKAGE-$VERSION"
25THIRD_PARTY="$(dirname $(realpath $(dirname "${BASH_SOURCE[0]}")))"
26INSTALL_DIR="$THIRD_PARTY/$PACKAGE_DIR"
27OUT_DIR="$INSTALL_DIR/$BUILD_DIR/$PACKAGE_DIR"
28OLD_DIR="$THIRD_PARTY/$PACKAGE_DIR.old"
29
30function check_hashes {
31  # Hashes generated via:
32  # FILENAME=Jinja2-2.7.1.tar.gz
33  # md5sum "$FILENAME" > "$FILENAME.md5"
34  # sha512sum "$FILENAME" > "$FILENAME.sha512"
35  # unset FILENAME
36
37  # MD5
38  if ! [ -f "$MD5_FILENAME" ]
39  then
40    echo "MD5 hash file $MD5_FILENAME not found, could not verify archive"
41    exit 1
42  fi
43
44  # 32-digit hash, followed by filename
45  MD5_HASHFILE_REGEX="^[0-9a-f]{32}  $FILENAME"
46  if ! grep --extended-regex --line-regex --silent \
47    "$MD5_HASHFILE_REGEX" "$MD5_FILENAME"
48  then
49    echo "MD5 hash file $MD5_FILENAME does not contain hash for $FILENAME," \
50         'could not verify archive'
51    echo 'Hash file contents are:'
52    cat "$MD5_FILENAME"
53    exit 1
54  fi
55
56  if ! md5sum --check "$MD5_FILENAME"
57  then
58    echo 'MD5 hash does not match,' \
59         "archive file $FILENAME corrupt or compromised!"
60    exit 1
61  fi
62
63  # SHA-512
64  if ! [ -f "$SHA512_FILENAME" ]
65  then
66    echo "SHA-512 hash file $SHA512_FILENAME not found," \
67         'could not verify archive'
68    exit 1
69  fi
70
71  # 128-digit hash, followed by filename
72  SHA512_HASHFILE_REGEX="^[0-9a-f]{128}  $FILENAME"
73  if ! grep --extended-regex --line-regex --silent \
74    "$SHA512_HASHFILE_REGEX" "$SHA512_FILENAME"
75  then
76    echo "SHA-512 hash file $SHA512_FILENAME does not contain hash for" \
77         "$FILENAME, could not verify archive"
78    echo 'Hash file contents are:'
79    cat "$SHA512_FILENAME"
80    exit 1
81  fi
82
83  if ! sha512sum --check "$SHA512_FILENAME"
84  then
85    echo 'SHA-512 hash does not match,' \
86         "archive file $FILENAME corrupt or compromised!"
87    exit 1
88  fi
89}
90
91
92################################################################################
93# Body
94
95cd "$INSTALL_DIR"
96echo "Downloading $SRC_URL"
97curl --remote-name "$SRC_URL"
98check_hashes
99tar xvzf "$FILENAME"
100# Copy extra files over
101for FILE in $CHROMIUM_FILES
102do
103  cp "$FILE" "$OUT_DIR"
104done
105
106cd "$BUILD_DIR"
107for FILE in $EXTRA_FILES
108do
109  cp "$FILE" "$OUT_DIR"
110done
111
112cd "$OUT_DIR"
113for FILE in $REMOVE_FILES
114do
115  rm -fr "$FILE"
116done
117
118# Replace with new directory
119cd ..
120mv "$INSTALL_DIR" "$OLD_DIR"
121mv "$PACKAGE_DIR" "$INSTALL_DIR"
122cd "$INSTALL_DIR"
123rm -fr "$OLD_DIR"
124