139 lines
6.1 KiB
Bash
Executable file
139 lines
6.1 KiB
Bash
Executable file
#!/bin/bash
|
||
|
||
COLOR_BLUE="\033[38;2;51;100;255m"
|
||
COLOR_RESET="\033[0m"
|
||
|
||
echo "${COLOR_BLUE}"
|
||
echo "=========================================="
|
||
echo " setting up coryd.dev locally "
|
||
echo "=========================================="
|
||
echo "${COLOR_RESET}"
|
||
|
||
# step 1: retrieve and build .env file from 1password
|
||
echo "${COLOR_BLUE}signing in to 1password...${COLOR_RESET}"
|
||
eval $(op signin)
|
||
|
||
echo "${COLOR_BLUE}fetching secrets from 1password...${COLOR_RESET}"
|
||
|
||
SECRETS_JSON='{
|
||
"POSTGREST_URL": "{{ op://Private/coryd.dev secrets/POSTGREST_URL }}",
|
||
"POSTGREST_API_KEY": "{{ op://Private/coryd.dev secrets/POSTGREST_API_KEY }}",
|
||
"MASTODON_ACCESS_TOKEN": "{{ op://Private/coryd.dev secrets/MASTODON_ACCESS_TOKEN }}",
|
||
"MASTODON_SYNDICATION_TOKEN": "{{ op://Private/coryd.dev secrets/MASTODON_SYNDICATION_TOKEN }}",
|
||
"FORWARDEMAIL_API_KEY": "{{ op://Private/coryd.dev secrets/FORWARDEMAIL_API_KEY }}",
|
||
"BOOK_IMPORT_TOKEN": "{{ op://Private/coryd.dev secrets/BOOK_IMPORT_TOKEN }}",
|
||
"WATCHING_IMPORT_TOKEN": "{{ op://Private/coryd.dev secrets/WATCHING_IMPORT_TOKEN }}",
|
||
"ARTIST_IMPORT_TOKEN": "{{ op://Private/coryd.dev secrets/ARTIST_IMPORT_TOKEN }}",
|
||
"TMDB_API_KEY": "{{ op://Private/coryd.dev secrets/TMDB_API_KEY }}",
|
||
"SEASONS_IMPORT_TOKEN": "{{ op://Private/coryd.dev secrets/SEASONS_IMPORT_TOKEN }}",
|
||
"NAVIDROME_SCROBBLE_TOKEN": "{{ op://Private/coryd.dev secrets/NAVIDROME_SCROBBLE_TOKEN }}",
|
||
"NAVIDROME_API_URL": "{{ op://Private/coryd.dev secrets/NAVIDROME_API_URL }}",
|
||
"NAVIDROME_API_TOKEN": "{{ op://Private/coryd.dev secrets/NAVIDROME_API_TOKEN }}",
|
||
"COOLIFY_REBUILD_TOKEN": "{{ op://Private/coryd.dev secrets/COOLIFY_REBUILD_TOKEN }}",
|
||
"COOLIFY_REBUILD_URL": "{{ op://Private/coryd.dev secrets/COOLIFY_REBUILD_URL }}"
|
||
}'
|
||
|
||
SECRETS=$(echo "$SECRETS_JSON" | op inject)
|
||
|
||
if [ -z "$SECRETS" ]; then
|
||
echo "error: failed to retrieve secrets from 1password."
|
||
exit 1
|
||
fi
|
||
|
||
echo "${COLOR_BLUE}writing .env file...${COLOR_RESET}"
|
||
echo "$SECRETS" | jq -r 'to_entries | .[] | "\(.key)=\(.value)"' > .env
|
||
|
||
# load environment variables from .env and export them
|
||
export $(grep -v '^#' .env | xargs)
|
||
|
||
# step 2: generate final config files from templates
|
||
echo "${COLOR_BLUE}generating configuration files from templates...${COLOR_RESET}"
|
||
mkdir -p generated
|
||
|
||
# escape special characters in the replacement string
|
||
escape_special_chars() {
|
||
printf '%s' "$1" | sed 's|[&/\ |]|\\&|g'
|
||
}
|
||
|
||
for file in scripts/templates/*.template; do
|
||
[ -e "$file" ] || continue
|
||
|
||
new_file="generated/$(basename "${file%.template}")"
|
||
cp "$file" "$new_file"
|
||
|
||
# replace placeholders
|
||
sed -i '' -e "s|{{POSTGREST_URL}}|$(escape_special_chars "$POSTGREST_URL")|g" "$new_file"
|
||
sed -i '' -e "s|{{POSTGREST_API_KEY}}|$(escape_special_chars "$POSTGREST_API_KEY")|g" "$new_file"
|
||
sed -i '' -e "s|{{MASTODON_ACCESS_TOKEN}}|$(escape_special_chars "$MASTODON_ACCESS_TOKEN")|g" "$new_file"
|
||
sed -i '' -e "s|{{MASTODON_SYNDICATION_TOKEN}}|$(escape_special_chars "$MASTODON_SYNDICATION_TOKEN")|g" "$new_file"
|
||
sed -i '' -e "s|{{FORWARDEMAIL_API_KEY}}|$(escape_special_chars "$FORWARDEMAIL_API_KEY")|g" "$new_file"
|
||
sed -i '' -e "s|{{BOOK_IMPORT_TOKEN}}|$(escape_special_chars "$BOOK_IMPORT_TOKEN")|g" "$new_file"
|
||
sed -i '' -e "s|{{WATCHING_IMPORT_TOKEN}}|$(escape_special_chars "$WATCHING_IMPORT_TOKEN")|g" "$new_file"
|
||
sed -i '' -e "s|{{ARTIST_IMPORT_TOKEN}}|$(escape_special_chars "$ARTIST_IMPORT_TOKEN")|g" "$new_file"
|
||
sed -i '' -e "s|{{TMDB_API_KEY}}|$(escape_special_chars "$TMDB_API_KEY")|g" "$new_file"
|
||
sed -i '' -e "s|{{SEASONS_IMPORT_TOKEN}}|$(escape_special_chars "$SEASONS_IMPORT_TOKEN")|g" "$new_file"
|
||
sed -i '' -e "s|{{NAVIDROME_SCROBBLE_TOKEN}}|$(escape_special_chars "$NAVIDROME_SCROBBLE_TOKEN")|g" "$new_file"
|
||
sed -i '' -e "s|{{NAVIDROME_API_URL}}|$(escape_special_chars "$NAVIDROME_API_URL")|g" "$new_file"
|
||
sed -i '' -e "s|{{NAVIDROME_API_TOKEN}}|$(escape_special_chars "$NAVIDROME_API_TOKEN")|g" "$new_file"
|
||
sed -i '' -e "s|{{COOLIFY_REBUILD_TOKEN}}|$(escape_special_chars "$COOLIFY_REBUILD_TOKEN")|g" "$new_file"
|
||
sed -i '' -e "s|{{COOLIFY_REBUILD_URL}}|$(escape_special_chars "$COOLIFY_REBUILD_URL")|g" "$new_file"
|
||
done
|
||
|
||
echo "${COLOR_BLUE}all configurations generated in the 'generated' folder.${COLOR_RESET}"
|
||
|
||
# step 3: ensure apache_modules.list exists
|
||
MODULES_LIST="scripts/lists/apache_modules.list"
|
||
if [ ! -f "$MODULES_LIST" ]; then
|
||
echo "apache_modules.list not found, generating it..."
|
||
a2query -m | awk '{print $1}' > "$MODULES_LIST"
|
||
fi
|
||
|
||
# step 4: ensure php_extensions.list exists
|
||
PHP_EXTENSIONS_LIST="scripts/lists/php_extensions.list"
|
||
if [ ! -f "$PHP_EXTENSIONS_LIST" ]; then
|
||
echo "php_extensions.list not found, generating it..."
|
||
dpkg --get-selections | awk '/php8.3/ {print $1}' > "$PHP_EXTENSIONS_LIST"
|
||
fi
|
||
|
||
# step 5: display manual installation instructions
|
||
echo "${COLOR_BLUE}"
|
||
echo "=========================================="
|
||
echo " setup complete! "
|
||
echo " your local environment is ready! 🚀 "
|
||
echo "=========================================="
|
||
echo "${COLOR_RESET}"
|
||
|
||
echo "${COLOR_BLUE}next steps:${COLOR_RESET}"
|
||
echo "1️⃣ move the coryd.dev.conf apache configuration to the correct location:"
|
||
echo " sudo a2ensite coryd.dev.conf"
|
||
echo " sudo systemctl reload apache2"
|
||
echo ""
|
||
echo "2️⃣ enable the required apache modules:"
|
||
if [ -f "$MODULES_LIST" ]; then
|
||
REQUIRED_MODULES=$(tr '\n' ' ' < "$MODULES_LIST" | sed 's/ *$//')
|
||
if [ -n "$REQUIRED_MODULES" ]; then
|
||
echo " sudo a2enmod $REQUIRED_MODULES && sudo systemctl restart apache2"
|
||
else
|
||
echo " no required modules found."
|
||
fi
|
||
else
|
||
echo " error: apache_modules.list not found."
|
||
fi
|
||
echo ""
|
||
echo "3️⃣ install the required php extensions:"
|
||
if [ -f "$PHP_EXTENSIONS_LIST" ]; then
|
||
REQUIRED_PHP_EXTENSIONS=$(tr '\n' ' ' < "$PHP_EXTENSIONS_LIST" | sed 's/ *$//')
|
||
|
||
if [ -n "$REQUIRED_PHP_EXTENSIONS" ]; then
|
||
echo " sudo apt install -y $REQUIRED_PHP_EXTENSIONS && sudo systemctl restart php8.3-fpm"
|
||
else
|
||
echo " no required php extensions found."
|
||
fi
|
||
else
|
||
echo " error: php_extensions.list not found."
|
||
fi
|
||
echo ""
|
||
echo "4️⃣ apply crontabs manually:"
|
||
echo " root: crontab -e"
|
||
echo " www-data: sudo crontab -u www-data -e"
|
||
echo "${COLOR_BLUE}all done! 🎉${COLOR_RESET}"
|