This commit is contained in:
Brian Zalewski 2023-07-13 02:58:08 +00:00
parent 90136fa0d6
commit 55476ece75
4 changed files with 58 additions and 35 deletions

View file

@ -25,26 +25,20 @@
{{ includeTemplate "universal/logg" }}
function gitomaticSetup() {
### Clone the repositories
logg info 'Cloning the repositories'
{{ range .user.gitomatic }}
logg info 'Checking for presence of {{ .path }}'
if [ ! -d "{{ .path }}" ]; then
logg info 'Cloning {{ .git }} to {{ .path }}'
git clone "{{ .git }}" "{{ .path }}"
fi
{{ end -}}
### Create Systemd service to run gitomatic
if command -v gitomatic > /dev/null; then
### 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
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 gitomatic`'
sudo launchctl load gitomatic
logg info 'Running `sudo launchctl start gitomatic`'
sudo launchctl start gitomatic
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
### Linux
logg info 'Copying `gitomatic` systemd unit file to /etc/systemd/system/'
@ -55,7 +49,7 @@ function gitomaticSetup() {
sudo systemctl enable --now gitomatic
fi
else
logg info 'Git-o-matic is not installed or it is not available in PATH'
logg info 'gitomatic is not installed or it is not available in PATH'
fi
}
gitomaticSetup

View file

@ -2,12 +2,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<dict>
<key>Disabled</key>
<false/>
<key>Label</key>
<string>gitomatic</string>
<key>Program</key>
<string>{{ .chezmoi.homeDir }}/.local/bin/gitomatic-service</string>
<string>/usr/local/bin/gitomatic-service</string>
<key>RunAtLoad</key>
</dict>
<true/>
</dict>
</plist>
{{- end }}
{{- end -}}

View file

@ -4,8 +4,8 @@ Description=Service to watch git repositories
[Service]
Type=simple
User={{ .user.username }}
ExecStart={{ .chezmoi.homeDir }}/.local/bin/gitomatic-service
User=root
ExecStart=/usr/local/bin/gitomatic-service
Restart=on-failure
[Install]

View file

@ -16,16 +16,42 @@
{{ 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 command -v gitomatic > /dev/null && command -v jq > /dev/null && command -v yq > /dev/null && command -v git > /dev/null; then
if [ -d /Applications ] && [ -d /System ]; then
USER_FOLDER="/Users"
else
USER_FOLDER="/home"
fi
### Cycle through user folder chezmoi.yaml configurations
while read FOLDER; do
USER_FROM_FOLDER="$(echo "$FOLDER" | sed 's/\/\(.*\)$/\1/')"
CHEZMOI_YAML="$USER_FOLDER/$USER_FROM_FOLDER/.config/chezmoi/chezmoi.yaml"
if [ -f "$CHEZMOI_YAML" ]; then
for IM in $(yq eval -o=j "$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
sudo su - "$USER_FROM_FOLDER" -c 'git clone "$GIT" "$GIT_PATH"'
fi
cd "$GIT_PATH"
sudo su - "$USER_FROM_FOLDER" -c 'gitomatic -email "$(git config user.email)" "$GIT_PATH" &'
done
fi
done < <(find "$USER_FOLDER" -mindepth 1 -maxdepth 1 -type d)
### Handle root user config
if [ -f /root/.config/chezmoi.chezmoi.yaml ]; then
for IM in $(yq eval -o=j /root/.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
fi
else
logg error '`gitomatic` should be installed!' && exit 1
logg error 'gitomatic, jq, yq, and git should be installed!' && exit 1
fi