Created
May 18, 2020 17:01
-
-
Save ragul28/6e5fc9ba7d1adbe761b8643b2a22a1a8 to your computer and use it in GitHub Desktop.
Easy webhook installation script to systemd.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
echo "[-] Installing webhook.." | |
wget https://github.com/adnanh/webhook/releases/download/2.6.11/webhook-linux-amd64.tar.gz | |
tar -xvf webhook*.tar.gz | |
sudo mv webhook-linux-amd64/webhook /usr/local/bin | |
rm -rf webhook-linux-amd64* | |
echo "[ok] Installing webhook." | |
sudo mkdir /opt/scripts | |
sudo mkdir /opt/hooks | |
sudo chown -R $USER:$USER /opt/scripts | |
sudo chown -R $USER:$USER /opt/hooks | |
hooksjson_location=/opt/hooks/hooks.json | |
cat > $hooksjson_location <<EOF | |
[ | |
{ | |
"id": "server01", | |
"execute-command": "/opt/scripts/deploy.sh", | |
"command-working-directory": "/opt/scripts/", | |
"pass-arguments-to-command": | |
[ | |
{ | |
"source": "payload", | |
"name": "object_attributes.status" | |
}, | |
{ | |
"source": "payload", | |
"name": "project.name" | |
}, | |
{ | |
"source": "payload", | |
"name": "user.username" | |
} | |
] | |
} | |
] | |
EOF | |
echo "[-] Installing webhook in sysd.." | |
file_location=/etc/systemd/system/webhook.service | |
cat > $file_location <<EOF | |
[Unit] | |
Description=webhook server for ci | |
ConditionPathExists=/usr/local/bin/webhook | |
After=network.target | |
[Service] | |
Type=simple | |
WorkingDirectory=/opt/hooks | |
ExecStart=/usr/local/bin/webhook -ip 0.0.0.0 -port 9225 -hooks /opt/hooks/hooks.json -verbose | |
Restart=on-failure | |
PrivateTmp=true | |
[Install] | |
WantedBy=default.target | |
EOF | |
systemctl daemon-reload | |
systemctl start webhook.service | |
systemctl enable webhook.service | |
echo "[ok] Installing webhook in sysd." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment