commit 2f723ac7ee669e7d348a5874f572589343feb8c7 Author: Steven Date: Fri Dec 5 13:48:32 2025 -0500 initial commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..0a2f4f0 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# scripts +Random scripts for personal use diff --git a/install/install-gh b/install/install-gh new file mode 100755 index 0000000..9317b2d --- /dev/null +++ b/install/install-gh @@ -0,0 +1,10 @@ +#!/bin/sh + +curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | \ + sudo dd of=/etc/apt/trusted.gpg.d/githubcli-archive-keyring.gpg + +echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/trusted.gpg.d/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | \ + sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null + +sudo apt update +sudo apt install gh diff --git a/install/install-go b/install/install-go new file mode 100755 index 0000000..d04df2f --- /dev/null +++ b/install/install-go @@ -0,0 +1,52 @@ +#!/usr/bin/env bash + +# Installs the latest Go release into $TARGETDIR (default: ~/.local) +# without requiring root access. Assumes the following suggested +# environment variables (which need to be set or changed in this script +# or after install completes): +# +# PATH="~/.local/bin:~/.local/bin/go/bin:$PATH" +# GOOS=linux +# GOARCH=amd64 +# GOPATH="~/.local/go" +# GOBIN="~/.local/go/bin" +# +# Note that the downloaded tar file is not removed and can be found in +# either $DOWNLOADS or /tmp. + +true "${TARGETDIR:="$HOME/.local"}" + +# change this to your target (detecting not always reliable) +declare GOOS=linux +declare GOARCH=amd64 + +lookup_file() { + curl -sSL "https://go.dev/dl/?mode=json" | + jq -r '.[0].files[] + | select(.os == "'"$GOOS"'") + | select(.arch == "'"$GOARCH"'") + | .filename' +} + +fetch() { + local filename + filename="$(lookup_file)" + [[ -z "$filename" ]] && echo "unable to fetch filename" 1>&2 && return 1 + local path="/tmp/$filename" + [[ -n "$DOWNLOADS" ]] && [[ -d "$DOWNLOADS" ]] && path="$DOWNLOADS/$filename" + curl -L "https://go.dev/dl/$filename" -o "$path" + echo "$path" +} + +install_latest_go() { + local dir="$1" path + [[ -z "$dir" ]] && dir="$TARGETDIR" + [[ -z "$dir" ]] && dir="$HOME/.local" + mkdir -p "$dir" 2>/dev/null + path="$(fetch)" + [[ -z "$path" ]] && echo "unable to fetch go tarball" 1>&2 && return 1 + rm -rf "$dir/go" && tar -C "$dir" -xzf "$path" # rm is required by instructions + echo "Add $dir/go/bin to your path and optionally set GOBIN=~/.local/bin" 1>&2 +} + +install_latest_go "$@" diff --git a/install/install-nodejs b/install/install-nodejs new file mode 100755 index 0000000..5502dfa --- /dev/null +++ b/install/install-nodejs @@ -0,0 +1,83 @@ +#!/usr/bin/env bash + +# Installs the latest NodeJS release into $TARGETDIR (default: ~/.local) + +true "${TARGETDIR:="$HOME/.local"}" + +UNAME=$(uname -s) +case "${UNAME}" in + Linux*) CURR_OS=LINUX;; + Darwin*) CURR_OS=MAC;; + *) CURR_OS=UNK;; +esac + +get_latest_release() { + curl --silent "https://api.github.com/repos/$1/releases/latest" | # Get latest release from GitHub api + jq -r '.tag_name' +} + +get_latest_release_tarball() { + curl --silent "https://api.github.com/repos/$1/releases/latest" | # Get latest release from GitHub api + jq -r '.tarball_url' +} + +fetch() { + local filename + filename="$(lookup_file)" + [[ -z "$filename" ]] && echo "unable to fetch filename" 1>&2 && return 1 + local path="/tmp/$filename" + [[ -n "$DOWNLOADS" ]] && [[ -d "$DOWNLOADS" ]] && path="$DOWNLOADS/$filename" + curl -L "https://go.dev/dl/$filename" -o "$path" + echo "$path" +} + +install_latest_nodejs() { + #local dir="$1" path + #[[ -z "$dir" ]] && dir="$TARGETDIR" + #[[ -z "$dir" ]] && dir="$HOME/.local" + #mkdir -p "$dir" 2>/dev/null + #path="$(fetch)" + #[[ -z "$path" ]] && echo "unable to fetch go tarball" 1>&2 && return 1 + #rm -rf "$dir/go" && tar -C "$dir" -xzf "$path" # rm is required by instructions + #echo "Add $dir/go/bin to your path and optionally set GOBIN=~/.local/bin" 1>&2 + RELVERS=$(get_latest_release "nodejs/node") + TARBALL=$(get_latest_release_tarball "nodejs/node") + TMPDIR=$(mktemp -d) + if [ $? -ne 0 ]; then + echo "Error creating temp directory.." + exit 1; + fi + + echo "Latest NodeJS from Github release is ${RELVERS}..." + + echo "Downloading NodeJS ${RELVERS} from ${TARBALL}..." + curl -L "https://github.com/nodejs/node/archive/refs/tags/${RELVERS}.tar.gz" -o "${TMPDIR}/nodejs_${RELVERS}.tar.gz" + if [ $? -ne 0 ]; then + echo "Error downloading latest nodejs tarball.." + exit 1; + fi + + mkdir "${TMPDIR}/nodejs" + + tar -xf "nodejs_${RELVERS}.tar.gz" -C "${TMPDIR}/nodejs" --strip-components=1 + if [ $? -ne 0 ]; then + echo "Error while trying to untar tarball ${TMPDIR}/nodejs_${RELVERS}.tar.gz" + exit 1 + fi + + cd "${TMPDIR}/nodejs" + + ./configure + if [ $? -ne 0 ]; then + echo "Error configuring build" + exit 1 + fi + + make + if [ $? -ne - ]; then + echo "Error running make" + exit 1 + fi +} + +install_latest_nodejs "$@" diff --git a/install/install-yq b/install/install-yq new file mode 100755 index 0000000..1c6e5ee --- /dev/null +++ b/install/install-yq @@ -0,0 +1,18 @@ +#!/bin/sh + +url="https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64" +dir=$(mktemp -d) + +cleanup () { + rm -rf "$dir" +} +trap cleanup EXIT + +curl -L "$url" -o "$dir/yq" +chmod +x "$dir/yq" + +# mkdir -p is not POSIX compliant +[ ! -d ~/.local ] && mkdir ~/.local +[ ! -d ~/.local/bin ] && mkdir ~/.local/bin + +cp "$dir/yq" ~/.local/bin