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