Skip to content

Commit 04bd5f6

Browse files
committed
[#3470] hammer: install postgresql only if not already installed
1 parent dffb0d7 commit 04bd5f6

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

hammer.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1956,14 +1956,22 @@ def link_pg_config():
19561956
packages.extend(['mysql80-server', 'mysql80-client'])
19571957

19581958
if 'pgsql' in features:
1959-
# Install the latest postgresql-client and postgresql-server.
1960-
_, output = execute("pkg search postgresql | grep -E 'postgresql[0-9]+-client' | tail -n 1 | "
1961-
"cut -d ' ' -f 1 | cut -d '-' -f 1-2", capture=True)
1962-
postgresql_client = output.strip()
1963-
_, output = execute("pkg search postgresql | grep -E 'postgresql[0-9]+-server' | tail -n 1 | "
1964-
"cut -d ' ' -f 1 | cut -d '-' -f 1-2", capture=True)
1965-
postgresql_server = output.strip()
1966-
packages.extend([postgresql_client, postgresql_server])
1959+
# Install the latest postgresql-client and postgresql-server,
1960+
# unless any postgresql-client or postgresql-server version is already installed.
1961+
for i in ['client', 'server']:
1962+
# Check if already installed.
1963+
_, output = execute('pkg info', capture=True)
1964+
m = re.search(f'postgresql[0-9]+-{i}', output)
1965+
if m is None:
1966+
# If not, go ahead and install.
1967+
_, output = execute('pkg search postgresql', capture=True)
1968+
found = re.findall(f'postgresql[0-9]+-{i}', output)
1969+
if len(found) == 0:
1970+
print(f'No postgresql[0-9]+-{i} found?')
1971+
sys.exit(1)
1972+
# There may be more matches. Results are sorted by pkg.
1973+
# Choose the last from the list which should be the latest version.
1974+
packages.append(found[-1])
19671975

19681976
if 'gssapi' in features:
19691977
packages.extend(['krb5-devel'])

0 commit comments

Comments
 (0)