install.fairie/home/.chezmoiscripts/universal/run_onchange_after_32-gitomatic.sh.tmpl

61 lines
3.2 KiB
Cheetah
Raw Normal View History

{{- 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" }}
2023-07-11 21:32:13 -07:00
function gitomaticSetup() {
### Create Systemd service to run gitomatic
if command -v gitomatic > /dev/null; then
2023-07-12 19:58:08 -07:00
### Copy bin to /usr/local/bin
logg info "Copying $HOME/.local/bin/gitomatic-service to /usr/local/bin/gitomatic-service"
sudo cp -f "$HOME/.local/bin/gitomatic-service" /usr/local/bin/gitomatic-service
2023-07-11 21:32:13 -07:00
if [ -d /Applications ] && [ -d /System ]; then
### macOS
logg info 'Copying `gitomatic` plist file to /Library/LaunchDaemons'
sudo cp -f "${XDG_CONFIG_HOME:-$HOME/.config}/gitomatic/gitomatic.plist" /Library/LaunchDaemons/gitomatic.plist
2023-07-17 10:41:49 -07:00
if ! sudo launchctl list | grep 'gitomatic' > /dev/null; then
logg info 'Running `sudo launchctl load /Library/LaunchDaemons/gitomatic.plist`'
sudo launchctl load /Library/LaunchDaemons/gitomatic.plist
logg info 'Running `sudo launchctl start /Library/LaunchDaemons/gitomatic.plist`'
sudo launchctl start /Library/LaunchDaemons/gitomatic.plist
else
logg info "gitomatic services appear to already be loaded"
2023-07-17 10:41:49 -07:00
fi
2023-07-11 21:32:13 -07:00
else
### Linux
logg info 'Copying `gitomatic` systemd unit file to /etc/systemd/system/'
sudo cp -f "${XDG_CONFIG_HOME:-$HOME/.config}/gitomatic/gitomatic.service" /etc/systemd/system/gitomatic.service
2023-07-11 21:32:13 -07:00
logg info 'Reloading systemd daemon'
sudo systemctl daemon-reload
logg info 'Enabling and starting `gitomatic` service'
sudo systemctl enable --now gitomatic
fi
else
2023-07-12 19:58:08 -07:00
logg info 'gitomatic is not installed or it is not available in PATH'
fi
2023-07-11 21:32:13 -07:00
}
gitomaticSetup
2023-07-10 01:11:30 -07:00
{{ end -}}