-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b62d855
commit 9fe77e4
Showing
2 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
File renamed without changes.
113 changes: 113 additions & 0 deletions
113
chezmoi/dot_local/bin/executable_dotfiles-install-go-pkgs.tmpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
#!/bin/bash | ||
# {{ template "scripts-library" }} | ||
|
||
# check if --update or -u flag is set | ||
set +u | ||
if [[ "${1}" == "--update" ]] || [[ "${1}" == "-u" ]]; then | ||
UPDATE=true | ||
else | ||
UPDATE=false | ||
fi | ||
set -u | ||
|
||
ensure_path_entry "${HOME}/.local/bin" "${HOME}/bin" "${HOME}/go/bin" "${HOME}/.cargo/bin" | ||
GOROOT="${HOME}/go" | ||
if [ -d "${HOME}/go/packages" ]; then | ||
export GOPATH | ||
export GOPATH="${GOROOT}/packages" | ||
ensure_path_entry "${GOPATH}/bin" | ||
fi | ||
|
||
if ! command -v go >/dev/null || [[ ! -d "${GOROOT}" ]]; then | ||
log_task "Installing go" | ||
"${HOME}/.local/bin/install-go" | ||
elif [[ "${UPDATE}" == "true" ]]; then | ||
# Get current and latest version numbers | ||
current_version="$(go version | awk '{print $3}')" | ||
latest_version="$(curl -s 'https://go.dev/VERSION?m=text')" | ||
|
||
# Compare versions and update if necessary | ||
if [[ "$current_version" != "$latest_version" ]]; then | ||
log_task "Upgrading Go from ${current_version} to ${latest_version}" | ||
"${HOME}/.local/bin/install-go" | ||
else | ||
log_task "Go is already up-to-date (${current_version})" | ||
fi | ||
else | ||
log_task "go is already installed" | ||
fi | ||
|
||
# install age | ||
if ! command -v age &>/dev/null; then | ||
log_task "Installing age" | ||
c go install filippo.io/age/cmd/...@latest | ||
elif [[ "${UPDATE}" == "true" ]]; then | ||
current_version="$(age --version | cut -d' ' -f2)" | ||
latest_version="$(curl -s https://api.github.com/repos/FiloSottile/age/releases/latest | grep tag_name | cut -d '"' -f4)" | ||
if [ "$current_version" != "$latest_version" ]; then | ||
log_task "Updating age from $current_version to $latest_version" | ||
go install filippo.io/age/cmd/...@latest | ||
else | ||
log_task "age is already up to date ($current_version)" | ||
fi | ||
else | ||
log_task "age is already installed" | ||
fi | ||
|
||
# install sops | ||
if ! command -v sops &>/dev/null; then | ||
log_task "Installing sops" | ||
c go install go.mozilla.org/sops/v3/cmd/sops@latest | ||
elif [[ "${UPDATE}" == "true" ]]; then | ||
# Get current and latest version numbers | ||
current_version="$(sops --version | awk '{print $NF}')" | ||
latest_version="$(curl -s https://api.github.com/repos/mozilla/sops/releases/latest | grep 'tag_name' | cut -d'"' -f4)" | ||
|
||
# Compare versions and update if necessary | ||
if [[ "$current_version" != "$latest_version" ]]; then | ||
log_task "Upgrading sops from ${current_version} to ${latest_version}" | ||
go install go.mozilla.org/sops/v3/cmd/sops@latest | ||
else | ||
log_task "sops is already up-to-date (${current_version})" | ||
fi | ||
else | ||
log_task "sops is already installed" | ||
fi | ||
|
||
# install go-task | ||
if ! command -v task &>/dev/null; then | ||
log_task "Installing go-task" | ||
c sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d -b ~/.local/bin | ||
elif [[ "${UPDATE}" == "true" ]]; then | ||
# Get current and latest version numbers | ||
current_version="$(task --version | awk '{print $3}')" | ||
latest_version="$(curl -s https://api.github.com/repos/go-task/task/releases/latest | grep 'tag_name' | cut -d'"' -f4)" | ||
|
||
# Compare versions and update if necessary | ||
if [[ "$current_version" != "$latest_version" ]]; then | ||
log_task "Upgrading go-task from ${current_version} to ${latest_version}" | ||
rm -f ~/.local/bin/task | ||
sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d -b ~/.local/bin | ||
else | ||
log_task "go-task is already up-to-date (${current_version})" | ||
fi | ||
else | ||
log_task "go-task is already installed" | ||
fi | ||
|
||
# https://raw.githubusercontent.com/go-task/task/main/completion/zsh/_task | ||
# copy completion file to ~/.local/share/zsh/site-functions | ||
task_completion_file="${HOME}/.local/share/zsh/site-functions/_task" | ||
if [[ ! -f "${task_completion_file}" ]]; then | ||
log_task "Installing task completion file" | ||
if [[ ! -d "${HOME}/.local/share/zsh/site-functions" ]]; then | ||
c mkdir -p "${HOME}/.local/share/zsh/site-functions" | ||
fi | ||
c wget https://raw.githubusercontent.com/go-task/task/main/completion/zsh/_task -O "${task_completion_file}" | ||
fi | ||
|
||
if [[ "${UPDATE}" == "true" ]]; then | ||
log_green "✅ Go-packages updated successfully. ✨ 🌟 ✨" | ||
else | ||
log_green "✅ Go-packages installed successfully. ✨ 🌟 ✨" | ||
fi |