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

@ -3,11 +3,14 @@
<!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>Disabled</key>
<false/>
<key>Label</key> <key>Label</key>
<string>gitomatic</string> <string>gitomatic</string>
<key>Program</key> <key>Program</key>
<string>{{ .chezmoi.homeDir }}/.local/bin/gitomatic-service</string> <string>/usr/local/bin/gitomatic-service</string>
<key>RunAtLoad</key> <key>RunAtLoad</key>
<true/>
</dict> </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
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 if [ ! -d "$GIT_PATH" ]; then
git clone "$GIT" "$GIT_PATH" git clone "$GIT" "$GIT_PATH"
fi fi
cd "$GIT_PATH" cd "$GIT_PATH"
gitomatic -email "$(git config user.email)" "$GIT_PATH" & gitomatic -email "$(git config user.email)" "$GIT_PATH" &
done done
else fi
logg error '`gitomatic` should be installed!' && exit 1 else
logg error 'gitomatic, jq, yq, and git should be installed!' && exit 1
fi fi