From 18689abd7388b2c765017c1b49c73690e4af9214 Mon Sep 17 00:00:00 2001 From: Andrejus Date: Fri, 9 Apr 2021 22:04:33 +0100 Subject: [PATCH 01/14] wip: dir organisation, script cleanup --- .dockerignore | 1 - .github/workflows/ci.yml | 11 ++ .github/workflows/main.yml | 10 -- .github/workflows/publish.yml | 14 ++ .gitignore | 14 +- Dockerfile | 54 ++++--- Makefile | 35 ----- README.md | 33 ++--- bootstrap.pl | 26 ---- config.json | 21 +++ files/.config/nvim/plugins.vim | 9 ++ files/.profile | 1 - install.pl | 62 -------- install/00-apt-pkglist | 19 --- install/00-apt.sh | 13 -- install/10-pyenv.sh | 24 ---- install/13-nvm.sh | 25 ---- install/14-yarn.sh | 18 --- install/17-elm.sh | 41 ------ install/35-kubectl.sh | 16 --- install/98-apt-clean.sh | 5 - install/99-screenfetch.sh | 11 -- install/utils.sh | 112 --------------- modules/published-dots/main.tf | 36 +++++ modules/published-dots/outputs.tf | 7 + modules/published-dots/variables.tf | 14 ++ scripts/_utils.sh | 78 ++++++++++ scripts/bootstrap.sh | 14 ++ scripts/install.sh | 54 +++++++ scripts/install/00-apt-pkglist | 4 + scripts/install/00-apt.sh | 2 + {install => scripts/install}/02-fish.sh | 11 +- {install => scripts/install}/03-ssh.sh | 5 - {install => scripts/install}/10-pyenv-pkglist | 4 +- scripts/install/10-pyenv.sh | 18 +++ {install => scripts/install}/11-python.sh | 12 +- {install => scripts/install}/12-poetry.sh | 10 +- scripts/install/13-nvm.sh | 11 ++ scripts/install/14-yarn.sh | 9 ++ {install => scripts/install}/15-java.sh | 4 - {install => scripts/install}/16-vim.sh | 2 - {install => scripts/install}/30-docker.sh | 26 +--- {install => scripts/install}/31-gcloud.sh | 8 +- {install => scripts/install}/32-firebase.sh | 3 - {install => scripts/install}/33-aws.sh | 2 - {install => scripts/install}/34-terraform.sh | 2 - scripts/install/98-apt-clean.sh | 2 + scripts/install/99-screenfetch.sh | 2 + scripts/publish.sh | 4 + scripts/setup.sh | 29 ++++ scripts/test.sh | 9 ++ setup.pl | 46 ------ tests/.gitignore | 3 + tests/.python-version | 2 +- tests/Makefile | 4 - tests/poetry.lock | 136 ++++++++++-------- tests/pyproject.toml | 1 + tests/run.sh | 5 + tests/test_binaries.py | 1 - 59 files changed, 508 insertions(+), 647 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 .github/workflows/main.yml create mode 100644 .github/workflows/publish.yml delete mode 100644 Makefile delete mode 100755 bootstrap.pl create mode 100644 config.json delete mode 100755 install.pl delete mode 100644 install/00-apt-pkglist delete mode 100755 install/00-apt.sh delete mode 100755 install/10-pyenv.sh delete mode 100755 install/13-nvm.sh delete mode 100755 install/14-yarn.sh delete mode 100755 install/17-elm.sh delete mode 100755 install/35-kubectl.sh delete mode 100755 install/98-apt-clean.sh delete mode 100755 install/99-screenfetch.sh delete mode 100755 install/utils.sh create mode 100644 modules/published-dots/main.tf create mode 100644 modules/published-dots/outputs.tf create mode 100644 modules/published-dots/variables.tf create mode 100755 scripts/_utils.sh create mode 100755 scripts/bootstrap.sh create mode 100755 scripts/install.sh create mode 100644 scripts/install/00-apt-pkglist create mode 100755 scripts/install/00-apt.sh rename {install => scripts/install}/02-fish.sh (52%) rename {install => scripts/install}/03-ssh.sh (64%) rename {install => scripts/install}/10-pyenv-pkglist (83%) create mode 100755 scripts/install/10-pyenv.sh rename {install => scripts/install}/11-python.sh (50%) rename {install => scripts/install}/12-poetry.sh (55%) create mode 100755 scripts/install/13-nvm.sh create mode 100755 scripts/install/14-yarn.sh rename {install => scripts/install}/15-java.sh (51%) rename {install => scripts/install}/16-vim.sh (92%) rename {install => scripts/install}/30-docker.sh (60%) rename {install => scripts/install}/31-gcloud.sh (54%) rename {install => scripts/install}/32-firebase.sh (75%) rename {install => scripts/install}/33-aws.sh (91%) rename {install => scripts/install}/34-terraform.sh (96%) create mode 100755 scripts/install/98-apt-clean.sh create mode 100755 scripts/install/99-screenfetch.sh create mode 100644 scripts/publish.sh create mode 100755 scripts/setup.sh create mode 100755 scripts/test.sh delete mode 100755 setup.pl create mode 100644 tests/.gitignore delete mode 100644 tests/Makefile create mode 100644 tests/run.sh diff --git a/.dockerignore b/.dockerignore index 1870bf8..77c370a 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,4 +1,3 @@ .gitignore .dockerignore Dockerfile -README.md diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..30fe21f --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,11 @@ +name: Dotfiles CI +on: [push] + +jobs: + tests: + name: Run test suite + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Run tests + run: ./scripts/test.sh diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml deleted file mode 100644 index 84d64ff..0000000 --- a/.github/workflows/main.yml +++ /dev/null @@ -1,10 +0,0 @@ -on: [push] - -jobs: - tests: - runs-on: ubuntu-latest - name: tests - steps: - - uses: actions/checkout@v2 - - name: Run tests - run: make test diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..c6f380e --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,14 @@ +name: Dotfiles publisher +on: + push: + branches: + - master + +jobs: + publish-installer: + name: Publish install script + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Publish to CDN + run: ./scripts/publish.sh diff --git a/.gitignore b/.gitignore index 2ccebbe..8c29169 100644 --- a/.gitignore +++ b/.gitignore @@ -1,11 +1,11 @@ +# install artefacts +**/tmp +**/logs +**/*.deb + # custom functions !files/.config/fish/functions/nvm.fish -# install artefacts -tmp -logs/* -**/*.deb - # setup files **/plugged **/autoload @@ -21,10 +21,6 @@ logs/* **/firebase **/pypoetry -# pytest -**/__pycache__ -**/.pytest_cache - # ssh env **/id_rsa* **/known_hosts* diff --git a/Dockerfile b/Dockerfile index 3df46cd..2d00845 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,28 +1,44 @@ -FROM ubuntu:bionic as install +# +# ubuntu-base: Base Ubuntu image with sudo user +# +FROM ubuntu:focal AS ubuntu-base -# Install sudo and make, git since built-in is skipped RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections -RUN apt-get -qqy update \ - && apt-get -qqy install curl git make software-properties-common sudo +ENV DEBIAN_FRONTEND noninteractive +RUN apt-get -qy update +RUN apt-get -qy install --no-install-recommends \ + apt-utils software-properties-common sudo # Create user with sudo priviledge -ARG USER="test-user" -RUN useradd --create-home -m "$USER" \ - && adduser "$USER" sudo -RUN echo "$USER ALL=(ALL) NOPASSWD: ALL" \ +RUN useradd -r -u 1001 --create-home -m "test-user" +RUN adduser "test-user" sudo +RUN echo "test-user ALL=(ALL) NOPASSWD: ALL" \ >>/etc/sudoers -# Filesystem steps -RUN rm /home/$USER/.profile /home/$USER/.bashrc -ENV WORKSPACE="/home/$USER/workspace" -ADD --chown=test-user . "$WORKSPACE/dotfiles" -WORKDIR "$WORKSPACE/dotfiles" -# Install steps +# +# source: Source steps +# +FROM ubuntu-base AS source + +ARG DOTFILES_DIR="/home/test-user/.dotfiles" +ADD --chown="test-user" . "$DOTFILES_DIR" +WORKDIR "$DOTFILES_DIR" + + +# +# install: Install steps +# +FROM source AS install + USER test-user -ARG TARGET="all" -ENV LOG_TARGET="STDOUT" -RUN make install TARGET=$TARGET +ENV USER=test-user +ENV UUID="docker" +RUN ./scripts/install.sh -# Test entrypoint -ENTRYPOINT [ "make", "--directory", "tests", "TARGET=$TARGET" ] + +# +# test: Test entrypoint +# +FROM install AS test +ENTRYPOINT [ "tests/run.sh" ] diff --git a/Makefile b/Makefile deleted file mode 100644 index 8bdd8d8..0000000 --- a/Makefile +++ /dev/null @@ -1,35 +0,0 @@ -# ---------------------------------------------------------------------------- # -# Local commands -# ---------------------------------------------------------------------------- # -.PHONY: clean install - -# Install dotfiles to home folder -all: - ./bootstrap.pl - -# @arg $TARGET binary to install -install: - ./install.pl - -clean: - rm -rf logs - -# ---------------------------------------------------------------------------- # -# Docker commands -# ---------------------------------------------------------------------------- # -.PHONY: build test start - -# Build and tag docker image -build: - docker build . -t dotfiles:latest - -# Run tests in docker container -# @arg $TARGET binary to install and test -test: - docker build . -t dotfiles:localtest \ - --build-arg TARGET=$$TARGET \ - && docker run dotfiles:localtest - -# Launch bash in docker container -start: - docker run -it dotfiles:latest /bin/bash diff --git a/README.md b/README.md index 4715238..65b4289 100644 --- a/README.md +++ b/README.md @@ -1,31 +1,28 @@ -# dotfiles +# andrejusk/dotfiles Collection of experimental dotfiles and supporting install scripts. -Tested on and compatible with: - -- Ubuntu 20.04 ## Install - wget https://raw.githubusercontent.com/andrejusk/dotfiles/master/setup.pl -qO - | perl + wget https://raw.githubusercontent.com/andrejusk/dotfiles/master/scripts/setup.sh -qO - | bash ## Stack -Shell: 🐟 fish (+ fisher) +### Shell +🐟 fish (+ fisher) -Editor: neovim (+ vim-plug) +### Editor +neovim (+ vim-plug) -Tools: +### Languages -- aws, gcloud, firebase -- docker (+ docker-compose) -- kubectl -- terraform -- screenfetch - -Languages: - -- java - js (nvm, node, yarn) - python (pyenv, poetry) -- ruby +- java + +### Tools + +- docker (+ docker-compose) +- terraform +- gcloud, firebase, awscli +- screenfetch diff --git a/bootstrap.pl b/bootstrap.pl deleted file mode 100755 index 6813a0a..0000000 --- a/bootstrap.pl +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env perl -use strict; -use warnings; -use autodie; - -use Cwd; -use Data::Dumper; -use Stow; - - -my $dir = getcwd; -my $target = $ENV{'HOME'}; -print "Stowing $dir/files to $target\n"; - -my %stow_options = ( dir => $dir, - target => $target ); -my $stow = new Stow(%stow_options); - -my @pkgs = ('files'); -$stow->plan_stow(@pkgs); -my %conflicts = $stow->get_conflicts; -if (%conflicts) { - my $dump = Dumper(%conflicts); - die("Failed to stow, conflicts: $dump"); -} -$stow->process_tasks(); diff --git a/config.json b/config.json new file mode 100644 index 0000000..9bb9624 --- /dev/null +++ b/config.json @@ -0,0 +1,21 @@ +{ + "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/.config/nvim/plugins.vim b/files/.config/nvim/plugins.vim index 8e2b537..d4bf0fc 100644 --- a/files/.config/nvim/plugins.vim +++ b/files/.config/nvim/plugins.vim @@ -152,12 +152,17 @@ Plug 'neoclide/coc.nvim', {'do': 'yarn install --frozen-lockfile'} \ 'coc-perl', \ 'coc-prettier', \ 'coc-python', + \ 'coc-react-refactor', \ 'coc-rust-analyzer', \ 'coc-sh', \ 'coc-snippets', + \ 'coc-styled-components', \ 'coc-svg', + \ 'coc-swagger', \ 'coc-tabnine', \ 'coc-toml', + \ 'coc-tslint', + \ 'coc-tslint-plugin', \ 'coc-tsserver', \ 'coc-vimlsp', \ 'coc-xml', @@ -165,6 +170,10 @@ Plug 'neoclide/coc.nvim', {'do': 'yarn install --frozen-lockfile'} \ ] " }}} +" ts +Plug 'HerringtonDarkholme/yats.vim' +Plug 'maxmellon/vim-jsx-pretty' + " elm Plug 'andys8/vim-elm-syntax' diff --git a/files/.profile b/files/.profile index 967c1b8..1bcbe86 100644 --- a/files/.profile +++ b/files/.profile @@ -34,7 +34,6 @@ fi # pyenv export PYENV_ROOT="$HOME/.pyenv" export PATH="$PYENV_ROOT/bin:$PATH" -export PATH="$PYENV_ROOT/shims:$PATH" if [ -d "$PYENV_ROOT" ]; then [ -x "$(command -v pyenv)" ] && eval "$(pyenv init -)" fi diff --git a/install.pl b/install.pl deleted file mode 100755 index c94e641..0000000 --- a/install.pl +++ /dev/null @@ -1,62 +0,0 @@ -#!/usr/bin/env perl -use strict; -use warnings; -use autodie; - -use File::Basename; - -# Prevent running as root -if ($< == 0) { - print "Failed: Running as root. Please run as user, not sudo\n"; - exit (1); -} - -my $dir = dirname(__FILE__); - -my $log_target = $ENV{'LOG_TARGET'} // ''; -my $log_path = ''; -if ($log_target ne 'STDOUT') { - # Generate unique logfile - my $log_dir = "$dir/logs"; - `mkdir -p $log_dir`; - my $uuid = `uuidgen`; - chomp $uuid; - $log_path = "$log_dir/$uuid.log"; -} -print "Logs: $log_path\n"; - -# Execute given command and log appropriately -# @arg 0 command to run -sub log_execute { - my $command = $log_path ne '' - ? "$_[0] >> $log_path 2>&1" - : $_[0]; - system($command) == 0 - or die "system $command failed: $?"; -} - - -# Ensure dependencies installed -log_execute("sudo apt-get update -qqy && sudo apt-get install -qqy build-essential liblocal-lib-perl cpanminus stow"); - -# Bootstrap files -log_execute("make -C $dir"); - -# Read scripts to be installed -my $install_dir = "$dir/install"; -print "Installing $install_dir\n"; -opendir($dir, $install_dir) or die "Could not open $install_dir\n"; -my @files = readdir($dir); -closedir($dir); -@files = grep(/^\d{2}-.*\.sh$/, @files); -@files = sort { lc($a) cmp lc($b) } @files; - -# Install selected targets -my $target = $ENV{'TARGET'} // 'all'; -if ($target ne 'all') { - @files = grep(/${target}/, @files); -} -foreach my $file (@files) { - print "Running $file...\r"; - log_execute("$install_dir/$file"); -} diff --git a/install/00-apt-pkglist b/install/00-apt-pkglist deleted file mode 100644 index a9b7ec4..0000000 --- a/install/00-apt-pkglist +++ /dev/null @@ -1,19 +0,0 @@ -apt-transport-https -bat -curl -cowsay -fd-find -fortune-mod -git -gnupg2 -jq -make -neovim -net-tools -openssh-client -openssh-server -ripgrep -ruby-full -software-properties-common -tmux -universal-ctags diff --git a/install/00-apt.sh b/install/00-apt.sh deleted file mode 100755 index 6898965..0000000 --- a/install/00-apt.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env bash -source "$(dirname $0)/utils.sh" - -clean -update -upgrade -echo "apt cleaned, updated, upgraded" - -package_list_file="$install_dir/00-apt-pkglist" -install_file "$package_list_file" -echo "list of dependencies installed" - -cat /etc/os-release diff --git a/install/10-pyenv.sh b/install/10-pyenv.sh deleted file mode 100755 index 1b5a5e4..0000000 --- a/install/10-pyenv.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env bash -source "$(dirname $0)/utils.sh" - -# pyenv is installed -if not_installed "pyenv"; then - - echo "Installing pyenv..." - - # Install pyenv prerequisites - # see https://github.com/pyenv/pyenv/wiki/common-build-problems - pyenv_list_file="$install_dir/10-pyenv-pkglist" - install_file "$pyenv_list_file" - - # Install pyenv - # see https://github.com/pyenv/pyenv-installer - run "https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer" \ - "bash" - -fi -echo "pyenv is installed, upgrading $PYENV_ROOT..." -git --git-dir="$PYENV_ROOT/.git" fetch -q -git --git-dir="$PYENV_ROOT/.git" rebase -q --autostash FETCH_HEAD - -pyenv --version diff --git a/install/13-nvm.sh b/install/13-nvm.sh deleted file mode 100755 index 58e9729..0000000 --- a/install/13-nvm.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env bash -source "$(dirname $0)/utils.sh" - -# nvm is installed -if not_installed "nvm"; then - - printf "Installing nvm...\n" - - # Install nvm - mkdir -p $NVM_DIR - run "https://raw.githubusercontent.com/nvm-sh/nvm/v0.36.0/install.sh" \ - "bash" - source "$NVM_DIR/nvm.sh" - nvm alias default node - nvm install node - -fi - -printf "nvm is installed, upgrading...\n" -run "https://raw.githubusercontent.com/nvm-sh/nvm/v0.36.0/install.sh" \ - "bash" - -nvm --version -nvm use node -node --version diff --git a/install/14-yarn.sh b/install/14-yarn.sh deleted file mode 100755 index 650f090..0000000 --- a/install/14-yarn.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/env bash -source "$(dirname $0)/utils.sh" - -# yarn is installed -if not_installed "yarn"; then - - echo "Installing yarn..." - - # Install yarn - curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add - - 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 - -echo "yarn is installed" -# yarn --version diff --git a/install/17-elm.sh b/install/17-elm.sh deleted file mode 100755 index 32e7b73..0000000 --- a/install/17-elm.sh +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/env bash -source "$(dirname $0)/utils.sh" - -if not_installed "elm"; then - # Download the 0.19.1 binary for Linux. - # - # +-----------+----------------------+ - # | FLAG | MEANING | - # +-----------+----------------------+ - # | -L | follow redirects | - # | -o elm.gz | name the file elm.gz | - # +-----------+----------------------+ - # - curl -L -o elm.gz https://github.com/elm/compiler/releases/download/0.19.1/binary-for-linux-64-bit.gz - - # There should now be a file named `elm.gz` on your Desktop. - # - # The downloaded file is compressed to make it faster to download. - # This next command decompresses it, replacing `elm.gz` with `elm`. - # - gunzip elm.gz - - # There should now be a file named `elm` on your Desktop! - # - # Every file has "permissions" about whether it can be read, written, or executed. - # So before we use this file, we need to mark this file as executable: - # - chmod +x elm - - # The `elm` file is now executable. That means running `~/Desktop/elm --help` - # should work. Saying `./elm --help` works the same. - # - # But we want to be able to say `elm --help` without specifying the full file - # path every time. We can do this by moving the `elm` binary to one of the - # directories listed in your `PATH` environment variable: - # - sudo mv elm /usr/local/bin/ - rm {elm,elm.gz} -fi - -npm install -g @elm-tooling/elm-language-server elm-format elm-test diff --git a/install/35-kubectl.sh b/install/35-kubectl.sh deleted file mode 100755 index 6458fa1..0000000 --- a/install/35-kubectl.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env bash -source "$(dirname $0)/utils.sh" - -if not_installed "kubectl"; then - echo "Installing kubectl..." - sudo apt-get update && sudo apt-get install -y apt-transport-https gnupg2 - - curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add - - - echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee -a /etc/apt/sources.list.d/kubernetes.list - - update - - install kubectl - refresh -fi diff --git a/install/98-apt-clean.sh b/install/98-apt-clean.sh deleted file mode 100755 index 3ebe748..0000000 --- a/install/98-apt-clean.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env bash -source "$(dirname $0)/utils.sh" - -echo "cleaning" -clean diff --git a/install/99-screenfetch.sh b/install/99-screenfetch.sh deleted file mode 100755 index 046e94b..0000000 --- a/install/99-screenfetch.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bash -source "$(dirname $0)/utils.sh" - -if not_installed "screenfetch"; then - echo "Installing screenfetch..." - install screenfetch -fi - -echo "screenfetch is installed" -screenfetch --version -screenfetch diff --git a/install/utils.sh b/install/utils.sh deleted file mode 100755 index 9f32904..0000000 --- a/install/utils.sh +++ /dev/null @@ -1,112 +0,0 @@ -#!/usr/bin/env bash -# ---------------------------------------------------------------------------- # -# Helper functions -# ---------------------------------------------------------------------------- # -clean() { - sudo apt-get clean -} - -update() { - sudo apt-get update -} - -# Non-interactive upgrade -upgrade() { - DEBIAN_FRONTEND=noninteractive \ - sudo apt-get \ - -o Dpkg::Options::="--force-confdef" \ - -o Dpkg::Options::="--force-confold" \ - -y \ - dist-upgrade - sudo apt-get -y autoremove -} - -# @arg $1 packages to install -install() { - sudo apt-get install -qqy $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 apt-key --keyring "/etc/apt/trusted.gpg.d/$2.gpg" add -} - -# @arg $1 URL to run -# @arg $2 binary to use -run() { - curl -fsSL $1 | $2 | indent -} - -# Symlink contents of source folder to target -# -# @arg $1 source folder -# @arg $2 target folder -link_folder() { - mkdir -p $2 - cp -srf $1/. $2 -} - -indent() { sed 's/^/ /'; } - -# @arg $1 binary to test -not_installed() { - ! [ -x "$(command -v $1)" ] -} - -# Refreshes PATH -refresh() { - hash -r -} - -# Add to PATH and refresh -# @arg $1 path to add to PATH -add_path() { - export PATH="$1:$PATH" - refresh -} - -export -f clean update upgrade install install_file add_ppa add_key run \ - link_folder indent not_installed refresh add_path - -# ---------------------------------------------------------------------------- # -# Shell colours -# ---------------------------------------------------------------------------- # -C_BLACK='\033[0;30m' -C_DGRAY='\033[1;30m' -C_RED='\033[0;31m' -C_LRED='\033[1;31m' -C_GREEN='\033[0;32m' -C_LGREEN='\033[1;32m' -C_ORANGE='\033[0;33m' -C_YELLOW='\033[1;33m' -C_BLUE='\033[0;34m' -C_LBLUE='\033[1;34m' -C_PURPLE='\033[0;35m' -C_LPURPLE='\033[1;35m' -C_CYAN='\033[0;36m' -C_LCYAN='\033[1;36m' -C_LGRAY='\033[0;37m' -C_WHITE='\033[1;37m' -C_NC='\033[0m' - -# ---------------------------------------------------------------------------- # -# Helper variables # -# ---------------------------------------------------------------------------- # -export PYTHON_KEYRING_BACKEND=keyring.backends.null.Keyring -install_dir="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )" -dotfiles_dir="$(dirname "$install_dir")" -source "$dotfiles_dir/files/.bash_profile" -refresh diff --git a/modules/published-dots/main.tf b/modules/published-dots/main.tf new file mode 100644 index 0000000..003d04d --- /dev/null +++ b/modules/published-dots/main.tf @@ -0,0 +1,36 @@ +# Static bucket +resource "google_storage_bucket" "bucket" { + provider = google-beta + + project = var.project + + name = var.domain + location = "EU" + storage_class = "MULTI_REGIONAL" + + versioning { + enabled = var.enable_versioning + } +} + +# Allow public read +resource "google_storage_default_object_acl" "bucket_acl" { + provider = google-beta + bucket = google_storage_bucket.bucket.name + role_entity = ["READER:allUsers"] +} + +# DNS entry +resource "google_dns_record_set" "cname" { + provider = google-beta + + depends_on = [google_storage_bucket.bucket] + + project = var.project + + name = "${var.domain}." + managed_zone = var.dns_zone + type = "CNAME" + ttl = 300 + rrdatas = ["c.storage.googleapis.com."] +} diff --git a/modules/published-dots/outputs.tf b/modules/published-dots/outputs.tf new file mode 100644 index 0000000..a0639ac --- /dev/null +++ b/modules/published-dots/outputs.tf @@ -0,0 +1,7 @@ +output "bucket_url" { + value = "storage.googleapis.com/${var.domain}" +} + +output "bucket_link" { + value = google_storage_bucket.bucket.self_link +} diff --git a/modules/published-dots/variables.tf b/modules/published-dots/variables.tf new file mode 100644 index 0000000..39fbdd9 --- /dev/null +++ b/modules/published-dots/variables.tf @@ -0,0 +1,14 @@ +variable "project" { + description = "Google Cloud project to host resources in" + type = string +} + +variable "domain" { + description = "DNS name to serve static content" + type = string +} + +variable "dns_zone" { + description = "Cloud DNS zone to use" + type = string +} diff --git a/scripts/_utils.sh b/scripts/_utils.sh new file mode 100755 index 0000000..b09ddbc --- /dev/null +++ b/scripts/_utils.sh @@ -0,0 +1,78 @@ +#!/usr/bin/env bash +function apt_update { + sudo apt-get update +} + +# @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 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 +} + +# @arg $1 binary to test +not_installed() { + ! [ -x "$(command -v $1)" ] +} + +# Refreshes PATH +refresh() { + hash -r +} + +# Add to PATH and refresh +# @arg $1 path to add to PATH +add_path() { + export PATH="$1:$PATH" + refresh +} diff --git a/scripts/bootstrap.sh b/scripts/bootstrap.sh new file mode 100755 index 0000000..9ad8030 --- /dev/null +++ b/scripts/bootstrap.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash +set -eo pipefail + +NAME=`basename "$0"` +REL_DIR=`dirname "$0"` +ABS_DIR=`readlink -f $REL_DIR/../` # Scripts are nested inside of /scripts + +# TODO +# Migrate to config.fish +rm $HOME/.bashrc +rm $HOME/.profile + +echo "Stowing $ABS_DIR to $HOME" +stow --dir=$ABS_DIR --target=$HOME files diff --git a/scripts/install.sh b/scripts/install.sh new file mode 100755 index 0000000..5cff4fe --- /dev/null +++ b/scripts/install.sh @@ -0,0 +1,54 @@ +#!/usr/bin/env bash +set -eo pipefail + +TIME=${TIME:-`date`} +UUID=${UUID:-`uuidgen`} +HOST=${HOST:-`hostname`} + +NAME=`basename "$0"` +REL_DIR=`dirname "$0"` +ABS_DIR=`readlink -f $REL_DIR/../` # Scripts are nested inside of /scripts + +LOG_DIR="$ABS_DIR/logs" +mkdir -p $LOG_DIR +LOG_TARGET=${LOG_TARGET:-$LOG_DIR/$UUID.log} + + +main() { + echo "Running $NAME at $TIME" + echo "Running as $USER on $HOST" + + # Prevent running as root + if [[ $EUID -eq 0 ]]; then + echo "Failed: Running as sudo. Please run as user" + 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 + done + + figlet -c "bootstrapping..." + $ABS_DIR/scripts/bootstrap.sh + source $HOME/.profile + + figlet -c "installing..." + export INSTALL_DIR="$REL_DIR/install" + for script in $INSTALL_DIR/*.sh; do + figlet -c `basename $script` + source $script + done + +} + +echo "main: Logging to $LOG_TARGET" +main 2>&1 |tee $LOG_TARGET diff --git a/scripts/install/00-apt-pkglist b/scripts/install/00-apt-pkglist new file mode 100644 index 0000000..dc5ae72 --- /dev/null +++ b/scripts/install/00-apt-pkglist @@ -0,0 +1,4 @@ +apt-transport-https +software-properties-common +ripgrep +universal-ctags diff --git a/scripts/install/00-apt.sh b/scripts/install/00-apt.sh new file mode 100755 index 0000000..b46d373 --- /dev/null +++ b/scripts/install/00-apt.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +cat /etc/os-release diff --git a/install/02-fish.sh b/scripts/install/02-fish.sh similarity index 52% rename from install/02-fish.sh rename to scripts/install/02-fish.sh index 5affbd6..5b32c08 100755 --- a/install/02-fish.sh +++ b/scripts/install/02-fish.sh @@ -1,22 +1,15 @@ #!/usr/bin/env bash -source "$(dirname $0)/utils.sh" - if not_installed "fish"; then - echo "installing fish..." add_ppa "fish-shell/release-3" update install fish fi - -echo "fish is installed" fish --version -fisher_location="$XDG_CONFIG_HOME/fish/functions/fisher.fish" +fisher_location="$HOME/.config/fish/functions/fisher.fish" if ! [ -f "$fisher_location" ]; then - echo "Installing fisher..." curl https://git.io/fisher --create-dirs -sLo "$fisher_location" + fish -c "fisher install jorgebucaran/fisher" fi -echo "fisher is installed, updating..." -fish -c "fisher update"; fish -c "fisher --version" diff --git a/install/03-ssh.sh b/scripts/install/03-ssh.sh similarity index 64% rename from install/03-ssh.sh rename to scripts/install/03-ssh.sh index ad40637..e2cb887 100755 --- a/install/03-ssh.sh +++ b/scripts/install/03-ssh.sh @@ -1,14 +1,9 @@ #!/usr/bin/env bash -source "$(dirname $0)/utils.sh" - -# ssh key exists ssh_target="$HOME/.ssh" ssh_key="$ssh_target/id_rsa" ssh_pub="$ssh_key.pub" if [ ! -f "$ssh_key" ]; then - echo "generating ssh key..." ssh-keygen -t rsa -b 4096 -f "$ssh_key" fi -echo "ssh key exists" cat "$ssh_pub" diff --git a/install/10-pyenv-pkglist b/scripts/install/10-pyenv-pkglist similarity index 83% rename from install/10-pyenv-pkglist rename to scripts/install/10-pyenv-pkglist index df0cd09..6f13840 100644 --- a/install/10-pyenv-pkglist +++ b/scripts/install/10-pyenv-pkglist @@ -2,9 +2,9 @@ build-essential libssl-dev libbz2-dev libreadline-dev -libreadline6 -libreadline6-dev libsqlite3-dev +libxml2-dev +libxmlsec1-dev llvm libncurses5-dev libncursesw5-dev diff --git a/scripts/install/10-pyenv.sh b/scripts/install/10-pyenv.sh new file mode 100755 index 0000000..9dcb604 --- /dev/null +++ b/scripts/install/10-pyenv.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash +if not_installed "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" \ + bash +fi + +export PATH="$HOME/.pyenv/bin:$PATH" +eval "$(pyenv init -)" +eval "$(pyenv virtualenv-init -)" + +pyenv update + +pyenv --version diff --git a/install/11-python.sh b/scripts/install/11-python.sh similarity index 50% rename from install/11-python.sh rename to scripts/install/11-python.sh index cad75be..df5c72e 100755 --- a/install/11-python.sh +++ b/scripts/install/11-python.sh @@ -1,18 +1,12 @@ #!/usr/bin/env bash -source "$(dirname $0)/utils.sh" export PYTHON_KEYRING_BACKEND=keyring.backends.null.Keyring -# python3 and pip3 are installed if not_installed "pip3"; then - - echo "Installing python3 and pip3..." - - pyenv install 3.7.0 - pyenv global 3.7.0 + pyenv install 3.9.0 + pyenv global 3.9.0 refresh - fi -echo "python3 and pip3 are installed, upgrading..." + pip install --upgrade pip pip3 install --upgrade pip python3 --version diff --git a/install/12-poetry.sh b/scripts/install/12-poetry.sh similarity index 55% rename from install/12-poetry.sh rename to scripts/install/12-poetry.sh index 86a0b9e..73c87fb 100755 --- a/install/12-poetry.sh +++ b/scripts/install/12-poetry.sh @@ -1,16 +1,10 @@ #!/usr/bin/env bash -source "$(dirname $0)/utils.sh" export PYTHON_KEYRING_BACKEND=keyring.backends.null.Keyring +add_path "$HOME/.local/bin" -# poetry is installed if not_installed "poetry"; then - - printf "Installing poetry...\n" - - # Install poetry pip3 install --user poetry - fi -printf "poetry is installed, upgrading...\n" + pip3 install --upgrade poetry poetry --version diff --git a/scripts/install/13-nvm.sh b/scripts/install/13-nvm.sh new file mode 100755 index 0000000..a840577 --- /dev/null +++ b/scripts/install/13-nvm.sh @@ -0,0 +1,11 @@ +#!/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 new file mode 100755 index 0000000..ef25ac3 --- /dev/null +++ b/scripts/install/14-yarn.sh @@ -0,0 +1,9 @@ +#!/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/install/15-java.sh b/scripts/install/15-java.sh similarity index 51% rename from install/15-java.sh rename to scripts/install/15-java.sh index fd88936..da89aa6 100755 --- a/install/15-java.sh +++ b/scripts/install/15-java.sh @@ -1,10 +1,6 @@ #!/usr/bin/env bash -source "$(dirname $0)/utils.sh" - if not_installed "java"; then - echo "Installing java..." install default-jre fi -echo "java is installed" java --version diff --git a/install/16-vim.sh b/scripts/install/16-vim.sh similarity index 92% rename from install/16-vim.sh rename to scripts/install/16-vim.sh index aaaf908..2b950a8 100755 --- a/install/16-vim.sh +++ b/scripts/install/16-vim.sh @@ -1,5 +1,4 @@ #!/usr/bin/env bash -source "$(dirname $0)/utils.sh" export PYTHON_KEYRING_BACKEND=keyring.backends.null.Keyring mkdir -p "$XDG_DATA_HOME/nvim/backup" @@ -13,7 +12,6 @@ echo "Installing neovim support"; pip3 install --user neovim pynvim 'python-language-server[all]' nvm use default npm install -g neovim -sudo gem install neovim echo "Running PlugInstall"; nvim --headless +UpdateRemotePlugins +PlugClean! +PlugInstall +PlugUpgrade +PlugUpdate +qall diff --git a/install/30-docker.sh b/scripts/install/30-docker.sh similarity index 60% rename from install/30-docker.sh rename to scripts/install/30-docker.sh index e758e21..208befe 100755 --- a/install/30-docker.sh +++ b/scripts/install/30-docker.sh @@ -1,13 +1,6 @@ #!/usr/bin/env bash -source "$(dirname $0)/utils.sh" - -# docker is installed DOCKER_FOLDER="$HOME/.docker" if not_installed "docker"; then - - printf "Installing docker...\n" - - # Create folder mkdir -p "$DOCKER_FOLDER" # Requirements @@ -15,8 +8,9 @@ if not_installed "docker"; then software-properties-common # Add repository - distro=$(lsb_release -si | tr '[:upper:]' '[:lower:]') # cast to lowercase - add_key "https://download.docker.com/linux/$distro/gpg" "docker-apt-key" + 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) \ @@ -31,31 +25,19 @@ if not_installed "docker"; then sudo chmod g+rwx "$DOCKER_FOLDER" -R fi -printf "docker is installed\n" docker --version -# docker-compose if installed if not_installed "docker-compose"; then - - printf "Installing docker-compose...\n" - - # Docker-compose pip3 install --user docker-compose - fi -printf "docker-compose is installed, upgrading\n" pip3 install --upgrade docker-compose docker-compose --version -# docker group exists -readonly docker_group='docker' +readonly docker_group="docker" if ! grep -q "$docker_group" /etc/group; then sudo groupadd "$docker_group" fi -printf "group '$docker_group' is created\n" -# user is in docker group if ! groups "$USER" | grep -q "\b$docker_group\b"; then sudo usermod -aG docker "$USER" fi -printf "user '$USER' is in '$docker_group' group\n" diff --git a/install/31-gcloud.sh b/scripts/install/31-gcloud.sh similarity index 54% rename from install/31-gcloud.sh rename to scripts/install/31-gcloud.sh index 5f60ce5..f1b25f3 100755 --- a/install/31-gcloud.sh +++ b/scripts/install/31-gcloud.sh @@ -1,12 +1,12 @@ #!/usr/bin/env bash -source "$(dirname $0)/utils.sh" - 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 + 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 - + 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 diff --git a/install/32-firebase.sh b/scripts/install/32-firebase.sh similarity index 75% rename from install/32-firebase.sh rename to scripts/install/32-firebase.sh index d64f237..cdd1e0c 100755 --- a/install/32-firebase.sh +++ b/scripts/install/32-firebase.sh @@ -1,8 +1,5 @@ #!/usr/bin/env bash -source "$(dirname $0)/utils.sh" - if not_installed "firebase"; then - echo "Installing firebase..." run "https://firebase.tools" "bash" fi diff --git a/install/33-aws.sh b/scripts/install/33-aws.sh similarity index 91% rename from install/33-aws.sh rename to scripts/install/33-aws.sh index b12087e..d96dc64 100755 --- a/install/33-aws.sh +++ b/scripts/install/33-aws.sh @@ -1,6 +1,4 @@ #!/usr/bin/env bash -source "$(dirname $0)/utils.sh" - curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" temp_dir=$(mktemp -d) unzip awscliv2.zip -d "$temp_dir" diff --git a/install/34-terraform.sh b/scripts/install/34-terraform.sh similarity index 96% rename from install/34-terraform.sh rename to scripts/install/34-terraform.sh index 42f3fc6..e5f20bf 100755 --- a/install/34-terraform.sh +++ b/scripts/install/34-terraform.sh @@ -1,6 +1,4 @@ #!/usr/bin/env bash -source "$(dirname $0)/utils.sh" - tf_version="0.14.6" if not_installed "terraform"; then echo "Installing terraform..." diff --git a/scripts/install/98-apt-clean.sh b/scripts/install/98-apt-clean.sh new file mode 100755 index 0000000..00c4492 --- /dev/null +++ b/scripts/install/98-apt-clean.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +clean diff --git a/scripts/install/99-screenfetch.sh b/scripts/install/99-screenfetch.sh new file mode 100755 index 0000000..7563217 --- /dev/null +++ b/scripts/install/99-screenfetch.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +screenfetch diff --git a/scripts/publish.sh b/scripts/publish.sh new file mode 100644 index 0000000..a070b6b --- /dev/null +++ b/scripts/publish.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +set -eo pipefail + +echo "Publishing..." diff --git a/scripts/setup.sh b/scripts/setup.sh new file mode 100755 index 0000000..f9f461b --- /dev/null +++ b/scripts/setup.sh @@ -0,0 +1,29 @@ +#!/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" + +# 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" +else + echo "Failed: Setup directory not empty $DOTFILES_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 +tar -C $tmp_dir -zxf $tmp_dest +mv $tmp_dir/$REPOSITORY-$BRANCH/* $DOTFILES_DIR +rm -rf $tmp_dir + +echo "Done!" +$DOTFILES_DIR/scripts/install.sh diff --git a/scripts/test.sh b/scripts/test.sh new file mode 100755 index 0000000..efbaf93 --- /dev/null +++ b/scripts/test.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash +set -euo pipefail + +tag=`uuidgen` +docker build . \ + -t dotfiles:$tag \ + --target test + +docker run dotfiles:$tag diff --git a/setup.pl b/setup.pl deleted file mode 100755 index 4a39524..0000000 --- a/setup.pl +++ /dev/null @@ -1,46 +0,0 @@ -#!/usr/bin/env perl -use strict; -use warnings; - - -use Archive::Tar; -use File::Copy; -use File::Temp (); -use IPC::System::Simple qw(capture); -use LWP::Simple; - - -print "Setting up...\n"; - -# GitHub repository to clone -my $author = $ENV{'DOTFILES_AUTHOR'} // 'andrejusk'; -my $repository = $ENV{'DOTFILES_REPOSITORY'} // 'dotfiles'; -my $branch = $ENV{'DOTFILES_BRANCH'} // 'master'; -print "Using repository $author/$repository at $branch\n"; - -# Install location -my $dotfiles_dir = $ENV{'DOTFILES_DIR'} // "$ENV{'HOME'}/.dotfiles"; - -# Download repo -my $repository_url = "https://github.com/$author/$repository/archive/$branch.tar.gz"; -my $temp_handle = File::Temp->new(); -my $repository_temp = $temp_handle->filename; -print "Downloading $repository_url to $repository_temp\n"; -getstore($repository_url, $repository_temp); - -# Extract repo -my $temp_dir = File::Temp->newdir(); -my $tar = Archive::Tar->new; -print "Extracting $repository_temp to $temp_dir\n"; -$tar->read($repository_temp); -$tar->setcwd($temp_dir); -$tar->extract(); - -# Move dotfiles out of temporary dir -my $temp_dotfiles_dir = "$temp_dir/$repository-$branch"; -print "Moving $temp_dotfiles_dir to $dotfiles_dir\n"; -move($temp_dotfiles_dir, $dotfiles_dir); - -# Install repo -print "Running installer\n"; -`$dotfiles_dir/install.pl`; diff --git a/tests/.gitignore b/tests/.gitignore new file mode 100644 index 0000000..294c9cb --- /dev/null +++ b/tests/.gitignore @@ -0,0 +1,3 @@ +# pytest +**/__pycache__ +**/.pytest_cache diff --git a/tests/.python-version b/tests/.python-version index 7c69a55..a5c4c76 100644 --- a/tests/.python-version +++ b/tests/.python-version @@ -1 +1 @@ -3.7.0 +3.9.0 diff --git a/tests/Makefile b/tests/Makefile deleted file mode 100644 index 25e5223..0000000 --- a/tests/Makefile +++ /dev/null @@ -1,4 +0,0 @@ -SHELL := /bin/bash -all: - poetry install - poetry run pytest diff --git a/tests/poetry.lock b/tests/poetry.lock index d926550..6377a43 100644 --- a/tests/poetry.lock +++ b/tests/poetry.lock @@ -1,19 +1,18 @@ [[package]] -category = "dev" -description = "Atomic file writes." -marker = "sys_platform == \"win32\"" name = "atomicwrites" +version = "1.3.0" +description = "Atomic file writes." +category = "dev" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" -version = "1.3.0" [[package]] -category = "dev" -description = "Classes Without Boilerplate" name = "attrs" +version = "19.3.0" +description = "Classes Without Boilerplate" +category = "dev" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" -version = "19.3.0" [package.extras] azure-pipelines = ["coverage", "hypothesis", "pympler", "pytest (>=4.3.0)", "six", "zope.interface", "pytest-azurepipelines"] @@ -22,22 +21,20 @@ docs = ["sphinx", "zope.interface"] tests = ["coverage", "hypothesis", "pympler", "pytest (>=4.3.0)", "six", "zope.interface"] [[package]] -category = "dev" -description = "Cross-platform colored terminal text." -marker = "sys_platform == \"win32\"" name = "colorama" +version = "0.4.3" +description = "Cross-platform colored terminal text." +category = "dev" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" -version = "0.4.3" [[package]] -category = "dev" -description = "Read metadata from Python packages" -marker = "python_version < \"3.8\"" name = "importlib-metadata" +version = "1.5.0" +description = "Read metadata from Python packages" +category = "dev" optional = false python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,>=2.7" -version = "1.5.0" [package.dependencies] zipp = ">=0.5" @@ -47,115 +44,130 @@ docs = ["sphinx", "rst.linker"] testing = ["packaging", "importlib-resources"] [[package]] -category = "dev" -description = "More routines for operating on iterables, beyond itertools" name = "more-itertools" +version = "8.2.0" +description = "More routines for operating on iterables, beyond itertools" +category = "dev" optional = false python-versions = ">=3.5" -version = "8.2.0" [[package]] -category = "dev" -description = "Core utilities for Python packages" name = "packaging" +version = "20.1" +description = "Core utilities for Python packages" +category = "dev" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" -version = "20.1" [package.dependencies] pyparsing = ">=2.0.2" six = "*" [[package]] -category = "dev" -description = "plugin and hook calling mechanisms for python" name = "pluggy" +version = "0.13.1" +description = "plugin and hook calling mechanisms for python" +category = "dev" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" -version = "0.13.1" [package.dependencies] -[package.dependencies.importlib-metadata] -python = "<3.8" -version = ">=0.12" +importlib-metadata = {version = ">=0.12", markers = "python_version < \"3.8\""} [package.extras] dev = ["pre-commit", "tox"] [[package]] -category = "dev" -description = "library with cross-python path, ini-parsing, io, code, log facilities" name = "py" +version = "1.8.1" +description = "library with cross-python path, ini-parsing, io, code, log facilities" +category = "dev" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" -version = "1.8.1" [[package]] -category = "dev" -description = "Python parsing module" name = "pyparsing" +version = "2.4.6" +description = "Python parsing module" +category = "dev" optional = false python-versions = ">=2.6, !=3.0.*, !=3.1.*, !=3.2.*" -version = "2.4.6" [[package]] -category = "dev" -description = "pytest: simple powerful testing with Python" name = "pytest" +version = "5.3.5" +description = "pytest: simple powerful testing with Python" +category = "dev" optional = false python-versions = ">=3.5" -version = "5.3.5" [package.dependencies] -atomicwrites = ">=1.0" +atomicwrites = {version = ">=1.0", markers = "sys_platform == \"win32\""} attrs = ">=17.4.0" -colorama = "*" +colorama = {version = "*", markers = "sys_platform == \"win32\""} +importlib-metadata = {version = ">=0.12", markers = "python_version < \"3.8\""} more-itertools = ">=4.0.0" packaging = "*" pluggy = ">=0.12,<1.0" py = ">=1.5.0" wcwidth = "*" -[package.dependencies.importlib-metadata] -python = "<3.8" -version = ">=0.12" - [package.extras] -checkqa-mypy = ["mypy (v0.761)"] +checkqa-mypy = ["mypy (==v0.761)"] testing = ["argcomplete", "hypothesis (>=3.56)", "mock", "nose", "requests", "xmlschema"] [[package]] +name = "pytest-parallel" +version = "0.1.0" +description = "a pytest plugin for parallel and concurrent testing" category = "dev" -description = "Python 2 and 3 compatibility utilities" -name = "six" -optional = false -python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*" -version = "1.14.0" - -[[package]] -category = "dev" -description = "Measures number of Terminal column cells of wide-character codes" -name = "wcwidth" optional = false python-versions = "*" -version = "0.1.8" + +[package.dependencies] +pytest = ">=3.0.0" +tblib = "*" [[package]] +name = "six" +version = "1.14.0" +description = "Python 2 and 3 compatibility utilities" category = "dev" -description = "Backport of pathlib-compatible object wrapper for zip files" -marker = "python_version < \"3.8\"" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*" + +[[package]] +name = "tblib" +version = "1.7.0" +description = "Traceback serialization library." +category = "dev" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" + +[[package]] +name = "wcwidth" +version = "0.1.8" +description = "Measures number of Terminal column cells of wide-character codes" +category = "dev" +optional = false +python-versions = "*" + +[[package]] name = "zipp" +version = "3.0.0" +description = "Backport of pathlib-compatible object wrapper for zip files" +category = "dev" optional = false python-versions = ">=3.6" -version = "3.0.0" [package.extras] docs = ["sphinx", "jaraco.packaging (>=3.2)", "rst.linker (>=1.9)"] testing = ["jaraco.itertools", "func-timeout"] [metadata] -content-hash = "76f248e0ec62688089444c71c5e62af7c3ca83978a893d09e6592e3621985fab" +lock-version = "1.1" python-versions = "^3.7" +content-hash = "74334db56ae752441434e742efb55e7b5499d3757b7ba674261897cb0b77c741" [metadata.files] atomicwrites = [ @@ -198,10 +210,18 @@ pytest = [ {file = "pytest-5.3.5-py3-none-any.whl", hash = "sha256:ff615c761e25eb25df19edddc0b970302d2a9091fbce0e7213298d85fb61fef6"}, {file = "pytest-5.3.5.tar.gz", hash = "sha256:0d5fe9189a148acc3c3eb2ac8e1ac0742cb7618c084f3d228baaec0c254b318d"}, ] +pytest-parallel = [ + {file = "pytest-parallel-0.1.0.tar.gz", hash = "sha256:4663a8fb805ac98b51e51de84d35ffd9717017fb71ed270440dc94b862466c20"}, + {file = "pytest_parallel-0.1.0-py3-none-any.whl", hash = "sha256:10693161e350b59466ca331bad964073555cda114cc0499bd826deeceee512ed"}, +] six = [ {file = "six-1.14.0-py2.py3-none-any.whl", hash = "sha256:8f3cd2e254d8f793e7f3d6d9df77b92252b52637291d0f0da013c76ea2724b6c"}, {file = "six-1.14.0.tar.gz", hash = "sha256:236bdbdce46e6e6a3d61a337c0f8b763ca1e8717c03b369e87a7ec7ce1319c0a"}, ] +tblib = [ + {file = "tblib-1.7.0-py2.py3-none-any.whl", hash = "sha256:289fa7359e580950e7d9743eab36b0691f0310fce64dee7d9c31065b8f723e23"}, + {file = "tblib-1.7.0.tar.gz", hash = "sha256:059bd77306ea7b419d4f76016aef6d7027cc8a0785579b5aad198803435f882c"}, +] wcwidth = [ {file = "wcwidth-0.1.8-py2.py3-none-any.whl", hash = "sha256:8fd29383f539be45b20bd4df0dc29c20ba48654a41e661925e612311e9f3c603"}, {file = "wcwidth-0.1.8.tar.gz", hash = "sha256:f28b3e8a6483e5d49e7f8949ac1a78314e740333ae305b4ba5defd3e74fb37a8"}, diff --git a/tests/pyproject.toml b/tests/pyproject.toml index 4ef3159..fff4231 100644 --- a/tests/pyproject.toml +++ b/tests/pyproject.toml @@ -9,6 +9,7 @@ python = "^3.7" [tool.poetry.dev-dependencies] pytest = "^5.3.5" +pytest-parallel = "^0.1.0" [build-system] requires = ["poetry>=0.12"] diff --git a/tests/run.sh b/tests/run.sh new file mode 100644 index 0000000..99e15bc --- /dev/null +++ b/tests/run.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash +set -euo pipefail + +poetry install +poetry run pytest diff --git a/tests/test_binaries.py b/tests/test_binaries.py index 835845b..427d160 100644 --- a/tests/test_binaries.py +++ b/tests/test_binaries.py @@ -67,7 +67,6 @@ binaries: List[str] = [ "node", "npm", "yarn", - # "elm", # language: java "java", From e5223a45dbd760d45de01b2930a5cff3a27a78f5 Mon Sep 17 00:00:00 2001 From: Andrejus Date: Fri, 16 Apr 2021 00:26:07 +0100 Subject: [PATCH 02/14] 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" From 0e2d2ebf4fc9e193a0fe676aa9fa4030d14159d8 Mon Sep 17 00:00:00 2001 From: Andrejus Date: Fri, 16 Apr 2021 00:31:13 +0100 Subject: [PATCH 03/14] fix: tests entrypoint --- Dockerfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 8235c52..523ce08 100644 --- a/Dockerfile +++ b/Dockerfile @@ -41,4 +41,6 @@ RUN ./scripts/install.sh # test: Test entrypoint # FROM install AS test -ENTRYPOINT [ "tests/run.sh" ] + +WORKDIR "${DOTFILES_DIR}/tests" +ENTRYPOINT [ "./run.sh" ] From 5985e4ca243b7fe727a021bcb967dc05e8a1953c Mon Sep 17 00:00:00 2001 From: Andrejus Kostarevas Date: Fri, 16 Apr 2021 12:11:47 +0100 Subject: [PATCH 04/14] fix: update tf module dir, add unstable deb key --- scripts/install.d/16-vim.sh | 1 + {modules/published-dots => terraform/module}/main.tf | 0 {modules/published-dots => terraform/module}/outputs.tf | 0 {modules/published-dots => terraform/module}/variables.tf | 0 4 files changed, 1 insertion(+) rename {modules/published-dots => terraform/module}/main.tf (100%) rename {modules/published-dots => terraform/module}/outputs.tf (100%) rename {modules/published-dots => terraform/module}/variables.tf (100%) diff --git a/scripts/install.d/16-vim.sh b/scripts/install.d/16-vim.sh index bb04f36..98ac9b6 100755 --- a/scripts/install.d/16-vim.sh +++ b/scripts/install.d/16-vim.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash # Install neovim from unstable debian repo +curl -fsSL "https://ftp-master.debian.org/keys/archive-key-10.asc" | sudo apt-key add - echo "deb http://deb.debian.org/debian unstable main" \ | sudo tee /etc/apt/sources.list.d/unstable.list echo "Package: neovim diff --git a/modules/published-dots/main.tf b/terraform/module/main.tf similarity index 100% rename from modules/published-dots/main.tf rename to terraform/module/main.tf diff --git a/modules/published-dots/outputs.tf b/terraform/module/outputs.tf similarity index 100% rename from modules/published-dots/outputs.tf rename to terraform/module/outputs.tf diff --git a/modules/published-dots/variables.tf b/terraform/module/variables.tf similarity index 100% rename from modules/published-dots/variables.tf rename to terraform/module/variables.tf From d768d3da1aaadd17914fa3524c550d66018683f6 Mon Sep 17 00:00:00 2001 From: Andrejus Date: Fri, 16 Apr 2021 12:11:47 +0100 Subject: [PATCH 05/14] fix: update tf module dir, add unstable deb key --- scripts/install.d/16-vim.sh | 1 + {modules/published-dots => terraform/module}/main.tf | 0 {modules/published-dots => terraform/module}/outputs.tf | 0 {modules/published-dots => terraform/module}/variables.tf | 0 4 files changed, 1 insertion(+) rename {modules/published-dots => terraform/module}/main.tf (100%) rename {modules/published-dots => terraform/module}/outputs.tf (100%) rename {modules/published-dots => terraform/module}/variables.tf (100%) diff --git a/scripts/install.d/16-vim.sh b/scripts/install.d/16-vim.sh index bb04f36..98ac9b6 100755 --- a/scripts/install.d/16-vim.sh +++ b/scripts/install.d/16-vim.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash # Install neovim from unstable debian repo +curl -fsSL "https://ftp-master.debian.org/keys/archive-key-10.asc" | sudo apt-key add - echo "deb http://deb.debian.org/debian unstable main" \ | sudo tee /etc/apt/sources.list.d/unstable.list echo "Package: neovim diff --git a/modules/published-dots/main.tf b/terraform/module/main.tf similarity index 100% rename from modules/published-dots/main.tf rename to terraform/module/main.tf diff --git a/modules/published-dots/outputs.tf b/terraform/module/outputs.tf similarity index 100% rename from modules/published-dots/outputs.tf rename to terraform/module/outputs.tf diff --git a/modules/published-dots/variables.tf b/terraform/module/variables.tf similarity index 100% rename from modules/published-dots/variables.tf rename to terraform/module/variables.tf From 1ba16634dedb08bf000fc020be3e18ff40258c86 Mon Sep 17 00:00:00 2001 From: Andrejus Date: Thu, 22 Apr 2021 19:05:29 +0100 Subject: [PATCH 06/14] fix: fish/nvim --- files/.config/fish/fish_plugins | 1 - scripts/install.d/02-fish.sh | 6 ++++++ scripts/install.d/16-vim.sh | 20 +++++++++++--------- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/files/.config/fish/fish_plugins b/files/.config/fish/fish_plugins index 6048da1..949607f 100644 --- a/files/.config/fish/fish_plugins +++ b/files/.config/fish/fish_plugins @@ -1,5 +1,4 @@ jethrokuan/z -jorgebucaran/fisher jorgebucaran/hydro jorgebucaran/replay.fish joseluisq/gitnow diff --git a/scripts/install.d/02-fish.sh b/scripts/install.d/02-fish.sh index 3f60092..4f38059 100755 --- a/scripts/install.d/02-fish.sh +++ b/scripts/install.d/02-fish.sh @@ -1,6 +1,12 @@ #!/usr/bin/env bash fish --version +current_shell=`readlink -f /proc/$$/exe` +fish_shell=`which fish` +if [[ "$current_shell" != "$fish_shell" ]]; then + chsh -s "$fish_shell" +fi + 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" diff --git a/scripts/install.d/16-vim.sh b/scripts/install.d/16-vim.sh index 98ac9b6..1d19578 100755 --- a/scripts/install.d/16-vim.sh +++ b/scripts/install.d/16-vim.sh @@ -1,15 +1,17 @@ #!/usr/bin/env bash # Install neovim from unstable debian repo -curl -fsSL "https://ftp-master.debian.org/keys/archive-key-10.asc" | sudo apt-key add - -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 +if ! bin_in_path "nvim"; then + curl -fsSL "https://ftp-master.debian.org/keys/archive-key-10.asc" | sudo apt-key add - + 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 +fi mkdir -p "$XDG_DATA_HOME/nvim/backup" plug_dir="$XDG_DATA_HOME/nvim/site/autoload" From 31f3fe90640014e0760bf85c76dcb01053bc4ec6 Mon Sep 17 00:00:00 2001 From: Andrejus Date: Mon, 26 Apr 2021 23:25:43 +0100 Subject: [PATCH 07/14] spacemacs, stow --- files/.config/fish/config.fish | 17 - files/{ => home}/.bash_profile | 0 files/{ => home}/.bashrc | 0 .../.config/alacritty/alacritty.yml | 14 +- files/{ => home}/.config/fish/fish_plugins | 1 + .../.config/fish/functions/.gitignore | 0 .../.config/fish/functions/nvm.fish | 0 files/{ => home}/.config/nvim/base.vim | 0 .../{ => home}/.config/nvim/coc-settings.json | 0 files/{ => home}/.config/nvim/init.vim | 0 files/{ => home}/.config/nvim/mappings.vim | 0 .../.config/nvim/plugins-config.vim | 0 files/{ => home}/.config/nvim/plugins.vim | 0 files/{ => home}/.gitconfig | 0 files/{ => home}/.gitignore_global | 0 files/{ => home}/.profile | 7 +- files/home/.spacemacs | 573 ++++++++++++++++++ files/{ => home}/.ssh/config | 0 scripts/_utils.sh | 22 +- scripts/bootstrap.sh | 17 - scripts/install.d/02-fish.sh | 3 +- scripts/install.d/13-nvm.sh | 5 +- scripts/install.d/17-emacs.sh | 4 + scripts/install.sh | 13 +- scripts/install_config.json | 12 +- 25 files changed, 632 insertions(+), 56 deletions(-) delete mode 100644 files/.config/fish/config.fish rename files/{ => home}/.bash_profile (100%) rename files/{ => home}/.bashrc (100%) rename files/{ => home}/.config/alacritty/alacritty.yml (90%) rename files/{ => home}/.config/fish/fish_plugins (84%) rename files/{ => home}/.config/fish/functions/.gitignore (100%) rename files/{ => home}/.config/fish/functions/nvm.fish (100%) rename files/{ => home}/.config/nvim/base.vim (100%) rename files/{ => home}/.config/nvim/coc-settings.json (100%) rename files/{ => home}/.config/nvim/init.vim (100%) rename files/{ => home}/.config/nvim/mappings.vim (100%) rename files/{ => home}/.config/nvim/plugins-config.vim (100%) rename files/{ => home}/.config/nvim/plugins.vim (100%) rename files/{ => home}/.gitconfig (100%) rename files/{ => home}/.gitignore_global (100%) rename files/{ => home}/.profile (94%) create mode 100644 files/home/.spacemacs rename files/{ => home}/.ssh/config (100%) delete mode 100755 scripts/bootstrap.sh create mode 100644 scripts/install.d/17-emacs.sh diff --git a/files/.config/fish/config.fish b/files/.config/fish/config.fish deleted file mode 100644 index b47f13e..0000000 --- a/files/.config/fish/config.fish +++ /dev/null @@ -1,17 +0,0 @@ -# Only execute in interactive shell -if status is-interactive - - # Fish specific - set fish_greeting - set --global hydro_symbol_prompt "\$" - set --global hydro_symbol_git_dirty "~" - if type -q base16-seti - base16-seti - end - - # Cross-shell setup - if begin; test -e $HOME/.profile; and type -q replay; end - replay "source $HOME/.profile" - end - -end diff --git a/files/.bash_profile b/files/home/.bash_profile similarity index 100% rename from files/.bash_profile rename to files/home/.bash_profile diff --git a/files/.bashrc b/files/home/.bashrc similarity index 100% rename from files/.bashrc rename to files/home/.bashrc diff --git a/files/.config/alacritty/alacritty.yml b/files/home/.config/alacritty/alacritty.yml similarity index 90% rename from files/.config/alacritty/alacritty.yml rename to files/home/.config/alacritty/alacritty.yml index c3c1914..27ee137 100644 --- a/files/.config/alacritty/alacritty.yml +++ b/files/home/.config/alacritty/alacritty.yml @@ -7,8 +7,12 @@ window: decorations: None startup_mode: Windowed + dimensions: + columns: 120 + lines: 32 + padding: - x: 7 + x: 12 y: 7 scrolling: @@ -16,7 +20,7 @@ scrolling: multiplier: 3 font: - size: 9.0 + size: 10.0 normal: family: FiraCode Nerd Font Mono style: Regular @@ -42,12 +46,6 @@ cursor: 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 } diff --git a/files/.config/fish/fish_plugins b/files/home/.config/fish/fish_plugins similarity index 84% rename from files/.config/fish/fish_plugins rename to files/home/.config/fish/fish_plugins index 949607f..85cb5ec 100644 --- a/files/.config/fish/fish_plugins +++ b/files/home/.config/fish/fish_plugins @@ -4,3 +4,4 @@ jorgebucaran/replay.fish joseluisq/gitnow tomyun/base16-fish PatrickF1/fzf.fish +jorgebucaran/fisher diff --git a/files/.config/fish/functions/.gitignore b/files/home/.config/fish/functions/.gitignore similarity index 100% rename from files/.config/fish/functions/.gitignore rename to files/home/.config/fish/functions/.gitignore diff --git a/files/.config/fish/functions/nvm.fish b/files/home/.config/fish/functions/nvm.fish similarity index 100% rename from files/.config/fish/functions/nvm.fish rename to files/home/.config/fish/functions/nvm.fish diff --git a/files/.config/nvim/base.vim b/files/home/.config/nvim/base.vim similarity index 100% rename from files/.config/nvim/base.vim rename to files/home/.config/nvim/base.vim diff --git a/files/.config/nvim/coc-settings.json b/files/home/.config/nvim/coc-settings.json similarity index 100% rename from files/.config/nvim/coc-settings.json rename to files/home/.config/nvim/coc-settings.json diff --git a/files/.config/nvim/init.vim b/files/home/.config/nvim/init.vim similarity index 100% rename from files/.config/nvim/init.vim rename to files/home/.config/nvim/init.vim diff --git a/files/.config/nvim/mappings.vim b/files/home/.config/nvim/mappings.vim similarity index 100% rename from files/.config/nvim/mappings.vim rename to files/home/.config/nvim/mappings.vim diff --git a/files/.config/nvim/plugins-config.vim b/files/home/.config/nvim/plugins-config.vim similarity index 100% rename from files/.config/nvim/plugins-config.vim rename to files/home/.config/nvim/plugins-config.vim diff --git a/files/.config/nvim/plugins.vim b/files/home/.config/nvim/plugins.vim similarity index 100% rename from files/.config/nvim/plugins.vim rename to files/home/.config/nvim/plugins.vim diff --git a/files/.gitconfig b/files/home/.gitconfig similarity index 100% rename from files/.gitconfig rename to files/home/.gitconfig diff --git a/files/.gitignore_global b/files/home/.gitignore_global similarity index 100% rename from files/.gitignore_global rename to files/home/.gitignore_global diff --git a/files/.profile b/files/home/.profile similarity index 94% rename from files/.profile rename to files/home/.profile index dc1bc8e..b724b0f 100644 --- a/files/.profile +++ b/files/home/.profile @@ -24,6 +24,7 @@ mkdir -p "$WORKSPACE" # dotfiles export DOTFILES=${DOTFILES:-"$HOME/.dotfiles"} + # pyenv export PYENV_ROOT="$HOME/.pyenv" export PATH="$PYENV_ROOT/bin:$PATH" @@ -39,16 +40,14 @@ export PATH="$POETRY_ROOT/bin:$PATH" export NVM_DIR=${NVM_DIR:-"$HOME/.nvm"} mkdir -p "$NVM_DIR" export PATH="$NVM_DIR/bin:$PATH" +VERSION=`cat $NVM_DIR/alias/lts/fermium` # Default v14 +export PATH="$NVM_DIR/versions/node/$VERSION/bin:$PATH" # yarn export YARN_DIR=${YARN_DIR:-"$HOME/.yarn"} mkdir -p "$YARN_DIR" export PATH="$YARN_DIR/bin:$PATH" -# editor -export EDITOR="nvim" -export VISUAL="nvim" - # fzf export FZF_DEFAULT_OPTS="--reverse" export FZF_DEFAULT_COMMAND='fdfind --type f --hidden --follow --exclude .git' diff --git a/files/home/.spacemacs b/files/home/.spacemacs new file mode 100644 index 0000000..7bf109e --- /dev/null +++ b/files/home/.spacemacs @@ -0,0 +1,573 @@ +;; -*- mode: emacs-lisp; lexical-binding: t -*- +;; This file is loaded by Spacemacs at startup. +;; It must be stored in your home directory. + +(defun dotspacemacs/layers () + "Layer configuration: +This function should only modify configuration layer settings." + (setq-default + ;; Base distribution to use. This is a layer contained in the directory + ;; `+distribution'. For now available distributions are `spacemacs-base' + ;; or `spacemacs'. (default 'spacemacs) + dotspacemacs-distribution 'spacemacs + + ;; Lazy installation of layers (i.e. layers are installed only when a file + ;; with a supported type is opened). Possible values are `all', `unused' + ;; and `nil'. `unused' will lazy install only unused layers (i.e. layers + ;; not listed in variable `dotspacemacs-configuration-layers'), `all' will + ;; lazy install any layer that support lazy installation even the layers + ;; listed in `dotspacemacs-configuration-layers'. `nil' disable the lazy + ;; installation feature and you have to explicitly list a layer in the + ;; variable `dotspacemacs-configuration-layers' to install it. + ;; (default 'unused) + dotspacemacs-enable-lazy-installation 'unused + + ;; If non-nil then Spacemacs will ask for confirmation before installing + ;; a layer lazily. (default t) + dotspacemacs-ask-for-lazy-installation t + + ;; List of additional paths where to look for configuration layers. + ;; Paths must have a trailing slash (i.e. `~/.mycontribs/') + dotspacemacs-configuration-layer-path '() + + ;; List of configuration layers to load. + dotspacemacs-configuration-layers '( + (typescript :variables + typescript-backend 'lsp + typescript-fmt-tool 'prettier) + react + javascript + ;; ---------------------------------------------------------------- + ;; Example of useful layers you may want to use right away. + ;; Uncomment some layer names and press `SPC f e R' (Vim style) or + ;; `M-m f e R' (Emacs style) to install them. + ;; ---------------------------------------------------------------- + auto-completion + better-defaults + emacs-lisp + git + helm + lsp + markdown + multiple-cursors + org + (shell :variables + shell-default-height 30 + shell-default-position 'bottom + shell-default-shell 'multi-term) + spell-checking + syntax-checking + version-control + treemacs) + + + ;; List of additional packages that will be installed without being wrapped + ;; in a layer (generally the packages are installed only and should still be + ;; loaded using load/require/use-package in the user-config section below in + ;; this file). If you need some configuration for these packages, then + ;; consider creating a layer. You can also put the configuration in + ;; `dotspacemacs/user-config'. To use a local version of a package, use the + ;; `:location' property: '(your-package :location "~/path/to/your-package/") + ;; Also include the dependencies as they will not be resolved automatically. + dotspacemacs-additional-packages '() + + ;; A list of packages that cannot be updated. + dotspacemacs-frozen-packages '() + + ;; A list of packages that will not be installed and loaded. + dotspacemacs-excluded-packages '() + + ;; Defines the behaviour of Spacemacs when installing packages. + ;; Possible values are `used-only', `used-but-keep-unused' and `all'. + ;; `used-only' installs only explicitly used packages and deletes any unused + ;; packages as well as their unused dependencies. `used-but-keep-unused' + ;; installs only the used packages but won't delete unused ones. `all' + ;; installs *all* packages supported by Spacemacs and never uninstalls them. + ;; (default is `used-only') + dotspacemacs-install-packages 'used-only)) + +(defun dotspacemacs/init () + "Initialization: +This function is called at the very beginning of Spacemacs startup, +before layer configuration. +It should only modify the values of Spacemacs settings." + ;; This setq-default sexp is an exhaustive list of all the supported + ;; spacemacs settings. + (setq-default + ;; If non-nil then enable support for the portable dumper. You'll need + ;; to compile Emacs 27 from source following the instructions in file + ;; EXPERIMENTAL.org at to root of the git repository. + ;; (default nil) + dotspacemacs-enable-emacs-pdumper nil + + ;; Name of executable file pointing to emacs 27+. This executable must be + ;; in your PATH. + ;; (default "emacs") + dotspacemacs-emacs-pdumper-executable-file "emacs" + + ;; Name of the Spacemacs dump file. This is the file will be created by the + ;; portable dumper in the cache directory under dumps sub-directory. + ;; To load it when starting Emacs add the parameter `--dump-file' + ;; when invoking Emacs 27.1 executable on the command line, for instance: + ;; ./emacs --dump-file=$HOME/.emacs.d/.cache/dumps/spacemacs-27.1.pdmp + ;; (default (format "spacemacs-%s.pdmp" emacs-version)) + dotspacemacs-emacs-dumper-dump-file (format "spacemacs-%s.pdmp" emacs-version) + + ;; If non-nil ELPA repositories are contacted via HTTPS whenever it's + ;; possible. Set it to nil if you have no way to use HTTPS in your + ;; environment, otherwise it is strongly recommended to let it set to t. + ;; This variable has no effect if Emacs is launched with the parameter + ;; `--insecure' which forces the value of this variable to nil. + ;; (default t) + dotspacemacs-elpa-https t + + ;; Maximum allowed time in seconds to contact an ELPA repository. + ;; (default 5) + dotspacemacs-elpa-timeout 5 + + ;; Set `gc-cons-threshold' and `gc-cons-percentage' when startup finishes. + ;; This is an advanced option and should not be changed unless you suspect + ;; performance issues due to garbage collection operations. + ;; (default '(100000000 0.1)) + dotspacemacs-gc-cons '(100000000 0.1) + + ;; Set `read-process-output-max' when startup finishes. + ;; This defines how much data is read from a foreign process. + ;; Setting this >= 1 MB should increase performance for lsp servers + ;; in emacs 27. + ;; (default (* 1024 1024)) + dotspacemacs-read-process-output-max (* 1024 1024) + + ;; If non-nil then Spacelpa repository is the primary source to install + ;; a locked version of packages. If nil then Spacemacs will install the + ;; latest version of packages from MELPA. Spacelpa is currently in + ;; experimental state please use only for testing purposes. + ;; (default nil) + dotspacemacs-use-spacelpa nil + + ;; If non-nil then verify the signature for downloaded Spacelpa archives. + ;; (default t) + dotspacemacs-verify-spacelpa-archives t + + ;; If non-nil then spacemacs will check for updates at startup + ;; when the current branch is not `develop'. Note that checking for + ;; new versions works via git commands, thus it calls GitHub services + ;; whenever you start Emacs. (default nil) + dotspacemacs-check-for-update nil + + ;; If non-nil, a form that evaluates to a package directory. For example, to + ;; use different package directories for different Emacs versions, set this + ;; to `emacs-version'. (default 'emacs-version) + dotspacemacs-elpa-subdirectory 'emacs-version + + ;; One of `vim', `emacs' or `hybrid'. + ;; `hybrid' is like `vim' except that `insert state' is replaced by the + ;; `hybrid state' with `emacs' key bindings. The value can also be a list + ;; with `:variables' keyword (similar to layers). Check the editing styles + ;; section of the documentation for details on available variables. + ;; (default 'vim) + dotspacemacs-editing-style 'hybrid + + ;; If non-nil show the version string in the Spacemacs buffer. It will + ;; appear as (spacemacs version)@(emacs version) + ;; (default t) + dotspacemacs-startup-buffer-show-version t + + ;; Specify the startup banner. Default value is `official', it displays + ;; the official spacemacs logo. An integer value is the index of text + ;; banner, `random' chooses a random text banner in `core/banners' + ;; directory. A string value must be a path to an image format supported + ;; by your Emacs build. + ;; If the value is nil then no banner is displayed. (default 'official) + dotspacemacs-startup-banner 'random + + ;; List of items to show in startup buffer or an association list of + ;; the form `(list-type . list-size)`. If nil then it is disabled. + ;; Possible values for list-type are: + ;; `recents' `recents-by-project' `bookmarks' `projects' `agenda' `todos'. + ;; List sizes may be nil, in which case + ;; `spacemacs-buffer-startup-lists-length' takes effect. + ;; The exceptional case is `recents-by-project', where list-type must be a + ;; pair of numbers, e.g. `(recents-by-project . (7 . 5))', where the first + ;; number is the project limit and the second the limit on the recent files + ;; within a project. + dotspacemacs-startup-lists '((recents . 5) + (projects . 7)) + + ;; True if the home buffer should respond to resize events. (default t) + dotspacemacs-startup-buffer-responsive t + + ;; The minimum delay in seconds between number key presses. (default 0.4) + dotspacemacs-startup-buffer-multi-digit-delay 0.4 + + ;; Default major mode for a new empty buffer. Possible values are mode + ;; names such as `text-mode'; and `nil' to use Fundamental mode. + ;; (default `text-mode') + dotspacemacs-new-empty-buffer-major-mode 'text-mode + + ;; Default major mode of the scratch buffer (default `text-mode') + dotspacemacs-scratch-mode 'text-mode + + ;; If non-nil, *scratch* buffer will be persistent. Things you write down in + ;; *scratch* buffer will be saved and restored automatically. + dotspacemacs-scratch-buffer-persistent nil + + ;; If non-nil, `kill-buffer' on *scratch* buffer + ;; will bury it instead of killing. + dotspacemacs-scratch-buffer-unkillable nil + + ;; Initial message in the scratch buffer, such as "Welcome to Spacemacs!" + ;; (default nil) + dotspacemacs-initial-scratch-message nil + + ;; List of themes, the first of the list is loaded when spacemacs starts. + ;; Press `SPC T n' to cycle to the next theme in the list (works great + ;; with 2 themes variants, one dark and one light) + dotspacemacs-themes '(spacemacs-dark + spacemacs-light) + + ;; Set the theme for the Spaceline. Supported themes are `spacemacs', + ;; `all-the-icons', `custom', `doom', `vim-powerline' and `vanilla'. The + ;; first three are spaceline themes. `doom' is the doom-emacs mode-line. + ;; `vanilla' is default Emacs mode-line. `custom' is a user defined themes, + ;; refer to the DOCUMENTATION.org for more info on how to create your own + ;; spaceline theme. Value can be a symbol or list with additional properties. + ;; (default '(spacemacs :separator wave :separator-scale 1.5)) + dotspacemacs-mode-line-theme '(spacemacs :separator wave :separator-scale 1.5) + + ;; If non-nil the cursor color matches the state color in GUI Emacs. + ;; (default t) + dotspacemacs-colorize-cursor-according-to-state t + + ;; Default font or prioritized list of fonts. The `:size' can be specified as + ;; a non-negative integer (pixel size), or a floating-point (point size). + ;; Point size is recommended, because it's device independent. (default 10.0) + dotspacemacs-default-font '("Source Code Pro" + :size 10.0 + :weight normal + :width normal) + + ;; The leader key (default "SPC") + dotspacemacs-leader-key "SPC" + + ;; The key used for Emacs commands `M-x' (after pressing on the leader key). + ;; (default "SPC") + dotspacemacs-emacs-command-key "SPC" + + ;; The key used for Vim Ex commands (default ":") + dotspacemacs-ex-command-key ":" + + ;; The leader key accessible in `emacs state' and `insert state' + ;; (default "M-m") + dotspacemacs-emacs-leader-key "M-m" + + ;; Major mode leader key is a shortcut key which is the equivalent of + ;; pressing ` m`. Set it to `nil` to disable it. (default ",") + dotspacemacs-major-mode-leader-key "," + + ;; Major mode leader key accessible in `emacs state' and `insert state'. + ;; (default "C-M-m" for terminal mode, "" for GUI mode). + ;; Thus M-RET should work as leader key in both GUI and terminal modes. + ;; C-M-m also should work in terminal mode, but not in GUI mode. + dotspacemacs-major-mode-emacs-leader-key (if window-system "" "C-M-m") + + ;; These variables control whether separate commands are bound in the GUI to + ;; the key pairs `C-i', `TAB' and `C-m', `RET'. + ;; Setting it to a non-nil value, allows for separate commands under `C-i' + ;; and TAB or `C-m' and `RET'. + ;; In the terminal, these pairs are generally indistinguishable, so this only + ;; works in the GUI. (default nil) + dotspacemacs-distinguish-gui-tab nil + + ;; Name of the default layout (default "Default") + dotspacemacs-default-layout-name "Default" + + ;; If non-nil the default layout name is displayed in the mode-line. + ;; (default nil) + dotspacemacs-display-default-layout nil + + ;; If non-nil then the last auto saved layouts are resumed automatically upon + ;; start. (default nil) + dotspacemacs-auto-resume-layouts nil + + ;; If non-nil, auto-generate layout name when creating new layouts. Only has + ;; effect when using the "jump to layout by number" commands. (default nil) + dotspacemacs-auto-generate-layout-names nil + + ;; Size (in MB) above which spacemacs will prompt to open the large file + ;; literally to avoid performance issues. Opening a file literally means that + ;; no major mode or minor modes are active. (default is 1) + dotspacemacs-large-file-size 1 + + ;; Location where to auto-save files. Possible values are `original' to + ;; auto-save the file in-place, `cache' to auto-save the file to another + ;; file stored in the cache directory and `nil' to disable auto-saving. + ;; (default 'cache) + dotspacemacs-auto-save-file-location 'cache + + ;; Maximum number of rollback slots to keep in the cache. (default 5) + dotspacemacs-max-rollback-slots 5 + + ;; If non-nil, the paste transient-state is enabled. While enabled, after you + ;; paste something, pressing `C-j' and `C-k' several times cycles through the + ;; elements in the `kill-ring'. (default nil) + dotspacemacs-enable-paste-transient-state nil + + ;; Which-key delay in seconds. The which-key buffer is the popup listing + ;; the commands bound to the current keystroke sequence. (default 0.4) + dotspacemacs-which-key-delay 0.4 + + ;; Which-key frame position. Possible values are `right', `bottom' and + ;; `right-then-bottom'. right-then-bottom tries to display the frame to the + ;; right; if there is insufficient space it displays it at the bottom. + ;; (default 'bottom) + dotspacemacs-which-key-position 'bottom + + ;; Control where `switch-to-buffer' displays the buffer. If nil, + ;; `switch-to-buffer' displays the buffer in the current window even if + ;; another same-purpose window is available. If non-nil, `switch-to-buffer' + ;; displays the buffer in a same-purpose window even if the buffer can be + ;; displayed in the current window. (default nil) + dotspacemacs-switch-to-buffer-prefers-purpose nil + + ;; If non-nil a progress bar is displayed when spacemacs is loading. This + ;; may increase the boot time on some systems and emacs builds, set it to + ;; nil to boost the loading time. (default t) + dotspacemacs-loading-progress-bar nil + + ;; If non-nil the frame is fullscreen when Emacs starts up. (default nil) + ;; (Emacs 24.4+ only) + dotspacemacs-fullscreen-at-startup nil + + ;; If non-nil `spacemacs/toggle-fullscreen' will not use native fullscreen. + ;; Use to disable fullscreen animations in OSX. (default nil) + dotspacemacs-fullscreen-use-non-native nil + + ;; If non-nil the frame is maximized when Emacs starts up. + ;; Takes effect only if `dotspacemacs-fullscreen-at-startup' is nil. + ;; (default nil) (Emacs 24.4+ only) + dotspacemacs-maximized-at-startup nil + + ;; If non-nil the frame is undecorated when Emacs starts up. Combine this + ;; variable with `dotspacemacs-maximized-at-startup' in OSX to obtain + ;; borderless fullscreen. (default nil) + dotspacemacs-undecorated-at-startup nil + + ;; A value from the range (0..100), in increasing opacity, which describes + ;; the transparency level of a frame when it's active or selected. + ;; Transparency can be toggled through `toggle-transparency'. (default 90) + dotspacemacs-active-transparency 90 + + ;; A value from the range (0..100), in increasing opacity, which describes + ;; the transparency level of a frame when it's inactive or deselected. + ;; Transparency can be toggled through `toggle-transparency'. (default 90) + dotspacemacs-inactive-transparency 90 + + ;; If non-nil show the titles of transient states. (default t) + dotspacemacs-show-transient-state-title t + + ;; If non-nil show the color guide hint for transient state keys. (default t) + dotspacemacs-show-transient-state-color-guide t + + ;; If non-nil unicode symbols are displayed in the mode line. + ;; If you use Emacs as a daemon and wants unicode characters only in GUI set + ;; the value to quoted `display-graphic-p'. (default t) + dotspacemacs-mode-line-unicode-symbols t + + ;; If non-nil smooth scrolling (native-scrolling) is enabled. Smooth + ;; scrolling overrides the default behavior of Emacs which recenters point + ;; when it reaches the top or bottom of the screen. (default t) + dotspacemacs-smooth-scrolling t + + ;; Show the scroll bar while scrolling. The auto hide time can be configured + ;; by setting this variable to a number. (default t) + dotspacemacs-scroll-bar-while-scrolling t + + ;; Control line numbers activation. + ;; If set to `t', `relative' or `visual' then line numbers are enabled in all + ;; `prog-mode' and `text-mode' derivatives. If set to `relative', line + ;; numbers are relative. If set to `visual', line numbers are also relative, + ;; but lines are only visual lines are counted. For example, folded lines + ;; will not be counted and wrapped lines are counted as multiple lines. + ;; This variable can also be set to a property list for finer control: + ;; '(:relative nil + ;; :visual nil + ;; :disabled-for-modes dired-mode + ;; doc-view-mode + ;; markdown-mode + ;; org-mode + ;; pdf-view-mode + ;; text-mode + ;; :size-limit-kb 1000) + ;; When used in a plist, `visual' takes precedence over `relative'. + ;; (default nil) + dotspacemacs-line-numbers 'relative + + ;; Code folding method. Possible values are `evil', `origami' and `vimish'. + ;; (default 'evil) + dotspacemacs-folding-method 'evil + + ;; If non-nil and `dotspacemacs-activate-smartparens-mode' is also non-nil, + ;; `smartparens-strict-mode' will be enabled in programming modes. + ;; (default nil) + dotspacemacs-smartparens-strict-mode nil + + ;; If non-nil smartparens-mode will be enabled in programming modes. + ;; (default t) + dotspacemacs-activate-smartparens-mode t + + ;; If non-nil pressing the closing parenthesis `)' key in insert mode passes + ;; over any automatically added closing parenthesis, bracket, quote, etc... + ;; This can be temporary disabled by pressing `C-q' before `)'. (default nil) + dotspacemacs-smart-closing-parenthesis nil + + ;; Select a scope to highlight delimiters. Possible values are `any', + ;; `current', `all' or `nil'. Default is `all' (highlight any scope and + ;; emphasis the current one). (default 'all) + dotspacemacs-highlight-delimiters 'all + + ;; If non-nil, start an Emacs server if one is not already running. + ;; (default nil) + dotspacemacs-enable-server nil + + ;; Set the emacs server socket location. + ;; If nil, uses whatever the Emacs default is, otherwise a directory path + ;; like \"~/.emacs.d/server\". It has no effect if + ;; `dotspacemacs-enable-server' is nil. + ;; (default nil) + dotspacemacs-server-socket-dir nil + + ;; If non-nil, advise quit functions to keep server open when quitting. + ;; (default nil) + dotspacemacs-persistent-server nil + + ;; List of search tool executable names. Spacemacs uses the first installed + ;; tool of the list. Supported tools are `rg', `ag', `pt', `ack' and `grep'. + ;; (default '("rg" "ag" "pt" "ack" "grep")) + dotspacemacs-search-tools '("rg" "ag" "pt" "ack" "grep") + + ;; Format specification for setting the frame title. + ;; %a - the `abbreviated-file-name', or `buffer-name' + ;; %t - `projectile-project-name' + ;; %I - `invocation-name' + ;; %S - `system-name' + ;; %U - contents of $USER + ;; %b - buffer name + ;; %f - visited file name + ;; %F - frame name + ;; %s - process status + ;; %p - percent of buffer above top of window, or Top, Bot or All + ;; %P - percent of buffer above bottom of window, perhaps plus Top, or Bot or All + ;; %m - mode name + ;; %n - Narrow if appropriate + ;; %z - mnemonics of buffer, terminal, and keyboard coding systems + ;; %Z - like %z, but including the end-of-line format + ;; If nil then Spacemacs uses default `frame-title-format' to avoid + ;; performance issues, instead of calculating the frame title by + ;; `spacemacs/title-prepare' all the time. + ;; (default "%I@%S") + dotspacemacs-frame-title-format "%I@%S" + + ;; Format specification for setting the icon title format + ;; (default nil - same as frame-title-format) + dotspacemacs-icon-title-format nil + + ;; Show trailing whitespace (default t) + dotspacemacs-show-trailing-whitespace t + + ;; Delete whitespace while saving buffer. Possible values are `all' + ;; to aggressively delete empty line and long sequences of whitespace, + ;; `trailing' to delete only the whitespace at end of lines, `changed' to + ;; delete only whitespace for changed lines or `nil' to disable cleanup. + ;; (default nil) + dotspacemacs-whitespace-cleanup nil + + ;; If non nil activate `clean-aindent-mode' which tries to correct + ;; virtual indentation of simple modes. This can interfer with mode specific + ;; indent handling like has been reported for `go-mode'. + ;; If it does deactivate it here. + ;; (default t) + dotspacemacs-use-clean-aindent-mode t + + ;; If non-nil shift your number row to match the entered keyboard layout + ;; (only in insert state). Currently supported keyboard layouts are: + ;; `qwerty-us', `qwertz-de' and `querty-ca-fr'. + ;; New layouts can be added in `spacemacs-editing' layer. + ;; (default nil) + dotspacemacs-swap-number-row nil + + ;; Either nil or a number of seconds. If non-nil zone out after the specified + ;; number of seconds. (default nil) + dotspacemacs-zone-out-when-idle nil + + ;; Run `spacemacs/prettify-org-buffer' when + ;; visiting README.org files of Spacemacs. + ;; (default nil) + dotspacemacs-pretty-docs nil + + ;; If nil the home buffer shows the full path of agenda items + ;; and todos. If non nil only the file name is shown. + dotspacemacs-home-shorten-agenda-source nil + + ;; If non-nil then byte-compile some of Spacemacs files. + dotspacemacs-byte-compile nil)) + +(defun dotspacemacs/user-env () + "Environment variables setup. +This function defines the environment variables for your Emacs session. By +default it calls `spacemacs/load-spacemacs-env' which loads the environment +variables declared in `~/.spacemacs.env' or `~/.spacemacs.d/.spacemacs.env'. +See the header of this file for more information." + (spacemacs/load-spacemacs-env)) + +(defun dotspacemacs/user-init () + "Initialization for user code: +This function is called immediately after `dotspacemacs/init', before layer +configuration. +It is mostly for variables that should be set before packages are loaded. +If you are unsure, try setting them in `dotspacemacs/user-config' first.") + + +(defun dotspacemacs/user-load () + "Library to load while dumping. +This function is called only while dumping Spacemacs configuration. You can +`require' or `load' the libraries of your choice that will be included in the +dump.") + + +(defun dotspacemacs/user-config () + "Configuration for user code: +This function is called at the very end of Spacemacs startup, after layer +configuration. +Put your configuration code here, except for variables that should be set +before packages are loaded.") + + +;; Do not write anything past this comment. This is where Emacs will +;; auto-generate custom variable definitions. +(defun dotspacemacs/emacs-custom-settings () + "Emacs custom settings. +This is an auto-generated function, do not modify its content directly, use +Emacs customize menu instead. +This function is called at the very end of Spacemacs initialization." +(custom-set-variables + ;; custom-set-variables was added by Custom. + ;; If you edit it by hand, you could mess it up, so be careful. + ;; Your init file should contain only one such instance. + ;; If there is more than one, they won't work right. + '(ansi-color-faces-vector + [default default default italic underline success warning error]) + '(custom-enabled-themes '(spacemacs-dark)) + '(custom-safe-themes + '("bffa9739ce0752a37d9b1eee78fc00ba159748f50dc328af4be661484848e476" default)) + '(evil-want-Y-yank-to-eol nil) + '(package-selected-packages + '(yasnippet-snippets xterm-color vterm unfill treemacs-magit terminal-here smeargle shell-pop orgit-forge orgit org-rich-yank org-projectile org-category-capture org-present org-pomodoro alert log4e gntp org-mime org-download org-cliplink org-brain mwim multi-term mmm-mode markdown-toc magit-section lsp-ui lsp-origami origami helm-org-rifle helm-lsp helm-gitignore helm-git-grep helm-company helm-c-yasnippet gnuplot gitignore-templates gitignore-mode gitconfig-mode gitattributes-mode git-timemachine git-messenger git-link git-gutter-fringe+ fringe-helper git-gutter+ gh-md fuzzy forge magit ghub closql emacsql-sqlite emacsql treepy git-commit with-editor transient flyspell-correct-helm flyspell-correct flycheck-pos-tip pos-tip evil-org eshell-z eshell-prompt-extras esh-help browse-at-remote auto-yasnippet auto-dictionary ac-ispell auto-complete tide web-mode typescript-mode rjsx-mode emmet-mode web-beautify tern prettier-js npm-mode nodejs-repl livid-mode skewer-mode js2-refactor yasnippet multiple-cursors js2-mode js-doc import-js grizzl impatient-mode htmlize simple-httpd helm-gtags ggtags dap-mode lsp-treemacs bui lsp-mode markdown-mode counsel-gtags counsel swiper ivy company add-node-modules-path ws-butler writeroom-mode winum which-key volatile-highlights vi-tilde-fringe uuidgen use-package undo-tree treemacs-projectile treemacs-persp treemacs-icons-dired treemacs-evil toc-org symon symbol-overlay string-inflection string-edit spaceline-all-the-icons restart-emacs request rainbow-delimiters quickrun popwin pcre2el password-generator paradox overseer org-superstar open-junk-file nameless multi-line macrostep lorem-ipsum link-hint indent-guide hybrid-mode hungry-delete hl-todo highlight-parentheses highlight-numbers highlight-indentation helm-xref helm-themes helm-swoop helm-purpose helm-projectile helm-org helm-mode-manager helm-make helm-ls-git helm-flx helm-descbinds helm-ag google-translate golden-ratio font-lock+ flycheck-package flycheck-elsa flx-ido fancy-battery eyebrowse expand-region evil-visualstar evil-visual-mark-mode evil-unimpaired evil-tutor evil-textobj-line evil-surround evil-numbers evil-nerd-commenter evil-mc evil-matchit evil-lisp-state evil-lion evil-indent-plus evil-iedit-state evil-goggles evil-exchange evil-escape evil-ediff evil-easymotion evil-collection evil-cleverparens evil-args evil-anzu eval-sexp-fu emr elisp-slime-nav editorconfig dumb-jump drag-stuff dotenv-mode dired-quick-sort diminish devdocs define-word column-enforce-mode clean-aindent-mode centered-cursor-mode auto-highlight-symbol auto-compile aggressive-indent ace-link ace-jump-helm-line)) + '(show-paren-mode t)) +(custom-set-faces + ;; custom-set-faces was added by Custom. + ;; If you edit it by hand, you could mess it up, so be careful. + ;; Your init file should contain only one such instance. + ;; If there is more than one, they won't work right. + ) +) diff --git a/files/.ssh/config b/files/home/.ssh/config similarity index 100% rename from files/.ssh/config rename to files/home/.ssh/config diff --git a/scripts/_utils.sh b/scripts/_utils.sh index d6a2b93..1406e50 100755 --- a/scripts/_utils.sh +++ b/scripts/_utils.sh @@ -27,7 +27,7 @@ function bin_in_path { # @arg $1 apt package to test function apt_installed { - dpkg --status $1 + dpkg --status $1 >/dev/null } function clean { @@ -65,3 +65,23 @@ function add_repository { function install_file { sudo apt-get install -qqf $(cat $1) } + +# @arg $1 JSON object containing the following keys +# * name - apt repository +# * target - gpg signing key url +function stow_package { + name=$(jq -r ".name" <<<"$1") + target=$(jq -r ".target" <<<"$1") + + case $target in + HOME) + rm $HOME/.bashrc || true + rm $HOME/.profile || true + target=$HOME + ;; + *) + ;; + esac + + sudo stow --dir="$ABS_DIR/files" --target=$target $name +} diff --git a/scripts/bootstrap.sh b/scripts/bootstrap.sh deleted file mode 100755 index 28d7cea..0000000 --- a/scripts/bootstrap.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env bash -set -eo pipefail - -# -# 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 - -# TODO -# Migrate to config.fish -rm $HOME/.bashrc -rm $HOME/.profile - -echo "Stowing $ABS_DIR to $HOME" -stow --dir=$ABS_DIR --target=$HOME files diff --git a/scripts/install.d/02-fish.sh b/scripts/install.d/02-fish.sh index 4f38059..adba7d0 100755 --- a/scripts/install.d/02-fish.sh +++ b/scripts/install.d/02-fish.sh @@ -1,7 +1,8 @@ #!/usr/bin/env bash fish --version -current_shell=`readlink -f /proc/$$/exe` +current_shell=`grep "^$USER" /etc/passwd` +current_shell=${current_shell##*:} fish_shell=`which fish` if [[ "$current_shell" != "$fish_shell" ]]; then chsh -s "$fish_shell" diff --git a/scripts/install.d/13-nvm.sh b/scripts/install.d/13-nvm.sh index a526a50..dd24ef5 100755 --- a/scripts/install.d/13-nvm.sh +++ b/scripts/install.d/13-nvm.sh @@ -8,7 +8,8 @@ fi [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm nvm --version -nvm install node -nvm use node +nvm alias default lts/fermium +nvm install lts/fermium +nvm use lts/fermium node --version diff --git a/scripts/install.d/17-emacs.sh b/scripts/install.d/17-emacs.sh new file mode 100644 index 0000000..fb2967d --- /dev/null +++ b/scripts/install.d/17-emacs.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +if [ ! -d ~/.emacs.d ]; then + git clone https://github.com/syl20bnr/spacemacs ~/.emacs.d +fi diff --git a/scripts/install.sh b/scripts/install.sh index 5c0fca7..bd0ac49 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -22,7 +22,7 @@ LOG_DIR="${ABS_DIR}/logs" mkdir -p "$LOG_DIR" LOG_TARGET=${LOG_TARGET:-"${LOG_DIR}/${UUID}.log"} -main() { +install() { echo "Running $NAME at $TIME" echo "Running as $USER on $HOST" @@ -53,8 +53,11 @@ main() { done # Install dotfiles on system and load them - figlet -c "Bootstrapping..." - $ABS_DIR/scripts/bootstrap.sh + figlet -c "Stowing..." + for i in $(jq ".stow_packages | keys | .[]" "$CONFIG"); do + value=$(jq -r ".stow_packages[$i]" "$CONFIG") + stow_package "$value" + done source "$HOME/.profile" # Run custom installer scripts @@ -65,5 +68,5 @@ main() { done } -echo "main: Logging to $LOG_TARGET" -main 2>&1 | tee "$LOG_TARGET" +echo "install: Logging to $LOG_TARGET" +install 2>&1 | tee "$LOG_TARGET" diff --git a/scripts/install_config.json b/scripts/install_config.json index db8652b..dcc762a 100644 --- a/scripts/install_config.json +++ b/scripts/install_config.json @@ -45,9 +45,11 @@ "devscripts", "docker-ce", "docker-ce-cli", + "emacs", "fd-find", "figlet", "fish", + "fonts-nanum", "fortune-mod", "google-cloud-sdk", "git", @@ -67,7 +69,9 @@ ], "node_dependencies": [ "firebase-tools", - "neovim" + "neovim", + "typescript", + "typescript-language-server" ], "pip_dependencies": [ "awscli", @@ -76,5 +80,11 @@ "poetry", "python-language-server[all]", "pyvim" + ], + "stow_packages": [ + { + "name": "home", + "target": "HOME" + } ] } \ No newline at end of file From fb50593834e5e9fe5b1ff8a04469f327ee0c0530 Mon Sep 17 00:00:00 2001 From: Andrejus Date: Tue, 27 Apr 2021 17:29:19 +0100 Subject: [PATCH 08/14] Restore config.fish, bump gitignore/utils --- files/home/.config/fish/.gitignore | 2 ++ files/home/.config/fish/config.fish | 17 +++++++++++++++++ files/home/.config/fish/fish_plugins | 1 - scripts/_utils.sh | 1 + 4 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 files/home/.config/fish/.gitignore create mode 100644 files/home/.config/fish/config.fish diff --git a/files/home/.config/fish/.gitignore b/files/home/.config/fish/.gitignore new file mode 100644 index 0000000..a94e2fd --- /dev/null +++ b/files/home/.config/fish/.gitignore @@ -0,0 +1,2 @@ +functions +!functions/nvm.fish diff --git a/files/home/.config/fish/config.fish b/files/home/.config/fish/config.fish new file mode 100644 index 0000000..b47f13e --- /dev/null +++ b/files/home/.config/fish/config.fish @@ -0,0 +1,17 @@ +# Only execute in interactive shell +if status is-interactive + + # Fish specific + set fish_greeting + set --global hydro_symbol_prompt "\$" + set --global hydro_symbol_git_dirty "~" + if type -q base16-seti + base16-seti + end + + # Cross-shell setup + if begin; test -e $HOME/.profile; and type -q replay; end + replay "source $HOME/.profile" + end + +end diff --git a/files/home/.config/fish/fish_plugins b/files/home/.config/fish/fish_plugins index 85cb5ec..949607f 100644 --- a/files/home/.config/fish/fish_plugins +++ b/files/home/.config/fish/fish_plugins @@ -4,4 +4,3 @@ jorgebucaran/replay.fish joseluisq/gitnow tomyun/base16-fish PatrickF1/fzf.fish -jorgebucaran/fisher diff --git a/scripts/_utils.sh b/scripts/_utils.sh index 1406e50..e2ea0ef 100755 --- a/scripts/_utils.sh +++ b/scripts/_utils.sh @@ -83,5 +83,6 @@ function stow_package { ;; esac + echo "Stowing $ABS_DIR/files/$name to $target" sudo stow --dir="$ABS_DIR/files" --target=$target $name } From e19d1cb4d346e725b68092a6934cbef8bb0ff1e5 Mon Sep 17 00:00:00 2001 From: Andrejus Date: Fri, 30 Apr 2021 18:57:51 +0100 Subject: [PATCH 09/14] fix: fish plugins/utils --- files/home/.config/fish/fish_plugins | 1 + scripts/_utils.sh | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/files/home/.config/fish/fish_plugins b/files/home/.config/fish/fish_plugins index 949607f..85cb5ec 100644 --- a/files/home/.config/fish/fish_plugins +++ b/files/home/.config/fish/fish_plugins @@ -4,3 +4,4 @@ jorgebucaran/replay.fish joseluisq/gitnow tomyun/base16-fish PatrickF1/fzf.fish +jorgebucaran/fisher diff --git a/scripts/_utils.sh b/scripts/_utils.sh index e2ea0ef..833eefa 100755 --- a/scripts/_utils.sh +++ b/scripts/_utils.sh @@ -75,8 +75,8 @@ function stow_package { case $target in HOME) - rm $HOME/.bashrc || true - rm $HOME/.profile || true + rm -f $HOME/.bashrc + rm -f $HOME/.profile target=$HOME ;; *) From 1f569c7e0921fe0b6e61ab26c2e07e65bcd91d7d Mon Sep 17 00:00:00 2001 From: Andrejus Date: Sun, 2 May 2021 21:53:29 +0100 Subject: [PATCH 10/14] feat: publish script and cleanup --- .dockerignore | 5 + .gitignore | 4 - README.md | 4 +- files/home/.config/alacritty/alacritty.yml | 4 +- files/home/.config/fish/.gitignore | 5 +- files/home/.config/fish/fish_plugins | 1 + files/home/.config/nvim/.gitignore | 1 + files/home/.profile | 8 +- scripts/install.d/12-poetry.sh | 2 - scripts/install.d/15-java.sh | 2 - scripts/install.d/17-emacs.sh | 1 + scripts/install.d/30-docker.sh | 2 + 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 - scripts/install_config.json | 1 + scripts/publish.sh | 11 +- scripts/setup.sh | 2 +- terraform/module/main.tf | 120 +++++++++++++++++---- terraform/module/outputs.tf | 4 +- terraform/module/variables.tf | 17 +++ 22 files changed, 144 insertions(+), 58 deletions(-) create mode 100644 files/home/.config/nvim/.gitignore delete mode 100644 scripts/install.d/12-poetry.sh delete mode 100755 scripts/install.d/15-java.sh delete mode 100755 scripts/install.d/31-gcloud.sh delete mode 100755 scripts/install.d/32-firebase.sh delete mode 100755 scripts/install.d/33-aws.sh delete mode 100755 scripts/install.d/34-terraform.sh mode change 100644 => 100755 scripts/publish.sh diff --git a/.dockerignore b/.dockerignore index 77c370a..70c8676 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,3 +1,8 @@ .gitignore .dockerignore Dockerfile + +**/plugged +**/completions +**/conf.d +**/fish_variables diff --git a/.gitignore b/.gitignore index 34b0f94..3032954 100644 --- a/.gitignore +++ b/.gitignore @@ -8,11 +8,7 @@ **/known_hosts* # setup files -**/plugged **/autoload -**/completions -**/conf.d -**/fish_variables **/gcloud **/coc **/configstore diff --git a/README.md b/README.md index 65b4289..e4bd754 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ -# andrejusk/dotfiles +# dots.andrejus.dev Collection of experimental dotfiles and supporting install scripts. ## Install - wget https://raw.githubusercontent.com/andrejusk/dotfiles/master/scripts/setup.sh -qO - | bash + wget https://dots.andrejus.dev/setup.sh -qO - | bash ## Stack diff --git a/files/home/.config/alacritty/alacritty.yml b/files/home/.config/alacritty/alacritty.yml index 27ee137..daa2955 100644 --- a/files/home/.config/alacritty/alacritty.yml +++ b/files/home/.config/alacritty/alacritty.yml @@ -1,5 +1,5 @@ -# env: -# TERM: xterm-256color +env: + TERM: xterm-256color window: dynamic_title: true diff --git a/files/home/.config/fish/.gitignore b/files/home/.config/fish/.gitignore index a94e2fd..20c132f 100644 --- a/files/home/.config/fish/.gitignore +++ b/files/home/.config/fish/.gitignore @@ -1,2 +1,3 @@ -functions -!functions/nvm.fish +completions +conf.d +fish_variables diff --git a/files/home/.config/fish/fish_plugins b/files/home/.config/fish/fish_plugins index 949607f..85cb5ec 100644 --- a/files/home/.config/fish/fish_plugins +++ b/files/home/.config/fish/fish_plugins @@ -4,3 +4,4 @@ jorgebucaran/replay.fish joseluisq/gitnow tomyun/base16-fish PatrickF1/fzf.fish +jorgebucaran/fisher diff --git a/files/home/.config/nvim/.gitignore b/files/home/.config/nvim/.gitignore new file mode 100644 index 0000000..ed0e3f9 --- /dev/null +++ b/files/home/.config/nvim/.gitignore @@ -0,0 +1 @@ +plugged diff --git a/files/home/.profile b/files/home/.profile index b724b0f..26b7d07 100644 --- a/files/home/.profile +++ b/files/home/.profile @@ -48,13 +48,6 @@ export YARN_DIR=${YARN_DIR:-"$HOME/.yarn"} mkdir -p "$YARN_DIR" export PATH="$YARN_DIR/bin:$PATH" -# fzf -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"} @@ -74,3 +67,4 @@ fi # (__) (__)(_")("_)\_)-' '-(_/(__) (__)(__) # alias j="z" +alias fd=`which fdfind` diff --git a/scripts/install.d/12-poetry.sh b/scripts/install.d/12-poetry.sh deleted file mode 100644 index bceaead..0000000 --- a/scripts/install.d/12-poetry.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/usr/bin/env bash -poetry --version diff --git a/scripts/install.d/15-java.sh b/scripts/install.d/15-java.sh deleted file mode 100755 index 0fdcee5..0000000 --- a/scripts/install.d/15-java.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/usr/bin/env bash -java --version diff --git a/scripts/install.d/17-emacs.sh b/scripts/install.d/17-emacs.sh index fb2967d..3bd6cbb 100644 --- a/scripts/install.d/17-emacs.sh +++ b/scripts/install.d/17-emacs.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash if [ ! -d ~/.emacs.d ]; then + echo "Cloning spacemacs" git clone https://github.com/syl20bnr/spacemacs ~/.emacs.d fi diff --git a/scripts/install.d/30-docker.sh b/scripts/install.d/30-docker.sh index 70a6ebd..3d9ad2e 100755 --- a/scripts/install.d/30-docker.sh +++ b/scripts/install.d/30-docker.sh @@ -3,9 +3,11 @@ docker --version readonly docker_group="docker" if ! grep -q "$docker_group" /etc/group; then + echo "Adding docker group" sudo groupadd "$docker_group" fi if ! groups "$USER" | grep -q "\b$docker_group\b"; then + echo "Adding user to docker group" sudo usermod -aG docker "$USER" fi diff --git a/scripts/install.d/31-gcloud.sh b/scripts/install.d/31-gcloud.sh deleted file mode 100755 index d6675f1..0000000 --- a/scripts/install.d/31-gcloud.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/usr/bin/env bash -gcloud --version diff --git a/scripts/install.d/32-firebase.sh b/scripts/install.d/32-firebase.sh deleted file mode 100755 index ed19a2a..0000000 --- a/scripts/install.d/32-firebase.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/usr/bin/env bash -firebase --version diff --git a/scripts/install.d/33-aws.sh b/scripts/install.d/33-aws.sh deleted file mode 100755 index bfb313c..0000000 --- a/scripts/install.d/33-aws.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/usr/bin/env bash -aws --version diff --git a/scripts/install.d/34-terraform.sh b/scripts/install.d/34-terraform.sh deleted file mode 100755 index 9cfbcc4..0000000 --- a/scripts/install.d/34-terraform.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/usr/bin/env bash -terraform --version diff --git a/scripts/install_config.json b/scripts/install_config.json index dcc762a..3086c10 100644 --- a/scripts/install_config.json +++ b/scripts/install_config.json @@ -51,6 +51,7 @@ "fish", "fonts-nanum", "fortune-mod", + "fzf", "google-cloud-sdk", "git", "kubectl", diff --git a/scripts/publish.sh b/scripts/publish.sh old mode 100644 new mode 100755 index 18c1bca..ff4b735 --- a/scripts/publish.sh +++ b/scripts/publish.sh @@ -1,8 +1,11 @@ #!/usr/bin/env bash set -eo pipefail -# -# Script that publishes the set up script for new installations. -# +BUCKET=${BUCKET:-"dots.andrejus.dev"} -echo "Publishing..." +NAME=$(basename "$0") +REL_DIR=$(dirname "$0") +ABS_DIR=$(readlink -f $REL_DIR/../) # Scripts are nested inside of /scripts + +# Publish setup script to public bucket +gsutil cp "$ABS_DIR/scripts/setup.sh" "gs://$BUCKET/setup.sh" diff --git a/scripts/setup.sh b/scripts/setup.sh index 6127a2b..dd0dfeb 100755 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -15,7 +15,7 @@ setup_dir=${DOTFILES_DIR:-$HOME/.dotfiles} # Prevent overwriting existing installation mkdir -p $setup_dir -if [ -z `ls -A $setup_dir` ]; then +if [[ -z $(ls -A $setup_dir) ]]; then echo "Setting up $setup_dir" else echo "Failed: Setup directory not empty $setup_dir" diff --git a/terraform/module/main.tf b/terraform/module/main.tf index 003d04d..9ef5acf 100644 --- a/terraform/module/main.tf +++ b/terraform/module/main.tf @@ -1,36 +1,112 @@ -# Static bucket +locals { + fqdn = "${var.domain}." +} + +# ================================================================= +# Public bucket for static content +# ================================================================= +resource "google_project_service" "storage" { + service = "storage.googleapis.com" +} + resource "google_storage_bucket" "bucket" { - provider = google-beta + name = var.domain + depends_on = [google_project_service.storage] - project = var.project + location = var.gcs_location +} - name = var.domain - location = "EU" - storage_class = "MULTI_REGIONAL" +resource "google_storage_default_object_access_control" "bucket_public" { + bucket = google_storage_bucket.bucket.name + role = "READER" + entity = "allUsers" +} - versioning { - enabled = var.enable_versioning + +# ================================================================= +# Expose bucket via HTTPS using Cloud CDN +# +# Adapted from +# https://medium.com/cognite/configuring-google-cloud-cdn-with-terraform-ab65bb0456a9 +# ================================================================= +resource "google_project_service" "compute" { + service = "compute.googleapis.com" +} + +resource "google_compute_backend_bucket" "backend" { + name = "${var.prefix}-backend" + depends_on = [google_project_service.compute] + + bucket_name = google_storage_bucket.bucket.name + description = "Bucket backend for serving static content through CDN" + enable_cdn = true +} + +resource "google_compute_url_map" "urlmap" { + name = "${var.prefix}-urlmap" + description = "URL map to bucket backend service" + default_service = google_compute_backend_bucket.backend.self_link +} + +resource "google_compute_managed_ssl_certificate" "certificate" { + name = "${var.prefix}-certificate" + depends_on = [google_project_service.compute] + + managed { + domains = [local.fqdn] } } -# Allow public read -resource "google_storage_default_object_acl" "bucket_acl" { - provider = google-beta - bucket = google_storage_bucket.bucket.name - role_entity = ["READER:allUsers"] +resource "google_compute_target_https_proxy" "https" { + name = "${var.prefix}-https-proxy" + url_map = google_compute_url_map.urlmap.self_link + ssl_certificates = [google_compute_managed_ssl_certificate.certificate.self_link] } -# DNS entry -resource "google_dns_record_set" "cname" { - provider = google-beta +resource "google_compute_global_address" "ipv4" { + name = "${var.prefix}-ipv4" + depends_on = [google_project_service.compute] - depends_on = [google_storage_bucket.bucket] + ip_version = "IPV4" + address_type = "EXTERNAL" +} - project = var.project +resource "google_compute_global_address" "ipv6" { + name = "${var.prefix}-ipv6" + depends_on = [google_project_service.compute] - name = "${var.domain}." + ip_version = "IPV6" + address_type = "EXTERNAL" +} + +resource "google_compute_global_forwarding_rule" "fwd_ipv4" { + name = "${var.prefix}-fwd-ipv4" + target = google_compute_target_https_proxy.https.self_link + ip_address = google_compute_global_address.ipv4.address + port_range = "443" +} + +resource "google_compute_global_forwarding_rule" "fwd_ipv6" { + name = "${var.prefix}-fwd-ipv6" + target = google_compute_target_https_proxy.https.self_link + ip_address = google_compute_global_address.ipv6.address + port_range = "443" +} + +resource "google_dns_record_set" "dns_a_record" { + name = local.fqdn managed_zone = var.dns_zone - type = "CNAME" - ttl = 300 - rrdatas = ["c.storage.googleapis.com."] + + type = "A" + ttl = var.dns_ttl + rrdatas = [google_compute_global_address.ipv4.address] +} + +resource "google_dns_record_set" "dns_aaaa_record" { + name = local.fqdn + managed_zone = var.dns_zone + + type = "AAAA" + ttl = var.dns_ttl + rrdatas = [google_compute_global_address.ipv6.address] } diff --git a/terraform/module/outputs.tf b/terraform/module/outputs.tf index a0639ac..d7b9c3b 100644 --- a/terraform/module/outputs.tf +++ b/terraform/module/outputs.tf @@ -1,7 +1,7 @@ output "bucket_url" { - value = "storage.googleapis.com/${var.domain}" + value = "storage.googleapis.com/${var.domain}" } output "bucket_link" { - value = google_storage_bucket.bucket.self_link + value = google_storage_bucket.bucket.self_link } diff --git a/terraform/module/variables.tf b/terraform/module/variables.tf index 39fbdd9..e37ac54 100644 --- a/terraform/module/variables.tf +++ b/terraform/module/variables.tf @@ -1,3 +1,8 @@ +variable "prefix" { + description = "Resource prefix" + default = "dots" +} + variable "project" { description = "Google Cloud project to host resources in" type = string @@ -12,3 +17,15 @@ variable "dns_zone" { description = "Cloud DNS zone to use" type = string } + +variable "gcs_location" { + type = string + description = "Google Stoage location to provision resources in" + default = "EU" # Multi-region, Europe +} + +variable "dns_ttl" { + type = number + description = "DNS TTL to use for records" + default = 3600 +} From 9c5f243cddbb0b6d55f707d85fcb3b8f35347bf1 Mon Sep 17 00:00:00 2001 From: Andrejus Date: Sun, 2 May 2021 23:00:42 +0100 Subject: [PATCH 11/14] feat: index page, publish ci --- .github/workflows/publish.yml | 15 +++++++++------ README.md | 21 ++++++++++++--------- files/home/.profile | 9 +++++++-- terraform/module/main.tf | 20 ++++++++++++++++++++ terraform/module/public/index.html | 24 ++++++++++++++++++++++++ 5 files changed, 72 insertions(+), 17 deletions(-) create mode 100644 terraform/module/public/index.html diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index c6f380e..ea3bacb 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,14 +1,17 @@ name: Dotfiles publisher -on: - push: - branches: - - master +on: [push] +# on: +# push: +# branches: +# - master jobs: publish-installer: - name: Publish install script + name: Publish setup script runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - name: Publish to CDN + - env: + APPLICATION_CREDENTIALS: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }} + name: Publish to CDN run: ./scripts/publish.sh diff --git a/README.md b/README.md index e4bd754..9214ef6 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # dots.andrejus.dev -Collection of experimental dotfiles and supporting install scripts. +Collection of my dotfiles and supporting install scripts ## Install @@ -8,21 +8,24 @@ Collection of experimental dotfiles and supporting install scripts. ## Stack -### Shell -🐟 fish (+ fisher) +Tested and maintained against Debian buster -### Editor -neovim (+ vim-plug) +### Shells + +- 🐟 fish (+ fisher) + +### Editors + +- neovim (+ vim-plug) +- emacs ### Languages -- js (nvm, node, yarn) +- node.js (nvm, yarn) - python (pyenv, poetry) -- java ### Tools -- docker (+ docker-compose) +- docker - terraform - gcloud, firebase, awscli -- screenfetch diff --git a/files/home/.profile b/files/home/.profile index 26b7d07..a3dd31f 100644 --- a/files/home/.profile +++ b/files/home/.profile @@ -40,8 +40,13 @@ export PATH="$POETRY_ROOT/bin:$PATH" export NVM_DIR=${NVM_DIR:-"$HOME/.nvm"} mkdir -p "$NVM_DIR" export PATH="$NVM_DIR/bin:$PATH" -VERSION=`cat $NVM_DIR/alias/lts/fermium` # Default v14 -export PATH="$NVM_DIR/versions/node/$VERSION/bin:$PATH" + +# node (default v14) +node_alias="$NVM_DIR/alias/lts/fermium" +if [ -f "$node_alias" ]; then + VERSION=`cat $node_alias` + export PATH="$NVM_DIR/versions/node/$VERSION/bin:$PATH" +fi # yarn export YARN_DIR=${YARN_DIR:-"$HOME/.yarn"} diff --git a/terraform/module/main.tf b/terraform/module/main.tf index 9ef5acf..5a8cfee 100644 --- a/terraform/module/main.tf +++ b/terraform/module/main.tf @@ -14,6 +14,10 @@ resource "google_storage_bucket" "bucket" { depends_on = [google_project_service.storage] location = var.gcs_location + website { + main_page_suffix = "index.html" + not_found_page = "index.html" + } } resource "google_storage_default_object_access_control" "bucket_public" { @@ -22,6 +26,22 @@ resource "google_storage_default_object_access_control" "bucket_public" { entity = "allUsers" } +resource "google_storage_bucket_object" "index" { + name = "index.html" + source = "${path.module}/public/index.html" + bucket = google_storage_bucket.bucket.name +} + +resource "google_service_account" "uploader_sa" { + account_id = "${var.prefix}-uploader-sa" + display_name = "Uploader Service Account" +} + +resource "google_storage_default_object_access_control" "upload" { + bucket = google_storage_bucket.bucket.name + role = "OWNER" + entity = "user-${google_service_account.uploader_sa.email}" +} # ================================================================= # Expose bucket via HTTPS using Cloud CDN diff --git a/terraform/module/public/index.html b/terraform/module/public/index.html new file mode 100644 index 0000000..b64b87f --- /dev/null +++ b/terraform/module/public/index.html @@ -0,0 +1,24 @@ + + + + andrejus.dev + + + + + + + + + +
+

Redirecting to GitHub repo...

+
+ + From e2e7c8cbcc43e04915b80e76ef011836d6e95d3c Mon Sep 17 00:00:00 2001 From: Andrejus Date: Sun, 2 May 2021 23:07:48 +0100 Subject: [PATCH 12/14] fix: setup gcloud --- .github/workflows/publish.yml | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index ea3bacb..722ce45 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -11,7 +11,11 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - env: - APPLICATION_CREDENTIALS: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }} - name: Publish to CDN + - name: Set up Cloud SDK + uses: google-github-actions/setup-gcloud@master + with: + project_id: ${{ secrets.GCP_PROJECT_ID }} + service_account_key: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }} + export_default_credentials: true + - name: Publish to CDN run: ./scripts/publish.sh From 7bba783de3a49a734b3ff70fddc608d32c3640df Mon Sep 17 00:00:00 2001 From: Andrejus Date: Sun, 2 May 2021 23:34:45 +0100 Subject: [PATCH 13/14] fix: publish CI --- .github/workflows/publish.yml | 9 ++++----- README.md | 4 ++++ terraform/module/main.tf | 27 ++++++++++++--------------- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 722ce45..3d936e2 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,9 +1,8 @@ name: Dotfiles publisher -on: [push] -# on: -# push: -# branches: -# - master +on: + push: + branches: + - master jobs: publish-installer: diff --git a/README.md b/README.md index 9214ef6..b34c462 100644 --- a/README.md +++ b/README.md @@ -4,10 +4,14 @@ Collection of my dotfiles and supporting install scripts ## Install +[![Dotfiles publisher](https://github.com/andrejusk/dotfiles/actions/workflows/publish.yml/badge.svg?branch=master)](https://github.com/andrejusk/dotfiles/actions/workflows/publish.yml) + wget https://dots.andrejus.dev/setup.sh -qO - | bash ## Stack +[![Dotfiles CI](https://github.com/andrejusk/dotfiles/actions/workflows/ci.yml/badge.svg)](https://github.com/andrejusk/dotfiles/actions/workflows/ci.yml) + Tested and maintained against Debian buster ### Shells diff --git a/terraform/module/main.tf b/terraform/module/main.tf index 5a8cfee..4c81429 100644 --- a/terraform/module/main.tf +++ b/terraform/module/main.tf @@ -3,12 +3,17 @@ locals { } # ================================================================= -# Public bucket for static content +# Public bucket for static content with uploader service account # ================================================================= resource "google_project_service" "storage" { service = "storage.googleapis.com" } +resource "google_service_account" "uploader_sa" { + account_id = "${var.prefix}-uploader-sa" + display_name = "Uploader Service Account" +} + resource "google_storage_bucket" "bucket" { name = var.domain depends_on = [google_project_service.storage] @@ -20,10 +25,13 @@ resource "google_storage_bucket" "bucket" { } } -resource "google_storage_default_object_access_control" "bucket_public" { +resource "google_storage_bucket_acl" "bucket_acl" { bucket = google_storage_bucket.bucket.name - role = "READER" - entity = "allUsers" + + role_entity = [ + "READER:allUsers", + "OWNER:user-${google_service_account.uploader_sa.email}", + ] } resource "google_storage_bucket_object" "index" { @@ -32,17 +40,6 @@ resource "google_storage_bucket_object" "index" { bucket = google_storage_bucket.bucket.name } -resource "google_service_account" "uploader_sa" { - account_id = "${var.prefix}-uploader-sa" - display_name = "Uploader Service Account" -} - -resource "google_storage_default_object_access_control" "upload" { - bucket = google_storage_bucket.bucket.name - role = "OWNER" - entity = "user-${google_service_account.uploader_sa.email}" -} - # ================================================================= # Expose bucket via HTTPS using Cloud CDN # From 38a8e81d69352db740bce9cd8d3d506d263bfae0 Mon Sep 17 00:00:00 2001 From: Andrejus Date: Sun, 2 May 2021 23:57:48 +0100 Subject: [PATCH 14/14] fix: CI --- .dockerignore | 1 + scripts/install.d/02-fish.sh | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.dockerignore b/.dockerignore index 70c8676..7723660 100644 --- a/.dockerignore +++ b/.dockerignore @@ -6,3 +6,4 @@ Dockerfile **/completions **/conf.d **/fish_variables +**/functions diff --git a/scripts/install.d/02-fish.sh b/scripts/install.d/02-fish.sh index adba7d0..ffbba54 100755 --- a/scripts/install.d/02-fish.sh +++ b/scripts/install.d/02-fish.sh @@ -5,12 +5,12 @@ current_shell=`grep "^$USER" /etc/passwd` current_shell=${current_shell##*:} fish_shell=`which fish` if [[ "$current_shell" != "$fish_shell" ]]; then - chsh -s "$fish_shell" + sudo usermod --shell "$fish_shell" "$USER" fi 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" + fish -c "curl -sL https://git.io/fisher | source && fisher update" fi fish -c "fisher update"