|
@@ -0,0 +1,95 @@
|
|
|
+#!/bin/bash
|
|
|
+
|
|
|
+# bachir soussi chiadmi
|
|
|
+
|
|
|
+# get the current position
|
|
|
+_cwd="$(pwd)"
|
|
|
+
|
|
|
+echo -e '\033[35m
|
|
|
+ __ __ _ _ _ _
|
|
|
+ \ \ / /__| |__| || |___ ___| |__
|
|
|
+ \ \/\/ / -_) `_ \ __ / _ \/ _ \ / /
|
|
|
+ \_/\_/\___|_.__/_||_\___/\___/_\_\
|
|
|
+\033[0m'
|
|
|
+
|
|
|
+# check for assets folder
|
|
|
+_assets="$_cwd/assets"
|
|
|
+if [ ! -d "$_assets" ]; then
|
|
|
+ _assets="$_cwd/../assets"
|
|
|
+ if [ ! -d "$_assets" ]; then
|
|
|
+ echo "!! can't find assets directory !!"
|
|
|
+ exit
|
|
|
+ fi
|
|
|
+fi
|
|
|
+
|
|
|
+while [ "$user" = "" ]
|
|
|
+do
|
|
|
+ read -p "enter an existing user name ? " user
|
|
|
+ if [ "$user" != "" ]; then
|
|
|
+ # check if user already exists
|
|
|
+ if id "$user" >/dev/null 2>&1; then
|
|
|
+ read -p "is user name $user correcte [y|n] " validated
|
|
|
+ if [ "$validated" = "y" ]; then
|
|
|
+ break
|
|
|
+ else
|
|
|
+ user=""
|
|
|
+ fi
|
|
|
+ else
|
|
|
+ echo "user $user doesn't exists, you must provide an existing user"
|
|
|
+ user=""
|
|
|
+ fi
|
|
|
+ fi
|
|
|
+done
|
|
|
+
|
|
|
+while [ "$_domain" = "" ]
|
|
|
+do
|
|
|
+read -p "enter a domain name ? " _domain
|
|
|
+if [ "$_domain" != "" ]; then
|
|
|
+ read -p "is domain $_domain correcte [y|n] " validated
|
|
|
+ if [ "$validated" = "y" ]; then
|
|
|
+ break
|
|
|
+ else
|
|
|
+ _domain=""
|
|
|
+ fi
|
|
|
+fi
|
|
|
+done
|
|
|
+
|
|
|
+# TODO check for /home/"$user"/www/"$_domain"
|
|
|
+if [ ! -d /home/"$user"/www/"$_domain" ]; then
|
|
|
+ echo "/home/$user/www/$_domain does not exists !"
|
|
|
+ exit
|
|
|
+fi
|
|
|
+
|
|
|
+# TODO check for /home/"$user"/git-repositories/"$_domain.git"
|
|
|
+if [ ! -d /home/"$user"/git-repositories/"$_domain.git" ]; then
|
|
|
+ echo "/home/$user/git-repositories/$_domain.git does not exists !"
|
|
|
+ exit
|
|
|
+fi
|
|
|
+
|
|
|
+apt-get install webhook
|
|
|
+
|
|
|
+# hook deploy script
|
|
|
+cp "$_assets"/webhook-deploy.sh /"$user"/webhook-deploy-"$_domain".sh
|
|
|
+sed -i -r "s/DOMAIN/$_domain/g" /"$user"/webhook-deploy-"$_domain".sh
|
|
|
+chmod +x /"$user"/webhook-deploy-"$_domain".sh
|
|
|
+
|
|
|
+# remove git bare repos hook
|
|
|
+mv /home/"$user"/git-repositories/"$_domain".git/hooks/post-receive /home/"$user"/git-repositories/"$_domain".git/hooks/post-receive.back
|
|
|
+
|
|
|
+# webhook conf
|
|
|
+touch /etc/webhook.conf
|
|
|
+echo "
|
|
|
+- id: deploy-app-$_domain
|
|
|
+ execute-command: /$user/webhook-deploy-$_domain.sh
|
|
|
+ command-working-directory: /home/$user/
|
|
|
+" >> /etc/webhook.conf
|
|
|
+
|
|
|
+# webhook service
|
|
|
+cp "$_assets"/webhook.service /etc/systemd/system/webhook.service
|
|
|
+systemctl enable webhook
|
|
|
+systemctl start webhook
|
|
|
+systemctl reload webhook
|
|
|
+
|
|
|
+ufw allow 9000
|
|
|
+
|
|
|
+echo "http://$_domain:9000/hooks/deploy-app-$_domain"
|