install.fairie/home/.chezmoiscripts/universal/run_onchange_after_32-gitomatic.sh.tmpl
2023-07-10 08:11:30 +00:00

57 lines
2.7 KiB
Cheetah

{{- 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 .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
{{ end -}}