From 212353f8d4c86640db00527dc468a6072ac502cc Mon Sep 17 00:00:00 2001 From: Brian Zalewski Date: Wed, 30 Nov 2022 05:43:19 +0000 Subject: [PATCH] Update dotfiles/.local/bin/provision, .config/Kvantum/kvantum.config, .config/age/expect, .config/age/run_once_before_decrypt-private-key.sh.tmpl, .config/alacritty/alacritty.yml, .config/asdf/asdfrc, .config/asdf/default-cargo-pkgs, .config/asdf/default-golang-pkgs, .config/asdf/default-python-pkgs, .config/asdf/default-ruby-pkgs, .config/bashtop/bashtop.cfg, .config/fontconfig/fonts.conf, .config/ghorg/conf.yaml, .config/gtk-2.0/gtkrc, .config/gtk-3.0/settings.ini, .config/himalaya/config.toml, .config/kitty/Betelgeuse-dark.conf, .config/kitty/Betelgeuse-light.conf, .config/kitty/kitty.conf, .config/misc/.warp/themes/betelgeuse_dark.yaml, .config/misc/.warp/themes/betelgeuse_light.yaml, .config/misc/.tmux.themer, .config/ngrok/ngrok.yml, .config/powershell/takuya.omp.json, .config/powershell/user_profile.ps1, .config/slack-term/config, .config/tabby/config.yaml, .config/terminator/config, .config/xfce4/terminal/terminalrc, .config/xfce4/xfconf/xfce-perchannel-xml/xsettings.xml, .config/xsettingsd/xsettingsd.conf, .config/batrc, .config/dircolors, .config/gtkrc, .config/kactivitymanagerdrc, .config/kcminputrc, .config/kdeglobals, .config/konsolerc, .config/ksplashrc, .config/ktimezonedrc, .config/kwinrc, .config/plasma-localerc, .config/plasmarc, .config/ripgreprc, .config/wgetrc, .config/whalebrew, .gnupg/public/apt.hashicorp.sig, .gnupg/public/unman.sig, .gnupg/public/wazuh.sig, dotfiles/.local/share/chezmoi/home/dot_bashrc --- .../Kvantum/kvantum.config | 0 {dotfiles/.config => .config}/age/expect | 0 ...un_once_before_decrypt-private-key.sh.tmpl | 0 .../alacritty/alacritty.yml | 0 {dotfiles/.config => .config}/asdf/asdfrc | 0 .../asdf/default-cargo-pkgs | 0 .../asdf/default-golang-pkgs | 0 .../asdf/default-python-pkgs | 0 .../asdf/default-ruby-pkgs | 0 .../.config => .config}/bashtop/bashtop.cfg | 0 {dotfiles/.config => .config}/batrc | 0 {dotfiles/.config => .config}/dircolors | 0 .../.config => .config}/fontconfig/fonts.conf | 0 {dotfiles/.config => .config}/ghorg/conf.yaml | 0 {dotfiles/.config => .config}/gtk-2.0/gtkrc | 0 .../.config => .config}/gtk-3.0/settings.ini | 0 {dotfiles/.config => .config}/gtkrc | 0 .../.config => .config}/himalaya/config.toml | 0 .../.config => .config}/kactivitymanagerdrc | 0 {dotfiles/.config => .config}/kcminputrc | 0 {dotfiles/.config => .config}/kdeglobals | 0 .../kitty/Betelgeuse-dark.conf | 0 .../kitty/Betelgeuse-light.conf | 0 .../.config => .config}/kitty/kitty.conf | 0 {dotfiles/.config => .config}/konsolerc | 0 {dotfiles/.config => .config}/ksplashrc | 0 {dotfiles/.config => .config}/ktimezonedrc | 0 {dotfiles/.config => .config}/kwinrc | 0 .../.config => .config}/misc/.tmux.themer | 0 .../misc/.warp/themes/betelgeuse_dark.yaml | 0 .../misc/.warp/themes/betelgeuse_light.yaml | 0 {dotfiles/.config => .config}/ngrok/ngrok.yml | 0 {dotfiles/.config => .config}/plasma-localerc | 0 {dotfiles/.config => .config}/plasmarc | 0 .../powershell/takuya.omp.json | 0 .../powershell/user_profile.ps1 | 0 {dotfiles/.config => .config}/ripgreprc | 0 .../.config => .config}/slack-term/config | 0 .../.config => .config}/tabby/config.yaml | 0 .../.config => .config}/terminator/config | 0 {dotfiles/.config => .config}/wgetrc | 0 {dotfiles/.config => .config}/whalebrew | 0 .../xfce4/terminal/terminalrc | 0 .../xfconf/xfce-perchannel-xml/xsettings.xml | 0 .../xsettingsd/xsettingsd.conf | 0 .../public/apt.hashicorp.sig | 0 {dotfiles/.gnupg => .gnupg}/public/unman.sig | 0 {dotfiles/.gnupg => .gnupg}/public/wazuh.sig | 0 dotfiles/.local/bin/provision | 193 ++++++++++++++++-- dotfiles/.local/share/chezmoi/home/dot_bashrc | 5 + 50 files changed, 178 insertions(+), 20 deletions(-) rename {dotfiles/.config => .config}/Kvantum/kvantum.config (100%) rename {dotfiles/.config => .config}/age/expect (100%) rename {dotfiles/.config => .config}/age/run_once_before_decrypt-private-key.sh.tmpl (100%) rename {dotfiles/.config => .config}/alacritty/alacritty.yml (100%) rename {dotfiles/.config => .config}/asdf/asdfrc (100%) rename {dotfiles/.config => .config}/asdf/default-cargo-pkgs (100%) rename {dotfiles/.config => .config}/asdf/default-golang-pkgs (100%) rename {dotfiles/.config => .config}/asdf/default-python-pkgs (100%) rename {dotfiles/.config => .config}/asdf/default-ruby-pkgs (100%) rename {dotfiles/.config => .config}/bashtop/bashtop.cfg (100%) rename {dotfiles/.config => .config}/batrc (100%) rename {dotfiles/.config => .config}/dircolors (100%) rename {dotfiles/.config => .config}/fontconfig/fonts.conf (100%) rename {dotfiles/.config => .config}/ghorg/conf.yaml (100%) rename {dotfiles/.config => .config}/gtk-2.0/gtkrc (100%) rename {dotfiles/.config => .config}/gtk-3.0/settings.ini (100%) rename {dotfiles/.config => .config}/gtkrc (100%) rename {dotfiles/.config => .config}/himalaya/config.toml (100%) rename {dotfiles/.config => .config}/kactivitymanagerdrc (100%) rename {dotfiles/.config => .config}/kcminputrc (100%) rename {dotfiles/.config => .config}/kdeglobals (100%) rename {dotfiles/.config => .config}/kitty/Betelgeuse-dark.conf (100%) rename {dotfiles/.config => .config}/kitty/Betelgeuse-light.conf (100%) rename {dotfiles/.config => .config}/kitty/kitty.conf (100%) rename {dotfiles/.config => .config}/konsolerc (100%) rename {dotfiles/.config => .config}/ksplashrc (100%) rename {dotfiles/.config => .config}/ktimezonedrc (100%) rename {dotfiles/.config => .config}/kwinrc (100%) rename {dotfiles/.config => .config}/misc/.tmux.themer (100%) rename {dotfiles/.config => .config}/misc/.warp/themes/betelgeuse_dark.yaml (100%) rename {dotfiles/.config => .config}/misc/.warp/themes/betelgeuse_light.yaml (100%) rename {dotfiles/.config => .config}/ngrok/ngrok.yml (100%) rename {dotfiles/.config => .config}/plasma-localerc (100%) rename {dotfiles/.config => .config}/plasmarc (100%) rename {dotfiles/.config => .config}/powershell/takuya.omp.json (100%) rename {dotfiles/.config => .config}/powershell/user_profile.ps1 (100%) rename {dotfiles/.config => .config}/ripgreprc (100%) rename {dotfiles/.config => .config}/slack-term/config (100%) rename {dotfiles/.config => .config}/tabby/config.yaml (100%) rename {dotfiles/.config => .config}/terminator/config (100%) rename {dotfiles/.config => .config}/wgetrc (100%) rename {dotfiles/.config => .config}/whalebrew (100%) rename {dotfiles/.config => .config}/xfce4/terminal/terminalrc (100%) rename {dotfiles/.config => .config}/xfce4/xfconf/xfce-perchannel-xml/xsettings.xml (100%) rename {dotfiles/.config => .config}/xsettingsd/xsettingsd.conf (100%) rename {dotfiles/.gnupg => .gnupg}/public/apt.hashicorp.sig (100%) rename {dotfiles/.gnupg => .gnupg}/public/unman.sig (100%) rename {dotfiles/.gnupg => .gnupg}/public/wazuh.sig (100%) diff --git a/dotfiles/.config/Kvantum/kvantum.config b/.config/Kvantum/kvantum.config similarity index 100% rename from dotfiles/.config/Kvantum/kvantum.config rename to .config/Kvantum/kvantum.config diff --git a/dotfiles/.config/age/expect b/.config/age/expect similarity index 100% rename from dotfiles/.config/age/expect rename to .config/age/expect diff --git a/dotfiles/.config/age/run_once_before_decrypt-private-key.sh.tmpl b/.config/age/run_once_before_decrypt-private-key.sh.tmpl similarity index 100% rename from dotfiles/.config/age/run_once_before_decrypt-private-key.sh.tmpl rename to .config/age/run_once_before_decrypt-private-key.sh.tmpl diff --git a/dotfiles/.config/alacritty/alacritty.yml b/.config/alacritty/alacritty.yml similarity index 100% rename from dotfiles/.config/alacritty/alacritty.yml rename to .config/alacritty/alacritty.yml diff --git a/dotfiles/.config/asdf/asdfrc b/.config/asdf/asdfrc similarity index 100% rename from dotfiles/.config/asdf/asdfrc rename to .config/asdf/asdfrc diff --git a/dotfiles/.config/asdf/default-cargo-pkgs b/.config/asdf/default-cargo-pkgs similarity index 100% rename from dotfiles/.config/asdf/default-cargo-pkgs rename to .config/asdf/default-cargo-pkgs diff --git a/dotfiles/.config/asdf/default-golang-pkgs b/.config/asdf/default-golang-pkgs similarity index 100% rename from dotfiles/.config/asdf/default-golang-pkgs rename to .config/asdf/default-golang-pkgs diff --git a/dotfiles/.config/asdf/default-python-pkgs b/.config/asdf/default-python-pkgs similarity index 100% rename from dotfiles/.config/asdf/default-python-pkgs rename to .config/asdf/default-python-pkgs diff --git a/dotfiles/.config/asdf/default-ruby-pkgs b/.config/asdf/default-ruby-pkgs similarity index 100% rename from dotfiles/.config/asdf/default-ruby-pkgs rename to .config/asdf/default-ruby-pkgs diff --git a/dotfiles/.config/bashtop/bashtop.cfg b/.config/bashtop/bashtop.cfg similarity index 100% rename from dotfiles/.config/bashtop/bashtop.cfg rename to .config/bashtop/bashtop.cfg diff --git a/dotfiles/.config/batrc b/.config/batrc similarity index 100% rename from dotfiles/.config/batrc rename to .config/batrc diff --git a/dotfiles/.config/dircolors b/.config/dircolors similarity index 100% rename from dotfiles/.config/dircolors rename to .config/dircolors diff --git a/dotfiles/.config/fontconfig/fonts.conf b/.config/fontconfig/fonts.conf similarity index 100% rename from dotfiles/.config/fontconfig/fonts.conf rename to .config/fontconfig/fonts.conf diff --git a/dotfiles/.config/ghorg/conf.yaml b/.config/ghorg/conf.yaml similarity index 100% rename from dotfiles/.config/ghorg/conf.yaml rename to .config/ghorg/conf.yaml diff --git a/dotfiles/.config/gtk-2.0/gtkrc b/.config/gtk-2.0/gtkrc similarity index 100% rename from dotfiles/.config/gtk-2.0/gtkrc rename to .config/gtk-2.0/gtkrc diff --git a/dotfiles/.config/gtk-3.0/settings.ini b/.config/gtk-3.0/settings.ini similarity index 100% rename from dotfiles/.config/gtk-3.0/settings.ini rename to .config/gtk-3.0/settings.ini diff --git a/dotfiles/.config/gtkrc b/.config/gtkrc similarity index 100% rename from dotfiles/.config/gtkrc rename to .config/gtkrc diff --git a/dotfiles/.config/himalaya/config.toml b/.config/himalaya/config.toml similarity index 100% rename from dotfiles/.config/himalaya/config.toml rename to .config/himalaya/config.toml diff --git a/dotfiles/.config/kactivitymanagerdrc b/.config/kactivitymanagerdrc similarity index 100% rename from dotfiles/.config/kactivitymanagerdrc rename to .config/kactivitymanagerdrc diff --git a/dotfiles/.config/kcminputrc b/.config/kcminputrc similarity index 100% rename from dotfiles/.config/kcminputrc rename to .config/kcminputrc diff --git a/dotfiles/.config/kdeglobals b/.config/kdeglobals similarity index 100% rename from dotfiles/.config/kdeglobals rename to .config/kdeglobals diff --git a/dotfiles/.config/kitty/Betelgeuse-dark.conf b/.config/kitty/Betelgeuse-dark.conf similarity index 100% rename from dotfiles/.config/kitty/Betelgeuse-dark.conf rename to .config/kitty/Betelgeuse-dark.conf diff --git a/dotfiles/.config/kitty/Betelgeuse-light.conf b/.config/kitty/Betelgeuse-light.conf similarity index 100% rename from dotfiles/.config/kitty/Betelgeuse-light.conf rename to .config/kitty/Betelgeuse-light.conf diff --git a/dotfiles/.config/kitty/kitty.conf b/.config/kitty/kitty.conf similarity index 100% rename from dotfiles/.config/kitty/kitty.conf rename to .config/kitty/kitty.conf diff --git a/dotfiles/.config/konsolerc b/.config/konsolerc similarity index 100% rename from dotfiles/.config/konsolerc rename to .config/konsolerc diff --git a/dotfiles/.config/ksplashrc b/.config/ksplashrc similarity index 100% rename from dotfiles/.config/ksplashrc rename to .config/ksplashrc diff --git a/dotfiles/.config/ktimezonedrc b/.config/ktimezonedrc similarity index 100% rename from dotfiles/.config/ktimezonedrc rename to .config/ktimezonedrc diff --git a/dotfiles/.config/kwinrc b/.config/kwinrc similarity index 100% rename from dotfiles/.config/kwinrc rename to .config/kwinrc diff --git a/dotfiles/.config/misc/.tmux.themer b/.config/misc/.tmux.themer similarity index 100% rename from dotfiles/.config/misc/.tmux.themer rename to .config/misc/.tmux.themer diff --git a/dotfiles/.config/misc/.warp/themes/betelgeuse_dark.yaml b/.config/misc/.warp/themes/betelgeuse_dark.yaml similarity index 100% rename from dotfiles/.config/misc/.warp/themes/betelgeuse_dark.yaml rename to .config/misc/.warp/themes/betelgeuse_dark.yaml diff --git a/dotfiles/.config/misc/.warp/themes/betelgeuse_light.yaml b/.config/misc/.warp/themes/betelgeuse_light.yaml similarity index 100% rename from dotfiles/.config/misc/.warp/themes/betelgeuse_light.yaml rename to .config/misc/.warp/themes/betelgeuse_light.yaml diff --git a/dotfiles/.config/ngrok/ngrok.yml b/.config/ngrok/ngrok.yml similarity index 100% rename from dotfiles/.config/ngrok/ngrok.yml rename to .config/ngrok/ngrok.yml diff --git a/dotfiles/.config/plasma-localerc b/.config/plasma-localerc similarity index 100% rename from dotfiles/.config/plasma-localerc rename to .config/plasma-localerc diff --git a/dotfiles/.config/plasmarc b/.config/plasmarc similarity index 100% rename from dotfiles/.config/plasmarc rename to .config/plasmarc diff --git a/dotfiles/.config/powershell/takuya.omp.json b/.config/powershell/takuya.omp.json similarity index 100% rename from dotfiles/.config/powershell/takuya.omp.json rename to .config/powershell/takuya.omp.json diff --git a/dotfiles/.config/powershell/user_profile.ps1 b/.config/powershell/user_profile.ps1 similarity index 100% rename from dotfiles/.config/powershell/user_profile.ps1 rename to .config/powershell/user_profile.ps1 diff --git a/dotfiles/.config/ripgreprc b/.config/ripgreprc similarity index 100% rename from dotfiles/.config/ripgreprc rename to .config/ripgreprc diff --git a/dotfiles/.config/slack-term/config b/.config/slack-term/config similarity index 100% rename from dotfiles/.config/slack-term/config rename to .config/slack-term/config diff --git a/dotfiles/.config/tabby/config.yaml b/.config/tabby/config.yaml similarity index 100% rename from dotfiles/.config/tabby/config.yaml rename to .config/tabby/config.yaml diff --git a/dotfiles/.config/terminator/config b/.config/terminator/config similarity index 100% rename from dotfiles/.config/terminator/config rename to .config/terminator/config diff --git a/dotfiles/.config/wgetrc b/.config/wgetrc similarity index 100% rename from dotfiles/.config/wgetrc rename to .config/wgetrc diff --git a/dotfiles/.config/whalebrew b/.config/whalebrew similarity index 100% rename from dotfiles/.config/whalebrew rename to .config/whalebrew diff --git a/dotfiles/.config/xfce4/terminal/terminalrc b/.config/xfce4/terminal/terminalrc similarity index 100% rename from dotfiles/.config/xfce4/terminal/terminalrc rename to .config/xfce4/terminal/terminalrc diff --git a/dotfiles/.config/xfce4/xfconf/xfce-perchannel-xml/xsettings.xml b/.config/xfce4/xfconf/xfce-perchannel-xml/xsettings.xml similarity index 100% rename from dotfiles/.config/xfce4/xfconf/xfce-perchannel-xml/xsettings.xml rename to .config/xfce4/xfconf/xfce-perchannel-xml/xsettings.xml diff --git a/dotfiles/.config/xsettingsd/xsettingsd.conf b/.config/xsettingsd/xsettingsd.conf similarity index 100% rename from dotfiles/.config/xsettingsd/xsettingsd.conf rename to .config/xsettingsd/xsettingsd.conf diff --git a/dotfiles/.gnupg/public/apt.hashicorp.sig b/.gnupg/public/apt.hashicorp.sig similarity index 100% rename from dotfiles/.gnupg/public/apt.hashicorp.sig rename to .gnupg/public/apt.hashicorp.sig diff --git a/dotfiles/.gnupg/public/unman.sig b/.gnupg/public/unman.sig similarity index 100% rename from dotfiles/.gnupg/public/unman.sig rename to .gnupg/public/unman.sig diff --git a/dotfiles/.gnupg/public/wazuh.sig b/.gnupg/public/wazuh.sig similarity index 100% rename from dotfiles/.gnupg/public/wazuh.sig rename to .gnupg/public/wazuh.sig diff --git a/dotfiles/.local/bin/provision b/dotfiles/.local/bin/provision index 4e6d6354..74395635 100644 --- a/dotfiles/.local/bin/provision +++ b/dotfiles/.local/bin/provision @@ -1,30 +1,183 @@ #!/usr/bin/env bash -# Install Homebrew -if ! type brew &> /dev/null; then - if type sudo &> /dev/null && sudo -n true; then - echo | /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" +set -eo pipefail + +### Qubes dom0 specific code at top +# The VM name that will manage the Ansible provisioning (for Qubes dom0) +ANSIBLE_PROVISION_VM="provision" + +# Ensure sys-whonix is configured (for Qubes dom0) +CONFIG_WIZARD_COUNT=0 +ENABLE_OBFSC='false' +function configureWizard() { + if xwininfo -root -tree | grep "Anon Connection Wizard"; then + WINDOW_ID="$(xwininfo -root -tree | grep "Anon Connection Wizard" | sed 's/^ *\([^ ]*\) .*/\1/')" + xdotool windowactivate "$WINDOW_ID" && sleep 1 && xdotool key 'Enter' && sleep 1 && xdotool key 'Tab Tab Enter' && sleep 24 && xdotool windowactivate "$WINDOW_ID" && sleep 1 && xdotool key 'Enter' && sleep 300 + qvm-shutdown --wait sys-whonix + sleep 3 + qvm-start sys-whonix + if xwininfo -root -tree | grep "systemcheck | Whonix" > /dev/null; then + WINDOW_ID_SYSCHECK="$(xwininfo -root -tree | grep "systemcheck | Whonix" | sed 's/^ *\([^ ]*\) .*/\1/')" + if xdotool windowactivate "$WINDOW_ID_SYS_CHECK"; then + sleep 1 + xdotool key 'Enter' + fi + fi else - /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" + sleep 3 + CONFIG_WIZARD_COUNT=$((CONFIG_WIZARD_COUNT + 1)) + if [[ "$CONFIG_WIZARD_COUNT" == '4' ]]; then + echo "The sys-whonix anon-connection-wizard utility did not open." + else + echo "Checking for anon-connection-wizard again.." + configureWizard + fi fi +} + +### Update via system package manager and install Homebrew dependencies +if command -v qubesctl > /dev/null; then + # Qubes dom0 + + ### Ensure dom0 is updated + if [ ! -f /root/dom0-updated ]; then + sudo qubesctl --show-output state.sls update.qubes-dom0 + sudo qubes-dom0-update --clean -y + touch /root/dom0-updated + fi + + ### Ensure sys-whonix is running + if ! qvm-check --running sys-whonix; then + qvm-start sys-whonix --skip-if-running + configureWizard > /dev/null + fi + + ### Ensure TemplateVMs are updated + if [ ! -f /root/templatevms-updated ]; then + # timeout of 10 minutes is added here because the whonix-gw VM does not like to get updated + # with this method. Anyone know how to fix this? + sudo timeout 600 qubesctl --show-output --skip-dom0 --templates state.sls update.qubes-vm &> /dev/null || EXIT_CODE=$? + while read RESTART_VM; do + qvm-shutdown --wait "$RESTART_VM" + done< <(qvm-ls --all --no-spinner --fields=name,state | grep Running | grep -v sys-net | grep -v sys-firewall | grep -v sys-whonix | grep -v dom0 | awk '{print $1}') + sudo touch /root/templatevms-updated + fi + + ### Ensure provisioning VM can run commands on any VM + echo "/bin/bash" | sudo tee /etc/qubes-rpc/qubes.VMShell + sudo chmod 755 /etc/qubes-rpc/qubes.VMShell + echo "$ANSIBLE_PROVISION_VM"' dom0 allow' | sudo tee /etc/qubes-rpc/policy/qubes.VMShell + echo "$ANSIBLE_PROVISION_VM"' $anyvm allow' | sudo tee -a /etc/qubes-rpc/policy/qubes.VMShell + sudo chown "$(whoami):$(whoami)" /etc/qubes-rpc/policy/qubes.VMShell + sudo chmod 644 /etc/qubes-rpc/policy/qubes.VMShell + + + ### Create provisioning VM and initialize the provisioning process from there + qvm-create --label red --template debian-11 "$ANSIBLE_PROVISION_VM" &> /dev/null || EXIT_CODE=$? + qvm-volume extend "$ANSIBLE_PROVISION_VM:private" "40G" + if [ -f ~/.vaultpass ]; then + qvm-run "$ANSIBLE_PROVISION_VM" 'rm -f ~/QubesIncoming/dom0/.vaultpass' + qvm-copy-to-vm "$ANSIBLE_PROVISION_VM" ~/.vaultpass + qvm-run "$ANSIBLE_PROVISION_VM" 'cp ~/QubesIncoming/dom0/.vaultpass ~/.vaultpass' + fi + qvm-run --pass-io "$ANSIBLE_PROVISION_VM" 'curl -sSL https://install.doctor/start > ~/start.sh && bash ~/start.sh' + exit 0 +elif command -v apt-get > /dev/null; then + # Debian / Ubuntu + sudo apt-get update + sudo apt-get install -y curl git +elif command -v dnf > /dev/null; then + # Fedora + sudo dnf install -y curl git +elif command -v yum > /dev/null; then + # CentOS + sudo yum install -y curl git +elif command -v pacman > /dev/null; then + # Archlinux + sudo pacman update + sudo pacman -Sy curl git +elif command -v zypper > /dev/null; then + # OpenSUSE + sudo zypper install -y curl git nodejs +elif command -v apk > /dev/null; then + # Alpine + apk add curl git +elif [ -d /Applications ] && [ -d /Library ]; then + # macOS + sudo xcode-select -p >/dev/null 2>&1 || xcode-select --install +elif command -v nix-env > /dev/null; then + # NixOS +elif [[ "$OSTYPE" == 'freebsd'* ]]; then + # FreeBSD +elif command -v pkg > /dev/null; then + # Termux +elif command -v xbps-install > /dev/null; then + # Void +elif [[ "$OSTYPE" == 'cygwin' ]] || [[ "$OSTYPE" == 'msys' ]] || [[ "$OSTYPE" == 'win32' ]]; then + # Windows + choco install -y curl git node fi -# Install Homebrew bundle and go-task -brew install go-task/tap/go-task -brew install jq -brew install yq +### Install Homebrew +ensurePackageManagerHomebrew() { + if ! command -v brew > /dev/null; then + if command -v sudo > /dev/null && sudo -n true; then + echo | bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" + else + logg info 'Homebrew is not installed. Password may be required.' + bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" || BREW_EXIT_CODE="$?" + if [ -n "$BREW_EXIT_CODE" ]; then + if command -v brew > /dev/null; then + logg warn 'Homebrew was installed but part of the installation failed. Attempting to fix..' + BREW_DIRS="share/man share/doc share/zsh/site-functions etc/bash_completion.d" + for BREW_DIR in $BREW_DIRS; do + if [ -d "$(brew --prefix)/$BREW_DIR" ]; then + sudo chown -R "$(whoami)" "$(brew --prefix)/$BREW_DIR" + fi + done + brew update --force --quiet + fi + fi + fi + fi +} +ensurePackageManagerHomebrew -# Ensure dotfiles are present -if [ ! -f "$HOME/.local/bin/install-dotfiles" ]; then - bash <(curl -sSL https://gitlab.com/megabyte-labs/misc/dotfiles/-/raw/master/dotfiles/.local/bin/install-dotfiles) +### Install installer dependencies via Homebrew +if command -v brew > /dev/null; then + brew install chezmoi go-task/tap/go-task jq node yq zx +fi + +### Ensure source files are present +if [ -d /usr/local/src/hiawatha ] && [ ! -w /usr/local/src/hiawatha ]; then + sudo chown -Rf "$USER":"$(id -g -n)" /usr/local/src/hiawatha +fi +if [ -d /usr/local/src/hiawatha/.git ]; then + git config pull.rebase false + git pull origin master else - chmod +x "$HOME/.local/bin/install-dotfiles" - install-dotfiles + rm -rf /usr/local/src/hiawatha + sudo git clone https://gitlab.com/megabyte-labs/dotfiles.git /usr/local/src/hiawatha + chown -Rf "$USER":"$(id -g -n)" /usr/local/src/hiawatha fi -# Use run alias to invoke the `$HOME/.local/Taskfile.yml` -if [ -z "$1" ]; then - run localhost:provision -else - run "localhost:provision:$1" -fi +### Copy folders +find /usr/local/src/hiawatha -maxdepth 1 -mindepth 1 -type d | while read FOLDER; do + BASENAME="$(basename "$FOLDER")" + if [ ! -d "$HOME/$BASENAME" ]; then + mkdir -p "$HOME/$BASENAME" + fi + cp -rf "$FOLDER/"* "$HOME/$BASENAME" +done + +### Copy files +find /usr/local/src/hiawatha -maxdepth 1 -mindepth 1 -type f | while read FILE; do + BASENAME="$(basename "$FILE")" + cp "$FILE" "$HOME/$BASENAME" + chmod 600 "$HOME/$BASENAME" +done + +### Ensure ~/.local/bin files are executable +find "$HOME/.local/bin" -maxdepth 1 -mindepth 1 -type f | while read BINFILE; do + chmod +x "$BINFILE" +done diff --git a/dotfiles/.local/share/chezmoi/home/dot_bashrc b/dotfiles/.local/share/chezmoi/home/dot_bashrc index 359bf59d..0a8f01be 100644 --- a/dotfiles/.local/share/chezmoi/home/dot_bashrc +++ b/dotfiles/.local/share/chezmoi/home/dot_bashrc @@ -34,6 +34,11 @@ fi ### History export HISTFILE="$XDG_STATE_HOME/bash/history" +### /etc/bashrc +if [ -f /etc/bashrc ]; then + . /etc/bashrc +fi + # Prompt (on bash only) if [ "$BASH_SUPPORT" = 'true' ]; then if [[ "$(hostname)" != *'-minimal' ]]; then