Skip to content

Commit

Permalink
task: make install script more generic and applicable to external ini…
Browse files Browse the repository at this point in the history
…t folders
  • Loading branch information
Dominick Leppich committed Nov 29, 2024
1 parent 8f4553d commit 8313ead
Showing 1 changed file with 30 additions and 11 deletions.
41 changes: 30 additions & 11 deletions install/install_samples.sh → install/install.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env bash
MY_PATH="$(dirname -- "${BASH_SOURCE[0]}")"
SAMPLES_DIR=$MY_PATH/samples
CACHE_FILE=$MY_PATH/cache.txt

# Check for parameters
FAIL=0
Expand Down Expand Up @@ -29,11 +28,17 @@ if [ -z $SAMPLE ]; then
ls $SAMPLES_DIR
read SAMPLE
fi
SAMPLE_PATH=$SAMPLES_DIR/$SAMPLE

if [ -d "$SAMPLE" ]; then
SAMPLE_PATH="$SAMPLE"
else
SAMPLE_PATH="$SAMPLES_DIR/$SAMPLE"
fi
if [ ! -e $SAMPLE_PATH ]; then
echo "Sample \"$SAMPLE\" does not exist!"
exit 1
fi
CACHE_FILE="$SAMPLE_PATH/cache.txt"

curl_call() {
curl --location "$HOST:$PORT/api/v1/$1" \
Expand All @@ -59,16 +64,22 @@ for INSTALL_DIR in $(ls $SAMPLE_PATH); do
ITEM_NAME=$(echo "$ITEM" | cut -d'.' -f1)
ITEM_IDENTIFIER=${ENDPOINT}_"${ITEM_NAME}"

ID=$(cat $CACHE_FILE | grep "$ITEM_IDENTIFIER;" | cut -d';' -f2)
if [ -f "$CACHE_FILE" ]; then
ID=$(cat $CACHE_FILE | grep "$ITEM_IDENTIFIER;" | cut -d';' -f2)
else
ID=""
fi
if [ -z "$ID" ]; then
JSON=$(cat $SAMPLE_PATH/$INSTALL_DIR/$ITEM)

# Replace ID placeholders
for CACHE_LINE in $(cat $CACHE_FILE); do
TEMPLATE_PLACEHOLDER="{{$(echo $CACHE_LINE | cut -d';' -f1)}}"
CACHE_ID=$(echo $CACHE_LINE | cut -d';' -f2)
JSON=$(echo $JSON | sed "s/$TEMPLATE_PLACEHOLDER/$CACHE_ID/g")
done
if [ -f "$CACHE_FILE" ]; then
for CACHE_LINE in $(cat $CACHE_FILE); do
TEMPLATE_PLACEHOLDER="{{$(echo $CACHE_LINE | cut -d';' -f1)}}"
CACHE_ID=$(echo $CACHE_LINE | cut -d';' -f2)
JSON=$(echo $JSON | sed "s/$TEMPLATE_PLACEHOLDER/$CACHE_ID/g")
done
fi

RESULT=$(curl_call $ENDPOINT "$JSON")

Expand All @@ -91,7 +102,11 @@ for INSTALL_DIR in $(ls $SAMPLE_PATH); do
for ITEM in $(ls $SAMPLE_PATH/$INSTALL_DIR | grep ".csv"); do
VOCABULARY_NAME=$(echo "$ITEM" | cut -d'.' -f1)
VOCABULARY_IDENTIFIER=vocabularies_${VOCABULARY_NAME}
VOCABULARY_ID=$(cat $CACHE_FILE | grep $VOCABULARY_IDENTIFIER | cut -d';' -f2)
if [ -f "$CACHE_FILE" ]; then
VOCABULARY_ID=$(cat $CACHE_FILE | grep $VOCABULARY_IDENTIFIER | cut -d';' -f2)
else
VOCABULARY_ID=""
fi

if [ ! -z "$VOCABULARY_ID" ]; then
curl_file_upload_call "vocabularies/$VOCABULARY_ID/import/csv" "$SAMPLE_PATH/$INSTALL_DIR/$ITEM"
Expand All @@ -103,8 +118,12 @@ for INSTALL_DIR in $(ls $SAMPLE_PATH); do
for ITEM in $(ls $SAMPLE_PATH/$INSTALL_DIR | grep ".xlsx"); do
VOCABULARY_NAME=$(echo "$ITEM" | cut -d'.' -f1)
VOCABULARY_IDENTIFIER=vocabularies_${VOCABULARY_NAME}
VOCABULARY_ID=$(cat $CACHE_FILE | grep $VOCABULARY_IDENTIFIER | cut -d';' -f2)

if [ -f "$CACHE_FILE" ]; then
VOCABULARY_ID=$(cat $CACHE_FILE | grep $VOCABULARY_IDENTIFIER | cut -d';' -f2)
else
VOCABULARY_ID=""
fi

if [ ! -z "$VOCABULARY_ID" ]; then
curl_file_upload_call "vocabularies/$VOCABULARY_ID/import/excel" "$SAMPLE_PATH/$INSTALL_DIR/$ITEM"
echo -e "\tImported \"$VOCABULARY_NAME\" vocabulary records"
Expand Down

0 comments on commit 8313ead

Please sign in to comment.