deployment-dcdn/bin/setup_webhook.sh

42 lines
1.5 KiB
Bash

#!/bin/bash
. bin/variables.sh
. bin/functions.sh
echo -e "${PURPLE}${BOLD}If it does not already exists, create a webhook at the following url${RESET}"
echo -e "${PURPLE}${BOLD}${repo_url}/settings/hooks/gitea/new${RESET}"
echo -e "${BLUE}${BOLD}Target URL ${RESET}${BLUE}https://${domain_name}/webhook.php${RESET}"
echo -e "${BLUE}${BOLD}Branch filter ${RESET}${BLUE}prod${RESET}"
echo -e "${BLUE}${BOLD}Authorization Header ${RESET}${ORANGE}Generate a safe string using \`openssl rand -base64 32\`${RESET}"
echo -e "${PURPLE}${BOLD}Enter the Authorization Header${RESET}"
read -s auth_header
install_pkg php
install_pkg php-fpm
install_pkg jq
rm /var/www/html/index.html
cp ./assets/webhook.php /var/www/html/
mkdir /var/www/webhook
cp ./assets/webhook.sh /var/www/webhook
chown www-data:www-data /var/www/webhook/webhook.sh
chmod u+x /var/www/webhook/webhook.sh
mkdir /var/www/webhook/logs
chown www-data:www-data /var/www/webhook/logs
get_ip
head -n $(($(wc -l < $CADDYFILE) - 2)) $CADDYFILE > temp_Caddyfile && mv temp_Caddyfile $CADDYFILE
echo "handle /webhook.php {" >> $CADDYFILE
echo "@unauthorized not header Authorization \"${auth_header}\"" >> $CADDYFILE
echo "respond @unauthorized \"Unauthorized access\"" >> $CADDYFILE
echo "root * /var/www/html" >> $CADDYFILE
echo "php_fastcgi unix//run/php/php8.2-fpm.sock" >> $CADDYFILE
echo "file_server" >> $CADDYFILE
echo "}" >> $CADDYFILE
echo "handle {" >> $CADDYFILE
echo "reverse_proxy ${ip}:3000" >> $CADDYFILE
echo "}" >> $CADDYFILE
echo "}" >> $CADDYFILE
caddy fmt $CADDYFILE -w
caddy reload -c $CADDYFILE