blob: 838f7a4d2c8eafc82452595d495498ce6d7e3013 [file] [log] [blame]
JvD_Ericsson16606602024-09-10 15:28:59 +01001#! /bin/bash
2#
3# ============LICENSE_START=======================================================
4# Copyright (C) 2024 Ericsson
5# Modifications Copyright (C) 2024 OpenInfra Foundation Europe
6# ================================================================================
7# Licensed under the Apache License, Version 2.0 (the "License");
8# you may not use this file except in compliance with the License.
9# You may obtain a copy of the License at
10#
11# http://www.apache.org/licenses/LICENSE-2.0
12#
13# Unless required by applicable law or agreed to in writing, software
14# distributed under the License is distributed on an "AS IS" BASIS,
15# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16# See the License for the specific language governing permissions and
17# limitations under the License.
18#
19# SPDX-License-Identifier: Apache-2.0
20# ============LICENSE_END=========================================================
21#
22
23set -e
24
25SOURCE_DIR="./target"
26TARGET_DIR="./sql_scripts"
27PLACEHOLDER1=":pguser"
28PLACEHOLDER2=":'pguser'"
JvD_Ericsson6c3717d2024-10-08 14:26:01 +010029REPLACEMENT_VALUE="${1:-topology_exposure_user}"
30REPLACEMENT2="'$REPLACEMENT_VALUE'"
JvD_Ericsson16606602024-09-10 15:28:59 +010031
32declare -A FILES
33FILES=( ["00_init-oran-smo-teiv-data.sql"]="01_init-teiv-exposure-data.sql"
34 ["01_init-oran-smo-teiv-model.sql"]="00_init-teiv-exposure-model.sql"
35 ["02_init-oran-smo-teiv-consumer-data.sql"]="02_init-teiv-exposure-consumer-data.sql")
36
37mkdir -p "$TARGET_DIR"
38
39for OLD_NAME in "${!FILES[@]}"; do
40 NEW_NAME="${FILES[$OLD_NAME]}"
41 if [ -f "$SOURCE_DIR/$OLD_NAME" ]; then
JvD_Ericsson6c3717d2024-10-08 14:26:01 +010042 sed "s/$PLACEHOLDER1/$REPLACEMENT_VALUE/g; s/$PLACEHOLDER2/$REPLACEMENT2/g" "$SOURCE_DIR/$OLD_NAME" > "${SOURCE_DIR}/${OLD_NAME}.tmp" && \
JvD_Ericsson16606602024-09-10 15:28:59 +010043 cp "${SOURCE_DIR}/${OLD_NAME}.tmp" "$TARGET_DIR/$NEW_NAME" && \
44 echo "Replaced pguser in $OLD_NAME, copied and renamed $OLD_NAME to $NEW_NAME in $TARGET_DIR."
45 else
46 echo "File $OLD_NAME does not exist in $SOURCE_DIR."
47 fi
48done
49
50echo "All tasks completed."