-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·129 lines (107 loc) · 3.69 KB
/
setup.sh
File metadata and controls
executable file
·129 lines (107 loc) · 3.69 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/bin/bash
# Configuration
PORT=5433
function prompt_skyflow_config() {
# Prompt for Skyflow configuration
read -p "Enter your Skyflow Account ID: " ACCOUNT_ID
read -p "Enter your Skyflow Vault ID: " VAULT_ID
read -p "Enter your Skyflow Auth Token or API Key: " BEARER_TOKEN
# Validate inputs are not empty
if [ -z "$VAULT_ID" ] || [ -z "$ACCOUNT_ID" ] || [ -z "$BEARER_TOKEN" ]; then
echo "Error: All Skyflow configuration values must be provided"
exit 1
fi
# Create temporary SQL file with replaced values
echo "Configuring Skyflow settings..."
sed -e "s/__SKYFLOW_VAULT_ID__/$VAULT_ID/g" \
-e "s/__SKYFLOW_ACCOUNT_ID__/$ACCOUNT_ID/g" \
-e "s/__SKYFLOW_BEARER_TOKEN__/$BEARER_TOKEN/g" \
postgres_setup.sql > postgres_setup_temp.sql
}
function create() {
echo "Installing PostgreSQL 17..."
brew install postgresql@17
echo "Installing build dependencies..."
brew install curl
brew install pkg-config
# Add PostgreSQL to PATH
echo "Adding PostgreSQL to PATH..."
export PATH="/opt/homebrew/opt/postgresql@17/bin:$PATH"
# Configure PostgreSQL to use custom port
echo "Configuring PostgreSQL port..."
echo "port = $PORT" >> /opt/homebrew/var/postgresql@17/postgresql.conf
echo "Starting PostgreSQL service..."
brew services start postgresql@17
# Wait for PostgreSQL to be ready with proper connection check
echo "Waiting for PostgreSQL to be ready..."
max_attempts=30
attempt=1
until pg_isready -h localhost -p $PORT >/dev/null 2>&1 || [ $attempt -eq $max_attempts ]; do
echo "Waiting for PostgreSQL to start (attempt $attempt of $max_attempts)..."
attempt=$((attempt + 1))
sleep 1
done
if [ $attempt -eq $max_attempts ]; then
echo "Failed to connect to PostgreSQL after $max_attempts attempts. Exiting..."
exit 1
fi
echo "PostgreSQL is ready!"
echo "Installing PostgreSQL HTTP extension..."
git clone https://github.com/pramsey/pgsql-http.git
cd pgsql-http
make USE_PGXS=1
make USE_PGXS=1 install
cd ..
rm -rf pgsql-http
# Prompt for Skyflow configuration before database setup
prompt_skyflow_config
echo "Creating database..."
createdb -p $PORT skyflow_demo
echo "Running setup SQL..."
psql -p $PORT -d skyflow_demo -f postgres_setup_temp.sql
rm postgres_setup_temp.sql # Clean up temporary SQL file
echo "Setup complete!"
echo
echo "Connection Details:"
echo "Host: localhost"
echo "Port: $PORT"
echo "Database: skyflow_demo"
echo "User: $USER (your system username)"
echo "Password: (none)"
echo "SSL: disabled"
echo
}
function destroy() {
echo "Stopping PostgreSQL service..."
brew services stop postgresql@17
echo "Uninstalling PostgreSQL..."
brew uninstall postgresql@17
echo "Removing PostgreSQL data directory..."
rm -rf /opt/homebrew/var/postgresql@17
echo "Cleanup complete!"
echo
echo "Note: You may want to remove the PostgreSQL PATH from your ~/.zshrc or ~/.bash_profile if you added it"
echo 'The line to remove is: export PATH="/opt/homebrew/opt/postgresql@17/bin:$PATH"'
}
# Check command line argument
case "$1" in
"create")
create
;;
"destroy")
destroy
;;
"recreate")
destroy
create
;;
*)
echo "Usage: $0 {create|destroy|recreate}"
echo
echo "Commands:"
echo " create - Install and configure PostgreSQL with Skyflow demo"
echo " destroy - Stop and remove PostgreSQL installation"
echo " recreate - Perform a destroy and a then a create"
exit 1
;;
esac