32 gitomatic (#61)

* Initial work to support gitomatic services

* Changes to create systemd service to run gitomatic

* Update logic after review

* Support MacOS
This commit is contained in:
enggnr 2023-07-09 10:14:11 +05:30 committed by GitHub
parent 168088b69a
commit 836af2b9be
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 105 additions and 0 deletions

View file

@ -193,6 +193,13 @@ data:
email: "{{ $gcloudEmail }}"
github:
username: "{{ $githubUsername }}"
gitomatic:
- git: https://github.com/megabyte-labs/install.doctor
path: $HOME/sources/install.doctor
- git: https://github.com/megabyte-labs/install.doctor-docs
path: $HOME/sources/install.doctor-docs
- git: https://github.com/megabyte-labs/install.doctor-site
path: $HOME/sources/install.doctor-site
gmail:
username: "{{ $gmailAddress }}"
gpg:

View file

@ -0,0 +1,56 @@
{{- if ne .host.distro.family "windows" -}}
#!/usr/bin/env bash
# @file git-o-matic Configuration
# @brief Starts service on Linux systems to monitor Git repositories
# @description
# git-o-matic is a tool to monitor git repositories and automatically pull/push changes. Multiple repositories can be
# monitored by running multiple instances of `gitomatic`. This script supports SSH Key based authentication only.
#
# If the `gitomatic` program is installed, this script creates and starts a Systemd service to monitor the repositories.
# The repositories are cloned if they are not available at the path.
#
# ## Notes
# * The author name and email address for commits are the same as `.user.name` and `.user.email` (configured in the `home/.chezmoi.yaml.tmpl` file)
# * `gitomatic` automatically pushes and pulls changes. The script does not change this behavior
# * `gitomatic` checks for changes every minute. This setting is not changed by this script
# * The User's default SSH Key is used for authentication
#
# ## Links
#
# * [gitomatic GitHub repository](https://github.com/muesli/gitomatic/)
# * [Systemd Unit file](https://github.com/megabyte-labs/install.doctor/blob/master/home/dot_config/gitomatic/gitomatic.service.tmpl)
# * [Helper script](https://github.com/megabyte-labs/install.doctor/blob/master/home/dot_local/bin/executable_gitomatic_service.tmpl)
{{ includeTemplate "universal/profile" }}
{{ includeTemplate "universal/logg" }}
### Clone the repositories
logg info 'Cloning the repositories'
{{ range .data.user.gitomatic }}
if [ ! -d {{ .path }} ] ; then
git clone {{ .git }} {{ .path }}
fi
{{ end -}}
### Create Systemd service to run gitomatic
if command -v gitomatic > /dev/null; then
if [ -d /Applications ] && [ -d /System ]; then
### macOS
logg info 'Copying `gitomatic` plist file to /Library/LaunchDaemons'
sudo cp -f {{ .chezmoi.homeDir }}/.config/gitomatic/gitomatic.plist /Library/LaunchDaemons/gitomatic.plist
logg info 'Running `sudo launchctl load com.gitomatic`'
sudo launchctl load com.gitomatic
logg info 'Running `sudo launchctl start com.gitomatic`'
sudo launchctl start com.gitomatic
else
### Linux
logg info 'Copying `gitomatic` systemd unit file to /etc/systemd/system/'
sudo cp -f {{ .chezmoi.homeDir }}/.config/gitomatic/gitomatic.service /etc/systemd/system/gitomatic.service
logg info 'Reloading systemd daemon'
sudo systemctl daemon-reload
logg info 'Enabling and starting `gitomatic` service'
sudo systemctl enable --now gitomatic
fi
else
logg info 'Git-o-matic is not installed or it is not available in PATH'
fi

View file

@ -0,0 +1,13 @@
{{- if eq .host.distro.family "darwin" -}}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.gitomatic</string>
<key>Program</key>
<string>{{ .chezmoi.homeDir }}/.local/bin/gitomatic_service</string>
<key>RunAtLoad</key>
</dict>
</plist>
{{ end }}

View file

@ -0,0 +1,12 @@
{{- if eq .host.distro.family "linux" -}}
[Unit]
Description=Service to watch git repositories
[Service]
Type=simple
ExecStart={{ .chezmoi.homeDir }}/.local/bin/gitomatic_service
Restart=on-failure
[Install]
WantedBy=multi-user.target
{{ end }}

View file

@ -0,0 +1,17 @@
#!/usr/bin/env bash
# @file .local/bin/gitomatic_service
# @brief Helper script to run gitomatic to monitor git repositories
# @description
# This script is executed by gitomatic systemd service. `gitomatic` does not support monitoring multiple
# repositories in a single process. This script starts as many gitomatic processes as there are repositories.
#
# ## Links
#
# [Systemd Unit file](https://github.com/megabyte-labs/install.doctor/blob/master/home/dot_config/gitomatic/gitomatic.service.tmpl)
{{ includeTemplate "universal/logg" }}
{{ range .data.user.gitomatic }}
gitomatic -author {{ $.data.user.name }} -email {{ $.data.user.email }} -privkey {{ $.chezmoi.homeDir }}/.ssh/id_rsa {{ .path }} &
{{ end -}}