diff --git a/.asdf b/.asdf deleted file mode 160000 index ccdd47d..0000000 --- a/.asdf +++ /dev/null @@ -1 +0,0 @@ -Subproject commit ccdd47df9b73d0a22235eb06ad4c48eb57360832 diff --git a/.gitignore b/.gitignore deleted file mode 100644 index f59ec20..0000000 --- a/.gitignore +++ /dev/null @@ -1 +0,0 @@ -* \ No newline at end of file diff --git a/.gitmodules b/.gitmodules index adda485..e69de29 100644 --- a/.gitmodules +++ b/.gitmodules @@ -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 diff --git a/.oh-my-zsh b/.oh-my-zsh deleted file mode 160000 index c92af18..0000000 --- a/.oh-my-zsh +++ /dev/null @@ -1 +0,0 @@ -Subproject commit c92af18c36c84cef0c785e1ae9cabc49a61a5c3a diff --git a/.zshrc b/.zshrc index edf383b..66d78d9 100644 --- a/.zshrc +++ b/.zshrc @@ -68,20 +68,6 @@ fi 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() { local loc=$1 if [[ -z "$loc" ]]; then @@ -117,5 +103,3 @@ alias l="ls -lah" alias ll="ls -lh" alias la="ls -lah" alias hexenc="hexdump -e '1/1 \"%02x\"'" - -install_asdf_plugins diff --git a/LICENSE b/LICENSE index 59b6960..6d9037b 100644 --- a/LICENSE +++ b/LICENSE @@ -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 this software and associated documentation files (the "Software"), to deal in diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..1cf37de --- /dev/null +++ b/install.sh @@ -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 ", 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 diff --git a/install.txt b/install.txt new file mode 100644 index 0000000..3d68829 --- /dev/null +++ b/install.txt @@ -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