install.fairie/home/dot_local/bin/executable_gitomatic-service.tmpl
Brian Zalewski 1bab833011 Latest
2023-07-09 08:11:02 +00:00

31 lines
1.2 KiB
Bash

#!/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.
#
# This feature allows you to specify git repositories and corresponding paths to keep in-sync, using both git
# push and pull.
#
# ## Links
#
# [Systemd Unit file](https://github.com/megabyte-labs/install.doctor/blob/master/home/dot_config/gitomatic/gitomatic.service.tmpl)
{{ includeTemplate "universal/profile" }}
{{ includeTemplate "universal/logg" }}
if command -v gitomatic > /dev/null; then
for IM in $(yq eval -o=j "${XDG_CONFIG_HOME:-$HOME/.config}/chezmoi/chezmoi.yaml" | jq -cr '.data.user.gitomatic[]'); do
GIT="$(echo $IM | jq -r '.git' -)"
GIT_PATH="$(echo $IM | jq -r '.path' -)"
if [ ! -d "$GIT_PATH" ]; then
git clone "$GIT" "$GIT_PATH"
fi
cd "$GIT_PATH"
gitomatic -email "$(git config user.email)" "$GIT_PATH" &
done
else
logg error '`gitomatic` should be installed!' && exit 1
fi