#!/bin/sh
# Copyright (C) 2021-2022 Greenbone AG
#
# SPDX-License-Identifier: GPL-3.0-or-later
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

#
# Helper script to create symlinks for development setups of pg-gvm
#

PREFIX_SHARE_DIR="/usr/share/postgresql"
PREFIX_EXTLIB_DIR="/usr/lib/postgresql"

REAL_SHARE_DIR="/usr/share/postgresql"
REAL_EXTLIB_DIR="/usr/lib/postgresql"

LIB_PREFIX="lib"
LIB_SUFFIX=".so"
LIB_FILE_NAME="${LIB_PREFIX}pg-gvm${LIB_SUFFIX}"

CONTROLOUT="pg-gvm.control"
SQLOUT="pg-gvm--22.6.sql"

echo "Creating links:"

echo "  $REAL_SHARE_DIR/extension/$CONTROLOUT"
ln -s "$PREFIX_SHARE_DIR/extension/$CONTROLOUT" \
   "$REAL_SHARE_DIR/extension/$CONTROLOUT"

for update_file in $(ls -1 $PREFIX_SHARE_DIR/extension/*.sql);
do
  update_basename=$(basename "$update_file")
  echo "  $REAL_SHARE_DIR/extension/$update_basename"
  ln -s "$update_file" "$REAL_SHARE_DIR/extension/$update_basename"
done

echo "  $REAL_EXTLIB_DIR/$LIB_FILE_NAME"
ln -s "$PREFIX_EXTLIB_DIR/$LIB_FILE_NAME" \
   "$REAL_EXTLIB_DIR/$LIB_FILE_NAME"
