-
Notifications
You must be signed in to change notification settings - Fork 0
/
tds_fdw-rpm
executable file
·105 lines (93 loc) · 2.11 KB
/
tds_fdw-rpm
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
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/bin/bash -e
SCRIPT=$(basename ${0})
VERSIONS="9.3 9.4 9.5 9.6 10 11 12 13 14 15 16"
function help() {
echo ""
echo "Script to build tds_fdw RPMs"
echo ""
echo "Syntax: "
echo ""
echo "${SCRIPT} -p <POSTGRESQL_MAJOR_VERSION>"
echo ""
echo "Where: "
echo " -p <POSTGRESQL_MAJOR_VERSION> PostgreSQL major version (format X.Y)"
echo ""
echo "Supported major versions:"
for version in ${VERSIONS}; do
echo "- $version"
done
echo ""
exit 1
}
function print_invalid_syntax() {
echo "Invalid syntax, use ${SCRIPT} -h"
}
function check_create_dir() {
if [ ! -d "./$1" ]; then
mkdir "./$1"
fi
}
function create_build_env() {
check_create_dir BUILD
check_create_dir BUILDROOT
check_create_dir RPMS
check_create_dir SOURCES
check_create_dir SPECS
check_create_dir SRPMS
}
function get_sources() {
if [ ! -f "./SOURCES/${2}" ]; then
echo "Downloading ${1} to "./SOURCES/${2}"..."
curl -L "${1}" -o "./SOURCES/${2}"
fi
}
get_url_source_from_spec() {
local VERSION=$(sed -rn 's/Version:\s*(.*)/\1/p' ${1})
local URL=$(sed -rn 's/Source:\s*(.*)/\1/p' ${1})
echo $(echo ${URL}|sed -e "s/%{version}/${VERSION}/g")
}
function build_rpm() {
rpmbuild --define "_topdir `pwd`" -ba "${1}"
return ${?}
}
# Parse options
while getopts "p:h" opts; do
case "${opts}" in
p) PG_VER=${OPTARG} ;;
h) help ;;
*) print_invalid_syntax
exit 1 ;;
esac
done
shift $((OPTIND-1))
if [ -z "${PG_VER}" ]; then
print_invalid_syntax
exit 1
fi
FOUND='FALSE'
for tver in ${VERSIONS}; do
if [ "${tver}" == "${PG_VER}" ]; then
FOUND='TRUE'
fi
done
if [ "${FOUND}" == 'FALSE' ]; then
echo "Invalid PostgreSQL major version"
exit 1
fi
echo "### Creating build environment..."
PG_SVER=$(echo ${PG_VER} | tr -d '.')
SPEC="SPECS/tds_fdw-${PG_SVER}.spec"
URL="$(get_url_source_from_spec ${SPEC})"
TGZ="$(basename ${URL})"
create_build_env
echo "### Downloading sources..."
get_sources ${URL} ${TGZ}
echo "### Building RPMs..."
build_rpm ${SPEC}
if [ $? -eq 0 ]; then
echo Your packages are available at $PWD/RPMS.
exit 0
else
echo There are errors. Check your log.
exit 2
fi