From 187a33a410f0aa8cc113d539dc58b688e62c8fc0 Mon Sep 17 00:00:00 2001 From: Brian Zalewski Date: Tue, 18 Apr 2023 04:57:54 +0000 Subject: [PATCH] Update 5 files - /home/.chezmoiscripts/universal/run_onchange_after_51-samba.sh.tmpl - /home/.chezmoiscripts/universal/run_onchange_after_53-tabby.sh.tmpl - /home/.chezmoiscripts/universal/run_onchange_after_59-connect-tailscale.sh.tmpl - /home/.chezmoiscripts/universal/run_onchange_after_81-k8s-digitalocean.sh.tmpl - /home/.chezmoi.yaml.tmpl --- home/.chezmoi.yaml.tmpl | 1 + .../run_onchange_after_51-samba.sh.tmpl | 6 ++-- .../run_onchange_after_53-tabby.sh.tmpl | 2 +- ...nchange_after_59-connect-tailscale.sh.tmpl | 3 ++ ...onchange_after_81-k8s-digitalocean.sh.tmpl | 28 +++++++++++++------ 5 files changed, 27 insertions(+), 13 deletions(-) diff --git a/home/.chezmoi.yaml.tmpl b/home/.chezmoi.yaml.tmpl index a54dbb8c..20796884 100644 --- a/home/.chezmoi.yaml.tmpl +++ b/home/.chezmoi.yaml.tmpl @@ -171,6 +171,7 @@ data: r2: "{{ $cloudflareR2AccountId }}" username: "{{ $cloudflareUsername }}" defaultBrowser: firefox + digitalOceanClusterId: b7fc4e37-ffe7-4ea1-887a-0e19ee077f32 # `domain` is kept here for backwards compatibility, but the .host.domain is the preferred selector domain: "{{ $domain }}" email: "{{ $email }}" diff --git a/home/.chezmoiscripts/universal/run_onchange_after_51-samba.sh.tmpl b/home/.chezmoiscripts/universal/run_onchange_after_51-samba.sh.tmpl index 9ba2bdeb..512d6e3e 100644 --- a/home/.chezmoiscripts/universal/run_onchange_after_51-samba.sh.tmpl +++ b/home/.chezmoiscripts/universal/run_onchange_after_51-samba.sh.tmpl @@ -58,19 +58,19 @@ if command -v smbd > /dev/null; then if [ -d /mnt/s3-private ] && [ ! -d /mnt/samba-private ]; then sudo ln -s /mnt/s3-private /mnt/samba-private else - sudo mkdir /mnt/samba-private + sudo mkdir -p /mnt/samba-private fi ### Ensure public Samba directory / symlink exists if [ -d /mnt/s3-public ] && [ ! -d /mnt/samba-public ]; then sudo ln -s /mnt/s3-public /mnt/samba-public else - sudo mkdir /mnt/samba-public + sudo mkdir -p /mnt/samba-public fi ### Copy the Samba server configuration file logg info "Copying Samba server configuration to /etc/samba/smb.conf" - sudo cp -f "${XDG_DATA_HOME:-$HOME/.config}/samba/config" "/etc/samba/smb.conf" + sudo cp -f "${XDG_CONFIG_HOME:-$HOME/.config}/samba/config" "/etc/samba/smb.conf" ### Reload configuration file changes smbcontrol smbd reload-config diff --git a/home/.chezmoiscripts/universal/run_onchange_after_53-tabby.sh.tmpl b/home/.chezmoiscripts/universal/run_onchange_after_53-tabby.sh.tmpl index c4292fef..b3dfbd08 100644 --- a/home/.chezmoiscripts/universal/run_onchange_after_53-tabby.sh.tmpl +++ b/home/.chezmoiscripts/universal/run_onchange_after_53-tabby.sh.tmpl @@ -47,7 +47,7 @@ {{ includeTemplate "universal/profile" }} {{ includeTemplate "universal/logg" }} -if [ -f "${XDG_CONFIG_HOME:-$HOME/.config}/tabby/plugins/package-lock.json" ]; then +if [ -f "${XDG_CONFIG_HOME:-$HOME/.config}/tabby/plugins/package.json" ]; then if [ -d "${XDG_CONFIG_HOME:-$HOME/.config}/tabby/plugins/node_modules" ]; then logg info 'Skipping Tabby plugin installation because it looks like the plugins were already installed since `node_modules` is present in ~/.config/tabby/plugins' else diff --git a/home/.chezmoiscripts/universal/run_onchange_after_59-connect-tailscale.sh.tmpl b/home/.chezmoiscripts/universal/run_onchange_after_59-connect-tailscale.sh.tmpl index 48243b26..318150e9 100644 --- a/home/.chezmoiscripts/universal/run_onchange_after_59-connect-tailscale.sh.tmpl +++ b/home/.chezmoiscripts/universal/run_onchange_after_59-connect-tailscale.sh.tmpl @@ -6,6 +6,9 @@ # This script ensures the `tailscaled` system daemon is installed on macOS. Then, on both macOS and Linux, it connects to the Tailscale # network if the `TAILSCALE_AUTH_KEY` variable is provided. +{{ includeTemplate "universal/profile" }} +{{ includeTemplate "universal/logg" }} + ### Install the Tailscale system daemon if [ -d /Applications ] && [ -d System ]; then # macOS diff --git a/home/.chezmoiscripts/universal/run_onchange_after_81-k8s-digitalocean.sh.tmpl b/home/.chezmoiscripts/universal/run_onchange_after_81-k8s-digitalocean.sh.tmpl index 12aba6da..2adfaaa6 100644 --- a/home/.chezmoiscripts/universal/run_onchange_after_81-k8s-digitalocean.sh.tmpl +++ b/home/.chezmoiscripts/universal/run_onchange_after_81-k8s-digitalocean.sh.tmpl @@ -6,16 +6,26 @@ # This script runs when `DIGITALOCEAN_ACCESS_TOKEN` is defined as an environment variable or as an encrypted key (see # [Secrets documentation](https://install.doctor/docs/customization/secrets#encrypted-secrets)). If the check passes, # then the script ensures the DigitalOcean CLI is installed (i.e. `doctl`). Then, it uses `doctl` to connect to the Kubernetes -# cluster defined by the `DIGITALOCEAN_K8S_ID` secret. -# This script detects the presence of various executables with Bash completions available and then -# conditionally adds the completions to the Bash completions folder. +# cluster defined by the the configuration stored under `.user.digitalOceanClusterId` in `home/.chezmoi.yaml.tmpl`. -### Ensure DigitalOcean CLI is instaled -if ! command -v doctl > /dev/null; then - logg info '`doctl` is missing - installing via Homebrew' - brew install doctl +{{ includeTemplate "universal/profile" }} +{{ includeTemplate "universal/logg" }} + +### Ensure `DIGITALOCEAN_ACCESS_TOKEN` is defined (used for headlessly connecting to the k8s cluster) +export DIGITALOCEAN_ACCESS_TOKEN="{{ if (stat (joinPath .chezmoi.sourceDir ".chezmoitemplates" "secrets" "DIGITALOCEAN_ACCESS_TOKEN")) }}{{ includeTemplate "secrets/DIGITALOCEAN_ACCESS_TOKEN" | decrypt }}{{ else }}{{ env "DIGITALOCEAN_ACCESS_TOKEN" }}{{ end }}" + +if [ -n "$DIGITALOCEAN_ACCESS_TOKEN" ] && [ -n '{{ .user.digitalOceanClusterId }}' ]; then + ### Ensure DigitalOcean CLI is instaled + if ! command -v doctl > /dev/null; then + logg info '`doctl` is missing - installing via Homebrew' + brew install doctl + fi + + ### Connect to the k8s cluster with `doctl` + logg info 'Connecting to the DigitalOcean k8s cluster with `doctl`' + doctl kubernetes cluster kubeconfig save {{ .user.digitalOceanClusterId }} +else + logg info 'Skipping connecting to the DigitalOcean k8s cluster because either the `DIGITALOCEAN_ACCESS_TOKEN` or the `.user.digitalOceanClusterId` is not defined' fi -doctl kubernetes cluster kubeconfig save b7fc4e37-ffe7-4ea1-887a-0e19ee077f32 - {{ end -}}