From 7351508b120c4189f6f78ceb209526625e1cb256 Mon Sep 17 00:00:00 2001 From: Evie Litherland-Smith Date: Tue, 16 May 2023 10:11:44 +0100 Subject: [PATCH] Add installer scripts and Makefile Scripts to install neovim, direnv and FiraCode nerd fonts if missing Make file handles calling installers, can clean up after as well --- Makefile | 16 ++++++ installers/direnv.sh | 109 +++++++++++++++++++++++++++++++++++++++++ installers/firacode.sh | 6 +++ installers/nvim.sh | 9 ++++ 4 files changed, 140 insertions(+) create mode 100644 Makefile create mode 100755 installers/direnv.sh create mode 100755 installers/firacode.sh create mode 100755 installers/nvim.sh diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..6cd7fc2 --- /dev/null +++ b/Makefile @@ -0,0 +1,16 @@ +CONFIG_DIR := $(if $(XDG_CONFIG_HOME), $(XDG_CONFIG_HOME), $(HOME)/.config) +BIN_DIR := $(HOME)/.local/bin + +.PHONY: default clean + +default: $(CONFIG_DIR) $(BIN_DIR) + fc-list | grep -iE "(fira.*code)*(nerd.*font)" > /dev/null || ./installers/firacode.sh && fc-cache + command -v nvim > /dev/null || ./installers/nvim.sh + command -v direnv > /dev/null || bin_path="$(BIN_DIR)" ./installers/direnv.sh + +clean: + [ -e $(HOME)/.fonts/FiraCode ] && rm -rf $(HOME)/.fonts/FiraCode + [ -e $(HOME)/.local/share/nvim ] && rm -rf $(HOME)/.local/share/nvim + [ -e $(HOME)/.local/state/nvim ] && rm -rf $(HOME)/.local/state/nvim + [ -e $(BIN_DIR)/nvim ] && rm $(BIN_DIR)/nvim + [ -e $(BIN_DIR)/direnv ] && rm $(BIN_DIR)/direnv diff --git a/installers/direnv.sh b/installers/direnv.sh new file mode 100755 index 0000000..f6796de --- /dev/null +++ b/installers/direnv.sh @@ -0,0 +1,109 @@ +#!/usr/bin/env bash +# +# A good old bash | curl script for direnv. +# +set -euo pipefail + +{ # Prevent execution if this script was only partially downloaded + + log() { + echo "[installer] $*" >&2 + } + + die() { + log "$@" + exit 1 + } + + at_exit() { + ret=$? + if [[ $ret -gt 0 ]]; then + log "the script failed with error $ret.\n" \ + "\n" \ + "To report installation errors, submit an issue to\n" \ + " https://github.com/direnv/direnv/issues/new/choose" + fi + exit "$ret" + } + trap at_exit EXIT + + kernel=$(uname -s | tr "[:upper:]" "[:lower:]") + case "${kernel}" in + mingw*) + kernel=windows + ;; + esac + case "$(uname -m)" in + x86_64) + machine=amd64 + ;; + i686 | i386) + machine=386 + ;; + aarch64 | arm64) + machine=arm64 + ;; + *) + die "Machine $(uname -m) not supported by the installer.\n" \ + "Go to https://direnv for alternate installation methods." + ;; + esac + log "kernel=$kernel machine=$machine" + + : "${use_sudo:=}" + : "${bin_path:=}" + + if [[ -z "$bin_path" ]]; then + log "bin_path is not set, you can set bin_path to specify the installation path" + log "e.g. export bin_path=/path/to/installation before installing" + log "looking for a writeable path from PATH environment variable" + for path in $(echo "$PATH" | tr ':' '\n'); do + if [[ -w $path ]]; then + bin_path=$path + break + fi + done + fi + if [[ -z "$bin_path" ]]; then + die "did not find a writeable path in $PATH" + fi + echo "bin_path=$bin_path" + + if [[ -n "${version:-}" ]]; then + release="tags/${version}" + else + release="latest" + fi + echo "release=$release" + + log "looking for a download URL" + download_url=$( + curl -fL "https://api.github.com/repos/direnv/direnv/releases/$release" \ + | grep browser_download_url \ + | cut -d '"' -f 4 \ + | grep "direnv.$kernel.$machine" + ) + echo "download_url=$download_url" + + log "downloading" + curl -o "$bin_path/direnv" -fL "$download_url" + chmod a+x "$bin_path/direnv" + + cat <