JvD_Ericsson | 1660660 | 2024-09-10 15:28:59 +0100 | [diff] [blame] | 1 | #! /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 | |
| 23 | set -e |
| 24 | |
| 25 | SOURCE_DIR="./target" |
| 26 | TARGET_DIR="./sql_scripts" |
| 27 | PLACEHOLDER1=":pguser" |
| 28 | PLACEHOLDER2=":'pguser'" |
JvD_Ericsson | 6c3717d | 2024-10-08 14:26:01 +0100 | [diff] [blame] | 29 | REPLACEMENT_VALUE="${1:-topology_exposure_user}" |
| 30 | REPLACEMENT2="'$REPLACEMENT_VALUE'" |
JvD_Ericsson | 1660660 | 2024-09-10 15:28:59 +0100 | [diff] [blame] | 31 | |
| 32 | declare -A FILES |
| 33 | FILES=( ["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 | |
| 37 | mkdir -p "$TARGET_DIR" |
| 38 | |
| 39 | for OLD_NAME in "${!FILES[@]}"; do |
| 40 | NEW_NAME="${FILES[$OLD_NAME]}" |
| 41 | if [ -f "$SOURCE_DIR/$OLD_NAME" ]; then |
JvD_Ericsson | 6c3717d | 2024-10-08 14:26:01 +0100 | [diff] [blame] | 42 | sed "s/$PLACEHOLDER1/$REPLACEMENT_VALUE/g; s/$PLACEHOLDER2/$REPLACEMENT2/g" "$SOURCE_DIR/$OLD_NAME" > "${SOURCE_DIR}/${OLD_NAME}.tmp" && \ |
JvD_Ericsson | 1660660 | 2024-09-10 15:28:59 +0100 | [diff] [blame] | 43 | 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 |
| 48 | done |
| 49 | |
| 50 | echo "All tasks completed." |