107 lines
3.6 KiB
Markdown
107 lines
3.6 KiB
Markdown
# Github webhook scripts
|
|
|
|
These are scripts to setup the basic webhook folder structure,
|
|
the clone base for one campaign and a simple crontab script to pull data from the repository
|
|
|
|
## Scripts
|
|
|
|
- base_setup.sh: setup for the folder structure, users, etc
|
|
- new_clone.sh: Basic clone script
|
|
- git_sync.sh: The script to run in crontab, to sync the changes
|
|
- switch_branch.sh: Switch from one branch to the other
|
|
- create_ssh_config.sh: setup ssh key and ssh config entry
|
|
|
|
## Run commands
|
|
|
|
### Settings
|
|
|
|
in `config/webhook.cfg` the following settings have to be entered
|
|
|
|
```ini
|
|
GIT_WEBHOOK_BASE_FOLDER="<BASE FOLDER>"
|
|
WWW_GROUP="<APACHE GROUP NAME>"
|
|
SUDO_USER="<SUDO USER NAME TO USE>"
|
|
USE_SUDO=<1: use sudo, 0: no sudo used>
|
|
```
|
|
|
|
The script will create the sudo user if needed automatically
|
|
|
|
### base_setup.sh
|
|
|
|
as is, if the folder exists it will only copy the scripts, will not alter or change anything.
|
|
|
|
Planned to get auto fixes for wrong ACL, etc or missing config settings
|
|
|
|
### SSH Key generation
|
|
|
|
A SSH Key has to be generated for each git respository that will be synced and the configuration has to be added to the ssh config file
|
|
|
|
```sh
|
|
create_ssh_config.sh [repo url full] ([jump proxy])
|
|
```
|
|
|
|
> [!notice]
|
|
> This will currently output the command to create the SSH key and the host config to add to the ssh config file
|
|
|
|
### new_clone.sh
|
|
|
|
Create a new clone
|
|
|
|
```sh
|
|
new_clone.sh -r <Repository URL> -b <Branch Name> [-H <Host name>] [-f <Folder name>] [-n <Remote name>]
|
|
```
|
|
|
|
The [host (-H)] is the SSH Host name entry, this will replace any "[host]:" in the [repository]. If the [host (-H)] is not set the host set in the [repository] will be used. If nothing found the script will abort. Note that if [host (-H)] is not set the host name will be the Repository name which has to match the SSH config setting.
|
|
|
|
A [branch (-B)] name must be set all the time.
|
|
|
|
An override folder naem can be set with `-f`
|
|
|
|
An optional [remote name] can be set, if not set "origin" will be used.
|
|
|
|
### git_sync.sh
|
|
|
|
Syncs changes, this is the script that should be placed into the crontab
|
|
|
|
```sh
|
|
git_sync.sh [repository] [branch] ([remote name])
|
|
```
|
|
|
|
The [repository] the the folder name inside the clone folder, on new clone it is output in the info line "... into (GIT REPOSITORY FOLDER)". All repository folders are in the "clone-base/" folder. The base folder is defined in the config/webhook.crf file.
|
|
|
|
A [branch] name must be set all the time.
|
|
|
|
An optional [remote name] can be set, if not set "origin" will be used.
|
|
|
|
All sync progress will be written to the log folder inside the base folder, the log file has the name of [repository]
|
|
|
|
Sample
|
|
|
|
```log
|
|
[2025-07-04 16:06:31] [<uniq id>] [START] git merge <repository folder> <remote name>/<branch>
|
|
[2025-07-04 16:06:31] [<uniq id>] Updating <sha>..<sha>
|
|
<git inforation>
|
|
[2025-07-04 16:06:31] [<uniq id>] [END]
|
|
```
|
|
|
|
#### What happens to local changes
|
|
|
|
Any local changes are stored in a backup branch and then reset and cleaned up. No local changes should be commited or synced up, this would break the pull only flow.
|
|
|
|
If there are changes and they have been reset it will show up in the log like this
|
|
|
|
```log
|
|
...
|
|
[2026-01-22 14:31:02] [F4222EC4] [!] Local or cached changes detected, creating backup branch and resetting changes
|
|
[2026-01-22 14:31:02] [F4222EC4] Reset log: HEAD is now at 633f6de Uppdate 14
|
|
...
|
|
```
|
|
|
|
If a clean up was run too it will show up as "Clean log" after the Reset log.
|
|
|
|
The reset will only reset local or cached changs (added) but not changed that have been commited. If changes have been commited a manual reset has to be done.
|
|
|
|
## TODO
|
|
|
|
Future versions will hold an incoming webhook handler and a polling scripts (systemd based)
|