• 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.10'
11SRC_URL='https://pypi.python.org/packages/56/e6/332789f295cf22308386cf5bbd1f4e00ed11484299c5d7383378cf48ba47/Jinja2-2.10.tar.gz'
12PACKAGE_DIR='jinja2'
13
14CHROMIUM_FILES="README.chromium OWNERS get_jinja2.sh"
15EXTRA_FILES='LICENSE AUTHORS'
16REMOVE_FILES='testsuite'
17
18FILENAME="$(basename $SRC_URL)"
19MD5_FILENAME="$FILENAME.md5"
20SHA512_FILENAME="$FILENAME.sha512"
21CHROMIUM_FILES+=" $MD5_FILENAME $SHA512_FILENAME"
22
23BUILD_DIR="$PACKAGE-$VERSION"
24THIRD_PARTY="$(dirname $(realpath $(dirname "${BASH_SOURCE[0]}")))"
25INSTALL_DIR="$THIRD_PARTY/$PACKAGE_DIR"
26OUT_DIR="$INSTALL_DIR/$BUILD_DIR/$PACKAGE_DIR"
27OLD_DIR="$THIRD_PARTY/$PACKAGE_DIR.old"
28
29function check_hashes {
30  # Hashes generated via:
31  # FILENAME=Jinja2-2.8.tar.gz
32  # md5sum "$FILENAME" > "$FILENAME.md5"
33  # sha512sum "$FILENAME" > "$FILENAME.sha512"
34  # unset FILENAME
35
36  # MD5
37  if ! [ -f "$MD5_FILENAME" ]
38  then
39    echo "MD5 hash file $MD5_FILENAME not found, could not verify archive"
40    exit 1
41  fi
42
43  # 32-digit hash, followed by filename
44  MD5_HASHFILE_REGEX="^[0-9a-f]{32}  $FILENAME"
45  if ! grep --extended-regex --line-regex --silent \
46    "$MD5_HASHFILE_REGEX" "$MD5_FILENAME"
47  then
48    echo "MD5 hash file $MD5_FILENAME does not contain hash for $FILENAME," \
49         'could not verify archive'
50    echo 'Hash file contents are:'
51    cat "$MD5_FILENAME"
52    exit 1
53  fi
54
55  if ! md5sum --check "$MD5_FILENAME"
56  then
57    echo 'MD5 hash does not match,' \
58         "archive file $FILENAME corrupt or compromised!"
59    exit 1
60  fi
61
62  # SHA-512
63  if ! [ -f "$SHA512_FILENAME" ]
64  then
65    echo "SHA-512 hash file $SHA512_FILENAME not found," \
66         'could not verify archive'
67    exit 1
68  fi
69
70  # 128-digit hash, followed by filename
71  SHA512_HASHFILE_REGEX="^[0-9a-f]{128}  $FILENAME"
72  if ! grep --extended-regex --line-regex --silent \
73    "$SHA512_HASHFILE_REGEX" "$SHA512_FILENAME"
74  then
75    echo "SHA-512 hash file $SHA512_FILENAME does not contain hash for" \
76         "$FILENAME, could not verify archive"
77    echo 'Hash file contents are:'
78    cat "$SHA512_FILENAME"
79    exit 1
80  fi
81
82  if ! sha512sum --check "$SHA512_FILENAME"
83  then
84    echo 'SHA-512 hash does not match,' \
85         "archive file $FILENAME corrupt or compromised!"
86    exit 1
87  fi
88}
89
90
91################################################################################
92# Body
93
94cd "$INSTALL_DIR"
95echo "Downloading $SRC_URL"
96curl --remote-name "$SRC_URL"
97check_hashes
98tar xvzf "$FILENAME"
99# Copy extra files over
100for FILE in $CHROMIUM_FILES
101do
102  cp "$FILE" "$OUT_DIR"
103done
104
105cd "$BUILD_DIR"
106for FILE in $EXTRA_FILES
107do
108  cp "$FILE" "$OUT_DIR"
109done
110
111cd "$OUT_DIR"
112for FILE in $REMOVE_FILES
113do
114  rm -fr "$FILE"
115done
116
117# Replace with new directory
118cd ..
119mv "$INSTALL_DIR" "$OLD_DIR"
120mv "$PACKAGE_DIR" "$INSTALL_DIR"
121cd "$INSTALL_DIR"
122rm -fr "$OLD_DIR"
123
124# Generating jinja2.gni
125cat > jinja2.gni <<EOF
126# DO NOT EDIT
127# This is generated from get_jinja2.sh.
128jinja2_sources = [
129EOF
130
131for i in $(LC_COLLATE=C ls *.py)
132do
133  echo "  \"//third_party/jinja2/${i}\"," >> jinja2.gni
134done
135
136echo "]" >> jinja2.gni
137