1- #! /bin/bash
1+ #! /usr/ bin/env bash
22set -e # Exit immediately if a command exits with a non-zero status.
33
4+ # This script should support running in bash or zsh
5+
46echo " Starting TypedAI configuration script..."
57echo " ---------------------------------------------------------------------"
68
@@ -26,21 +28,19 @@ update_env_variable() {
2628 echo " $var_name =$new_value " >> " $file_path "
2729 echo " Added $var_name to $file_path ."
2830 fi
29- [ -f " $temp_file " ] && rm -f " $temp_file "
31+ rm -f " $temp_file "
3032}
3133
3234# --- Python Setup ---
3335echo " "
3436echo " --- Stage 1: Python Environment Setup ---"
35- # Source the script part. Use '|| exit 1' to ensure main script exits if part fails.
3637source ./bin/configure_parts/python_setup || exit 1
3738echo " Python environment setup complete."
3839echo " ---------------------------------------------------------------------"
3940
4041# --- Node.js Setup ---
4142echo " "
4243echo " --- Node.js Environment Setup (using fnm) ---"
43- # Source the script part. Use '|| exit 1' to ensure main script exits if part fails.
4444source ./bin/configure_parts/nodejs_setup || exit 1
4545echo " Node.js environment setup complete."
4646echo " ---------------------------------------------------------------------"
@@ -78,50 +78,15 @@ echo "---------------------------------------------------------------------"
7878# --- Google Cloud Platform Services Configuration ---
7979echo " "
8080echo " --- Google Cloud Platform (GCP) Services Configuration ---"
81- USE_GCP_SERVICES=false
82- GCP_SETUP_SUCCESS=false
83-
84- # Check current GCLOUD_PROJECT to suggest default for GCP usage
85- # Source local.env carefully to get existing values without erroring on unset variables
86- (set +e; set +u; source ./variables/local.env)
87- CURRENT_GCLOUD_PROJECT=${GCLOUD_PROJECT:- } # Use parameter expansion for robustness
88-
89- GCP_PROMPT_DEFAULT=" n"
90- if [ -n " $CURRENT_GCLOUD_PROJECT " ]; then # If project is already set, assume user wants GCP
91- GCP_PROMPT_DEFAULT=" y"
92- fi
93-
94- read -r -p " Do you plan to use any Google Cloud services (e.g., Vertex AI, Gemini, Cloud Tracing)? (Y/n, default: $GCP_PROMPT_DEFAULT ) " gcp_choice
95- gcp_choice_lower=$( echo " $gcp_choice " | tr ' [:upper:]' ' [:lower:]' )
96-
97- if [[ " $gcp_choice_lower " == " y" ]] || ([[ -z " $gcp_choice " ]] && [[ " $GCP_PROMPT_DEFAULT " == " y" ]]); then
98- echo " Configuring Google Cloud services..."
99- # Source the script part. Check its exit code.
100- if source ./bin/configure_parts/gcp_services_setup; then
101- update_env_variable " ./variables/local.env" " TRACE_AGENT_ENABLED" " true"
102- USE_GCP_SERVICES=true # Mark that GCP services are configured for this session
103- GCP_SETUP_SUCCESS=true
104- echo " GCP services configured. TRACE_AGENT_ENABLED set to true."
105- else
106- echo " GCP services setup failed or was exited by the user. TRACE_AGENT_ENABLED will be set to false."
107- update_env_variable " ./variables/local.env" " TRACE_AGENT_ENABLED" " false"
108- GCP_SETUP_SUCCESS=false
109- fi
110- else
111- echo " Skipping Google Cloud services configuration."
112- update_env_variable " ./variables/local.env" " TRACE_AGENT_ENABLED" " false"
113- GCP_SETUP_SUCCESS=false
114- fi
115-
116- # Refresh GCLOUD_PROJECT in case gcp_services_setup set it
117- (set +e; set +u; source ./variables/local.env)
118- CURRENT_GCLOUD_PROJECT=${GCLOUD_PROJECT:- }
81+ # This script will ask the user if they want to set up GCP and handle the full flow.
82+ # It exports GCP_SETUP_SUCCESS and CURRENT_GCLOUD_PROJECT for use in later steps.
83+ source ./bin/configure_parts/gcp_services_setup || exit 1
84+ echo " GCP services check complete."
11985echo " ---------------------------------------------------------------------"
12086
12187# --- Application Setup (local.env, Angular, CLI paths) ---
12288echo " "
12389echo " --- Application Configuration and Frontend ---"
124- # Source the script part. Use '|| exit 1' to ensure main script exits if it fails.
12590# This part is expected to create ./variables/local.env if it doesn't exist.
12691source ./bin/configure_parts/app_setup || exit 1
12792echo " Application configuration and frontend setup complete."
@@ -130,117 +95,21 @@ echo "---------------------------------------------------------------------"
13095
13196# --- Database Setup ---
13297echo " "
133- echo " --- Stage 5: Database Setup ---"
134- # Source local.env again to ensure we have the latest DATABASE_TYPE if it was set previously
135- (set +e; set +u; source ./variables/local.env)
136- CURRENT_DB_TYPE=${DATABASE_TYPE:- }
137-
138- echo " Choose a database type for TypedAI."
139- echo " Current setting in ./variables/local.env: DATABASE_TYPE=${CURRENT_DB_TYPE:- Not set} "
140- echo " "
141- PS3=" Select database option: " # Prompt for select
142- OPTIONS=()
143- OPTION_ACTIONS=() # Parallel array to store actions
144-
145- # Option 1: Firestore (only if GCP services are configured OR GCLOUD_PROJECT is already set from a previous run)
146- # Check if GCP setup was successful in this run OR if GCLOUD_PROJECT is already present in local.env
147- if [ " $GCP_SETUP_SUCCESS " = true ] || [ -n " $CURRENT_GCLOUD_PROJECT " ]; then
148- OPTIONS+=(" Firestore (Native Mode, via Google Cloud)" )
149- OPTION_ACTIONS+=(" firestore" )
150- else
151- echo " Note: Firestore (Native Mode) option is unavailable because GCP services are not configured or GCLOUD_PROJECT is not set."
152- fi
153-
154- OPTIONS+=(" PostgreSQL (Requires Docker or a separate PostgreSQL instance)" )
155- OPTION_ACTIONS+=(" postgres" )
156- OPTIONS+=(" In-Memory (Data is lost when the application stops; for quick testing only)" )
157- OPTION_ACTIONS+=(" inmemory" )
158-
159- if [ -n " $CURRENT_DB_TYPE " ]; then
160- OPTIONS+=(" Keep current setting ($CURRENT_DB_TYPE )" )
161- OPTION_ACTIONS+=(" keep" )
162- fi
163- OPTIONS+=(" Exit configuration" )
164- OPTION_ACTIONS+=(" exit" )
165-
166- # Use a loop to handle invalid input and re-prompt
167- while true ; do
168- select opt in " ${OPTIONS[@]} " ; do
169- choice_idx=$(( REPLY - 1 ))
170- ACTION=${OPTION_ACTIONS[$choice_idx]}
171-
172- if [ -n " $ACTION " ]; then
173- case $ACTION in
174- firestore)
175- echo " You selected Firestore."
176- update_env_variable " ./variables/local.env" " DATABASE_TYPE" " firestore"
177- # Ensure GCLOUD_PROJECT is available for firestore_setup
178- # This check is also inside firestore_setup, but good to have here too.
179- (set +e; set +u; source ./variables/local.env) # Re-source in case it was just set
180- if [ -z " $GCLOUD_PROJECT " ]; then
181- echo " Error: GCLOUD_PROJECT not set. Firestore setup cannot proceed."
182- echo " Please re-run ./bin/configure and enable GCP services with a project ID."
183- exit 1 # Critical for Firestore
184- fi
185- # Source the script part. Use '|| exit 1' to ensure main script exits if part fails.
186- source ./bin/configure_parts/firestore_setup || exit 1
187- break 2 # Break out of select and while loop
188- ;;
189- postgres)
190- echo " You selected PostgreSQL."
191- update_env_variable " ./variables/local.env" " DATABASE_TYPE" " postgres"
192- # Source the script part. Use '|| exit 1' to ensure main script exits if part fails.
193- source ./bin/configure_parts/postgres_setup || exit 1
194- break 2 # Break out of select and while loop
195- ;;
196- inmemory)
197- echo " You selected In-Memory database."
198- update_env_variable " ./variables/local.env" " DATABASE_TYPE" " memory"
199- echo " In-Memory database selected. No further setup needed for the database itself."
200- break 2 # Break out of select and while loop
201- ;;
202- keep)
203- echo " Keeping current database setting: $CURRENT_DB_TYPE ."
204- # Optionally re-run setup for current DB type if it's Firestore or Postgres
205- if [ " $CURRENT_DB_TYPE " == " firestore" ]; then
206- read -r -p " Re-run Firestore setup/check steps? (y/N) " rerun_fs
207- if [[ " $rerun_fs " =~ ^[Yy]$ ]]; then
208- # Ensure GCLOUD_PROJECT is available before re-running Firestore setup
209- (set +e; set +u; source ./variables/local.env)
210- if [ -z " $GCLOUD_PROJECT " ]; then
211- echo " Error: GCLOUD_PROJECT not set. Cannot re-run Firestore setup."
212- echo " Please ensure it's set in ./variables/local.env."
213- else
214- source ./bin/configure_parts/firestore_setup || echo " Warning: Re-running Firestore setup failed."
215- fi
216- fi
217- elif [ " $CURRENT_DB_TYPE " == " postgres" ]; then
218- read -r -p " Re-run PostgreSQL setup/check steps? (y/N) " rerun_pg
219- if [[ " $rerun_pg " =~ ^[Yy]$ ]]; then source ./bin/configure_parts/postgres_setup || echo " Warning: Re-running PostgreSQL setup failed." ; fi
220- fi
221- break 2 # Break out of select and while loop
222- ;;
223- exit)
224- echo " Exiting configuration as requested."
225- exit 0
226- ;;
227- * ) echo " Invalid option $REPLY " ; continue ;; # Invalid input, stay in select
228- esac
229- else
230- echo " Invalid option $REPLY " # Should not happen with select, but for safety
231- continue # Stay in select
232- fi
233- done
234- done # End while true loop for select
235-
236- echo " Database setup choice processed."
98+ echo " --- Database Setup ---"
99+ source ./bin/configure_parts/db_setup || exit 1
237100echo " ---------------------------------------------------------------------"
238101
102+
239103echo " "
240104echo " --- Configuration Complete ---"
241105echo " All selected setup steps have been processed."
242106echo " Please review any specific instructions or warnings displayed above."
243- echo " If you configured shell environments (e.g., for fnm), you might need to source your shell config or open a new terminal."
244107echo " "
245- echo " Next steps: 'npm run start:local' (backend) and 'cd frontend && npm run start:local' (frontend)."
108+ echo " ✅ Configuration complete."
109+ echo " To apply the environment changes, you MUST open a new terminal window or run 'source ~/.zshrc' (or ~/.bashrc)."
110+ echo " "
111+ echo " Next steps:"
112+ echo " - Backend a: 'npm run start:local'"
113+ echo " - Frontend: 'cd frontend && npm run start:local'"
246114echo " done"
115+ exit 0
0 commit comments