Fixed gitomatic

This commit is contained in:
Brian Zalewski 2023-11-27 08:32:46 +00:00
parent 55d98b00b3
commit b49ce97c6e
7 changed files with 60 additions and 8 deletions

View file

@ -208,7 +208,7 @@ data:
username: "{{ $githubUsername }}"
gitomatic:
- git: "{{ default "git@github.com:megabyte-labs/install.doctor.git" (env "START_REPO") }}"
path: /usr/local/src/install.doctor
path: "~/.local/share/chezmoi"
gmail:
username: "{{ $gmailAddress }}"
gpg:

View file

@ -0,0 +1,31 @@
{{- if (ne .host.distro.family "windows") -}}
#!/usr/bin/env bash
# @file Configure Root Home Folder
# @brief Configures the root user's folder so that they have access to executables installed by provisioning user
# @description
# This script configures the root user's folder so that scripts running as the root user can:
#
# 1. Access binaries installed by the provisioning user (by setting the appropriate `~/.bashrc` and `~/.zshrc` symlinks)
# 2. Use the same shell profile rules that the provisioning user uses (by symlinking the `~/.config/shell`, `~/.bashrc`, and `~/.zshrc` locations)
{{ includeTemplate "universal/profile" }}
{{ includeTemplate "universal/logg" }}
### Detect root folder
if [ -d /var/root ]; then
ROOT_FOLDER="/var/root"
elif [ -d /root ]; then
ROOT_FOLDER="/root"
else
logg warn 'Unable to find root user folder location'
fi
### Copy minimal set of profile configuration files
if [ -n "$ROOT_FOLDER" ]; then
logg info "Copying ~/.bashrc to $ROOT_FOLDER/.bashrc" && sudo cp -f "$HOME/.bashrc" "$ROOT_FOLDER/.bashrc"
logg info "Copying ~/.zshrc to $ROOT_FOLDER/.zshrc" && sudo cp -f "$HOME/.zshrc" "$ROOT_FOLDER/.zshrc"
logg info "Ensuring ~/.config folder exists" && sudo mkdir -p "$ROOT_FOLDER/.config"
logg info "Copying ~/.config/shell to $ROOT_FOLDER/.config/shell" && sudo rm -rf "$HOME/.config/shell" && sudo cp -rf "$HOME/.config/shell" "$ROOT_FOLDER/.config/shell"
fi
{{ end -}}

View file

@ -30,16 +30,21 @@ function gitomaticSetup() {
### 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
### Copy gitomatic to global directory
if [ ! -f /usr/local/bin/gitomatic ]; then
logg info 'Copying gitomatic executable to /usr/local/bin/gitomatic' && sudo cp -f "$(which gitomatic)" /usr/local/bin/gitomatic
fi
if [ -d /Applications ] && [ -d /System ]; then
### macOS
logg info 'Copying gitomatic plist file to /Library/LaunchDaemons'
sudo cp -f "${XDG_CONFIG_HOME:-$HOME/.config}/gitomatic/gitomatic.plist" /Library/LaunchDaemons/gitomatic.plist
sudo cp -f "${XDG_CONFIG_HOME:-$HOME/.config}/gitomatic/com.github.muesli.gitomatic.plist" /Library/LaunchDaemons/com.github.muesli.gitomatic.plist
if ! sudo launchctl list | grep 'gitomatic' > /dev/null; then
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
logg info 'Running sudo launchctl load /Library/LaunchDaemons/com.github.muesli.gitomatic.plist'
sudo launchctl load /Library/LaunchDaemons/com.github.muesli.gitomatic.plist
logg info 'Running sudo launchctl start /Library/LaunchDaemons/com.github.muesli.gitomatic.plist'
sudo launchctl start /Library/LaunchDaemons/com.github.muesli.gitomatic.plist
else
logg info "gitomatic services appear to already be loaded"
fi

View file

@ -46,6 +46,11 @@ case $- in
*) return;;
esac
### Escape if user is root
if [ "$USER" = 'root' ]; then
return
fi
### History
export HISTFILE="$XDG_STATE_HOME/bash/history"

View file

@ -6,11 +6,17 @@
<key>Disabled</key>
<false/>
<key>Label</key>
<string>gitomatic</string>
<string>com.github.muesli.gitomatic</string>
<key>Program</key>
<string>/usr/local/bin/gitomatic-service</string>
<key>RunAtLoad</key>
<true/>
<key>UserName</key>
<string>root</string>
<key>StandardErrorPath</key>
<string>/var/log/com.github.muesli.gitomatic.error.log</string>
<key>StandardOutPath</key>
<string>/var/log/com.github.muesli.gitomatic.debug.log</string>
</dict>
</plist>
{{- end -}}

View file

@ -40,7 +40,7 @@ if command -v gitomatic > /dev/null && command -v jq > /dev/null && command -v y
done < <(find "$USER_FOLDER" -mindepth 1 -maxdepth 1 -type d)
### Handle root user config
if [ -f /root/.config/chezmoi.chezmoi.yaml ]; then
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' -)"

View file

@ -16,6 +16,11 @@ case $- in
*) return;;
esac
### Escape if user is root
if [ "$USER" = 'root' ]; then
return
fi
### Misc.
export HISTFILE="$XDG_STATE_HOME/zsh/history"
export ZLE_RPROMPT_INDENT=0