-
Notifications
You must be signed in to change notification settings - Fork 11
/
fetch_build_files
executable file
·92 lines (76 loc) · 1.96 KB
/
fetch_build_files
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/bin/bash
# make bash behave
set -euo pipefail
IFS=$'\n\t'
# constants
stdout=1
stderr=2
success=0
failure=1
badusage=64
noinput=66
packagingurl='https://github.com/citusdata/packaging'
download=$(mktemp)
# outputs usage message on specified device before exiting with provided status
usage() {
cat << 'E_O_USAGE' >&"$1"
usage: fetch_build_files project format target_directory
project : 'citus', 'enterprise', 'hll', or 'rebalancer'
format : 'deb', 'rpm', or 'pgxn'
fetch_build_files fetches files needed to package a specified Citus project for
a specified software packaging system.
E_O_USAGE
exit "${2}";
}
if [ "$#" -eq 1 ] && [ "${1}" = '-h' ]; then
usage $stdout $success
fi
if [ "$#" -ne 3 ]; then
usage $stderr $badusage
fi
case "${1}" in
citus|enterprise|hll|rebalancer)
project=${1}
;;
*)
echo "$0: unknown project -- ${1}" >&2
usage $stderr $badusage
;;
esac
case "${2}" in
deb)
format='debian'
;;
rpm)
format='redhat'
;;
pgxn)
format='pgxn'
;;
*)
echo "$0: unknown format -- ${2}" >&2
usage $stderr $badusage
;;
esac
targetdir=$3
# validate inputs
if ! [ -d "${targetdir}" ]; then
echo "$0: ${targetdir}: Is not a directory" >&2
exit $noinput
elif [ ! -e "${targetdir}" ]; then
echo "$0: ${targetdir}: No such file" >&2
exit $noinput
elif [ ! -r "${targetdir}" ]; then
echo "$0: ${targetdir}: Permission denied" >&2
exit $noinput
fi
downloadurl="${packagingurl}/archive/${format}-${project}.tar.gz"
# download a tarball of the build files
httpcode=$(curl -sL "${downloadurl}" -w "%{http_code}" -o "${download}")
if [ "${httpcode}" -ne 200 ]; then
echo "$0: could not fetch build tarball from ${downloadurl}" >&2
echo "$0: HTTP code was: ${httpcode}" >&2
exit $failure
fi
# expand them directly into the target directory
tar xf "${download}" -C "${targetdir}" --strip-components 1