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
This commit is contained in:
Evie Litherland-Smith 2023-05-16 10:11:44 +01:00
parent 2d695e5276
commit 7351508b12
4 changed files with 140 additions and 0 deletions

16
Makefile Normal file
View file

@ -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

109
installers/direnv.sh Executable file
View file

@ -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 <<DONE
The direnv binary is now available in:
$bin_path/direnv
The last step is to configure your shell to use it. For example for bash, add
the following lines at the end of your ~/.bashrc:
eval "\$(direnv hook bash)"
Then restart the shell.
For other shells, see https://direnv.net/docs/hook.html
Thanks!
DONE
}

6
installers/firacode.sh Executable file
View file

@ -0,0 +1,6 @@
mkdir -p $HOME/.fonts
cd $HOME/.fonts
curl -sSLO https://github.com/ryanoasis/nerd-fonts/releases/download/v3.0.0/FiraCode.zip
unzip FiraCode.zip -d FiraCode
rm FiraCode.zip
fc-cache

9
installers/nvim.sh Executable file
View file

@ -0,0 +1,9 @@
curl -sSLO https://github.com/neovim/neovim/releases/download/stable/nvim.appimage
curl -sSLO https://github.com/neovim/neovim/releases/download/stable/nvim.appimage.sha256sum
sha256sum -c nvim.appimage.sha256sum || {
rm nvim.appimage nvim.appimage.sha256sum
exit 1
}
rm nvim.appimage.sha256sum
chmod a+x nvim.appimage
mv nvim.appimage $HOME/.local/bin/nvim