-
Notifications
You must be signed in to change notification settings - Fork 1
/
ci
executable file
·153 lines (138 loc) · 5.49 KB
/
ci
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/bin/bash -e
BASE_DIR=$(dirname "${0}")
source "${BASE_DIR}/lib/actions"
source "${BASE_DIR}/lib/checks"
source "${BASE_DIR}/lib/colours"
source "${BASE_DIR}/lib/help"
source "${BASE_DIR}/lib/messages"
# Language (force it so getopt messages are always in english, as the script)
LANG=en_EN
# Get script name
SCRIPT=$(basename ${0})
# Supported distributions and PostgreSQL versions
SUPPORTEDDISTROS="centos7 rockylinux8 ubuntu18.04 ubuntu20.04 opensuseleap15.5"
SUPPORTEDPGVERS="9.6 10 11 12 13 14 15 16"
# Ignored combinations, will exit without errors so the CI does not fail
IGNOREDCOMBINATIONS="centos7|16"
# read the options
ARGS=$(getopt -o h --long help,action:,distro:,pgver:,tdsdir:,mssqlhost:,mssqlport:,mssqldb:,mssqluser:,mssqlpass:,postgresdb:,postgresuser:,postgrespass:,max_retries:,wait_sec:,unattended_debugging -n "${SCRIPT}" -- "$@")
if [ $? -ne 0 ];
then
print_incorrect_syntax
exit 1
fi
eval set -- "${ARGS}"
# extract options and their arguments into variables
while true ; do
case "${1}" in
-h|--help) help "${SUPPORTEDPGVERS}" "${SUPPORTEDDISTROS}"; exit 1;;
--action) ACTION="${2}"; shift 2;;
--distro) export DISTRO="${2}"; shift 2;;
--pgver) export PG_VER="${2}"; shift 2;;
--tdsdir) export TDSDIR="${2}"; shift 2;;
--mssqlhost) export MSSQLHOST="${2}"; shift 2;;
--mssqlport) export MSSQLPORT="${2}"; shift 2;;
--mssqldb) export MSSQLDB="${2}"; shift 2;;
--mssqluser) export MSSQLUSER="${2}"; shift 2;;
--mssqlpass) export MSSQLPASS="${2}"; shift 2;;
--postgreshost) export POSTGRESHOST="${2}"; shift 2;;
--postgresport) export POSTGRESPORT="${2}"; shift 2;;
--postgresdb) export POSTGRESDB="${2}"; shift 2;;
--postgresuser) export POSTGRESUSER="${2}"; shift 2;;
--postgrespass) export POSTGRESPASS="${2}"; shift 2;;
--max_retries) export MAX_RETRIES="${2}"; shift 2;;
--wait_sec) export WAIT_SEC="${2}"; shift 2;;
--unattended_debugging) export UNATTENDED_DEBUG="TRUE"; shift 1;;
--) shift ; break ;;
*) print_incorrect_syntax; exit 1;;
esac
done
# Check arguments for actions
case "${ACTION}" in
get_info) ;;
mod_build) if [ -z "${TDSDIR}" ]; then print_incorrect_syntax; exit 1;
elif [ ! -d ${TDSDIR} ]; then
print_error_folder_doesnt_exist "${TSDIR}"
exit 1
fi;;
mod_install) if [ -z "${TDSDIR}" ]; then print_incorrect_syntax; exit 1;
elif [ ! -d ${TDSDIR} ]; then
print_error_folder_doesnt_exist "${TSDIR}"
exit 1
fi;;
pg_stop) ;;
pg_start) ;;
pg_confdb) if ! $(check_postgres_vars); then
print_incorrect_syntax
exit 1
fi;;
mssql_test) if ! $(check_postgres_vars) && ! $(check_mssql_vars); then
print_incorrect_syntax
exit 1
elif [ -z "${TDSDIR}" ]; then print_incorrect_syntax; exit 1;
elif [ ! -d ${TDSDIR} ]; then
print_error_folder_doesnt_exist "${TSDIR}"
exit 1
fi;;
pg_test) if ! $(check_postgres_vars); then
print_incorrect_syntax
exit 1
elif [ -z "${TDSDIR}" ]; then print_incorrect_syntax; exit 1;
elif [ ! -d ${TDSDIR} ]; then
print_error_folder_doesnt_exist "${TSDIR}"
exit 1
fi;;
pg_dropdb) if ! $(check_postgres_vars); then
print_incorrect_syntax
exit 1
fi;;
*) print_error_unknown_action
exit 1;
esac
export PG_VER_FULL="${PG_VER}"
export SHORTVER_FULL="$(echo ${PG_VER}|tr -d '.')"
# Check PostgreSQL version
PG_VER="$(check_pgver)"
if [ "${PG_VER}" == "" ]; then
print_error_unknown_unsupported_pgver
exit 1
fi
export PG_VER="${PG_VER/-testing}"
export SHORTVER="${SHORTVER_FULL/-testing}"
# Check distribution
export DISTRO="$(detect_distro)"
if [ "${DISTRO}" == "" ]; then
print_error_unsupported_distro
exit 1
fi
export SHORTDISTRO="$(echo ${DISTRO}|tr -d '.')"
for IGNOREDCOMBINATION in ${IGNOREDCOMBINATIONS}; do
IGNOREDDISTRO=$(echo ${IGNOREDCOMBINATION}|cut -d'|' -f1)
IGNOREDVER=$(echo ${IGNOREDCOMBINATION}|cut -d'|' -f2)
if [ "${IGNOREDDISTRO}" == "${DISTRO}" ] && [ "${IGNOREDVER}" == "${PG_VER}" ]; then
echo "${IGNOREDDISTRO} with PostgreSQL ${IGNOREDVER} is not available"
exit 0
fi
done
# End setting variables to be passed to the jail
export POSTGRESSCHEMA="postgresql${SHORTVER_FULL/-}_${SHORTDISTRO}_test"
export MSSQLSCHEMA="${POSTGRESSCHEMA}"
if [[ "${DISTRO}" =~ ^(centos|rockylinux)[0-9]$ ]]; then
export PGBIN_PATH="/usr/pgsql-${PG_VER}/bin"
export POSTGRESPORT=$(sed -n 's/^port = \([0-9]*\).*/\1/p' /var/lib/pgsql/${PG_VER}/data/postgresql.conf)
elif [[ "${DISTRO}" =~ ^(opensuseleap)[0-9]{2}.[0-9]+$ ]]; then
export PGBIN_PATH="/usr/pgsql-${PG_VER}/bin"
export POSTGRESPORT=$(sed -n 's/^port = \([0-9]*\).*/\1/p' /var/lib/pgsql/${PG_VER}/data/postgresql.conf)
elif [[ "${DISTRO}" =~ ^ubuntu[0-9]{2}.[0-9]{2}$ ]]; then
export PGBIN_PATH="/usr/lib/postgresql/${PG_VER}/bin"
export POSTGRESPORT=$(sed -n 's/^port = \([0-9]*\).*/\1/p' /etc/postgresql/${PG_VER}/main/postgresql.conf)
fi
if [ -f /usr/bin/python3 ]; then
export PYTHON=/usr/bin/python3
else
export PYTHON=/usr/bin/python
fi
if [ "${POSTGRESPORT}" == "" ]; then
POSTGRESPORT="5432"
fi
${ACTION}