-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev.sh
More file actions
55 lines (47 loc) · 1.7 KB
/
dev.sh
File metadata and controls
55 lines (47 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/bash
# Check if the first argument is 'start-server'
if [ "$1" = 'start-server' ]; then
echo "Starting the server with Flask in Debug Mode..."
# Start Flask application
flask run
# Check if the first argument is 'setup-db'
elif [ "$1" = 'setup-db' ]; then
echo "Creating Organization in CKAN..."
# Create an organization in CKAN
curl -X POST http://ckan:5000/api/3/action/organization_create \
-H "Authorization: $CKAN_ADMIN_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "stelar-klms",
"title": "STELAR KLMS",
"description": "Default Organization for STELAR KLMS",
"image_url": "/stelar/static/stelar.png",
"state": "active"
}'
echo "Setting up the database..."
# Construct the PostgreSQL URL
psql='/usr/bin/psql' # psql executable
URL="postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}/${POSTGRES_DB}" # Constructing the db URI
# Check if psql is executable
if ! [ -x "$psql" ]; then
echo "Error: $psql cannot be executed, skipping SQL execution"
exit 1
fi
# Loop over all .sql files in /schemas and execute them
for sql_file in /schemas/*.sql; do
if [ -f "$sql_file" ]; then # Check if the file exists
echo "Executing $sql_file..."
psql "$URL" "-v" "ON_ERROR_STOP=on" "-f" "$sql_file"
# Check the exit status
if [ $? -ne 0 ]; then
echo "Error executing $sql_file"
exit 1
fi
else
echo "No SQL files found in /schemas."
fi
done
else
echo "Invalid command. Use 'start-server' or 'setup-db'."
exit 1
fi