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" }} {{ includeTemplate "universal/logg" }}
function gitomaticSetup() { 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 ### Create Systemd service to run gitomatic
if command -v gitomatic > /dev/null; then 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 if [ -d /Applications ] && [ -d /System ]; then
### macOS ### macOS
logg info 'Copying `gitomatic` plist file to /Library/LaunchDaemons' logg info 'Copying `gitomatic` plist file to /Library/LaunchDaemons'
sudo cp -f "{{ .chezmoi.homeDir }}/.config/gitomatic/gitomatic.plist" /Library/LaunchDaemons/gitomatic.plist sudo cp -f "{{ .chezmoi.homeDir }}/.config/gitomatic/gitomatic.plist" /Library/LaunchDaemons/gitomatic.plist
logg info 'Running `sudo launchctl load gitomatic`' logg info 'Running `sudo launchctl load /Library/LaunchDaemons/gitomatic.plist`'
sudo launchctl load gitomatic sudo launchctl load /Library/LaunchDaemons/gitomatic.plist
logg info 'Running `sudo launchctl start gitomatic`' logg info 'Running `sudo launchctl start /Library/LaunchDaemons/gitomatic.plist`'
sudo launchctl start gitomatic sudo launchctl start /Library/LaunchDaemons/gitomatic.plist
else else
### Linux ### Linux
logg info 'Copying `gitomatic` systemd unit file to /etc/systemd/system/' logg info 'Copying `gitomatic` systemd unit file to /etc/systemd/system/'
@ -55,7 +49,7 @@ function gitomaticSetup() {
sudo systemctl enable --now gitomatic sudo systemctl enable --now gitomatic
fi fi
else 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 fi
} }
gitomaticSetup gitomaticSetup

View file

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

View file

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

View file

@ -16,16 +16,42 @@
{{ includeTemplate "universal/profile" }} {{ includeTemplate "universal/profile" }}
{{ includeTemplate "universal/logg" }} {{ includeTemplate "universal/logg" }}
if command -v gitomatic > /dev/null; then if command -v gitomatic > /dev/null && command -v jq > /dev/null && command -v yq > /dev/null && command -v git > /dev/null; then
for IM in $(yq eval -o=j "${XDG_CONFIG_HOME:-$HOME/.config}/chezmoi/chezmoi.yaml" | jq -cr '.data.user.gitomatic[]'); do if [ -d /Applications ] && [ -d /System ]; then
GIT="$(echo $IM | jq -r '.git' -)" USER_FOLDER="/Users"
GIT_PATH="$(echo $IM | jq -r '.path' -)" else
if [ ! -d "$GIT_PATH" ]; then USER_FOLDER="/home"
git clone "$GIT" "$GIT_PATH" 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 fi
cd "$GIT_PATH" done < <(find "$USER_FOLDER" -mindepth 1 -maxdepth 1 -type d)
gitomatic -email "$(git config user.email)" "$GIT_PATH" &
done ### 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 else
logg error '`gitomatic` should be installed!' && exit 1 logg error 'gitomatic, jq, yq, and git should be installed!' && exit 1
fi fi