Add install script

We are removing the submodules and the expectation that this git
repository exists one's home directory. Instead, the script will copy
the necessary files.

We also are removing the code to install the latest the latest ruby and
nodejs versions on first start from .zshrc. We will do this in
install.sh
This commit is contained in:
Kevin Cotugno 2024-02-15 14:53:01 -07:00
parent 4aae02a647
commit 5cde6657c9
8 changed files with 169 additions and 26 deletions

1
.asdf

@ -1 +0,0 @@
Subproject commit ccdd47df9b73d0a22235eb06ad4c48eb57360832

1
.gitignore vendored
View File

@ -1 +0,0 @@
*

6
.gitmodules vendored
View File

@ -1,6 +0,0 @@
[submodule ".oh-my-zsh"]
path = .oh-my-zsh
url = https://code.cotugno.family/kevin/ohmyzsh.git
[submodule ".asdf"]
path = .asdf
url = https://code.cotugno.family/kevin/asdf.git

@ -1 +0,0 @@
Subproject commit c92af18c36c84cef0c785e1ae9cabc49a61a5c3a

16
.zshrc
View File

@ -68,20 +68,6 @@ fi
mkdir -p "$HOME/.local/bin" && export PATH="$HOME/.local/bin:$PATH" mkdir -p "$HOME/.local/bin" && export PATH="$HOME/.local/bin:$PATH"
function install_asdf_plugins() {
if [[ ! $(command -v asdf) ]]; then return; fi
local asdf_plugins=(ruby nodejs)
foreach plugin in $asdf_plugins; do
if [[ ! -d "$HOME/.asdf/plugins/$plugin" ]]; then
echo "Installing asdf $plugin plugin"
asdf plugin add $plugin https://github.com/asdf-vm/asdf-$plugin.git
asdf install $plugin latest
fi
done
}
function weather() { function weather() {
local loc=$1 local loc=$1
if [[ -z "$loc" ]]; then if [[ -z "$loc" ]]; then
@ -117,5 +103,3 @@ alias l="ls -lah"
alias ll="ls -lh" alias ll="ls -lh"
alias la="ls -lah" alias la="ls -lah"
alias hexenc="hexdump -e '1/1 \"%02x\"'" alias hexenc="hexdump -e '1/1 \"%02x\"'"
install_asdf_plugins

View File

@ -1,4 +1,4 @@
Copyright 2018 Kevin Cotugno Copyright 2018-2024 Kevin Cotugno
Permission is hereby granted, free of charge, to any person obtaining a copy of Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in this software and associated documentation files (the "Software"), to deal in

145
install.sh Executable file
View File

@ -0,0 +1,145 @@
#!/usr/bin/env bash
set -eo pipefail
user=$(whoami)
if [ "x$HOME" = "x" ]; then
echo "HOME must be set"
exit 1
fi
function is_sudo() {
if [ "x$SUDO_UID" != "x" ]; then
echo "Please run without sudo"
exit 1
fi
}
function detect_os() {
# Adapted from https://unix.stackexchange.com/a/6348
if [ -f /etc/os-release ]; then
# freedesktop.org and systemd
. /etc/os-release
OS=Arch
VER=$VERSION_ID
elif type lsb_release >/dev/null 2>&1; then
# linuxbase.org
OS=$(lsb_release -si)
VER=$(lsb_release -sr)
elif [ -f /etc/lsb-release ]; then
# For some versions of Debian/Ubuntu without lsb_release command
. /etc/lsb-release
OS=$DISTRIB_ID
VER=$DISTRIB_RELEASE
elif [ -f /etc/debian_version ]; then
# Older Debian/Ubuntu/etc.
OS=Debian
VER=$(cat /etc/debian_version)
else
# Fall back to uname, e.g. "Linux <version>", also works for BSD, etc.
OS=$(uname -s)
VER=$(uname -r)
fi
OS=$(echo "$OS" | tr '[:upper:]' '[:lower:]')
}
function detect_package_manager() {
local sudo
if [ "x$user" != "xroot" ]; then sudo="sudo "; fi
if [ "x$OS" = "xarch" ]; then
install_package_cmd="${sudo}pacman -S --noconfirm"
check_package_cmd="pacman -Q"
elif [ "x$OS" = "xdebian" ]; then
install_package_cmd="${sudo}apt-get install -y"
elif [ "x$OS" = "darwin" ]; then
if [ "x$user" != "xroot" ]; then
echo "Running as root on macOS is unsupported"
exit 1
fi
install_package_cmd="brew install"
check_package_cmd="brew list --formula"
else
echo "Unknown and unsupported package manager"
exit 1
fi
}
function check_package_installed() {
$check_package_cmd "$1" &>/dev/null || return 1
}
function install_git() {
if check_package_installed lazygit; then
echo "Git is already installed...skipping"
return
fi
echo "Installing git..."
$install_package_cmd lazygit
}
function install_oh_my_zsh() {
local oh_my_zsh_dir="$HOME/.oh-my-zsh"
if [ -d "$oh_my_zsh_dir" ]; then
echo "Oh My Zsh is already installed"
return
fi
echo "Installing Oh My Zsh..."
git -C "$HOME" clone https://code.cotugno.family/kevin/ohmyzsh.git "$(basename "$oh_my_zsh_dir")"
}
function install_asdf() {
local asdf_dir="$HOME/.asdf"
if [ -d "$asdf_dir" ]; then
echo "asdf is already installed"
return
fi
echo "Installing asdf..."
if [ "$OS" = "darwin" ]; then
$install_package_cmd asdf
. "/usr/local/opt/asdf/libexec/asdf.sh"
else
git -C "$HOME" clone https://code.cotugno.family/kevin/asdf.git "$(basename "$asdf_dir")"
git -C "$asdf_dir" checkout "$(git -C "$asdf_dir" describe --tags --abbrev=0)"
. "$asdf_dir/asdf.sh"
fi
}
function setup_asdf() {
local asdf_plugins=(ruby nodejs)
for plugin in ${asdf_plugins[@]}; do
if [[ ! -d "$HOME/.asdf/plugins/$plugin" ]]; then
echo "Installing asdf $plugin plugin"
asdf plugin add "$plugin"
asdf install "$plugin" latest
else
echo "asdf plugin $plugin already installed"
fi
done
}
function install_files() {
for file in $(cat install.txt); do
echo "Installing $file"
if [ "$(dirname "$file")" != "." ]; then
mkdir -p "$HOME/$(dirname "$file")"
fi
cp "$file" "$HOME/$file"
done
}
is_sudo
detect_os
detect_package_manager
install_git
install_oh_my_zsh
install_asdf
setup_asdf
install_files

23
install.txt Normal file
View File

@ -0,0 +1,23 @@
.alacritty.toml
.config/nvim/init.lua
.config/nvim/lazy-lock.json
.config/nvim/lazyvim.json
.config/nvim/lua/config/autocmds.lua
.config/nvim/lua/config/keymaps.lua
.config/nvim/lua/config/lazy.lua
.config/nvim/lua/config/options.lua
.config/nvim/lua/plugins/apex.lua
.config/nvim/lua/plugins/gruvbox.lua
.config/nvim/lua/plugins/neo-tree.lua
.config/nvim/lua/plugins/telescope.lua
.config/nvim/stylua.toml
.emacs.d/init.el
.emacs.d/themes/solarized/LICENSE
.emacs.d/themes/solarized/solarized-definitions.el
.emacs.d/themes/solarized/solarized-theme.el
.local/bin/ansible-become-password
.local/bin/ansible-vault-password
.local/lib/get-env-var.rb
.tmux.conf
.tool-versions
.zshrc