This commit is contained in:
admin 2025-05-15 12:20:52 -06:00
parent c2fb4eabf9
commit 7f2745862e
5 changed files with 354 additions and 50 deletions

5
.gitignore vendored
View File

@ -1,5 +1,9 @@
# Ignore all files in specific directories but keep .gitkeep files
# .env files
.env
.env*
# code-server directories
configs/code-server/.config/code-server/*
!configs/code-server/.config/code-server/.gitkeep
@ -39,5 +43,4 @@ answer-data/*
!answer-data/.gitkeep
.vscode

354
config.sh
View File

@ -20,40 +20,285 @@ EOF
# Get the absolute path of the script directory
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
ENV_FILE="$SCRIPT_DIR/.env"
SERVICES_YAML="$SCRIPT_DIR/configs/homepage/services.yaml"
WIDGETS_YAML="$SCRIPT_DIR/configs/homepage/widgets.yaml"
MKDOCS_MAIN_HTML="$SCRIPT_DIR/mkdocs/docs/overrides/main.html"
echo "Looking for .env file at: $ENV_FILE"
# Check if .env file exists
# Initialize a new .env file if it doesn't exist
if [ ! -f "$ENV_FILE" ]; then
echo "Error: .env file not found at $ENV_FILE"
echo "Creating a backup plan - searching for .env in current directory..."
if [ -f ".env" ]; then
ENV_FILE=".env"
echo "Found .env in current directory. Using: $ENV_FILE"
else
echo "Still no .env file found. Please make sure the .env file exists."
exit 1
fi
echo "No .env file found. Creating a new one from scratch."
touch "$ENV_FILE"
initialize_env_file
else
echo "Found existing .env file. Will update values."
# Create a backup of the existing file
backup_env_file
fi
# Function to update the services.yaml file with the new domain
update_services_yaml() {
local new_domain=$1
if [ ! -f "$SERVICES_YAML" ]; then
echo "Warning: services.yaml file not found at $SERVICES_YAML"
return 1
fi
echo "Updating service URLs in services.yaml..."
# Create a backup of the services.yaml file
local timestamp=$(date +"%Y%m%d_%H%M%S")
local backup_file="${SERVICES_YAML}.backup_${timestamp}"
cp "$SERVICES_YAML" "$backup_file"
echo "Created backup of services.yaml at $backup_file"
# Get the content of the services.yaml file
local content=$(cat "$SERVICES_YAML")
# Extract all unique domains from the file using grep with a more robust pattern
local domains=$(echo "$content" | grep -o 'https://[^[:space:]"]*' | cut -d'/' -f3 | sort | uniq)
# Check if we found any domains
if [ -z "$domains" ]; then
echo "Warning: Could not find any URLs in services.yaml"
return 1
fi
echo "Found these domains in services.yaml:"
echo "$domains"
# Extract the base domain pattern (e.g., betteredmonton.org)
local base_domain_pattern=$(echo "$domains" | head -1 | sed -E 's/^[^.]+\.//')
if [ -z "$base_domain_pattern" ]; then
echo "Warning: Could not extract base domain pattern from URLs"
return 1
fi
echo "Detected base domain pattern: $base_domain_pattern"
echo "Will replace with: $new_domain"
# Create a temporary file for the updated content
local temp_file=$(mktemp)
# Replace domain in all URLs
if ! echo "$content" | sed "s|$base_domain_pattern|$new_domain|g" > "$temp_file"; then
echo "Error: Failed to update domains in the file"
rm -f "$temp_file"
return 1
fi
# Check if the file has any changes
if ! grep -q "$new_domain" "$temp_file"; then
echo "Warning: No domain replacements were made. Check the domain pattern matching."
cat "$temp_file" | grep -o 'https://[^[:space:]"]*' | head -5
rm -f "$temp_file"
return 1
fi
# Count the number of URLs with the new domain
local replacements=$(grep -o "https://[^[:space:]\"]*$new_domain" "$temp_file" | wc -l)
# Move the modified file to replace the original
mv "$temp_file" "$SERVICES_YAML"
echo "Updated $replacements URLs in services.yaml to use $new_domain"
echo "Examples of updated URLs:"
grep -o "https://[^[:space:]\"]*$new_domain" "$SERVICES_YAML" | head -5
return 0
}
# Function to update the login URL in MkDocs main.html
update_mkdocs_main_html() {
local new_domain=$1
if [ ! -f "$MKDOCS_MAIN_HTML" ]; then
echo "Warning: MkDocs main.html not found at $MKDOCS_MAIN_HTML"
return 1
fi
echo "Updating login button URL in MkDocs main.html..."
# Create a backup of the main.html file
local timestamp=$(date +"%Y%m%d_%H%M%S")
local backup_file="${MKDOCS_MAIN_HTML}.backup_${timestamp}"
cp "$MKDOCS_MAIN_HTML" "$backup_file"
echo "Created backup of main.html at $backup_file"
# Create a new file for the modified content
local new_file="${MKDOCS_MAIN_HTML}.new"
# Extract the current login URL from the login button
local login_line=$(grep -A 1 "{% block announce %}" "$MKDOCS_MAIN_HTML" | grep "login-button")
local current_url=$(echo "$login_line" | grep -o 'https://[^"]*')
if [ -z "$current_url" ] || [ -z "$login_line" ]; then
echo "Warning: Could not find the login button URL in main.html"
return 1
fi
# Create the replacement login line with the new domain
local new_login_line=$(echo "$login_line" | sed "s|$current_url|https://homepage.$new_domain|g")
# Create the new file by replacing the login line
while IFS= read -r line; do
if [[ "$line" == "$login_line" ]]; then
echo "$new_login_line" >> "$new_file"
else
echo "$line" >> "$new_file"
fi
done < "$MKDOCS_MAIN_HTML"
# Move the new file to replace the original
mv "$new_file" "$MKDOCS_MAIN_HTML"
echo "Updated login button URL in main.html from '$current_url' to 'https://homepage.$new_domain'"
return 0
}
# Function to create a timestamped backup of the .env file
backup_env_file() {
local timestamp=$(date +"%Y%m%d_%H%M%S")
local backup_file="$ENV_FILE.backup_$timestamp"
echo "Creating backup of current .env file to: $backup_file"
if cp "$ENV_FILE" "$backup_file"; then
echo "Backup created successfully!"
return 0
else
echo "Failed to create backup file. Proceeding with caution..."
return 1
if [ -f "$ENV_FILE" ]; then
local timestamp=$(date +"%Y%m%d_%H%M%S")
local backup_file="$ENV_FILE.backup_$timestamp"
echo "Creating backup of current .env file to: $backup_file"
if cp "$ENV_FILE" "$backup_file"; then
echo "Backup created successfully!"
return 0
else
echo "Failed to create backup file. Proceeding with caution..."
return 1
fi
fi
}
# Create a backup of the current .env file before making any changes
backup_env_file
# Function to initialize the .env file with default values
initialize_env_file() {
echo "Initializing new .env file with default values..."
# Create the new .env file with header
cat > "$ENV_FILE" << EOL
# Never share this file publicly. It contains sensitive information.
# This file is used to configure various applications and services.
# Generated by Changemaker Config Wizard on $(date)
# Domain Configuration
DOMAIN=changeme.org
BASE_DOMAIN=https://changeme.org
# Listmonk Configuration
LISTMONK_ADMIN_USER=admin
LISTMONK_ADMIN_PASSWORD=strongpassword
LISTMONK_PORT=9000
LISTMONK_HOSTNAME=listmonk.changeme.org
# Database Credentials
POSTGRES_USER=listmonk
POSTGRES_PASSWORD=$(generate_password 20)
POSTGRES_DB=listmonk
# Monica CRM Configuration
MONICA_APP_KEY=base64:$(openssl rand -base64 32)
MONICA_DB_USERNAME=monica
MONICA_DB_PASSWORD=$(generate_password 20)
MONICA_MYSQL_DATABASE=monica
MONICA_MYSQL_USER=monica
MONICA_MYSQL_PASSWORD=$(generate_password 20)
# MkDocs Configuration
USER_ID=1000
GROUP_ID=1000
MKDOCS_PORT=4000
# Flatnotes Configuration
FLATNOTES_PUID=1000
FLATNOTES_PGID=1000
FLATNOTES_AUTH_TYPE=password
FLATNOTES_USERNAME=user
FLATNOTES_PASSWORD=changeMe!
FLATNOTES_SECRET_KEY=$(generate_password 32)
FLATNOTES_PORT=8089
# Gitea Configuration
GITEA_DB_TYPE=mysql
GITEA_DB_HOST=gitea-db:3306
GITEA_DB_NAME=gitea
GITEA_DB_USER=gitea
GITEA_DB_PASSWD=$(generate_password 24)
GITEA_DB_ROOT_PASSWORD=$(generate_password 24)
GITEA_WEB_PORT=3030
GITEA_SSH_PORT=2225
GITEA_ROOT_URL=https://gitea.changeme.org
GITEA_DOMAIN=gitea.changeme.org
# Apache Answer Configuration
ANSWER_APP_PORT=9080
# Excalidraw Configuration
EXCALIDRAW_PORT=3333
EXCALIDRAW_LIBRARY_URL=https://libraries.excalidraw.com
EXCALIDRAW_LIBRARY_BACKEND=https://us-central1-excalidraw-room-persistence.cloudfunctions.net/libraries
EXCALIDRAW_PUBLIC_URL=https://excalidraw.changeme.org
EXCALIDRAW_PUBLIC_SOCKET_URL=https://excalidraw.changeme.org
# Code Server Configuration
CODE_SERVER_PORT=8888
USER_NAME=coder
# Cloudflare Credentials
CF_AUTH_EMAIL=
CF_API_TOKEN=
CF_ZONE_ID=
CF_TUNNEL_ID=
CF_DOMAIN=changeme.org
# NocoDB Configuration
NOCODB_PORT=8090
NOCODB_JWT_SECRET=$(generate_password 32)
NOCODB_DB_NAME=nocodb
NOCODB_DB_USER=noco
NOCODB_DB_PASSWORD=$(generate_password 20)
# OpenWebUI Configuration
OPEN_WEBUI_PORT=3005
OPEN_WEBUI_URL=https://open-webui.changeme.org
# N8N Configuration
N8N_PORT=5678
N8N_HOST=n8n.changeme.org
N8N_ENCRYPTION_KEY=$(generate_password 32)
N8N_USER_EMAIL=admin@example.com
N8N_USER_PASSWORD=changeMe
GENERIC_TIMEZONE=UTC
# ConvertX Configuration
CONVERTX_PORT=3100
CONVERTX_JWT_SECRET=$(generate_password 48)
# Rocket.Chat Configuration
ROCKETCHAT_IMAGE=registry.rocket.chat/rocketchat/rocket.chat
ROCKETCHAT_RELEASE=latest
ROCKETCHAT_PORT=3004
ROCKETCHAT_CONTAINER_PORT=3000
ROCKETCHAT_ROOT_URL=https://rocket.changeme.org
ROCKETCHAT_DEPLOYMENT_ENVIRONMENT=changemaker
ROCKETCHAT_MONGODB_VERSION=6.0
ROCKETCHAT_MONGODB_HOST=mongodb-rocketchat
ROCKETCHAT_MONGODB_PORT=27017
ROCKETCHAT_MONGODB_DATABASE=rocketchat
ROCKETCHAT_MONGODB_REPLICA_SET=rs0
ROCKETCHAT_MONGODB_ENABLE_JOURNAL=true
ROCKETCHAT_MONGODB_ALLOW_EMPTY_PASSWORD=yes
# Additional Configuration
EOL
echo "New .env file created with default values."
}
# Function to generate a random secure password
generate_password() {
@ -75,7 +320,6 @@ update_env_var() {
local escaped_value=$(echo "$value" | sed 's/[\/&]/\\&/g')
# Make a temporary backup of the .env file before modification
# Adding "_tmp" to distinguish from the main backup
cp "$ENV_FILE" "$ENV_FILE.bak_tmp"
if grep -q "^$key=" "$ENV_FILE"; then
@ -116,6 +360,54 @@ update_env_var() {
rm -f "$ENV_FILE.bak_tmp"
}
# Function to update the greeting widget in widgets.yaml
update_widgets_yaml() {
local new_domain=$1
if [ ! -f "$WIDGETS_YAML" ]; then
echo "Warning: widgets.yaml file not found at $WIDGETS_YAML"
return 1
fi
echo "Updating greeting widget in widgets.yaml..."
# Create a backup of the widgets.yaml file
local timestamp=$(date +"%Y%m%d_%H%M%S")
local backup_file="${WIDGETS_YAML}.backup_${timestamp}"
cp "$WIDGETS_YAML" "$backup_file"
echo "Created backup of widgets.yaml at $backup_file"
# Extract the site name (domain without TLD) for the greeting text
local site_name=$(echo "$new_domain" | cut -d. -f1)
# Create a temporary file for the modified content
local temp_file=$(mktemp)
# Read the file and replace the greeting text and href
awk -v site_name="$site_name" -v domain="$new_domain" '
/- greeting:/ {
print $0;
getline; print $0; # text_size line
getline; gsub(/text: .*/, "text: " site_name); print $0; # text line
getline; gsub(/href: .*/, "href: https://" domain); print $0; # href line
next;
}
{ print $0; }
' "$WIDGETS_YAML" > "$temp_file"
# Move the temporary file to replace the original
mv "$temp_file" "$WIDGETS_YAML"
echo "Updated greeting widget in widgets.yaml:"
echo " - Set text to: $site_name"
echo " - Set href to: https://$new_domain"
return 0
}
# Make sure the initialize_env_file function is available
initialize_env_file
echo -e "\n\nWelcome to Changemaker Config!\n"
echo "This script will help you configure your Changemaker instance."
echo "Please provide the following information:"
@ -150,6 +442,18 @@ echo -e "\nConfiguring OpenWebUI..."
update_env_var "OPEN_WEBUI_PORT" "3005"
update_env_var "OPEN_WEBUI_URL" "https://open-webui.$domain_name"
# Update service URLs in the services.yaml file
echo -e "\nUpdating service URLs in services.yaml file..."
update_services_yaml "$domain_name"
# Update the greeting widget in widgets.yaml
echo -e "\nUpdating greeting widget in widgets.yaml..."
update_widgets_yaml "$domain_name"
# After domain configuration and updating services.yaml, update the login button URL
echo -e "\nUpdating login button URL in MkDocs main.html..."
update_mkdocs_main_html "$domain_name"
echo -e "Domain settings have been updated successfully!\n"
# Listmonk Admin Credentials configuration
@ -208,7 +512,7 @@ if [ -z "$n8n_email" ]; then
fi
if [ -z "$n8n_password" ]; then
echo "Using default N8N admin password"
echo "Using default N8N admin password: changeMe"
n8n_password="changeMe"
fi

View File

@ -1,79 +1,77 @@
---
# For configuration options and examples, please see:
# https://gethomepage.dev/configs/services/
- Essential Tools:
- code-server:
href: https://code-server.betteredmonton.org
href: https://code-server.test.com
description: VS Code in the browser
icon: code-server
- Flatnotes:
href: https://flatnotes.betteredmonton.org
href: https://flatnotes.test.com
description: Note-taking app - connected directly to blog
icon: flatnotes
- Listmonk:
href: https://listmonk.betteredmonton.org
href: https://listmonk.test.com
description: Newsletter & mailing list manager
icon: listmonk
- NocoDB:
href: https://nocodb.betteredmonton.org
href: https://nocodb.test.com
description: Open Source Airtable Alternative
icon: mdi-database
- Content Creation:
- MkDocs:
href: https://live.betteredmonton.org
href: https://live.test.com
description: Website generator & documentation
icon: mkdocs
- Excalidraw:
href: https://excalidraw.betteredmonton.org
href: https://excalidraw.test.com
description: Collaborative drawing tool
icon: mdi-draw-pen
- Gitea:
href: https://gitea.betteredmonton.org
href: https://gitea.test.com
description: Self-hosted Git service
icon: gitea
- OpenWebUI:
href: https://open-webui.betteredmonton.org
href: https://open-webui.test.com
description: UI for Ollama models
icon: mdi-robot-happy
- Community & Data:
- Monica CRM:
href: https://monica.betteredmonton.org
href: https://monica.test.com
description: Personal CRM
icon: monica
- Answer:
href: https://answer.betteredmonton.org
href: https://answer.test.com
description: Q&A platform for teams
icon: mdi-help-circle
- Ferdium:
href: https://ferdium.betteredmonton.org
href: https://ferdium.test.com
description: All-in-one messaging app
icon: ferdium
- Rocket.Chat:
href: https://rocket.betteredmonton.org
href: https://rocket.test.com
description: Team collaboration platform
icon: mdi-rocket
- Development:
- Ollama:
href: https://ollama.betteredmonton.org
href: https://ollama.test.com
description: Local AI model server
icon: ollama
- Portainer:
href: https://portainer.betteredmonton.org
href: https://portainer.test.com
description: Docker management UI
icon: portainer
- Mini QR:
href: https://mini-qr.betteredmonton.org
href: https://mini-qr.test.com
description: QR Code Generator
icon: mdi-qrcode-edit
- ConvertX:
href: https://convertx.betteredmonton.org
href: https://convertx.test.com
description: File conversion tool
icon: mdi-file-sync
- n8n:
href: https://n8n.betteredmonton.org
href: https://n8n.test.com
description: Workflow automation
icon: n8n

4
configs/homepage/widgets.yaml Executable file → Normal file
View File

@ -9,8 +9,8 @@
- greeting:
text_size: xl
text: betteredmonton
href: https://betteredmonton.org
text: test
href: https://test.com
- datetime:
text_size: xl

View File

@ -1,4 +1,3 @@
{% extends "base.html" %} {% block extrahead %} {% endblock %} {% block announce %}
<a href="https://homepage.betteredmonton.org" class="login-button">Login</a>
Changemaker Archive. <a href="https://changemaker.bnkops.com">Learn more</a>
{% endblock %} {% block scripts %} {{ super() }} {% endblock %}
<a href="https://homepage.test.com" class="login-button">Login</a>
Changemaker Archive. <a href="https://docs.bnkops.com">Learn more</a>