Skip to content

Commit

Permalink
Update install.sh process to be consistent with each other. Remove un…
Browse files Browse the repository at this point in the history
…used civit token
  • Loading branch information
Layoric committed Oct 25, 2024
1 parent e5fb538 commit ce163b2
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 51 deletions.
1 change: 0 additions & 1 deletion AiServer/wwwroot/lib/data/media-models.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"sampler": "dpmpp_2m_sde_gpu",
"width": 1024,
"height": 1024,
"downloadApiKeyVar": "CIVITAI_TOKEN",
"url": "https://huggingface.co/CompVis/jib-mix-realistic-xl-v140-crystal-clarity",
"downloadUrl": "https://huggingface.co/CompVis/jib-mix-realistic-xl-v140-crystal-clarity/resolve/main/jibMixRealisticXL_v140CrystalClarity.safetensors?download=true"
},
Expand Down
127 changes: 77 additions & 50 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,49 @@ install_using_go() {
}

setup_ai_provider() {
# Ensure gum is installed
install_gum
# Initialize/reset .env file
: > .env

# Reusable style function for headers
style_header() {
gum style \
--foreground="#00FFFF" \
--border-foreground="#00FFFF" \
--border double \
--align center \
--width 50 \
"$1"
}

# Reusable input prompt function
get_input() {
local prompt="$1"
local default="$2"
local is_password="$3"
local placeholder="$4"

echo
gum style --foreground="#CCCCCC" "$prompt"
[ -n "$default" ] && gum style --foreground="#888888" "Default: $default"

local input_args=(
--value "${default:-}"
--placeholder "$placeholder"
--prompt "> "
--prompt.foreground="#00FFFF"
)
[ "$is_password" = "true" ] && input_args+=(--password)

gum input "${input_args[@]}"
}

# Reusable function to write to .env
write_env() {
echo "$1=$2" >> .env
}

# Provider setup
style_header "AI Provider Configuration"

# Define supported providers and their environment variables
declare -A PROVIDER_ENV_VARS=(
Expand All @@ -120,99 +161,85 @@ setup_ai_provider() {
# Initialize array to store selected environment variables
declare -A SELECTED_ENV_VARS

# First, check for existing environment variables
# Check existing environment variables
for provider in "${!PROVIDER_ENV_VARS[@]}"; do
env_var="${PROVIDER_ENV_VARS[$provider]}"

if [ -n "${!env_var}" ]; then
echo "Existing $env_var found for $provider:"
echo "${!env_var}" | cut -c1-10
USE_EXISTING=$(gum confirm "Use existing $env_var?" && echo "yes" || echo "no")
if [ "$USE_EXISTING" = "yes" ]; then
gum style --foreground="#CCCCCC" "Found existing $provider API key:"
gum style --foreground="#888888" "$(echo "${!env_var}" | cut -c1-10)..."

if gum confirm "Use existing $provider API key?"; then
SELECTED_ENV_VARS[$env_var]="${!env_var}"
echo "Added $provider configuration"
gum style --foreground="#00FF00" "✓ Using existing $provider configuration"
fi
fi
done

# Keep asking for additional providers until user chooses to complete setup
# Provider selection loop
while true; do
echo "Do you want to add any more providers or complete setup?"
style_header "Provider Selection"
ACTION=$(gum choose "Add provider" "Complete setup")

if [ "$ACTION" = "Complete setup" ]; then
break
fi
[ "$ACTION" = "Complete setup" ] && break

# Filter out already selected providers
# Filter available providers
AVAILABLE_PROVIDERS=()
for provider in "${!PROVIDER_ENV_VARS[@]}"; do
env_var="${PROVIDER_ENV_VARS[$provider]}"
if [ -z "${SELECTED_ENV_VARS[$env_var]}" ]; then
AVAILABLE_PROVIDERS+=("$provider")
fi
[ -z "${SELECTED_ENV_VARS[$env_var]}" ] && AVAILABLE_PROVIDERS+=("$provider")
done

# If no more providers available
if [ ${#AVAILABLE_PROVIDERS[@]} -eq 0 ]; then
echo "No more providers available to add."
# Check if providers are available
[ ${#AVAILABLE_PROVIDERS[@]} -eq 0 ] && {
gum style --foreground="#FFFF00" "No more providers available to add."
break
fi
}

# Select provider to add
# Get provider selection and API key
SELECTED_PROVIDER=$(gum choose --height 10 "${AVAILABLE_PROVIDERS[@]}")
ENV_VAR="${PROVIDER_ENV_VARS[$SELECTED_PROVIDER]}"

# Get API key
API_KEY=$(gum input --password --placeholder "Enter your $ENV_VAR")
API_KEY=$(get_input "Enter your $SELECTED_PROVIDER API key" "" "true" "Enter API key")

SELECTED_ENV_VARS[$ENV_VAR]="$API_KEY"
echo "Added $SELECTED_PROVIDER configuration"
gum style --foreground="#00FF00" "Added $SELECTED_PROVIDER configuration"
done

# Ask for AUTH_SECRET
AUTH_SECRET=$(gum input --password --placeholder "What Auth Secret would you like to use? (default p@55wOrd)")
if [ -z "$AUTH_SECRET" ]; then
AUTH_SECRET="p@55wOrd"
fi
# Get Auth Secret
AUTH_SECRET=$(get_input "Set your Auth Secret" "p@55wOrd" "true" "Enter Auth Secret")

# Save all environment variables to .env file
: > .env # Clear the file
# Save configuration
for env_var in "${!SELECTED_ENV_VARS[@]}"; do
echo "$env_var=${SELECTED_ENV_VARS[$env_var]}" >> .env
write_env "$env_var" "${SELECTED_ENV_VARS[$env_var]}"
done
echo "AUTH_SECRET=$AUTH_SECRET" >> .env
echo "Environment variables saved to .env file."
write_env "AUTH_SECRET" "$AUTH_SECRET"

gum style --foreground="#00FF00" "✓ Environment variables saved to .env file"

# Ask if the user wants to run "AI Server"
# Server setup
style_header "AI Server Setup"
if gum confirm "Do you want to run AI Server?"; then
echo "Starting AI Server..."
gum style --foreground="#CCCCCC" "Starting AI Server..."
docker compose up -d

# Wait for the server to start
sleep 5

# Ask about ComfyUI Agent setup only if AI Server was started
if gum confirm "Do you want to configure a local ComfyUI Agent with your AI Server for testing?"; then
echo "Setting up ComfyUI Agent..."
if gum confirm "Do you want to configure a local ComfyUI Agent?"; then
gum style --foreground="#CCCCCC" "Setting up ComfyUI Agent..."

# Initialize and update submodules
git submodule init
git submodule update

# Check if the agent-comfy directory exists and install script is executable
if [ -f "./agent-comfy/install.sh" ]; then
# Export necessary environment variables for the install script
export AI_SERVER_AUTH_SECRET="$AUTH_SECRET"
export AI_SERVER_URL="http://localhost:5006"

chmod +x "./agent-comfy/install.sh"
./agent-comfy/install.sh

# Optionally unset the environment variables after installation
unset AI_SERVER_AUTH_SECRET
unset AI_SERVER_URL
else
echo "Error: Could not find agent-comfy/install.sh"
gum style --foreground="#FF0000" "Error: Could not find agent-comfy/install.sh"
exit 1
fi
fi
Expand All @@ -223,10 +250,10 @@ setup_ai_provider() {
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
xdg-open "http://localhost:5006"
else
echo "Please open http://localhost:5006 in your browser."
gum style --foreground="#CCCCCC" "Please open http://localhost:5006 in your browser"
fi
else
echo "AI Server not started. You can run it later with 'docker compose up -d'"
gum style --foreground="#CCCCCC" "AI Server not started. Run later with 'docker compose up -d'"
fi
}

Expand Down

0 comments on commit ce163b2

Please sign in to comment.