site-deploy/init.sh
2020-07-07 14:15:08 +02:00

45 lines
1.6 KiB
Bash
Executable File

#!/bin/bash
exe() {
echo "running $@"
$@
}
SITE_REPO_DEFAULT="https://git.chaospott.de/chaospott/site.git"
SITE_DOMAIN_DEFAULT="chaospott.de"
REDIRECT_DOMAIN_DEFAULT="www.chaospott.de"
echo "Where should the site store all volumes?"
read -p "PATH: " VOLUMES_PATH_RAW
read -p "Hook endpoint ID (just make something up):" ENDPOINT_ID
read -p "Hook endpoint Password:" ENDPOINT_PW
read -p "Hook Domain (NOT site domain):" HOOK_DOMAIN
read -p "Repo (Default: Repo for chaospott.de):" SITE_REPO
read -p "Domain (Default: chaospott.de):" SITE_DOMAIN
read -p "Domain(s) to redirect (Default: www.chaospott.de)" REDIRECT_DOMAIN
#set defaults
if [ -z "$SITE_REPO" ]; then SITE_REPO="$SITE_REPO_DEFAULT"; fi
if [ -z "$SITE_DOMAIN" ]; then SITE_DOMAIN="$SITE_DOMAIN_DEFAULT"; fi
if [ -z "$REDIRECT_DOMAIN" ]; then REDIRECT_DOMAIN="$REDIRECT_DOMAIN_DEFAULT"; fi
VOLUMES_PATH=$(echo $VOLUMES_PATH_RAW | sed 's/\/$//g')
echo "Creating volumes structure"
exe mkdir -p $VOLUMES_PATH/static
exe git clone $SITE_REPO $VOLUMES_PATH/repo
exe cp -rv configs/webhook $VOLUME
echo """[
{
\"id\": \"$ENDPOINT_ID\",
\"execute-command\": \"/webhook/reload.sh\",
\"command-working-directory\": \"/repo\",
\"match\":
{
\"secret\": \"$ENDPOINT_PW\"
}
}
]""" > $VOLUMES_PATH/webhook/hooks.json
echo """DATA_ROOT=$VOLUMES_PATH
WEBHOOK_DOMAIN=$HOOK_DOMAIN
DOMAIN=$SITE_DOMAIN
REDIRECT_DOMAIN=$REDIRECT_DOMAIN""" > .env
exe chmod 777 $VOLUMES_PATH -Rc
echo "configure your git with the following hook URL:"
echo "https://$HOOK_DOMAIN/hooks/$ENDPOINT_ID"