diff --git a/.config/setup/22-install-github-packages.sh b/.config/setup/22-install-github-packages.sh new file mode 100755 index 0000000..13d5478 --- /dev/null +++ b/.config/setup/22-install-github-packages.sh @@ -0,0 +1,3 @@ +#! /usr/bin/sh + +ghup diff --git a/.config/setup/22-install-rust-analyzer.sh b/.config/setup/22-install-rust-analyzer.sh deleted file mode 100755 index 32496f3..0000000 --- a/.config/setup/22-install-rust-analyzer.sh +++ /dev/null @@ -1,5 +0,0 @@ -#! /usr/bin/sh - -mkdir -p ~/.local/bin -curl --location https://github.com/rust-lang/rust-analyzer/releases/latest/download/rust-analyzer-x86_64-unknown-linux-gnu.gz | gunzip --to-stdout - > ~/.local/bin/rust-analyzer -chmod +x ~/.local/bin/rust-analyzer diff --git a/.config/setup/23-install-dolt.sh b/.config/setup/23-install-dolt.sh deleted file mode 100755 index 9b1452a..0000000 --- a/.config/setup/23-install-dolt.sh +++ /dev/null @@ -1,4 +0,0 @@ -#! /usr/bin/sh - -mkdir -p ~/.local/bin -curl --location https://github.com/dolthub/dolt/releases/latest/download/dolt-linux-amd64.tar.gz | tar xz --directory="${HOME}"/.local/bin/ --strip-components=2 dolt-linux-amd64/bin/dolt diff --git a/.local/bin/ghup b/.local/bin/ghup new file mode 100755 index 0000000..74de4a3 --- /dev/null +++ b/.local/bin/ghup @@ -0,0 +1,45 @@ +#! /usr/bin/sh + +STATE_DIR="$(systemd-path user-state-private)"/github-versions +mkdir -p "${STATE_DIR}" + +github_update() { + package="$1" + repo="$2" + resource="$3" + post_fetch="$4" + + response=$(curl --silent "https://api.github.com/repos/${repo}/releases/latest") + latest_version=$(printf '%s' "${response}" | jq --raw-output .name) + VERSION_FILE="${STATE_DIR}/${package}" + + install="false" + if [ -f "${VERSION_FILE}" ]; then + installed_version=$(cat "${VERSION_FILE}") + if [ "${installed_version}" = "${latest_version}" ]; then + echo "Latest version \"${package} ${installed_version}\" is already installed" + else + echo "Upgrading \"${package} ${installed_version}\" -> \"${package} ${latest_version}\"..." + install="true" + fi + else + echo "Installing \"${package} ${latest_version}\"..." + install="true" + fi + + if [ "${install}" = "true" ]; then + asset=$(printf '%s' "${response}" | jq --raw-output ".assets[] | select(.name == \"${resource}\").browser_download_url") + curl --location "${asset}" | "${post_fetch}" && \ + echo "${latest_version}" > "${VERSION_FILE}" && \ + echo "Successfully installed \"${package} ${latest_version}\"" + fi +} + +PKG_DIR="$(systemd-path user-shared)"/github-versions +if [ -d "${PKG_DIR}" ]; then + echo "Starting iteration" + for package in "${PKG_DIR}"/*; do + # shellcheck source=/dev/null + . "${package}" + done +fi diff --git a/.local/bin/upgrade b/.local/bin/upgrade index 1d46f44..65af1db 100755 --- a/.local/bin/upgrade +++ b/.local/bin/upgrade @@ -24,3 +24,4 @@ apt_update pipx_update rustup update cargo_update +ghup diff --git a/.local/share/github-versions/dolt b/.local/share/github-versions/dolt new file mode 100755 index 0000000..72b1559 --- /dev/null +++ b/.local/share/github-versions/dolt @@ -0,0 +1,12 @@ +#! /usr/bin/sh + +package=dolt +repo=dolthub/dolt +resource=dolt-linux-amd64.tar.gz + +install_dolt() { + tar xz --directory="$(systemd-path user-binaries)" --strip-components=2 dolt-linux-amd64/bin/dolt + chmod 550 "$(systemd-path user-binaries)"/dolt +} + +github_update "${package}" "${repo}" "${resource}" install_dolt diff --git a/.local/share/github-versions/rust-analyzer b/.local/share/github-versions/rust-analyzer new file mode 100755 index 0000000..9452be9 --- /dev/null +++ b/.local/share/github-versions/rust-analyzer @@ -0,0 +1,14 @@ +#! /usr/bin/sh + +package=rust-analyzer +repo=rust-lang/rust-analyzer +resource=rust-analyzer-x86_64-unknown-linux-gnu.gz + +install_rust_analyzer() { + tempfile="$(mktemp)" + gunzip --to-stdout - > "${tempfile}" + chmod 550 "${tempfile}" + mv "${tempfile}" "$(systemd-path user-binaries)"/rust-analyzer +} + +github_update "${package}" "${repo}" "${resource}" install_rust_analyzer