This commit is contained in:
Brian Zalewski 2023-12-25 06:50:02 +00:00
parent 0c2c17b8ab
commit 37f9beeff8
21 changed files with 796 additions and 394 deletions

File diff suppressed because it is too large Load diff

View file

@ -1,8 +1,8 @@
PATH=/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/sbin:/opt/homebrew/bin:$HOME/.local/bin
*/5 * * * * command -v autorestic > /dev/null && . "$HOME/.config/shell/apps.sh" && autorestic -c "$HOME/.config/autorestic/autorestic-user.yml" --ci cron > /tmp/autorestic.log 2>&1
* * * * * command -v dagu-cron > /dev/null && dagu-cron
30 4 * * * command -v ghorg > /dev/null && ghorg reclone
*/5 * * * * command -v autorestic > /dev/null && autorestic -c "$HOME/.config/autorestic/autorestic-user.yml" --ci cron > /tmp/autorestic.log 2>&1
* * * * * command -v dagu-start-all > /dev/null && test -f "$HOME/.config/shell/exports.sh" && . "$HOME/.config/shell/exports.sh" && dagu-start-all
30 4 * * * command -v ghorg > /dev/null && test -f "$HOME/.config/shell/exports.sh" && . "$HOME/.config/shell/exports.sh" && ghorg reclone
# * * * * * command to be executed
# ┯ ┯ ┯ ┯ ┯

View file

@ -36,6 +36,11 @@ elif command -v htop > /dev/null; then
alias top='bashtop'
fi
### batcat
if command -v batcat > /dev/null; then
alias bat='batcat'
fi
### bat
if command -v bat > /dev/null; then
export MANPAGER="sh -c 'col -bx | bat -l man -p'"
@ -43,7 +48,7 @@ if command -v bat > /dev/null; then
alias cat='bat -pp'
alias less='bat --paging=always'
help() {
"$@" --help 2>&1 | bathelp
"$@" --help 2>&1 | bat-help
}
fi
@ -70,6 +75,11 @@ else
alias ls='ls -AlhF --color=auto'
fi
### fdfind
if command -v fdfind > /dev/null; then
alias fd='fdfind'
fi
### gping
# Replacement for ping that includes graph
if command -v gping > /dev/null; then
@ -101,6 +111,11 @@ if command -v mitmweb > /dev/null; then
alias mitmweb='mitmweb --set confdir=${XDG_CONFIG_HOME:-$HOME/.config}/mitmproxy'
fi
### readlink
if command -v greadlink > /dev/null && [ -d /Applications ] && [ -d /System ]; then
alias readlink='greadlink'
fi
### ripgrep
if command -v rg > /dev/null; then
alias rgrep='rg --color=auto'
@ -109,6 +124,11 @@ fi
### xclip
alias xclip='xclip -selection c'
### yank
if command -v yank-cli > /dev/null; then
alias yank='yank-cli'
fi
### Zola
if command -v org.getzola.zola > /dev/null; then
alias zola="flatpak run org.getzola.zola"

View file

@ -55,6 +55,9 @@ export PATH="$HOME/.local/bin/firejail:$PATH"
export PATH="$HOME/.local/bin/flatpak:$PATH"
export PATH="$HOME/.local/bin/gpt:$PATH"
export PATH="$HOME/.local/bin/pipx:$PATH"
if [ -f /usr/bin/qubes-session ]; then
export PATH="$HOME/.local/bin/qubes:$PATH"
fi
export SSH_KEY_PATH="$HOME/.ssh/id_rsa"
### Homebrew
@ -112,6 +115,9 @@ fi
export ANSIBLE_HOME="${XDG_DATA_HOME:-$HOME/.local/share}/ansible"
export ANSIBLE_CONFIG="$ANSIBLE_HOME/ansible.cfg"
export ANSIBLE_GALAXY_CACHE_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/ansible/galaxy_cache"
if [ -f /usr/bin/qubes-session ]; then
export PATH="$PATH:$HOME/.local/share/ansible-qubes/bin"
fi
### Aqua
export AQUA_ROOT_DIR="${XDG_DATA_HOME:-$HOME/.local/share}/aqua"
@ -278,6 +284,14 @@ export HOMEBREW_CASK_OPTS="--appdir=/Applications --display-times --no-quarantin
### HTTPie
export HTTPIE_CONFIG_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/httpie"
### IntelliJ IDEA
if [ -f "/Applications/IntelliJ IDEA CE.app/Contents/MacOS/idea" ]; then
export PATH="$PATH:/Applications/IntelliJ IDEA CE.app/Contents/MacOS"
alias idea.sh='idea'
elif [ -f "/snap/intellij-idea-community/current/bin/idea.sh" ]; then
export PATH="$PATH:/snap/intellij-idea-community/current/bin"
fi
### IPFS
export IPFS_PATH="${XDG_DATA_HOME:-$HOME/.local/share}/ipfs"

View file

@ -2,30 +2,30 @@
# @file ~/.local/bin/add-usergroup
# @brief Add a user and a group with the same name on either Linux or macOS
# @description
# This script is utilized by other scripts to ensure that there is both a user and group
# named by the single argument that this executable accepts. It checks whether or not
# there is already a user / group with the name present on the system before running
# any code. On macOS, it assigns the user an ID that equal to the maximum user ID present
# on the system plus one.
# This script is utilized by other scripts to ensure that there is both a user and group
# named by the single argument that this executable accepts. It checks whether or not
# there is already a user / group with the name present on the system before running
# any code. On macOS, it assigns the user an ID that equal to the maximum user ID present
# on the system plus one.
# Check if the script is being run as root
if [[ $EUID -ne 0 ]]; then
if command -v logg > /dev/null; then
logg error "This script must be run as root"
else
echo -e "\e[91mThis script must be run as root\e[0m"
fi
exit 1
if command -v logg > /dev/null; then
logg error "This script must be run as root"
else
echo -e "\e[91mThis script must be run as root\e[0m"
fi
exit 1
fi
# Check if the correct number of arguments is provided
if [[ $# -ne 2 ]]; then
if command -v logg > /dev/null; then
logg info "Usage: $0 <user> <group>"
else
echo -e "\e[93mUsage: $0 <user> <group>\e[0m"
fi
exit 1
if command -v logg > /dev/null; then
logg info "Usage: $0 <user> <group>"
else
echo -e "\e[93mUsage: $0 <user> <group>\e[0m"
fi
exit 1
fi
USER=$1
@ -33,89 +33,89 @@ GROUP=$2
# Check if the operating system is macOS
if [ -d /Applications ] && [ -d /System ]; then
if command -v logg > /dev/null; then
logg info "Creating group and user ${GROUP} on macOS..."
else
echo -e "\e[96mCreating group and user ${GROUP} on macOS...\e[0m"
fi
if command -v logg > /dev/null; then
logg info "Creating group and user ${GROUP} on macOS..."
else
echo -e "\e[96mCreating group and user ${GROUP} on macOS...\e[0m"
fi
# Ensure group exists
if ! dscl . read "/Groups/$GROUP" gid &> /dev/null; then
MAX_ID_GROUP="$(dscl . -list /Groups gid | awk '{print $2}' | sort -ug | tail -1)"
PRIMARY_GROUP_ID="$((MAX_ID_GROUP+1))"
dscl . create "/Groups/$GROUP"
# This also sets the PrimaryGroupID
sudo dscl . create "/Groups/$GROUP" gid "$PRIMARY_GROUP_ID"
sudo dscl . append "/Groups/$GROUP" GroupMembership "$USER"
else
PRIMARY_GROUP_ID="$(dscl . read "/Groups/$GROUP" gid | awk '{print $2}')"
fi
# Ensure group exists
if ! dscl . read "/Groups/$GROUP" gid &> /dev/null; then
MAX_ID_GROUP="$(dscl . -list /Groups gid | awk '{print $2}' | sort -ug | tail -1)"
PRIMARY_GROUP_ID="$((MAX_ID_GROUP+1))"
dscl . create "/Groups/$GROUP"
# This also sets the PrimaryGroupID
sudo dscl . create "/Groups/$GROUP" gid "$PRIMARY_GROUP_ID"
sudo dscl . append "/Groups/$GROUP" GroupMembership "$USER"
else
PRIMARY_GROUP_ID="$(dscl . read "/Groups/$GROUP" gid | awk '{print $2}')"
fi
# Ensure user exists
if ! dscl . read "/Users/$GROUP" UniqueID &> /dev/null; then
MAX_ID_USER="$(dscl . -list /Users UniqueID | sort -nr -k 2 | head -1 | grep -oE "[0-9]+$")"
UNIQUE_ID="$((MAX_ID_USER+1))"
sudo dscl . create "/Users/$GROUP"
sudo dscl . create "/Users/$GROUP" UniqueID "$UNIQUE_ID"
sudo dscl . create "/Users/$GROUP" PrimaryGroupID "$PRIMARY_GROUP_ID"
else
UNIQUE_ID="$(dscl . read "/Users/$GROUP" UniqueID | awk '{print $2}')"
fi
# Ensure user exists
if ! dscl . read "/Users/$GROUP" UniqueID &> /dev/null; then
MAX_ID_USER="$(dscl . -list /Users UniqueID | sort -nr -k 2 | head -1 | grep -oE "[0-9]+$")"
UNIQUE_ID="$((MAX_ID_USER+1))"
sudo dscl . create "/Users/$GROUP"
sudo dscl . create "/Users/$GROUP" UniqueID "$UNIQUE_ID"
sudo dscl . create "/Users/$GROUP" PrimaryGroupID "$PRIMARY_GROUP_ID"
else
UNIQUE_ID="$(dscl . read "/Users/$GROUP" UniqueID | awk '{print $2}')"
fi
# Add the user to the group
sudo dseditgroup -o edit -t user -a "$GROUP" "$GROUP"
# Add the current user to the group
sudo dseditgroup -o edit -t user -a "$USER" "$GROUP"
# Add USER group to the group
sudo dseditgroup -o edit -t group -a "$USER" "$GROUP"
# Add the user to the group
sudo dseditgroup -o edit -t user -a "$GROUP" "$GROUP"
# Add the current user to the group
sudo dseditgroup -o edit -t user -a "$USER" "$GROUP"
# Add USER group to the group
sudo dseditgroup -o edit -t group -a "$USER" "$GROUP"
if command -v logg > /dev/null; then
logg info "Group and user ${GROUP} created successfully on macOS"
else
echo -e "\e[92mGroup and user ${GROUP} created successfully on macOS\e[0m"
fi
if command -v logg > /dev/null; then
logg info "Group and user ${GROUP} created successfully on macOS"
else
echo -e "\e[92mGroup and user ${GROUP} created successfully on macOS\e[0m"
fi
elif [[ "$(uname)" == "Linux" ]]; then
if command -v logg > /dev/null; then
logg info "Creating group and user ${GROUP} on Linux..."
else
echo -e "\e[96mCreating group and user ${GROUP} on Linux...\e[0m"
fi
# Check if the group already exists
if ! grep -qE "^${GROUP}:" /etc/group; then
# Create the group
groupadd "${GROUP}"
else
if command -v logg > /dev/null; then
logg info "Creating group and user ${GROUP} on Linux..."
logg info "Group ${GROUP} already exists"
else
echo -e "\e[96mCreating group and user ${GROUP} on Linux...\e[0m"
fi
# Check if the group already exists
if ! grep -qE "^${GROUP}:" /etc/group; then
# Create the group
groupadd "${GROUP}"
else
if command -v logg > /dev/null; then
logg info "Group ${GROUP} already exists"
else
echo -e "\e[93mGroup ${GROUP} already exists\e[0m"
fi
fi
# Check if the user already exists
if ! id -u "${GROUP}" >/dev/null 2>&1; then
# Create the user and assign it to the group
useradd -g "${GROUP}" "${GROUP}"
else
if command -v logg > /dev/null; then
logg info "User ${GROUP} already exists"
else
echo -e "\e[93mUser ${GROUP} already exists\e[0m"
fi
echo -e "\e[93mGroup ${GROUP} already exists\e[0m"
fi
fi
# Check if the user already exists
if ! id -u "${GROUP}" >/dev/null 2>&1; then
# Create the user and assign it to the group
useradd -g "${GROUP}" "${GROUP}"
else
if command -v logg > /dev/null; then
logg success "Group and user ${GROUP} created successfully on Linux"
logg info "User ${GROUP} already exists"
else
echo -e "\e[92mGroup and user ${GROUP} created successfully on Linux\e[0m"
echo -e "\e[93mUser ${GROUP} already exists\e[0m"
fi
fi
if command -v logg > /dev/null; then
logg success "Group and user ${GROUP} created successfully on Linux"
else
echo -e "\e[92mGroup and user ${GROUP} created successfully on Linux\e[0m"
fi
fi
# If the operating system is neither macOS nor Linux, display an error message
if command -v logg > /dev/null; then
logg error "Unsupported operating system"
logg error "Unsupported operating system"
else
echo -e "\e[91mUnsupported operating system\e[0m"
echo -e "\e[91mUnsupported operating system\e[0m"
fi

View file

@ -1,12 +1,12 @@
#!/usr/bin/env bash
backupMacPrefs() {
if [ -d /Applications ] && [ -d /System ]; then
if command -v macprefs > /dev/null; then
logg info 'Backing up macOS preferences with macprefs'
macprefs backup -t system_preferences startup_items shared_file_lists app_store_preferences internet_accounts
fi
if [ -d /Applications ] && [ -d /System ]; then
if command -v macprefs > /dev/null; then
logg info 'Backing up macOS preferences with macprefs'
macprefs backup -t system_preferences startup_items shared_file_lists app_store_preferences internet_accounts
fi
fi
}
backupMacPrefs

View file

@ -17,22 +17,22 @@
{{ includeTemplate "universal/logg" }}
if command -v mackup > /dev/null; then
### Create symlinks pointing to stored configurations
logg info 'Symlinking ~/.mackup and ~/.mackup.cfg'
ln -s "${XDG_CONFIG_HOME:-$HOME/.config}/mackup/.mackup/" ~/.mackup
ln -s "${XDG_CONFIG_HOME:-$HOME/.config}/mackup/.mackup.cfg" ~/.mackup.cfg
### Create symlinks pointing to stored configurations
logg info 'Symlinking ~/.mackup and ~/.mackup.cfg'
ln -s "${XDG_CONFIG_HOME:-$HOME/.config}/mackup/.mackup/" ~/.mackup
ln -s "${XDG_CONFIG_HOME:-$HOME/.config}/mackup/.mackup.cfg" ~/.mackup.cfg
### Run mackup
logg info 'Running mackup'
mackup $* || echo ''
### Run mackup
logg info 'Running mackup'
mackup $* || echo ''
### Remove temporary configuration files
logg info 'Removing symlinked ~/.mackup and ~/.mackup.cfg configurations'
rm -f ~/.mackup
rm -f ~/.mackup.cfg
### Remove temporary configuration files
logg info 'Removing symlinked ~/.mackup and ~/.mackup.cfg configurations'
rm -f ~/.mackup
rm -f ~/.mackup.cfg
### Print success message
logg success 'Successfully ran backup-apps'
### Print success message
logg success 'Successfully ran backup-apps'
else
logg error 'mackup is not installed' && exit 1
logg error 'mackup is not installed' && exit 1
fi

View file

@ -6,9 +6,9 @@
### Create backups
if [ -d "${XDG_CONFIG_HOME:-$HOME/.config}/dconf/settings" ]; then
DCONF_TMP="$(mktemp)"
logg info 'Moving ~/.config/dconf/settings to '"$DCONF_TMP"
cp -rf "${XDG_CONFIG_HOME:-$HOME/.config}/dconf/settings" "$DCONF_TMP"
DCONF_TMP="$(mktemp)"
logg info 'Moving ~/.config/dconf/settings to '"$DCONF_TMP"
cp -rf "${XDG_CONFIG_HOME:-$HOME/.config}/dconf/settings" "$DCONF_TMP"
fi
### Ensure ~/.config/dconf/settings exists
@ -16,12 +16,12 @@ mkdir -p "${XDG_CONFIG_HOME:-$HOME/.config}/dconf/settings"
### Overwrite ~/.config/dconf/settings configurations so we can diff with Chezmoi
find "${XDG_CONFIG_HOME:-$HOME/.config}/dconf/settings" -mindepth 1 -maxdepth 1 -type f | while read DCONF_CONFIG_FILE; do
DCONF_SETTINGS_ID="/$(basename "$DCONF_CONFIG_FILE" | sed 's/\./\//g')/"
logg info 'Dumping '"$DCONF_SETTINGS_ID"' to '"$DCONF_CONFIG_FILE"
dconf dump "$DCONF_SETTINGS_ID" > "$DCONF_CONFIG_FILE"
logg success 'Saved new configuration to '"$DCONF_CONFIG_FILE"
logg info 'Printing diff for '"$DCONF_CONFIG_FILE"
chezmoi diff "$DCONF_CONFIG_FILE" || true
DCONF_SETTINGS_ID="/$(basename "$DCONF_CONFIG_FILE" | sed 's/\./\//g')/"
logg info 'Dumping '"$DCONF_SETTINGS_ID"' to '"$DCONF_CONFIG_FILE"
dconf dump "$DCONF_SETTINGS_ID" > "$DCONF_CONFIG_FILE"
logg success 'Saved new configuration to '"$DCONF_CONFIG_FILE"
logg info 'Printing diff for '"$DCONF_CONFIG_FILE"
chezmoi diff "$DCONF_CONFIG_FILE" || true
done
{{ end -}}

View file

@ -2,52 +2,52 @@
# @file .local/bin/gitomatic-service
# @brief Helper script to run gitomatic to monitor git repositories
# @description
# This script is executed by gitomatic systemd service. `gitomatic` does not support monitoring multiple
# repositories in a single process. This script starts as many gitomatic processes as there are repositories.
# This script is executed by gitomatic systemd service. `gitomatic` does not support monitoring multiple
# repositories in a single process. This script starts as many gitomatic processes as there are repositories.
#
# This feature allows you to specify git repositories and corresponding paths to keep in-sync, using both git
# push and pull.
# This feature allows you to specify git repositories and corresponding paths to keep in-sync, using both git
# push and pull.
#
# ## Links
# ## Links
#
# [Systemd Unit file](https://github.com/megabyte-labs/install.doctor/blob/master/home/dot_config/gitomatic/gitomatic.service.tmpl)
# [Systemd Unit file](https://github.com/megabyte-labs/install.doctor/blob/master/home/dot_config/gitomatic/gitomatic.service.tmpl)
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
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
### 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
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
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
echo 'gitomatic, jq, yq, and git should be installed!' && exit 1
echo 'gitomatic, jq, yq, and git should be installed!' && exit 1
fi

View file

@ -1,4 +1,3 @@
{{- if eq .host.qubes true -}}
#!/usr/bin/env bash
# Creates a Qube on RAM disk and opens Firefox if the Qube does not already exist.
@ -27,4 +26,3 @@ else
sudo rm -rf /var/log/pacat.new.log
sudo rm -rf /var/log/qubesdb.new.log
fi
{{ end -}}

View file

@ -1,3 +0,0 @@
{{- if (eq .host.distro.id "ubuntu") -}}
/usr/bin/batcat
{{- end -}}

View file

@ -1,3 +0,0 @@
{{- if (eq .host.qubes true) -}}
{{ .host.home }}/.local/share/ansible-qubes/bin/bombshell-client
{{- end -}}

View file

@ -1,3 +0,0 @@
{{- if (eq .host.distro.id "ubuntu") -}}
/usr/bin/fdfind
{{- end -}}

View file

@ -1,5 +0,0 @@
{{- if (eq .host.distro.family "darwin") -}}
/Applications/IntelliJ\ IDEA\ CE.app/Contents/MacOS/idea
{{- else if eq .host.distro.family "linux" -}}
/snap/intellij-idea-community/current/bin/idea.sh
{{- end -}}

View file

@ -1,4 +0,0 @@
{{- if (eq .host.qubes true) -}}
{{ .host.home }}/.local/share/ansible-qubes/bin/qrun
{{- end -}}

View file

@ -1,3 +0,0 @@
{{- if (eq .host.qubes true) -}}
{{ .host.home }}/.local/share/ansible-qubes/bin/qssh
{{- end -}}

View file

@ -1,4 +0,0 @@
{{- if (eq .host.qubes true) -}}
{{ .host.home }}/.local/share/ansible-qubes/bin/qssh
{{- end -}}

View file

@ -1,3 +0,0 @@
{{- if (eq .host.distro.family "darwin") -}}
/usr/local/bin/greadlink
{{- end -}}

View file

@ -1,3 +0,0 @@
{{- if (eq .host.distro.family "darwin") -}}
/bin/stty
{{- end -}}

View file

@ -1,3 +0,0 @@
{{- if (eq .host.distro.id "ubuntu") -}}
/usr/bin/yank-cli
{{- end -}}