add install targets

This commit is contained in:
Andrejus
2020-03-25 19:57:24 +00:00
parent 826cc598b9
commit ae4fc2832c
19 changed files with 111 additions and 196 deletions

View File

@@ -1,12 +1,10 @@
on: [push] on: [push]
jobs: jobs:
build: tests:
runs-on: ubuntu-latest runs-on: ubuntu-latest
name: name: tests
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- name: Build Docker image - name: Run tests
run: make build
- name: Test Docker image
run: make test run: make test

View File

@@ -1,44 +1,27 @@
from ubuntu:bionic from ubuntu:bionic as install
# ---------------------------------------------------------------------------- # # Install sudo and make, git since built-in is skipped
# (usually) Cached steps
# ---------------------------------------------------------------------------- #
# See bootstrap.sh
ENV FAST_MODE="true"
ENV WORKSPACE="$HOME/workspace"
# Set Noninteractive
RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections
RUN apt-get -qqy update \
# Install sudo for compatibility, git since built-in is skipped, make && apt-get -qqy install sudo git make
RUN apt-get -y update \
&& apt-get -y install sudo git make
# Create user with sudo priviledge # Create user with sudo priviledge
ENV USER="test-user" ARG USER="test-user"
RUN useradd --create-home -m "$USER" \ RUN useradd --create-home -m "$USER" \
&& adduser "$USER" sudo && adduser "$USER" sudo
RUN echo "$USER ALL=(ALL) NOPASSWD: ALL" \ RUN echo "$USER ALL=(ALL) NOPASSWD: ALL" \
>> /etc/sudoers >>/etc/sudoers
# ---------------------------------------------------------------------------- #
# Filesystem copy steps
# ---------------------------------------------------------------------------- #
# Filesystem steps
ENV WORKSPACE="/home/$USER/workspace"
ADD --chown=test-user . "$WORKSPACE/dotfiles" ADD --chown=test-user . "$WORKSPACE/dotfiles"
WORKDIR "$WORKSPACE/dotfiles" WORKDIR "$WORKSPACE/dotfiles"
# ---------------------------------------------------------------------------- #
# Install steps # Install steps
# ---------------------------------------------------------------------------- #
USER test-user USER test-user
RUN make ENV FAST_MODE="true"
ARG TARGET="all"
RUN make TARGET=$TARGET
# ---------------------------------------------------------------------------- # # Test entrypoint
# Test steps ENTRYPOINT [ "make", "--directory", "tests", "TARGET=$TARGET" ]
# ---------------------------------------------------------------------------- #
WORKDIR "$WORKSPACE/dotfiles/tests"
ENTRYPOINT ["make"]

View File

@@ -1,14 +1,12 @@
# dotfiles Makefile SHELL := /bin/bash
# ---------------------------------------------------------------------------- # # ---------------------------------------------------------------------------- #
# Local target commands (warning: affects local environment) # Local commands
# ---------------------------------------------------------------------------- # # ---------------------------------------------------------------------------- #
.PHONY: clean .PHONY: clean
# Install dotfiles locally
all: all:
./bootstrap.sh ./bootstrap.sh
# Clean up after install
clean: clean:
rm -f .dotlock rm -f .dotlock
@@ -21,9 +19,12 @@ clean:
build: build:
docker build . -t dotfiles:latest docker build . -t dotfiles:latest
# Run tests in docker container (args to specify test) # Run tests in docker container
# @arg $TARGET binary to install and test
test: test:
docker run dotfiles:latest docker build . -t dotfiles:localtest \
--build-arg TARGET=$$TARGET \
&& docker run dotfiles:localtest
# Launch bash in docker container # Launch bash in docker container
start: start:

View File

@@ -1,14 +1,22 @@
# set PATH so it includes user's private bin if it exists # set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then if [ -d "$HOME/bin" ]; then
PATH="$HOME/bin:$PATH" PATH="$HOME/bin:$PATH"
fi fi
# config # config
export XDG_DATA_HOME="$HOME/.local/share" if [ -z "$XDG_DATA_HOME" ]; then
export XDG_CONFIG_HOME="$HOME/.config" export XDG_DATA_HOME="$HOME/.local/share"
mkdir -p "$XDG_DATA_HOME"
fi
if [ -z "$XDG_CONFIG_HOME" ]; then
export XDG_CONFIG_HOME="$HOME/.config"
mkdir -p "$XDG_CONFIG_HOME"
fi
# workspace # workspace
export WORKSPACE="$HOME/workspace" if [ -z "$WORKSPACE" ]; then
export WORKSPACE="$HOME/workspace"
fi
# .local # .local
export PATH="$HOME/.local/bin:$PATH" export PATH="$HOME/.local/bin:$PATH"
@@ -24,6 +32,6 @@ export POETRY_ROOT="$HOME/.poetry"
export PATH="$POETRY_ROOT/bin:$PATH" export PATH="$POETRY_ROOT/bin:$PATH"
# nvm # nvm
export NVM_DIR="$HOME/.nvm" export NVM_DIR="$XDG_CONFIG_HOME/nvm"
export PATH="$NVM_DIR/bin:$PATH" export PATH="$NVM_DIR/bin:$PATH"
[ -s "$NVM_DIR/nvm.sh" ] && source "$NVM_DIR/nvm.sh" [ -s "$NVM_DIR/nvm.sh" ] && source "$NVM_DIR/nvm.sh"

View File

@@ -1,35 +1,35 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -o pipefail
# Script to set up dependencies and run installer
# #
# Script to set up and run dotfiles installer # 1. Install git using `apt-get` if not already in $PATH
# * see $FAST_MODE
# #
# Installs git using `apt-get` if not in $PATH # 2. Create workspace folder if one doesn't already exist
# step may be skipped, # * see $WORKSPACE
# @see $FAST_MODE
# #
# Pulls latest target repository using git # 3. Pull latest target repository using `git`
# @see $REPOSITORY # * see $REPOSITORY, $FAST_MODE
# #
# Creates workspace if one doesn't already exist # 4. Run installer
# @see $WORKSPACE # * see $INSTALLER
#
# Runs installer
# @see $INSTALLER
# #
# #
# Usage # Usage
# #
# i. Run script # i. Run script
# #
# $ ./bootstrap.sh # * $ ./bootstrap.sh
# $ /path/to/bootstrap.sh # * $ /path/to/bootstrap.sh
# #
# ii. Download and run script # ii. Download and run script
# #
# a. non-interactively # a. non-interactively
# $ wget path.to/bootstrap.sh -qO - | bash # * $ wget path.to/bootstrap.sh -qO - | bash
# #
# b. interactively # b. interactively
# $ bash <(wget -qO- path.to/bootstrap.sh) # * $ bash <(wget -qO- path.to/bootstrap.sh)
# #
# #
# Configuration # Configuration
@@ -45,46 +45,38 @@
# #
# $FAST_MODE - whether to skip git (and speed up install steps) # $FAST_MODE - whether to skip git (and speed up install steps)
# @defualt false # @defualt false
#
#
set -o pipefail
echo "setting up..." echo "setting up..."
# Variables: $REPOSITORY # Inistialise variables
if [ -z "$REPOSITORY" ]; then
export REPOSITORY="andrejusk/dotfiles"
fi
export repository_url="https://github.com/$REPOSITORY.git"
echo "using repository: $repository_url"
# Variables: $WORKSPACE
if [ -z "$WORKSPACE" ]; then if [ -z "$WORKSPACE" ]; then
export WORKSPACE="$HOME/workspace" export WORKSPACE="$HOME/workspace"
fi fi
export dotfiles_dir="$WORKSPACE/dotfiles" export dotfiles_dir="$WORKSPACE/dotfiles"
echo "using dir: $dotfiles_dir" echo "using dir: $dotfiles_dir"
# Variables: $INSTALLER if [ -z "$REPOSITORY" ]; then
if [ -z "$INSTALLER" ]; then export REPOSITORY="andrejusk/dotfiles"
export INSTALLER="install.sh";
fi fi
export installer="$dotfiles_dir/$INSTALLER" repository_url="git@github.com:$REPOSITORY.git"
echo "using repository: $repository_url"
if [ -z "$INSTALLER" ]; then
INSTALLER="install.sh";
fi
installer="$dotfiles_dir/$INSTALLER"
echo "using installer: $installer" echo "using installer: $installer"
# Pull latest git if not skipped # Ensure repo is available
if [ -z "$FAST_MODE" ]; then if [ -z "$FAST_MODE" ]; then
# Set to falsy variable
export FAST_MODE=false export FAST_MODE=false
# Ensure git is installed
if ! [ -x "$(command -v git)" ]; then if ! [ -x "$(command -v git)" ]; then
echo "installing git..." echo "installing git..."
sudo apt-get update -qqy sudo apt-get update -qqy
sudo apt-get install git -qqy sudo apt-get install git -qqy
fi fi
# Ensure latest is pulled
echo "pulling latest..." echo "pulling latest..."
if ! [ -d "$dotfiles_dir" ]; then if ! [ -d "$dotfiles_dir" ]; then
mkdir -p "$dotfiles_dir" mkdir -p "$dotfiles_dir"
@@ -96,9 +88,10 @@ if [ -z "$FAST_MODE" ]; then
fi fi
# Install dotfiles # Run installer
echo "installing..." echo "installing..."
cd "$dotfiles_dir" source "$dotfiles_dir/bash/.profile"
chmod +x "$installer" chmod +x "$installer"
"$installer" "$installer"
echo "done!" echo "done!"

View File

@@ -1,9 +1,8 @@
#!/usr/bin/env bash #!/usr/bin/env bash
#
# Invokes all install scripts.
#
set -euo pipefail set -euo pipefail
source "$dotfiles_dir/utils.sh"
export install_dir="$dotfiles_dir/install"
source "$install_dir/utils.sh"
printf "\nInstalling ${C_CYAN}$REPOSITORY${C_NC}" printf "\nInstalling ${C_CYAN}$REPOSITORY${C_NC}"
printf " as ${C_YELLOW}$USER${C_NC}\n" printf " as ${C_YELLOW}$USER${C_NC}\n"
@@ -21,24 +20,26 @@ if [ -f "$install_lock_file" ]; then
printf "Please wait for script to exit or ${C_YELLOW}make clean${C_NC}\n" printf "Please wait for script to exit or ${C_YELLOW}make clean${C_NC}\n"
exit 1 exit 1
fi fi
touch "$install_lock_file" # Requires clean touch "$install_lock_file"
# Run all install scripts # Install all scripts by default
export install_dir="$dotfiles_dir/install" if [ -z "$TARGET" ]; then
readonly script_filter="$install_dir/*.sh" # Don't escape to unwrap glob TARGET="all"
for script in $script_filter; do fi
[ -e "$script" ] || continue
# Get script name, split by dash if [ "$TARGET" == "all" ]; then
script_name="$(basename "$script" ".sh")" scripts=($install_dir/*.sh)
IFS='-' read -a script_fields <<< "$script_name" else
scripts=($install_dir/*-{apt,bash,$TARGET}.sh)
fi
for script in "${scripts[@]}"; do
script_name="$(basename $script .sh)"
IFS='-' read -a script_fields <<<"$script_name"
script_number=${script_fields[0]} script_number=${script_fields[0]}
script_target=${script_fields[1]} script_target=${script_fields[1]}
# Log execution
printf "\nRunning #$script_number ${C_YELLOW}$script_target${C_NC}...\n${C_DGRAY}" printf "\nRunning #$script_number ${C_YELLOW}$script_target${C_NC}...\n${C_DGRAY}"
# Run and indent output
chmod +x "$script" chmod +x "$script"
source "$HOME/.bashrc" && "$script" | indent source "$HOME/.bashrc" && "$script" | indent
printf "${C_NC}" printf "${C_NC}"
@@ -46,7 +47,6 @@ for script in $script_filter; do
# Clean up if fails # Clean up if fails
done || make clean done || make clean
# Clean up and exit
printf "\nDone! Cleaning up...\n${C_DGRAY}" printf "\nDone! Cleaning up...\n${C_DGRAY}"
make clean make clean
printf "${C_NC}\n" printf "${C_NC}\n"

View File

@@ -1,20 +1,13 @@
#!/usr/bin/env bash #!/usr/bin/env bash
#
# apt update and upgrade
#
# Install list of packages in 00-apt-pkglist
#
# pre clean # apt clean, update, upgrade
clean clean
# apt update, upgrade
update update
upgrade upgrade
# Package installs # Install list of packages in 00-apt-pkglist
package_list_file="$install_dir/00-apt-pkglist" package_list_file="$install_dir/00-apt-pkglist"
install_file "$package_list_file" install_file "$package_list_file"
# Log version # Log OS version
cat /etc/os-release cat /etc/os-release

View File

@@ -1,11 +1,8 @@
#!/usr/bin/env bash #!/usr/bin/env bash
#
# After running this script:
# 1. bash dotfiles are symlinked
#
# 1. bash dotfiles are symlinked # bash dotfiles are symlinked
bash_source="$dotfiles_dir/bash" bash_source="$dotfiles_dir/bash"
bash_target="$HOME" bash_target="$HOME"
link_folder "$bash_source" "$bash_target" link_folder "$bash_source" "$bash_target"
printf "bash dotfiles are linked\n" echo "bash dotfiles are linked"
bash --version

View File

@@ -1,53 +1,39 @@
#!/usr/bin/env bash #!/usr/bin/env bash
#
# After running this script:
# 1. fish shell is installed
# 2. fish shell is default login shell
# 3. fish dotfiles are symlinked
# 4. fisher is installed
#
# 1. fish shell is installed # fish shell is installed
if not_installed "fish"; then if not_installed "fish"; then
echo "Installing fish..."
printf "Installing fish...\n"
# Add fish repository
add_ppa "fish-shell/release-3" add_ppa "fish-shell/release-3"
update update
# Install fish
install fish install fish
fi fi
printf "fish is installed\n" echo "fish is installed"
fish --version fish --version
# 2. fish shell is default login shell # fish shell is default login shell
current_shell="$(getent passwd $USER | cut -d: -f7)" current_shell="$(getent passwd $USER | cut -d: -f7)"
fish_path="$(which fish)" fish_path="$(which fish)"
if [ "$current_shell" != "$fish_path" ]; then if [ "$current_shell" != "$fish_path" ]; then
echo "setting fish as default, current shell was $current_shell"
printf "setting fish as default, current shell was $current_shell\n"
# Update default login shell
sudo chsh -s "$fish_path" "$USER" sudo chsh -s "$fish_path" "$USER"
sudo usermod -s "$fish_path" "$USER" sudo usermod -s "$fish_path" "$USER"
fi fi
printf "fish is default login shell\n" echo "fish is default login shell"
# 3. fish dotfiles are symlinked # fish dotfiles are symlinked
fish_source="$dotfiles_dir/fish" fish_source="$dotfiles_dir/fish"
fish_target="$XDG_CONFIG_HOME/fish" fish_target="$XDG_CONFIG_HOME/fish"
link_folder "$fish_source" "$fish_target" link_folder "$fish_source" "$fish_target"
printf "fish dotfiles linked\n" echo "fish dotfiles linked"
# 4. fisher is installed # fisher is installed
fisher_location="$XDG_CONFIG_HOME/fish/functions/fisher.fish" fisher_location="$XDG_CONFIG_HOME/fish/functions/fisher.fish"
if ! [ -f "$fisher_location" ]; then if ! [ -f "$fisher_location" ]; then
printf "Installing fisher...\n" echo "Installing fisher..."
# Install fisher # Install fisher
curl https://git.io/fisher --create-dirs -sLo "$fisher_location" curl https://git.io/fisher --create-dirs -sLo "$fisher_location"

View File

@@ -1,22 +1,17 @@
#!/usr/bin/env bash #!/usr/bin/env bash
#
# After running this script:
# 1. ssh key exists
# 2. ssh dotfiles are symlinked
#
# 1. ssh key exists # 1. ssh key exists
ssh_target="$HOME/.ssh" ssh_target="$HOME/.ssh"
ssh_key="$ssh_target/id_rsa" ssh_key="$ssh_target/id_rsa"
ssh_pub="$ssh_key.pub" ssh_pub="$ssh_key.pub"
if [ ! -f "$ssh_key" ]; then if [ ! -f "$ssh_key" ]; then
printf "generating ssh key...\n" echo "generating ssh key..."
ssh-keygen -t rsa -b 4096 -f "$ssh_key" ssh-keygen -t rsa -b 4096 -f "$ssh_key"
fi fi
printf "ssh key exists\n" echo "ssh key exists"
# 2. ssh dotfiles are symlinked # 2. ssh dotfiles are symlinked
ssh_source="$dotfiles_dir/ssh" ssh_source="$dotfiles_dir/ssh"
link_folder "$ssh_source" "$ssh_target" link_folder "$ssh_source" "$ssh_target"
printf "ssh dotfiles are symlinked\n" echo "ssh dotfiles are symlinked"
cat "$ssh_pub" cat "$ssh_pub"

View File

@@ -1,8 +1,4 @@
#!/usr/bin/env bash #!/usr/bin/env bash
#
# After running this script:
# 1. git dotfiles are symlinked
#
# 1. git dotfiles are symlinked # 1. git dotfiles are symlinked
git_source="$dotfiles_dir/git" git_source="$dotfiles_dir/git"

View File

@@ -1,13 +1,9 @@
#!/usr/bin/env bash #!/usr/bin/env bash
#
# After running this script:
# 1. pyenv is installed
#
# 1. pyenv is installed # 1. pyenv is installed
if not_installed "pyenv"; then if not_installed "pyenv"; then
printf "Installing pyenv...\n" echo "Installing pyenv..."
# Install pyenv prerequisites # Install pyenv prerequisites
# see https://github.com/pyenv/pyenv/wiki/common-build-problems # see https://github.com/pyenv/pyenv/wiki/common-build-problems
@@ -20,6 +16,6 @@ if not_installed "pyenv"; then
"bash" "bash"
fi fi
printf "pyenv is installed, upgrading...\n" echo "pyenv is installed, upgrading..."
git --git-dir="$PYENV_ROOT/.git" pull git --git-dir="$PYENV_ROOT/.git" pull
pyenv --version pyenv --version

View File

@@ -1,19 +1,15 @@
#!/usr/bin/env bash #!/usr/bin/env bash
#
# After running this script:
# 1. python3 and pip3 are installed
#
# 1. python3 and pip3 are installed # 1. python3 and pip3 are installed
if not_installed "pip3"; then if not_installed "pip3"; then
printf "Installing python3 and pip3...\n" echo "Installing python3 and pip3..."
pyenv install 3.7.0 pyenv install 3.7.0
pyenv global 3.7.0 pyenv global 3.7.0
fi fi
printf "python3 and pip3 are installed, upgrading...\n" echo "python3 and pip3 are installed, upgrading..."
pip3 install --upgrade pip pip3 install --upgrade pip
python3 --version python3 --version
pip3 --version pip3 --version

View File

@@ -1,8 +1,4 @@
#!/usr/bin/env bash #!/usr/bin/env bash
#
# After running this script:
# 1. poetry is installed
#
# 1. poetry is installed # 1. poetry is installed
if not_installed "poetry"; then if not_installed "poetry"; then

View File

@@ -1,8 +1,4 @@
#!/usr/bin/env bash #!/usr/bin/env bash
#
# After running this script:
# 1. nvm is installed
#
# 1. nvm is installed # 1. nvm is installed
if not_installed "nvm"; then if not_installed "nvm"; then
@@ -10,10 +6,12 @@ if not_installed "nvm"; then
printf "Installing nvm...\n" printf "Installing nvm...\n"
# Install nvm # Install nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.2/install.sh | bash run "https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.2/install.sh" \
refresh "bash"
source "$NVM_DIR/nvm.sh"
fi fi
printf "nvm is installed, upgrading...\n" printf "nvm is installed, upgrading...\n"
git --git-dir="$NVM_DIR/.git" pull git --git-dir="$NVM_DIR/.git" pull
nvm update --lts node nvm update --lts node

View File

@@ -1,11 +1,4 @@
#!/usr/bin/env bash #!/usr/bin/env bash
#
# After running this script:
# 1. docker is installed
# 2. docker-compose if installed
# 3. docker group exists
# 4. user is in docker group
#
# 1. docker is installed # 1. docker is installed
DOCKER_FOLDER="$HOME/.docker" DOCKER_FOLDER="$HOME/.docker"

View File

@@ -1,8 +1,4 @@
#!/usr/bin/env bash #!/usr/bin/env bash
#
# After running this script:
# 1. keybase is installed
#
# 1.keybase is installed # 1.keybase is installed
if not_installed "keybase"; then if not_installed "keybase"; then

View File

@@ -1,8 +1,4 @@
#!/usr/bin/env bash #!/usr/bin/env bash
#
# Alias commands and utilities.
#
# ---------------------------------------------------------------------------- # # ---------------------------------------------------------------------------- #
# Helper functions # Helper functions
# ---------------------------------------------------------------------------- # # ---------------------------------------------------------------------------- #
@@ -83,10 +79,6 @@ add_path() {
refresh refresh
} }
# ---------------------------------------------------------------------------- #
# Function exports
# ---------------------------------------------------------------------------- #
export -f clean update upgrade install install_file add_ppa add_key run \ export -f clean update upgrade install install_file add_ppa add_key run \
link_folder indent not_installed refresh add_path link_folder indent not_installed refresh add_path

View File

@@ -1,6 +1,4 @@
# dotfiles tests Makefile
SHELL := /bin/bash SHELL := /bin/bash
all: all:
source ${HOME}/.bashrc
poetry install poetry install
poetry run pytest poetry run pytest