From b49ce97c6e3f82f5827df30ea8440796b473f04a Mon Sep 17 00:00:00 2001
From: Brian Zalewski <59970525+ProfessorManhattan@users.noreply.github.com>
Date: Mon, 27 Nov 2023 08:32:46 +0000
Subject: [PATCH] Fixed gitomatic
---
home/.chezmoi.yaml.tmpl | 2 +-
...nge_after_06-configure-root-folder.sh.tmpl | 31 +++++++++++++++++++
.../run_onchange_after_32-gitomatic.sh.tmpl | 15 ++++++---
home/dot_bashrc | 5 +++
...=> com.github.muesli.gitomatic.plist.tmpl} | 8 ++++-
.../bin/executable_gitomatic-service.tmpl | 2 +-
home/dot_zshrc | 5 +++
7 files changed, 60 insertions(+), 8 deletions(-)
create mode 100644 home/.chezmoiscripts/universal/run_onchange_after_06-configure-root-folder.sh.tmpl
rename home/dot_config/gitomatic/{gitomatic.plist.tmpl => com.github.muesli.gitomatic.plist.tmpl} (58%)
diff --git a/home/.chezmoi.yaml.tmpl b/home/.chezmoi.yaml.tmpl
index 91039164..20c4d2e5 100644
--- a/home/.chezmoi.yaml.tmpl
+++ b/home/.chezmoi.yaml.tmpl
@@ -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:
diff --git a/home/.chezmoiscripts/universal/run_onchange_after_06-configure-root-folder.sh.tmpl b/home/.chezmoiscripts/universal/run_onchange_after_06-configure-root-folder.sh.tmpl
new file mode 100644
index 00000000..ae0539ba
--- /dev/null
+++ b/home/.chezmoiscripts/universal/run_onchange_after_06-configure-root-folder.sh.tmpl
@@ -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 -}}
diff --git a/home/.chezmoiscripts/universal/run_onchange_after_32-gitomatic.sh.tmpl b/home/.chezmoiscripts/universal/run_onchange_after_32-gitomatic.sh.tmpl
index 7a0eea4a..ba2fba99 100644
--- a/home/.chezmoiscripts/universal/run_onchange_after_32-gitomatic.sh.tmpl
+++ b/home/.chezmoiscripts/universal/run_onchange_after_32-gitomatic.sh.tmpl
@@ -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
diff --git a/home/dot_bashrc b/home/dot_bashrc
index 3f382e2a..6c3510e2 100644
--- a/home/dot_bashrc
+++ b/home/dot_bashrc
@@ -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"
diff --git a/home/dot_config/gitomatic/gitomatic.plist.tmpl b/home/dot_config/gitomatic/com.github.muesli.gitomatic.plist.tmpl
similarity index 58%
rename from home/dot_config/gitomatic/gitomatic.plist.tmpl
rename to home/dot_config/gitomatic/com.github.muesli.gitomatic.plist.tmpl
index 418cf3e1..a5adad68 100644
--- a/home/dot_config/gitomatic/gitomatic.plist.tmpl
+++ b/home/dot_config/gitomatic/com.github.muesli.gitomatic.plist.tmpl
@@ -6,11 +6,17 @@
Disabled
Label
- gitomatic
+ com.github.muesli.gitomatic
Program
/usr/local/bin/gitomatic-service
RunAtLoad
+ UserName
+ root
+ StandardErrorPath
+ /var/log/com.github.muesli.gitomatic.error.log
+ StandardOutPath
+ /var/log/com.github.muesli.gitomatic.debug.log
{{- end -}}
\ No newline at end of file
diff --git a/home/dot_local/bin/executable_gitomatic-service.tmpl b/home/dot_local/bin/executable_gitomatic-service.tmpl
index 8b45537d..4f585f3d 100644
--- a/home/dot_local/bin/executable_gitomatic-service.tmpl
+++ b/home/dot_local/bin/executable_gitomatic-service.tmpl
@@ -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' -)"
diff --git a/home/dot_zshrc b/home/dot_zshrc
index 0d3c4c3d..5a5aef12 100644
--- a/home/dot_zshrc
+++ b/home/dot_zshrc
@@ -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