From e07607c72248cac2ea3b86c264623a855812153b Mon Sep 17 00:00:00 2001 From: Kilian Tyler Date: Wed, 4 Sep 2024 00:03:58 -0400 Subject: [PATCH] fix: starting script fixes --- ...run_once_before_0-decrypt_age_key.sh.tmpl} | 6 + .../runOnce/run_once_before_1-darwin.sh.tmpl | 59 +++++++++ ...run_once_before_1-install-programs.sh.tmpl | 113 ------------------ ...h.tmpl => run_once_before_1-linux.sh.tmpl} | 0 .../runOnce/run_once_before_2-comtrya.sh.tmpl | 8 -- .../run_once_before_3-nerdfont.sh.tmpl | 35 ------ .../run_once_before_4-gpg-keys.sh.tmpl | 11 -- 7 files changed, 65 insertions(+), 167 deletions(-) rename dotfiles/.chezmoiscripts/runOnce/{run_once_before_0000-decrypt_age_key.sh.tmpl => run_once_before_0-decrypt_age_key.sh.tmpl} (61%) create mode 100644 dotfiles/.chezmoiscripts/runOnce/run_once_before_1-darwin.sh.tmpl delete mode 100644 dotfiles/.chezmoiscripts/runOnce/run_once_before_1-install-programs.sh.tmpl rename dotfiles/.chezmoiscripts/runOnce/{run_once_before_0-linux.sh.tmpl => run_once_before_1-linux.sh.tmpl} (100%) delete mode 100644 dotfiles/.chezmoiscripts/runOnce/run_once_before_2-comtrya.sh.tmpl delete mode 100644 dotfiles/.chezmoiscripts/runOnce/run_once_before_3-nerdfont.sh.tmpl delete mode 100644 dotfiles/.chezmoiscripts/runOnce/run_once_before_4-gpg-keys.sh.tmpl diff --git a/dotfiles/.chezmoiscripts/runOnce/run_once_before_0000-decrypt_age_key.sh.tmpl b/dotfiles/.chezmoiscripts/runOnce/run_once_before_0-decrypt_age_key.sh.tmpl similarity index 61% rename from dotfiles/.chezmoiscripts/runOnce/run_once_before_0000-decrypt_age_key.sh.tmpl rename to dotfiles/.chezmoiscripts/runOnce/run_once_before_0-decrypt_age_key.sh.tmpl index de9e4fc..0842793 100644 --- a/dotfiles/.chezmoiscripts/runOnce/run_once_before_0000-decrypt_age_key.sh.tmpl +++ b/dotfiles/.chezmoiscripts/runOnce/run_once_before_0-decrypt_age_key.sh.tmpl @@ -1,5 +1,11 @@ #!/usr/bin/env bash +# ----------------------------------- +# author: @kiliantyler +# title: Decrypt Age Key +# description: Decrypts the Age key used by chezmoi +# ----------------------------------- + if [ ! -f "${HOME}/.config/chezmoi/key.txt" ]; then mkdir -p "${HOME}/.config/chezmoi" chezmoi age decrypt --output "${HOME}/.config/chezmoi/key.txt" --passphrase "{{ .chezmoi.sourceDir }}/key.txt.age" diff --git a/dotfiles/.chezmoiscripts/runOnce/run_once_before_1-darwin.sh.tmpl b/dotfiles/.chezmoiscripts/runOnce/run_once_before_1-darwin.sh.tmpl new file mode 100644 index 0000000..b5a614e --- /dev/null +++ b/dotfiles/.chezmoiscripts/runOnce/run_once_before_1-darwin.sh.tmpl @@ -0,0 +1,59 @@ +{{- if eq .chezmoi.os "darwin" -}} +#!/usr/bin/env zsh + +# ----------------------------------- +# author: @kiliantyler +# title: Installs Xcode Command Line Tools +# description: Installs Xcode Command Line Tools if they are not already installed +# ----------------------------------- + +fail() { + echo "$1" >&2 + exit 1 +} + + +# ----------------------------------- +# Ensure we are running in zsh +# Make this check POSIX compliant +# ----------------------------------- + +if [ -z "${ZSH_VERSION:-}" ]; then + fail "Please run this script in zsh" +fi + +should_install_command_line_tools() { + ! [[ -e "/Library/Developer/CommandLineTools/usr/bin/git" ]] +} + +chomp() { + printf "%s" "${1/"$'\n'"/}" +} + +# ----------------------------------- +# Xcode Command Line Tools Installation +# ----------------------------------- + +if should_install_command_line_tools; then + echo "Installing Xcode Command Line Tools" + # This temporary file prompts the 'softwareupdate' utility to list the Command Line Tools + clt_placeholder="/tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress" + command sudo touch "${clt_placeholder}" + + clt_label_command="/usr/sbin/softwareupdate -l | + grep -B 1 -E 'Command Line Tools' | + awk -F'*' '/^ *\\*/ {print \$2}' | + sed -e 's/^ *Label: //' -e 's/^ *//' | + sort -V | + tail -n1" + clt_label="$(chomp "$(/bin/bash -c "${clt_label_command}")")" + + if [[ -n "${clt_label}" ]] + then + command sudo "/usr/sbin/softwareupdate" "-i" "${clt_label}" + command sudo "/usr/bin/xcode-select" "--switch" "/Library/Developer/CommandLineTools" + fi + command sudo "/bin/rm" "-f" "${clt_placeholder}" +fi + +{{ end }} diff --git a/dotfiles/.chezmoiscripts/runOnce/run_once_before_1-install-programs.sh.tmpl b/dotfiles/.chezmoiscripts/runOnce/run_once_before_1-install-programs.sh.tmpl deleted file mode 100644 index 912ee3a..0000000 --- a/dotfiles/.chezmoiscripts/runOnce/run_once_before_1-install-programs.sh.tmpl +++ /dev/null @@ -1,113 +0,0 @@ -#!/usr/bin/env bash - -# ----------------------------------- -# author: @kiliantyler -# title: Install Programs -# description: Install programs used by the rest of the dotfiles -# ----------------------------------- - -# ----------------------------------- -# Xcode Command Line Tools -# ----------------------------------- - -{{ if eq .chezmoi.os "darwin" -}} -# Check if Xcode Command Line Tools are installed -if ! xcode-select -p &> /dev/null; then - echo "Installing Xcode Command Line Tools..." - xcode-select --install -fi -{{- end }} - -# ----------------------------------- -# Rosetta -# ----------------------------------- - -{{ if (and (eq .chezmoi.os "darwin") (eq .chezmoi.arch "arm64")) }} -# Check if Rosetta is installed -if ! pkgutil --pkg-info com.apple.pkg.RosettaUpdateAuto >/dev/null 2>&1; then - echo "Installing Rosetta..." - softwareupdate --install-rosetta -fi -{{- end }} - -# ----------------------------------- -# Homebrew -# ----------------------------------- - -{{ if (or (eq .chezmoi.os "darwin") (eq .chezmoi.os "linux")) -}} -# Check if Homebrew is installed -if ! command -v brew &> /dev/null; then - echo "Installing Homebrew..." - /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" -fi -{{- end }} - -# ----------------------------------- -# asdf -# ----------------------------------- - -# Install asdf - -{{ if (or (eq .chezmoi.os "darwin") (eq .chezmoi.os "linux")) -}} -# Check if asdf is installed -if [[ ! -d ~/.asdf ]]; then - # TODO: Renovate this version - asdfVersion="0.14.0" - echo "Installing asdf..." - git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v${asdfVersion} -fi - -# Add asdf to shell - -if ! command -v asdf &> /dev/null; then - echo "Adding asdf to shell..." - source ~/.asdf/asdf.sh -fi - -# Add asdf plugin manager - -if ! asdf plugin-list | grep -q "asdf-plugin-manager"; then - # TODO: Renovate this version - asdfPluginManagerVersion="1.3.1" - echo "Adding asdf plugin manager..." - asdf plugin add asdf-plugin-manager https://github.com/asdf-community/asdf-plugin-manager.git - asdf plugin update asdf-plugin-manager v${asdfPluginManagerVersion} - asdf install asdf-plugin-manager ${asdfPluginManagerVersion} - asdf global asdf-plugin-manager ${asdfPluginManagerVersion} -fi -{{- end }} - -# ----------------------------------- -# comtrya -# ----------------------------------- - -{{ if (or (eq .chezmoi.os "darwin") (eq .chezmoi.os "linux")) -}} -BIN_LOCATION="{{ .chezmoi.homeDir }}/.bin" -if [[ ! -d $BIN_LOCATION ]]; then - mkdir -p $BIN_LOCATION -fi -COMTRYA_BINARY=comtrya -COMTRYA_FILE=${BIN_LOCATION}/${COMTRYA_BINARY} -# Check if comtrya is installed -if [[ ! -f $COMTRYA_FILE ]]; then - echo "Installing comtrya..." - OWNER=comtrya - REPO=comtrya - - COMTRYA_VERSION=$(curl -sI https://github.com/$OWNER/$REPO/releases/${VERSION:=latest} | grep -i "location:" | awk -F"/" '{ printf "%s", $NF }' | tr -d '\r') - {{ if eq .chezmoi.arch "arm64" -}} - COMTRYA_ARCH_SUFFIX="-aarch64" - {{- else -}} - COMTRYA_ARCH_SUFFIX="-x86_64" - {{- end }} - {{ if eq .chezmoi.os "darwin" -}} - COMTRYA_OS_SUFFIX="-apple-darwin" - {{- else -}} - COMTRYA_OS_SUFFIX="-unknown-linux-gnu" - {{- end }} - COMTRYA_SUFFIX="${COMTRYA_ARCH_SUFFIX}${COMTRYA_OS_SUFFIX}" - COMTRYA_URL=https://github.com/$OWNER/$REPO/releases/download/$COMTRYA_VERSION/${COMTRYA_BINARY}${COMTRYA_SUFFIX} - curl -sSL $COMTRYA_URL --output "$COMTRYA_FILE" - chmod +x $COMTRYA_FILE -fi -{{- end }} \ No newline at end of file diff --git a/dotfiles/.chezmoiscripts/runOnce/run_once_before_0-linux.sh.tmpl b/dotfiles/.chezmoiscripts/runOnce/run_once_before_1-linux.sh.tmpl similarity index 100% rename from dotfiles/.chezmoiscripts/runOnce/run_once_before_0-linux.sh.tmpl rename to dotfiles/.chezmoiscripts/runOnce/run_once_before_1-linux.sh.tmpl diff --git a/dotfiles/.chezmoiscripts/runOnce/run_once_before_2-comtrya.sh.tmpl b/dotfiles/.chezmoiscripts/runOnce/run_once_before_2-comtrya.sh.tmpl deleted file mode 100644 index d387ca1..0000000 --- a/dotfiles/.chezmoiscripts/runOnce/run_once_before_2-comtrya.sh.tmpl +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env bash - -# check if ~/.bin is in PATH -if [[ ":$PATH:" != *":$HOME/.bin:"* ]]; then - export PATH="$HOME/.bin:$PATH" -fi - -{{/* comtrya -d {{ .chezmoi.workingTree }}/comtrya apply */}} diff --git a/dotfiles/.chezmoiscripts/runOnce/run_once_before_3-nerdfont.sh.tmpl b/dotfiles/.chezmoiscripts/runOnce/run_once_before_3-nerdfont.sh.tmpl deleted file mode 100644 index 8bfb71c..0000000 --- a/dotfiles/.chezmoiscripts/runOnce/run_once_before_3-nerdfont.sh.tmpl +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/bash - -{{ if eq .chezmoi.os "linux" }} - -[[ "$(command -v unzip)" ]] || { - echo "We cannot find the unzip command. First, install the unzip command." - return 1 -} - -font_name="FiraCode" - -echo "Starting download of $font_name nerd font" - -url="https://github.com/ryanoasis/nerd-fonts/releases/latest/download/$font_name.zip" - -if [ "$(command -v curl)" ]; then - curl -OL "$url" -elif [ "$(command -v wget)" ]; then - wget "$url" -else - echo "We cannot find the curl or wget command. First, install the curl or wget command." - return 1 -fi - -echo "creating fonts folder: ${HOME}/.fonts" -mkdir -p "$HOME/.fonts" -echo "unzipping $font_name.zip" -unzip "$font_name.zip" -d "$HOME/.fonts/$font_name/" -[[ -f "$font_name.zip" ]] && rm "$font_name.zip" -echo "updating font cache" -[[ "$(command -v fc-cache)" ]] && \ - fc-cache -fv - -echo "Finished installing $font_name nerd font" -{{ end }} diff --git a/dotfiles/.chezmoiscripts/runOnce/run_once_before_4-gpg-keys.sh.tmpl b/dotfiles/.chezmoiscripts/runOnce/run_once_before_4-gpg-keys.sh.tmpl deleted file mode 100644 index 7618571..0000000 --- a/dotfiles/.chezmoiscripts/runOnce/run_once_before_4-gpg-keys.sh.tmpl +++ /dev/null @@ -1,11 +0,0 @@ -{{- if eq .chezmoi.os "linux" -}} -#!/bin/bash - -# Microsoft -sudo apt-get install wget gpg -wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > packages.microsoft.gpg -sudo install -D -o root -g root -m 644 packages.microsoft.gpg /etc/apt/keyrings/packages.microsoft.gpg - -# TODO: Move to Comtrya -echo "deb [arch=amd64,arm64,armhf signed-by=/etc/apt/keyrings/packages.microsoft.gpg] https://packages.microsoft.com/repos/code stable main" | sudo tee /etc/apt/sources.list.d/vscode.list > /dev/null -{{- end -}} \ No newline at end of file