From e5223a45dbd760d45de01b2930a5cff3a27a78f5 Mon Sep 17 00:00:00 2001 From: Andrejus Date: Fri, 16 Apr 2021 00:26:07 +0100 Subject: [PATCH] wip: further cleanup --- .gitignore | 10 +- Dockerfile | 12 +- config.json | 21 ---- files/.bashrc | 6 +- files/.config/alacritty/alacritty.yml | 57 +++++++++ files/.config/fish/config.fish | 4 +- files/.config/fish/functions/.gitignore | 6 + files/.profile | 41 +++--- scripts/_utils.sh | 117 ++++++++---------- scripts/bootstrap.sh | 5 +- scripts/install.d/00-apt-pkglist | 2 + scripts/{install => install.d}/00-apt.sh | 0 scripts/install.d/02-fish.sh | 10 ++ scripts/{install => install.d}/03-ssh.sh | 0 .../{install => install.d}/10-pyenv-pkglist | 0 scripts/{install => install.d}/10-pyenv.sh | 5 +- scripts/{install => install.d}/11-python.sh | 7 +- scripts/install.d/12-poetry.sh | 2 + scripts/install.d/13-nvm.sh | 14 +++ scripts/install.d/14-yarn.sh | 7 ++ scripts/install.d/15-java.sh | 2 + scripts/install.d/16-vim.sh | 24 ++++ scripts/install.d/30-docker.sh | 11 ++ scripts/install.d/31-gcloud.sh | 2 + scripts/install.d/32-firebase.sh | 2 + scripts/install.d/33-aws.sh | 2 + scripts/install.d/34-terraform.sh | 2 + .../{install => install.d}/98-apt-clean.sh | 0 .../{install => install.d}/99-screenfetch.sh | 0 scripts/install.sh | 71 ++++++----- scripts/install/00-apt-pkglist | 4 - scripts/install/02-fish.sh | 15 --- scripts/install/12-poetry.sh | 10 -- scripts/install/13-nvm.sh | 11 -- scripts/install/14-yarn.sh | 9 -- scripts/install/15-java.sh | 6 - scripts/install/16-vim.sh | 18 --- scripts/install/30-docker.sh | 43 ------- scripts/install/31-gcloud.sh | 15 --- scripts/install/32-firebase.sh | 8 -- scripts/install/33-aws.sh | 14 --- scripts/install/34-terraform.sh | 29 ----- scripts/install_config.json | 80 ++++++++++++ scripts/publish.sh | 4 + scripts/run.sh | 13 ++ scripts/setup.sh | 33 ++--- scripts/test.sh | 9 +- tests/run.sh | 3 +- 48 files changed, 405 insertions(+), 361 deletions(-) delete mode 100644 config.json create mode 100644 files/.config/alacritty/alacritty.yml create mode 100644 files/.config/fish/functions/.gitignore create mode 100644 scripts/install.d/00-apt-pkglist rename scripts/{install => install.d}/00-apt.sh (100%) create mode 100755 scripts/install.d/02-fish.sh rename scripts/{install => install.d}/03-ssh.sh (100%) rename scripts/{install => install.d}/10-pyenv-pkglist (100%) rename scripts/{install => install.d}/10-pyenv.sh (68%) rename scripts/{install => install.d}/11-python.sh (64%) create mode 100644 scripts/install.d/12-poetry.sh create mode 100755 scripts/install.d/13-nvm.sh create mode 100755 scripts/install.d/14-yarn.sh create mode 100755 scripts/install.d/15-java.sh create mode 100755 scripts/install.d/16-vim.sh create mode 100755 scripts/install.d/30-docker.sh create mode 100755 scripts/install.d/31-gcloud.sh create mode 100755 scripts/install.d/32-firebase.sh create mode 100755 scripts/install.d/33-aws.sh create mode 100755 scripts/install.d/34-terraform.sh rename scripts/{install => install.d}/98-apt-clean.sh (100%) rename scripts/{install => install.d}/99-screenfetch.sh (100%) delete mode 100644 scripts/install/00-apt-pkglist delete mode 100755 scripts/install/02-fish.sh delete mode 100755 scripts/install/12-poetry.sh delete mode 100755 scripts/install/13-nvm.sh delete mode 100755 scripts/install/14-yarn.sh delete mode 100755 scripts/install/15-java.sh delete mode 100755 scripts/install/16-vim.sh delete mode 100755 scripts/install/30-docker.sh delete mode 100755 scripts/install/31-gcloud.sh delete mode 100755 scripts/install/32-firebase.sh delete mode 100755 scripts/install/33-aws.sh delete mode 100755 scripts/install/34-terraform.sh create mode 100644 scripts/install_config.json create mode 100755 scripts/run.sh mode change 100644 => 100755 tests/run.sh diff --git a/.gitignore b/.gitignore index 8c29169..34b0f94 100644 --- a/.gitignore +++ b/.gitignore @@ -3,13 +3,13 @@ **/logs **/*.deb -# custom functions -!files/.config/fish/functions/nvm.fish +# ssh env +**/id_rsa* +**/known_hosts* # setup files **/plugged **/autoload -**/functions **/completions **/conf.d **/fish_variables @@ -20,7 +20,3 @@ **/TabNine **/firebase **/pypoetry - -# ssh env -**/id_rsa* -**/known_hosts* diff --git a/Dockerfile b/Dockerfile index 2d00845..8235c52 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,12 @@ # -# ubuntu-base: Base Ubuntu image with sudo user +# debian-buster: Base Debian image with sudo user # -FROM ubuntu:focal AS ubuntu-base +FROM debian:buster AS debian-base RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections ENV DEBIAN_FRONTEND noninteractive -RUN apt-get -qy update -RUN apt-get -qy install --no-install-recommends \ +RUN apt-get -qq update +RUN apt-get -qq install --no-install-recommends \ apt-utils software-properties-common sudo # Create user with sudo priviledge @@ -19,7 +19,7 @@ RUN echo "test-user ALL=(ALL) NOPASSWD: ALL" \ # # source: Source steps # -FROM ubuntu-base AS source +FROM debian-base AS source ARG DOTFILES_DIR="/home/test-user/.dotfiles" ADD --chown="test-user" . "$DOTFILES_DIR" @@ -33,7 +33,7 @@ FROM source AS install USER test-user ENV USER=test-user -ENV UUID="docker" +ARG UUID="docker" RUN ./scripts/install.sh diff --git a/config.json b/config.json deleted file mode 100644 index 9bb9624..0000000 --- a/config.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "apt_dependencies": [ - "bat", - "curl", - "cowsay", - "fd-find", - "figlet", - "fortune-mod", - "git", - "gnupg2", - "jq", - "make", - "neovim", - "net-tools", - "openssh-client", - "openssh-server", - "screenfetch", - "stow", - "tmux" - ] -} diff --git a/files/.bashrc b/files/.bashrc index 7871ed1..b7119dc 100644 --- a/files/.bashrc +++ b/files/.bashrc @@ -1,3 +1,3 @@ -[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm -[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion -[ -f ~/.fzf.bash ] && source ~/.fzf.bash +# Load nvm bash dependency +[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm +[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion diff --git a/files/.config/alacritty/alacritty.yml b/files/.config/alacritty/alacritty.yml new file mode 100644 index 0000000..c3c1914 --- /dev/null +++ b/files/.config/alacritty/alacritty.yml @@ -0,0 +1,57 @@ +# env: +# TERM: xterm-256color + +window: + dynamic_title: true + dynamic_padding: true + decorations: None + startup_mode: Windowed + + padding: + x: 7 + y: 7 + +scrolling: + history: 10000 + multiplier: 3 + +font: + size: 9.0 + normal: + family: FiraCode Nerd Font Mono + style: Regular + + bold: + family: FiraCode Nerd Font Mono + style: Bold + + italic: + family: FiraSansCondensed NF + style: Italic + + bold_italic: + family: FiraSansCondensed NF + style: Bold Italic + +draw_bold_text_with_bright_colors: false +background_opacity: 0.95 + +cursor: + style: Beam + unfocused_hollow: true + +live_config_reload: true + +shell: + program: /usr/bin/fish + args: + - --interactive + - --login + +key_bindings: + - { key: V, mods: Control|Shift, action: Paste } + - { key: C, mods: Control|Shift, action: Copy } + - { key: Insert, mods: Shift, action: PasteSelection } + - { key: Key0, mods: Control, action: ResetFontSize } + - { key: Plus, mods: Control, action: IncreaseFontSize } + - { key: Minus, mods: Control, action: DecreaseFontSize } diff --git a/files/.config/fish/config.fish b/files/.config/fish/config.fish index 0f526b9..b47f13e 100644 --- a/files/.config/fish/config.fish +++ b/files/.config/fish/config.fish @@ -1,5 +1,6 @@ # Only execute in interactive shell -if status --is-interactive +if status is-interactive + # Fish specific set fish_greeting set --global hydro_symbol_prompt "\$" @@ -12,4 +13,5 @@ if status --is-interactive if begin; test -e $HOME/.profile; and type -q replay; end replay "source $HOME/.profile" end + end diff --git a/files/.config/fish/functions/.gitignore b/files/.config/fish/functions/.gitignore new file mode 100644 index 0000000..fbe730d --- /dev/null +++ b/files/.config/fish/functions/.gitignore @@ -0,0 +1,6 @@ +# Ignore all +**/* +!.gitignore + +# Keep custom functions +!nvm.fish diff --git a/files/.profile b/files/.profile index 1bcbe86..dc1bc8e 100644 --- a/files/.profile +++ b/files/.profile @@ -6,30 +6,23 @@ # << >> || \\,-.// # (__) (__)(_") (_/(__) # + # set PATH so it includes user's private bin -export PATH="$HOME/bin:$PATH" export PATH="$HOME/.local/bin:$PATH" +mkdir -p ~/.local/bin # xdg data & config -if [ -z "$XDG_DATA_HOME" ]; then - export XDG_DATA_HOME="$HOME/.local/share" -fi +export XDG_DATA_HOME=${XDG_DATA_HOME:-"$HOME/.local/share"} mkdir -p "$XDG_DATA_HOME" -if [ -z "$XDG_CONFIG_HOME" ]; then - export XDG_CONFIG_HOME="$HOME/.config" -fi +export XDG_CONFIG_HOME=${XDG_CONFIG_HOME:-"$HOME/.config"} mkdir -p "$XDG_CONFIG_HOME" # workspace -if [ -z "$WORKSPACE" ]; then - export WORKSPACE="$HOME/workspace" -fi +export WORKSPACE=${WORKSPACE:-"$HOME/workspace"} mkdir -p "$WORKSPACE" # dotfiles -if [ -z "$DOTFILES" ]; then - export DOTFILES="$HOME/.dotfiles" -fi +export DOTFILES=${DOTFILES:-"$HOME/.dotfiles"} # pyenv export PYENV_ROOT="$HOME/.pyenv" @@ -43,14 +36,12 @@ export POETRY_ROOT="$HOME/.poetry" export PATH="$POETRY_ROOT/bin:$PATH" # nvm -if [ -z "$NVM_DIR" ]; then - export NVM_DIR="$HOME/.nvm" -fi +export NVM_DIR=${NVM_DIR:-"$HOME/.nvm"} mkdir -p "$NVM_DIR" export PATH="$NVM_DIR/bin:$PATH" # yarn -export YARN_DIR="$HOME/.yarn" +export YARN_DIR=${YARN_DIR:-"$HOME/.yarn"} mkdir -p "$YARN_DIR" export PATH="$YARN_DIR/bin:$PATH" @@ -63,9 +54,17 @@ export FZF_DEFAULT_OPTS="--reverse" export FZF_DEFAULT_COMMAND='fdfind --type f --hidden --follow --exclude .git' export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND" export FZF_COMPLETION_TRIGGER='**' +[ -f ~/.fzf.bash ] && source ~/.fzf.bash + +# z (jump around) +export Z_DATA_DIR=${Z_DATA:-"$XDG_DATA_HOME/z"} +export Z_DATA=${Z_DATA:-"$Z_DATA_DIR/data"} +export Z_OWNER=${Z_OWNER:-$USER} # nix -if [ -e ~/.nix-profile/etc/profile.d/nix.sh ]; then . ~/.nix-profile/etc/profile.d/nix.sh; fi +if [ -e $HOME/.nix-profile/etc/profile.d/nix.sh ]; then + . $HOME/.nix-profile/etc/profile.d/nix.sh +fi # _ _ _ ____ # U /"\ u |"| ___ U /"\ u / __"| u @@ -75,10 +74,4 @@ if [ -e ~/.nix-profile/etc/profile.d/nix.sh ]; then . ~/.nix-profile/etc/profile # \\ >> // \\.-,_|___|_,-.\\ >> )( (__) # (__) (__)(_")("_)\_)-' '-(_/(__) (__)(__) # -alias vim='nvim' -alias vi='vim' - -alias bat='batcat' -alias cat='bat' - alias j="z" diff --git a/scripts/_utils.sh b/scripts/_utils.sh index b09ddbc..d6a2b93 100755 --- a/scripts/_utils.sh +++ b/scripts/_utils.sh @@ -1,78 +1,67 @@ #!/usr/bin/env bash -function apt_update { - sudo apt-get update -} +# Utility functions for common tasks -# @arg $1 debian package to install if not present -function apt_install { - if ! dpkg -s $1; then - sudo apt-get install -y $1 - fi -} - -# ---------------------------------------------------------------------------- # -# Helper functions -# ---------------------------------------------------------------------------- # -clean() { - sudo apt-get clean -} - -update() { - apt_update -} - -# @arg $1 packages to install -install() { - apt_install $1 - refresh -} - -# @arg $1 package list file to install -install_file() { - sudo apt-get install -qqyf $(cat $1) - refresh -} - -# @arg $1 repository to add -add_ppa() { - sudo add-apt-repository -y ppa:$1 -} - -# @arg $1 url to add -# @arg $2 keyring to add to -add_key() { - curl -fsSL $1 \ - | sudo gpg --no-default-keyring --keyring $2 --import - +# @arg $1 URL to download +# @arg $2 Path to file +function download_file { + curl \ + --silent \ + --show-error \ + --location \ + --output $2 \ + $1 } # @arg $1 URL to run # @arg $2 binary to use -run() { - curl -fsSL $1 | $2 -} - -# Symlink contents of source folder to target -# -# @arg $1 source folder -# @arg $2 target folder -link_folder() { - mkdir -p $2 - cp -srf $1/. $2 +function download_run { + file=$(mktemp) + download_file $1 $file + cat $file | $2 } # @arg $1 binary to test -not_installed() { - ! [ -x "$(command -v $1)" ] +function bin_in_path { + command -v $1 } -# Refreshes PATH -refresh() { - hash -r +# @arg $1 apt package to test +function apt_installed { + dpkg --status $1 } -# Add to PATH and refresh -# @arg $1 path to add to PATH -add_path() { - export PATH="$1:$PATH" - refresh +function clean { + sudo apt-get clean -qq +} + +function update { + sudo apt-get update -qq +} + +# @arg $1 apt package to install if not present +function install { + if ! apt_installed $1; then + sudo apt-get install -qq $1 + fi +} + +# Add apt repository +# @arg $1 JSON object containing the following keys +# * repository - apt repository +# * signingKey - gpg signing key url +# * components - apt components +function add_repository { + repository=$(jq -r ".repository" <<<"$1") + if ! grep -q "^deb .*${repository}" /etc/apt/sources.list; then + signingKey=$(jq -r ".signingKey" <<<"$1") + components=$(jq -r ".components" <<<"$1") + curl -fsSL $signingKey | sudo apt-key add - + source="deb [arch=$(dpkg --print-architecture)] ${repository} ${components}" + sudo add-apt-repository --yes "$source" + fi +} + +# @arg $1 package list file to install +function install_file { + sudo apt-get install -qqf $(cat $1) } diff --git a/scripts/bootstrap.sh b/scripts/bootstrap.sh index 9ad8030..28d7cea 100755 --- a/scripts/bootstrap.sh +++ b/scripts/bootstrap.sh @@ -1,7 +1,10 @@ #!/usr/bin/env bash set -eo pipefail -NAME=`basename "$0"` +# +# Script that stows all tracked dotfiles into the user's home directory. +# + REL_DIR=`dirname "$0"` ABS_DIR=`readlink -f $REL_DIR/../` # Scripts are nested inside of /scripts diff --git a/scripts/install.d/00-apt-pkglist b/scripts/install.d/00-apt-pkglist new file mode 100644 index 0000000..2bc2679 --- /dev/null +++ b/scripts/install.d/00-apt-pkglist @@ -0,0 +1,2 @@ +bat +ripgrep diff --git a/scripts/install/00-apt.sh b/scripts/install.d/00-apt.sh similarity index 100% rename from scripts/install/00-apt.sh rename to scripts/install.d/00-apt.sh diff --git a/scripts/install.d/02-fish.sh b/scripts/install.d/02-fish.sh new file mode 100755 index 0000000..3f60092 --- /dev/null +++ b/scripts/install.d/02-fish.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash +fish --version + +fisher_location="$XDG_CONFIG_HOME/fish/functions/fisher.fish" +if ! [ -f $fisher_location ]; then + fish -c "curl -sL https://git.io/fisher | source && fisher install jorgebucaran/fisher" +fi + +fish -c "fisher update" +fish -c "fisher --version" diff --git a/scripts/install/03-ssh.sh b/scripts/install.d/03-ssh.sh similarity index 100% rename from scripts/install/03-ssh.sh rename to scripts/install.d/03-ssh.sh diff --git a/scripts/install/10-pyenv-pkglist b/scripts/install.d/10-pyenv-pkglist similarity index 100% rename from scripts/install/10-pyenv-pkglist rename to scripts/install.d/10-pyenv-pkglist diff --git a/scripts/install/10-pyenv.sh b/scripts/install.d/10-pyenv.sh similarity index 68% rename from scripts/install/10-pyenv.sh rename to scripts/install.d/10-pyenv.sh index 9dcb604..14d8d01 100755 --- a/scripts/install/10-pyenv.sh +++ b/scripts/install.d/10-pyenv.sh @@ -1,15 +1,14 @@ #!/usr/bin/env bash -if not_installed "pyenv"; then +if ! bin_in_path "pyenv"; then # see https://github.com/pyenv/pyenv/wiki/common-build-problems pyenv_list_file="$INSTALL_DIR/10-pyenv-pkglist" install_file "$pyenv_list_file" # see https://github.com/pyenv/pyenv-installer - run "https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer" \ + download_run "https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer" \ bash fi -export PATH="$HOME/.pyenv/bin:$PATH" eval "$(pyenv init -)" eval "$(pyenv virtualenv-init -)" diff --git a/scripts/install/11-python.sh b/scripts/install.d/11-python.sh similarity index 64% rename from scripts/install/11-python.sh rename to scripts/install.d/11-python.sh index df5c72e..9999c6e 100755 --- a/scripts/install/11-python.sh +++ b/scripts/install.d/11-python.sh @@ -1,13 +1,16 @@ #!/usr/bin/env bash export PYTHON_KEYRING_BACKEND=keyring.backends.null.Keyring -if not_installed "pip3"; then +if ! bin_in_path "pip3"; then pyenv install 3.9.0 pyenv global 3.9.0 - refresh fi pip install --upgrade pip pip3 install --upgrade pip python3 --version pip3 --version + +for dep in `jq -r ".pip_dependencies[]" $CONFIG`; do + pip3 install --upgrade $dep +done diff --git a/scripts/install.d/12-poetry.sh b/scripts/install.d/12-poetry.sh new file mode 100644 index 0000000..bceaead --- /dev/null +++ b/scripts/install.d/12-poetry.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +poetry --version diff --git a/scripts/install.d/13-nvm.sh b/scripts/install.d/13-nvm.sh new file mode 100755 index 0000000..a526a50 --- /dev/null +++ b/scripts/install.d/13-nvm.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash +nvm_version="v0.38.0" +if ! bin_in_path "nvm"; then + download_run "https://raw.githubusercontent.com/nvm-sh/nvm/${nvm_version}/install.sh" \ + "bash" +fi + +[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm + +nvm --version +nvm install node +nvm use node + +node --version diff --git a/scripts/install.d/14-yarn.sh b/scripts/install.d/14-yarn.sh new file mode 100755 index 0000000..81c5477 --- /dev/null +++ b/scripts/install.d/14-yarn.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +yarn --version + +for dep in `jq -r ".node_dependencies[]" $CONFIG`; do + yarn global add $dep + yarn global upgrade $dep +done diff --git a/scripts/install.d/15-java.sh b/scripts/install.d/15-java.sh new file mode 100755 index 0000000..0fdcee5 --- /dev/null +++ b/scripts/install.d/15-java.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +java --version diff --git a/scripts/install.d/16-vim.sh b/scripts/install.d/16-vim.sh new file mode 100755 index 0000000..bb04f36 --- /dev/null +++ b/scripts/install.d/16-vim.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash + +# Install neovim from unstable debian repo +echo "deb http://deb.debian.org/debian unstable main" \ + | sudo tee /etc/apt/sources.list.d/unstable.list +echo "Package: neovim +Pin: release a=unstable +Pin-Priority: 900" \ + | sudo tee /etc/apt/preferences.d/neovim +update +install neovim + +mkdir -p "$XDG_DATA_HOME/nvim/backup" +plug_dir="$XDG_DATA_HOME/nvim/site/autoload" +mkdir -p "$plug_dir" +plug_target="$plug_dir/plug.vim" +if [ ! -f $plug_target ]; then + download_file \ + https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim \ + "$plug_target" +fi + +nvim --headless +UpdateRemotePlugins +PlugClean! +PlugInstall +PlugUpgrade +PlugUpdate +qall +nvim --version diff --git a/scripts/install.d/30-docker.sh b/scripts/install.d/30-docker.sh new file mode 100755 index 0000000..70a6ebd --- /dev/null +++ b/scripts/install.d/30-docker.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash +docker --version + +readonly docker_group="docker" +if ! grep -q "$docker_group" /etc/group; then + sudo groupadd "$docker_group" +fi + +if ! groups "$USER" | grep -q "\b$docker_group\b"; then + sudo usermod -aG docker "$USER" +fi diff --git a/scripts/install.d/31-gcloud.sh b/scripts/install.d/31-gcloud.sh new file mode 100755 index 0000000..d6675f1 --- /dev/null +++ b/scripts/install.d/31-gcloud.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +gcloud --version diff --git a/scripts/install.d/32-firebase.sh b/scripts/install.d/32-firebase.sh new file mode 100755 index 0000000..ed19a2a --- /dev/null +++ b/scripts/install.d/32-firebase.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +firebase --version diff --git a/scripts/install.d/33-aws.sh b/scripts/install.d/33-aws.sh new file mode 100755 index 0000000..bfb313c --- /dev/null +++ b/scripts/install.d/33-aws.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +aws --version diff --git a/scripts/install.d/34-terraform.sh b/scripts/install.d/34-terraform.sh new file mode 100755 index 0000000..9cfbcc4 --- /dev/null +++ b/scripts/install.d/34-terraform.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +terraform --version diff --git a/scripts/install/98-apt-clean.sh b/scripts/install.d/98-apt-clean.sh similarity index 100% rename from scripts/install/98-apt-clean.sh rename to scripts/install.d/98-apt-clean.sh diff --git a/scripts/install/99-screenfetch.sh b/scripts/install.d/99-screenfetch.sh similarity index 100% rename from scripts/install/99-screenfetch.sh rename to scripts/install.d/99-screenfetch.sh diff --git a/scripts/install.sh b/scripts/install.sh index 5cff4fe..5c0fca7 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -1,18 +1,26 @@ #!/usr/bin/env bash set -eo pipefail -TIME=${TIME:-`date`} -UUID=${UUID:-`uuidgen`} -HOST=${HOST:-`hostname`} +# +# Script that installs system dependencies specified in a config, +# and runs all post-install scripts contained in a subdirectory. +# -NAME=`basename "$0"` -REL_DIR=`dirname "$0"` -ABS_DIR=`readlink -f $REL_DIR/../` # Scripts are nested inside of /scripts +TIME=${TIME:-$(date)} +UUID=${UUID:-$(uuidgen)} +HOST=${HOST:-$(hostname)} -LOG_DIR="$ABS_DIR/logs" -mkdir -p $LOG_DIR -LOG_TARGET=${LOG_TARGET:-$LOG_DIR/$UUID.log} +NAME=$(basename "$0") +REL_DIR=$(dirname "$0") +ABS_DIR=$(readlink -f $REL_DIR/../) # Scripts are nested inside of /scripts +UTILS="${REL_DIR}/_utils.sh" +CONFIG="${REL_DIR}/install_config.json" +INSTALL_DIR="${REL_DIR}/install.d" + +LOG_DIR="${ABS_DIR}/logs" +mkdir -p "$LOG_DIR" +LOG_TARGET=${LOG_TARGET:-"${LOG_DIR}/${UUID}.log"} main() { echo "Running $NAME at $TIME" @@ -24,31 +32,38 @@ main() { exit 1 fi - echo "Loading utils" - source $REL_DIR/_utils.sh - - apt_update - - echo "Installing jq..." - apt_install jq - - echo "Installing apt dependencies..." - for dep in `jq -r ".apt_dependencies[]" $ABS_DIR/config.json`; do - apt_install $dep + # Load installer dependencies + source "$UTILS" + update + install jq + for dep in $(jq -r ".apt_core_dependencies[]" "$CONFIG"); do + install "$dep" done - figlet -c "bootstrapping..." - $ABS_DIR/scripts/bootstrap.sh - source $HOME/.profile + # Add apt repositories + for i in $(jq ".apt_repositories | keys | .[]" "$CONFIG"); do + value=$(jq -r ".apt_repositories[$i]" "$CONFIG") + add_repository "$value" + done + update - figlet -c "installing..." - export INSTALL_DIR="$REL_DIR/install" + # Install apt dependencies + for dep in $(jq -r ".apt_dependencies[]" "$CONFIG"); do + install "$dep" + done + + # Install dotfiles on system and load them + figlet -c "Bootstrapping..." + $ABS_DIR/scripts/bootstrap.sh + source "$HOME/.profile" + + # Run custom installer scripts + figlet -c "Installing..." for script in $INSTALL_DIR/*.sh; do - figlet -c `basename $script` + figlet -c "$(basename $script)" source $script done - } echo "main: Logging to $LOG_TARGET" -main 2>&1 |tee $LOG_TARGET +main 2>&1 | tee "$LOG_TARGET" diff --git a/scripts/install/00-apt-pkglist b/scripts/install/00-apt-pkglist deleted file mode 100644 index dc5ae72..0000000 --- a/scripts/install/00-apt-pkglist +++ /dev/null @@ -1,4 +0,0 @@ -apt-transport-https -software-properties-common -ripgrep -universal-ctags diff --git a/scripts/install/02-fish.sh b/scripts/install/02-fish.sh deleted file mode 100755 index 5b32c08..0000000 --- a/scripts/install/02-fish.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env bash -if not_installed "fish"; then - add_ppa "fish-shell/release-3" - update - install fish -fi -fish --version - -fisher_location="$HOME/.config/fish/functions/fisher.fish" -if ! [ -f "$fisher_location" ]; then - curl https://git.io/fisher --create-dirs -sLo "$fisher_location" - fish -c "fisher install jorgebucaran/fisher" -fi - -fish -c "fisher --version" diff --git a/scripts/install/12-poetry.sh b/scripts/install/12-poetry.sh deleted file mode 100755 index 73c87fb..0000000 --- a/scripts/install/12-poetry.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env bash -export PYTHON_KEYRING_BACKEND=keyring.backends.null.Keyring -add_path "$HOME/.local/bin" - -if not_installed "poetry"; then - pip3 install --user poetry -fi - -pip3 install --upgrade poetry -poetry --version diff --git a/scripts/install/13-nvm.sh b/scripts/install/13-nvm.sh deleted file mode 100755 index a840577..0000000 --- a/scripts/install/13-nvm.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bash -run "https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh" \ - "bash" - -[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm - -nvm --version -nvm install node -nvm use node - -node --version diff --git a/scripts/install/14-yarn.sh b/scripts/install/14-yarn.sh deleted file mode 100755 index ef25ac3..0000000 --- a/scripts/install/14-yarn.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env bash -if not_installed "yarn"; then - add_key https://dl.yarnpkg.com/debian/pubkey.gpg - echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list - update - sudo apt install --no-install-recommends yarn -fi - -yarn --version diff --git a/scripts/install/15-java.sh b/scripts/install/15-java.sh deleted file mode 100755 index da89aa6..0000000 --- a/scripts/install/15-java.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env bash -if not_installed "java"; then - install default-jre -fi - -java --version diff --git a/scripts/install/16-vim.sh b/scripts/install/16-vim.sh deleted file mode 100755 index 2b950a8..0000000 --- a/scripts/install/16-vim.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/env bash -export PYTHON_KEYRING_BACKEND=keyring.backends.null.Keyring - -mkdir -p "$XDG_DATA_HOME/nvim/backup" -plug_target="$XDG_DATA_HOME/nvim/site/autoload/plug.vim" -if [ ! -f $plug_target ]; then - echo "Downloading vim-plug to $plug_target"; - curl -fLo "$plug_target" --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim -fi - -echo "Installing neovim support"; -pip3 install --user neovim pynvim 'python-language-server[all]' -nvm use default -npm install -g neovim - -echo "Running PlugInstall"; -nvim --headless +UpdateRemotePlugins +PlugClean! +PlugInstall +PlugUpgrade +PlugUpdate +qall -nvim --version diff --git a/scripts/install/30-docker.sh b/scripts/install/30-docker.sh deleted file mode 100755 index 208befe..0000000 --- a/scripts/install/30-docker.sh +++ /dev/null @@ -1,43 +0,0 @@ -#!/usr/bin/env bash -DOCKER_FOLDER="$HOME/.docker" -if not_installed "docker"; then - mkdir -p "$DOCKER_FOLDER" - - # Requirements - install apt-transport-https ca-certificates curl gnupg-agent \ - software-properties-common - - # Add repository - distro=$(lsb_release -si | tr "[:upper:]" "[:lower:]") # cast to lowercase - add_key "https://download.docker.com/linux/$distro/gpg" \ - "gnupg-ring:/etc/apt/trusted.gpg.d/docker-apt-key.gpg" - sudo add-apt-repository -y \ - "deb [arch=amd64] https://download.docker.com/linux/$distro \ - $(lsb_release -cs) \ - stable" - update - - # Install - install docker-ce - - # Chown - sudo chown "$USER":"$USER" "$DOCKER_FOLDER" -R - sudo chmod g+rwx "$DOCKER_FOLDER" -R - -fi -docker --version - -if not_installed "docker-compose"; then - pip3 install --user docker-compose -fi -pip3 install --upgrade docker-compose -docker-compose --version - -readonly docker_group="docker" -if ! grep -q "$docker_group" /etc/group; then - sudo groupadd "$docker_group" -fi - -if ! groups "$USER" | grep -q "\b$docker_group\b"; then - sudo usermod -aG docker "$USER" -fi diff --git a/scripts/install/31-gcloud.sh b/scripts/install/31-gcloud.sh deleted file mode 100755 index f1b25f3..0000000 --- a/scripts/install/31-gcloud.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env bash -if not_installed "gcloud"; then - echo "Installing gcloud..." - # Add the Cloud SDK distribution URI as a package source - echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] http://packages.cloud.google.com/apt cloud-sdk main" \ - | sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list - # Import the Google Cloud Platform public key - curl https://packages.cloud.google.com/apt/doc/apt-key.gpg \ - | sudo apt-key --keyring /usr/share/keyrings/cloud.google.gpg add - - update - install google-cloud-sdk - refresh -fi - -gcloud --version diff --git a/scripts/install/32-firebase.sh b/scripts/install/32-firebase.sh deleted file mode 100755 index cdd1e0c..0000000 --- a/scripts/install/32-firebase.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env bash -if not_installed "firebase"; then - run "https://firebase.tools" "bash" -fi - -echo "firebase is installed, upgrading..." -curl -sL firebase.tools | upgrade=true bash -firebase --version diff --git a/scripts/install/33-aws.sh b/scripts/install/33-aws.sh deleted file mode 100755 index d96dc64..0000000 --- a/scripts/install/33-aws.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env bash -curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" -temp_dir=$(mktemp -d) -unzip awscliv2.zip -d "$temp_dir" -rm awscliv2.zip - -if not_installed "aws"; then - echo "Installing awscli..." - sudo $temp_dir/aws/install -fi - -echo "awscli is installed, upgrading..." -sudo $temp_dir/aws/install --update -aws --version diff --git a/scripts/install/34-terraform.sh b/scripts/install/34-terraform.sh deleted file mode 100755 index e5f20bf..0000000 --- a/scripts/install/34-terraform.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env bash -tf_version="0.14.6" -if not_installed "terraform"; then - echo "Installing terraform..." - tf_archive="terraform_${tf_version}_linux_amd64.zip" - wget "https://releases.hashicorp.com/terraform/${tf_version}/${tf_archive}" - unzip "$tf_archive" -d "$dotfiles_dir/tmp" - rm "$tf_archive" - mkdir -p ~/.local/bin - mv "$dotfiles_dir/tmp/terraform" ~/.local/bin - rm "$dotfiles_dir/tmp/terraform" -fi - -echo "terraform is installed" -terraform --version - -tf_lsp_version="0.13.0" -if not_installed "terraform-ls"; then - echo "Installing terraform-ls..." - tf_lsp_archive="terraform-ls_${tf_lsp_version}_linux_amd64.zip" - wget "https://releases.hashicorp.com/terraform-ls/${tf_lsp_version}/${tf_lsp_archive}" - unzip "${tf_lsp_archive}" -d "$dotfiles_dir/tmp" - rm "${tf_lsp_archive}" - mkdir -p ~/.local/bin - mv "$dotfiles_dir/tmp/terraform-ls" ~/.local/bin - rm "$dotfiles_dir/tmp/terraform-ls" -fi - -echo "terraform-lsp is installed" diff --git a/scripts/install_config.json b/scripts/install_config.json new file mode 100644 index 0000000..db8652b --- /dev/null +++ b/scripts/install_config.json @@ -0,0 +1,80 @@ +{ + "apt_repositories": [ + { + "signingKey": "https://apt.releases.hashicorp.com/gpg", + "repository": "https://apt.releases.hashicorp.com", + "components": "buster main" + }, + { + "signingKey": "https://dl.yarnpkg.com/debian/pubkey.gpg", + "repository": "https://dl.yarnpkg.com/debian", + "components": "stable main" + }, + { + "signingKey": "https://packages.cloud.google.com/apt/doc/apt-key.gpg", + "repository": "https://packages.cloud.google.com/apt", + "components": "cloud-sdk main" + }, + { + "signingKey": "https://packages.cloud.google.com/apt/doc/apt-key.gpg", + "repository": "https://apt.kubernetes.io/", + "components": "kubernetes-xenial main" + }, + { + "signingKey": "https://download.docker.com/linux/debian/gpg", + "repository": "https://download.docker.com/linux/debian", + "components": "buster stable" + }, + { + "signingKey": "https://download.opensuse.org/repositories/shells:fish/Debian_10/Release.key", + "repository": "https://download.opensuse.org/repositories/shells:/fish/Debian_10/", + "components": "/" + } + ], + "apt_core_dependencies": [ + "curl", + "gnupg", + "gnupg2" + ], + "apt_dependencies": [ + "apt-transport-https", + "ca-certificates", + "containerd.io", + "cowsay", + "default-jre", + "devscripts", + "docker-ce", + "docker-ce-cli", + "fd-find", + "figlet", + "fish", + "fortune-mod", + "google-cloud-sdk", + "git", + "kubectl", + "lsb-release", + "make", + "net-tools", + "openssh-client", + "openssh-server", + "screenfetch", + "stow", + "terraform", + "terraform-ls", + "tmux", + "unzip", + "yarn" + ], + "node_dependencies": [ + "firebase-tools", + "neovim" + ], + "pip_dependencies": [ + "awscli", + "docker-compose", + "neovim", + "poetry", + "python-language-server[all]", + "pyvim" + ] +} \ No newline at end of file diff --git a/scripts/publish.sh b/scripts/publish.sh index a070b6b..18c1bca 100644 --- a/scripts/publish.sh +++ b/scripts/publish.sh @@ -1,4 +1,8 @@ #!/usr/bin/env bash set -eo pipefail +# +# Script that publishes the set up script for new installations. +# + echo "Publishing..." diff --git a/scripts/run.sh b/scripts/run.sh new file mode 100755 index 0000000..259fcc0 --- /dev/null +++ b/scripts/run.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash +set -euo pipefail + +tag=$(uuidgen) +docker build . \ + --build-arg UUID=$tag \ + --tag dotfiles:$tag \ + --target install + +docker run \ + -v "$(pwd)"/logs:/home/test-user/.dotfiles/logs \ + dotfiles:$tag + /bin/bash diff --git a/scripts/setup.sh b/scripts/setup.sh index f9f461b..6127a2b 100755 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -1,29 +1,34 @@ #!/usr/bin/env bash set -eo pipefail -# GitHub repository details -AUTHOR=${AUTHOR:-andrejusk} -REPOSITORY=${REPOSITORY:-dotfiles} -BRANCH=${BRANCH:-master} -echo "Using repository $AUTHOR/$REPOSITORY at $BRANCH" +# +# Script that checks out a compatible dotfiles repository +# and runs the installer to set up a new installation. +# -# Target folder to checkout to -DOTFILES_DIR=${DOTFILES_DIR:-$HOME/.dotfiles} -mkdir -p $DOTFILES_DIR -if [ -z `ls -A $DOTFILES_DIR` ]; then - echo "Setting up $DOTFILES_DIR" +author=${GITHUB_AUTHOR:-andrejusk} +repository=${GITHUB_REPOSITORY:-dotfiles} +branch=${GITHUB_BRANCH:-master} +echo "Using repository $author/$repository at $branch" + +setup_dir=${DOTFILES_DIR:-$HOME/.dotfiles} + +# Prevent overwriting existing installation +mkdir -p $setup_dir +if [ -z `ls -A $setup_dir` ]; then + echo "Setting up $setup_dir" else - echo "Failed: Setup directory not empty $DOTFILES_DIR" + echo "Failed: Setup directory not empty $setup_dir" exit 1 fi # Download and untar repo tmp_dir=`mktemp -d` tmp_dest="$tmp_dir/dotfiles.tar.gz" -wget "https://github.com/$AUTHOR/$REPOSITORY/archive/$BRANCH.tar.gz" -qO $tmp_dest +wget "https://github.com/$author/$repository/archive/$branch.tar.gz" -qO $tmp_dest tar -C $tmp_dir -zxf $tmp_dest -mv $tmp_dir/$REPOSITORY-$BRANCH/* $DOTFILES_DIR +mv $tmp_dir/$repository-$branch/* $setup_dir rm -rf $tmp_dir echo "Done!" -$DOTFILES_DIR/scripts/install.sh +$setup_dir/scripts/install.sh diff --git a/scripts/test.sh b/scripts/test.sh index efbaf93..ec9bfc6 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -1,9 +1,12 @@ #!/usr/bin/env bash set -euo pipefail -tag=`uuidgen` +tag=$(uuidgen) docker build . \ - -t dotfiles:$tag \ + --build-arg UUID=$tag \ + --tag dotfiles:$tag \ --target test -docker run dotfiles:$tag +docker run \ + -v "$(pwd)"/logs:/home/test-user/.dotfiles/logs \ + dotfiles:$tag diff --git a/tests/run.sh b/tests/run.sh old mode 100644 new mode 100755 index 99e15bc..defd17d --- a/tests/run.sh +++ b/tests/run.sh @@ -1,5 +1,4 @@ #!/usr/bin/env bash set -euo pipefail -poetry install -poetry run pytest +bash -l -c "poetry install && poetry run pytest"