diff --git a/home/.chezmoi.yaml.tmpl b/home/.chezmoi.yaml.tmpl index ffa788c6..affa938c 100644 --- a/home/.chezmoi.yaml.tmpl +++ b/home/.chezmoi.yaml.tmpl @@ -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: diff --git a/home/.chezmoiscripts/universal/run_onchange_after_32-gitomatic.sh.tmpl b/home/.chezmoiscripts/universal/run_onchange_after_32-gitomatic.sh.tmpl new file mode 100644 index 00000000..9dedb67f --- /dev/null +++ b/home/.chezmoiscripts/universal/run_onchange_after_32-gitomatic.sh.tmpl @@ -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 diff --git a/home/dot_config/gitomatic/gitomatic.plist.tmpl b/home/dot_config/gitomatic/gitomatic.plist.tmpl new file mode 100644 index 00000000..fc9ed4df --- /dev/null +++ b/home/dot_config/gitomatic/gitomatic.plist.tmpl @@ -0,0 +1,13 @@ +{{- if eq .host.distro.family "darwin" -}} + + + + + Label + com.gitomatic + Program + {{ .chezmoi.homeDir }}/.local/bin/gitomatic_service + RunAtLoad + + +{{ end }} diff --git a/home/dot_config/gitomatic/gitomatic.service.tmpl b/home/dot_config/gitomatic/gitomatic.service.tmpl new file mode 100644 index 00000000..609bfa23 --- /dev/null +++ b/home/dot_config/gitomatic/gitomatic.service.tmpl @@ -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 }} diff --git a/home/dot_local/bin/executable_gitomatic_service.tmpl b/home/dot_local/bin/executable_gitomatic_service.tmpl new file mode 100644 index 00000000..c1574d2e --- /dev/null +++ b/home/dot_local/bin/executable_gitomatic_service.tmpl @@ -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 -}}