install.fairie/home/dot_local/bin/post-installx/executable_post-gitomatic.sh

53 lines
2.6 KiB
Bash
Raw Normal View History

2024-05-03 19:40:44 -07:00
#!/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
2024-05-27 20:45:14 -07:00
set -Eeuo pipefail
2024-05-27 20:50:11 -07:00
trap "gum log -sl error 'Script encountered an error!'" ERR
2024-05-27 04:15:03 -07:00
2024-05-03 19:40:44 -07:00
if command -v gitomatic > /dev/null; then
2024-05-27 20:45:14 -07:00
### Copy gitomatic-service to /usr/local/bin
2024-05-27 20:50:11 -07:00
gum log -sl info "Copying $HOME/.local/bin/gitomatic-service to /usr/local/bin/gitomatic-service"
2024-05-27 20:45:14 -07:00
sudo cp -f "$HOME/.local/bin/gitomatic-service" /usr/local/bin/gitomatic-servic
2024-05-03 19:40:44 -07:00
### Copy gitomatic to global directory
if [ ! -f /usr/local/bin/gitomatic ]; then
2024-05-27 20:50:11 -07:00
gum log -sl info 'Copying gitomatic executable to /usr/local/bin/gitomatic'
2024-05-27 20:45:14 -07:00
sudo cp -f "$(which gitomatic)" /usr/local/bin/gitomatic
fi
2024-05-03 19:40:44 -07:00
if [ -d /Applications ] && [ -d /System ]; then
### macOS
2024-05-27 20:50:11 -07:00
gum log -sl info 'Enabling the com.github.muesli.gitomatic LaunchDaemon'
2024-05-27 20:45:14 -07:00
load-service com.github.muesli.gitomatic
2024-05-03 19:40:44 -07:00
else
### Linux
2024-05-27 20:50:11 -07:00
gum log -sl info 'Copying gitomatic systemd unit file to /etc/systemd/system/'
2024-05-27 20:45:14 -07:00
sudo cp -f "${XDG_CONFIG_HOME:-$HOME/.config}/gitomatic/gitomatic.service" /etc/systemd/system/gitomatic.service
2024-05-27 20:50:11 -07:00
gum log -sl info 'Reloading systemd daemon'
2024-05-27 20:45:14 -07:00
sudo systemctl daemon-reload
2024-05-27 20:50:11 -07:00
gum log -sl info 'Enabling and starting gitomatic service'
2024-05-27 20:45:14 -07:00
sudo systemctl enable --now gitomatic
2024-05-03 19:40:44 -07:00
fi
else
2024-05-27 20:50:11 -07:00
gum log -sl info 'gitomatic is not installed or it is not available in PATH'
2024-05-03 19:40:44 -07:00
fi