intsall fix attempts

add pyenv path after install

use https repository

install apt-utils

set FAST_MODE in bootstrap.sh

keep truthy FAST_MODE variable

source bashrc after linking

clean up errors

further install fixes

further cleanup

fix fisher install

chmod +x install

remove source bashrc from make
This commit is contained in:
Andrejus
2020-03-02 21:14:55 +00:00
parent e2bd54995a
commit 0d87c48e9c
23 changed files with 165 additions and 95 deletions

View File

@@ -4,20 +4,20 @@ from ubuntu:bionic
# (usually) Cached steps # (usually) Cached steps
# ---------------------------------------------------------------------------- # # ---------------------------------------------------------------------------- #
# Set variables up, FAST_MODE to prevent git and upgrade # Set FAST_MODE to prevent git and upgrade
ENV FAST_MODE="true" ENV FAST_MODE="true"
ENV WORKSPACE="$HOME/workspace" ENV WORKSPACE="$HOME/workspace"
# Install sudo for compatibility, git since it is skipped, make # Install sudo for compatibility, git since it is skipped, make
# Triple quiet mode (-qq implies -y, pipe to /dev/null) # Triple quiet mode (-qq implies -y, pipe to /dev/null)
RUN apt-get -qq update && \ RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections
apt-get -qq install sudo git make \ RUN apt-get -y update \
< /dev/null > /dev/null && apt-get -y install sudo git make
# Create user with sudo priviledge # Create user with sudo priviledge
ENV USER="test-user" ENV 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" >> /etc/sudoers RUN echo "$USER ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
# ---------------------------------------------------------------------------- # # ---------------------------------------------------------------------------- #
@@ -28,9 +28,6 @@ RUN echo "$USER ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
ADD --chown=test-user . "$WORKSPACE/dotfiles" ADD --chown=test-user . "$WORKSPACE/dotfiles"
WORKDIR "$WORKSPACE/dotfiles" WORKDIR "$WORKSPACE/dotfiles"
# Allow execution
RUN chmod +x ./bootstrap.sh
# ---------------------------------------------------------------------------- # # ---------------------------------------------------------------------------- #
# Install steps # Install steps
# ---------------------------------------------------------------------------- # # ---------------------------------------------------------------------------- #
@@ -44,4 +41,4 @@ RUN make install
# ---------------------------------------------------------------------------- # # ---------------------------------------------------------------------------- #
# Run tests # Run tests
RUN make test || true CMD ["make", "test"]

View File

@@ -1,19 +1,28 @@
.PHONY: clean # dotfiles Makefile
# ---------------------------------------------------------------------------- #
# Local target commands (warning: affects local environment)
# ---------------------------------------------------------------------------- #
.PHONY: install clean
# Install dotfiles locally
install: SHELL:=/bin/bash
install:
chmod +x ./bootstrap.sh
./bootstrap.sh
# Clean up after install
clean: clean:
rm -f .dotlock rm -f .dotlock
.PHONY: install # ---------------------------------------------------------------------------- #
install: # Docker commands
bash bootstrap.sh # ---------------------------------------------------------------------------- #
.PHONY: build run
.PHONY: test # Build and tag latest docker image
test:
bash test.sh
.PHONY: build
build: build:
docker build . -t dotfiles:latest docker build . -t dotfiles:latest
.PHONY: run # Run latest docker container
run: run:
docker run -it dotfiles:latest /bin/bash docker run -it dotfiles:latest /bin/bash

View File

@@ -1,7 +1,11 @@
# .local
export PATH="$HOME/.local/bin:$PATH"
# pyenv # pyenv
export PATH="$HOME/.pyenv/bin:$PATH" PYENV_ROOT="$HOME/.pyenv"
eval "$(pyenv init -)" export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv virtualenv-init -)" export PATH="$PYENV_ROOT/shims:$PATH"
# poetry # poetry
export PATH="$HOME/.poetry/bin:$PATH" POETRY_ROOT="$HOME/.poetry"
export PATH="$POETRY_ROOT/bin:$PATH"

33
bootstrap.sh Normal file → Executable file
View File

@@ -8,13 +8,19 @@
# #
# Usage: # Usage:
# #
# i. Run in new bash shell. # i. Run script.
# #
# $ bash bootstrap.sh # $ bash bootstrap.sh
# $ bash /path/to/bootstrap.sh # $ bash /path/to/bootstrap.sh
# $ wget path.to/bootstrap.sh -qO - | bash # $ wget path.to/bootstrap.sh -qO - | bash
# #
# ii. Source into existing bash shell. # ii. Run explicitly in a bash shell.
#
# $ bash bootstrap.sh
# $ bash /path/to/bootstrap.sh
# $ wget path.to/bootstrap.sh -qO - | bash
#
# iii. Source into existing shell.
# #
# $ source bootstrap.sh # $ source bootstrap.sh
# $ source /path/to/bootstrap.sh # $ source /path/to/bootstrap.sh
@@ -33,7 +39,7 @@
# @default "install.sh" # @default "install.sh"
# #
# $FAST_MODE - whether to skip git (and speed up install steps) # $FAST_MODE - whether to skip git (and speed up install steps)
# @defualt unset # @defualt unset, i.e. false
# #
# #
set -o pipefail set -o pipefail
@@ -41,26 +47,31 @@ echo "setting up..."
# Variables: $REPOSITORY # Variables: $REPOSITORY
if [ -z "$REPOSITORY" ]; then if [ -z "$REPOSITORY" ]; then
REPOSITORY="andrejusk/dotfiles" export REPOSITORY="andrejusk/dotfiles"
fi fi
readonly repository_url="git@github.com:$REPOSITORY.git" export repository_url="https://github.com/$REPOSITORY.git"
echo "using repository: $repository_url" echo "using repository: $repository_url"
# Variables: $WORKSPACE # Variables: $WORKSPACE
if [ -z "$WORKSPACE" ]; then if [ -z "$WORKSPACE" ]; then
WORKSPACE="$HOME/workspace" export WORKSPACE="$HOME/workspace"
fi fi
readonly dotfiles_dir="$WORKSPACE/dotfiles" export dotfiles_dir="$WORKSPACE/dotfiles"
echo "using dir: $dotfiles_dir" echo "using dir: $dotfiles_dir"
# Variables: $INSTALLER # Variables: $INSTALLER
if [ -z "$INSTALLER" ]; then INSTALLER="install.sh"; fi if [ -z "$INSTALLER" ]; then
readonly installer="$dotfiles_dir/$INSTALLER" export INSTALLER="install.sh";
fi
export installer="$dotfiles_dir/$INSTALLER"
echo "using installer: $installer" echo "using installer: $installer"
# Pull latest git if not skipped # Pull latest git if not skipped
if [ -z "$FAST_MODE" ]; then if [ -z "$FAST_MODE" ]; then
# Set to falsy variable
export FAST_MODE=false
# Ensure git is installed # Ensure git is installed
if ! [ -x "$(command -v git)" ]; then if ! [ -x "$(command -v git)" ]; then
echo "installing git..." echo "installing git..."
@@ -81,6 +92,8 @@ if [ -z "$FAST_MODE" ]; then
fi fi
# Install dotfiles # Install dotfiles
echo "installing..."
cd "$dotfiles_dir" cd "$dotfiles_dir"
source "$installer" chmod +x "$installer"
"$installer"
echo "done!" echo "done!"

View File

@@ -1,7 +1,6 @@
# Pyenv # Pyenv
export PATH="$HOME/.pyenv/bin:$PATH" setenv PYENV_ROOT "$HOME/.pyenv"
eval (pyenv init -) setenv PATH "$PYENV_ROOT/shims:$PYENV_ROOT/bin:$PATH"
eval (pyenv virtualenv-init -)
# Poetry # Poetry
set -gx PATH $HOME/.poetry/bin $PATH set -gx PATH $HOME/.poetry/bin $PATH

View File

@@ -24,7 +24,7 @@ fi
touch "$install_lock_file" # Requires clean touch "$install_lock_file" # Requires clean
# Run all install scripts # Run all install scripts
readonly install_dir="$dotfiles_dir/install" export install_dir="$dotfiles_dir/install"
readonly script_filter="$install_dir/*.sh" # Don't escape to unwrap glob readonly script_filter="$install_dir/*.sh" # Don't escape to unwrap glob
for script in $script_filter; do for script in $script_filter; do
@@ -36,7 +36,8 @@ for script in $script_filter; do
printf "\nRunning ${C_YELLOW}$script_name${C_NC}...\n${C_DGRAY}" printf "\nRunning ${C_YELLOW}$script_name${C_NC}...\n${C_DGRAY}"
# Run and indent output # Run and indent output
source "$script" | indent chmod +x "$script"
source "$HOME/.bashrc" && "$script" | indent
printf "${C_NC}" printf "${C_NC}"
# Clean up if fails # Clean up if fails

13
install/00-apt.sh Normal file → Executable file
View File

@@ -5,15 +5,16 @@
# Install list of packages in ./00-apt-pkglist # Install list of packages in ./00-apt-pkglist
# #
# apt update, upgrade if not fast # pre clean
clean
# apt update, upgrade
update update
if [ -z "$FAST_MODE" ]; then upgrade
upgrade
fi
# Package installs # Package installs
readonly 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 version
cat /etc/os-release cat /etc/os-release

4
install/01-bash.sh Normal file → Executable file
View File

@@ -5,7 +5,7 @@
# #
# 1. bash dotfiles are symlinked # 1. bash dotfiles are symlinked
readonly bash_source="$dotfiles_dir/bash" bash_source="$dotfiles_dir/bash"
readonly bash_target="$HOME" bash_target="$HOME"
link_folder "$bash_source" "$bash_target" link_folder "$bash_source" "$bash_target"
printf "bash dotfiles are linked\n" printf "bash dotfiles are linked\n"

36
install/02-fish.sh Normal file → Executable file
View File

@@ -4,6 +4,7 @@
# 1. fish shell is installed # 1. fish shell is installed
# 2. fish shell is default login shell # 2. fish shell is default login shell
# 3. fish dotfiles are symlinked # 3. fish dotfiles are symlinked
# 4. fisher is installed
# #
# 1. fish shell is installed # 1. fish shell is installed
@@ -12,24 +13,22 @@ if not_installed "fish"; then
printf "Installing fish...\n" printf "Installing fish...\n"
# Add fish repository # Add fish repository
app_ppa "fish-shell/release-3" add_ppa "fish-shell/release-3"
update update
# Install fish # Install fish
install fish install fish
# Install fisher
set -q XDG_CONFIG_HOME; or set XDG_CONFIG_HOME ~/.config
curl https://git.io/fisher --create-dirs -sLo $XDG_CONFIG_HOME/fish/functions/fisher.fish
fish -c fisher
fi fi
printf "fish is installed\n" printf "fish is installed\n"
fish --version fish --version
# 2. fish shell is default login shell # 2. fish shell is default login shell
readonly fish_path="$(which fish)" current_shell="$(getent passwd $USER | cut -d: -f7)"
if [ "$SHELL" != fish_path ]; then fish_path="$(which fish)"
if [ "$current_shell" != "$fish_path" ]; then
printf "setting fish as default, current shell was $current_shell\n"
# Update default login shell # Update default login shell
sudo chsh -s "$fish_path" "$USER" sudo chsh -s "$fish_path" "$USER"
@@ -39,7 +38,24 @@ fi
printf "fish is default login shell\n" printf "fish is default login shell\n"
# 3. fish dotfiles are symlinked # 3. fish dotfiles are symlinked
readonly fish_source="$dotfiles_dir/fish" fish_source="$dotfiles_dir/fish"
readonly fish_target="$HOME/.config/fish" fish_target="$HOME/.config/fish"
link_folder "$fish_source" "$fish_target" link_folder "$fish_source" "$fish_target"
printf "fish dotfiles linked\n" printf "fish dotfiles linked\n"
# 4. fisher is installed
XDG_CONFIG_HOME="$HOME/.config"
fisher_location="$XDG_CONFIG_HOME/fish/functions/fisher.fish"
if ! [ -f "$fisher_location" ]; then
printf "Installing fisher...\n"
# Install fisher
curl https://git.io/fisher --create-dirs -sLo "$fisher_location"
fi
printf "fisher is installed, updating...\n"
fish -c "fisher"
fish -c "fisher --version"
export XDG_CONFIG_HOME

8
install/03-ssh.sh Normal file → Executable file
View File

@@ -6,9 +6,9 @@
# #
# 1. ssh key exists # 1. ssh key exists
readonly ssh_target="$HOME/.ssh" ssh_target="$HOME/.ssh"
readonly ssh_key="$ssh_target/id_rsa" ssh_key="$ssh_target/id_rsa"
readonly 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" printf "generating ssh key...\n"
ssh-keygen -t rsa -b 4096 -f "$ssh_key" ssh-keygen -t rsa -b 4096 -f "$ssh_key"
@@ -16,7 +16,7 @@ fi
printf "ssh key exists\n" printf "ssh key exists\n"
# 2. ssh dotfiles are symlinked # 2. ssh dotfiles are symlinked
readonly 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" printf "ssh dotfiles are symlinked\n"
cat "$ssh_pub" cat "$ssh_pub"

4
install/04-git.sh Normal file → Executable file
View File

@@ -5,8 +5,8 @@
# #
# 1. git dotfiles are symlinked # 1. git dotfiles are symlinked
readonly git_source="$dotfiles_dir/git" git_source="$dotfiles_dir/git"
readonly git_target="$HOME" git_target="$HOME"
link_folder "$git_source" "$git_target" link_folder "$git_source" "$git_target"
printf "git dotfiles linked\n" printf "git dotfiles linked\n"
git --version git --version

13
install/10-pyenv-pkglist Normal file
View File

@@ -0,0 +1,13 @@
build-essential
libssl-dev
libbz2-dev
libreadline-dev
libsqlite3-dev
llvm
libncurses5-dev
libncursesw5-dev
xz-utils
tk-dev
libffi-dev
liblzma-dev
python-openssl

16
install/10-pyenv.sh Normal file → Executable file
View File

@@ -5,30 +5,22 @@
# #
# 1. pyenv is installed # 1. pyenv is installed
export PYENV_ROOT="$HOME/.pyenv"
if not_installed "pyenv"; then if not_installed "pyenv"; then
printf "Installing pyenv...\n" printf "Installing pyenv...\n"
# 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
install make build-essential libssl-dev zlib1g-dev libbz2-dev \ pyenv_list_file="$install_dir/10-pyenv-pkglist"
libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev \ install_file "$pyenv_list_file"
xz-utils tk-dev libffi-dev liblzma-dev python-openssl git
# Add to install path
add_path "$HOME/.pyenv/bin"
# Install pyenv # Install pyenv
# see https://github.com/pyenv/pyenv-installer # see https://github.com/pyenv/pyenv-installer
run "https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer" \ run "https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer" \
"bash" "bash"
refresh
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
fi fi
printf "pyenv is installed, upgrading...\n" printf "pyenv is installed, upgrading...\n"
readonly pyenv_root=$(pyenv root) git --git-dir="$PYENV_ROOT/.git" pull
git --git-dir="$pyenv_root" pull
pyenv --version pyenv --version

1
install/11-python.sh Normal file → Executable file
View File

@@ -11,7 +11,6 @@ if not_installed "pip3"; then
pyenv install 3.7.0 pyenv install 3.7.0
pyenv global 3.7.0 pyenv global 3.7.0
pyenv local 3.7.0
fi fi
printf "python3 and pip3 are installed, upgrading...\n" printf "python3 and pip3 are installed, upgrading...\n"

0
install/12-poetry.sh Normal file → Executable file
View File

9
install/20-docker.sh Normal file → Executable file
View File

@@ -8,9 +8,13 @@
# #
# 1. docker is installed # 1. docker is installed
DOCKER_FOLDER="$HOME/.docker"
if not_installed "docker"; then if not_installed "docker"; then
printf "Installing docker...\n" printf "Installing docker...\n"
# Create folder
mkdir -p "$DOCKER_FOLDER"
# Requirements # Requirements
install apt-transport-https ca-certificates curl gnupg-agent \ install apt-transport-https ca-certificates curl gnupg-agent \
@@ -28,8 +32,8 @@ if not_installed "docker"; then
install docker-ce install docker-ce
# Chown # Chown
sudo chown "$USER":"$USER" "$HOME/.docker" -R sudo chown "$USER":"$USER" "$DOCKER_FOLDER" -R
sudo chmod g+rwx "$HOME/.docker" -R sudo chmod g+rwx "$DOCKER_FOLDER" -R
fi fi
printf "docker is installed\n" printf "docker is installed\n"
@@ -43,7 +47,6 @@ if not_installed "docker-compose"; then
# Docker-compose # Docker-compose
pip3 install --user docker-compose pip3 install --user docker-compose
fi fi
printf "docker-compose is installed, upgrading\n" printf "docker-compose is installed, upgrading\n"
pip3 install --upgrade docker-compose pip3 install --upgrade docker-compose

0
install/21-keybase.sh Normal file → Executable file
View File

5
install/99-apt-clean.sh Normal file → Executable file
View File

@@ -1,5 +1,4 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Clean up # post clean
sudo apt-get -y autoremove clean
sudo apt-get -y autoclean

0
install/999-screenfetch.sh Normal file → Executable file
View File

View File

@@ -1,9 +0,0 @@
#!/usr/bin/env bash
#
# Invokes all test scripts.
#
set -euo pipefail
cd ./tests
poetry install
poetry run pytest

11
tests/Makefile Normal file
View File

@@ -0,0 +1,11 @@
# dotfiles tests Makefile
# ---------------------------------------------------------------------------- #
# Test commands
# ---------------------------------------------------------------------------- #
.PHONY: test
# Import .bashrc and run test suite
test: SHELL:=/bin/bash
test:
poetry install
poetry run pytest

View File

@@ -3,12 +3,22 @@
# Alias commands and utilities. # Alias commands and utilities.
# #
# ---------------------------------------------------------------------------- #
# Helper functions
# ---------------------------------------------------------------------------- #
clean() {
sudo apt-get clean
}
update() { update() {
sudo apt-get update -qq sudo apt-get update -qq
} }
# Non-interactive upgrade # Non-interactive upgrade
# Skip if FAST_MODE is defined
upgrade() { upgrade() {
[ "$FAST_MODE" != false ] && return
DEBIAN_FRONTEND=noninteractive \ DEBIAN_FRONTEND=noninteractive \
sudo apt-get dist-upgrade -qq \ sudo apt-get dist-upgrade -qq \
-o Dpkg::Options::="--force-confdef" \ -o Dpkg::Options::="--force-confdef" \
@@ -23,18 +33,20 @@ install() {
# @arg $1 package list file to install # @arg $1 package list file to install
install_file() { install_file() {
sudo apt-get install -qq $(cat $1) sudo apt-get install -fqq $(cat $1)
refresh refresh
} }
# @arg $1 repository to add # @arg $1 repository to add
app_ppa() { add_ppa() {
sudo add-apt-repository -y ppa:$1 sudo add-apt-repository -y ppa:$1
} }
# @arg $1 url to add # @arg $1 url to add
add_key() { add_key() {
curl -fsSL $1 | sudo apt-key add - APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE=true \
curl -fsSL $1 \
| sudo apt-key add -
} }
# @arg $1 URL to run # @arg $1 URL to run
@@ -71,7 +83,17 @@ add_path() {
refresh refresh
} }
# Colors # ---------------------------------------------------------------------------- #
# Function exports
# ---------------------------------------------------------------------------- #
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_BLACK='\033[0;30m'
C_DGRAY='\033[1;30m' C_DGRAY='\033[1;30m'
C_RED='\033[0;31m' C_RED='\033[0;31m'