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
# ---------------------------------------------------------------------------- #
# Set variables up, FAST_MODE to prevent git and upgrade
# Set FAST_MODE to prevent git and upgrade
ENV FAST_MODE="true"
ENV WORKSPACE="$HOME/workspace"
# Install sudo for compatibility, git since it is skipped, make
# Triple quiet mode (-qq implies -y, pipe to /dev/null)
RUN apt-get -qq update && \
apt-get -qq install sudo git make \
< /dev/null > /dev/null
RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections
RUN apt-get -y update \
&& apt-get -y install sudo git make
# Create user with sudo priviledge
ENV USER="test-user"
RUN useradd --create-home -m $USER && \
adduser $USER sudo
RUN useradd --create-home -m $USER \
&& adduser $USER sudo
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"
WORKDIR "$WORKSPACE/dotfiles"
# Allow execution
RUN chmod +x ./bootstrap.sh
# ---------------------------------------------------------------------------- #
# Install steps
# ---------------------------------------------------------------------------- #
@@ -44,4 +41,4 @@ RUN make install
# ---------------------------------------------------------------------------- #
# 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:
rm -f .dotlock
.PHONY: install
install:
bash bootstrap.sh
# ---------------------------------------------------------------------------- #
# Docker commands
# ---------------------------------------------------------------------------- #
.PHONY: build run
.PHONY: test
test:
bash test.sh
.PHONY: build
# Build and tag latest docker image
build:
docker build . -t dotfiles:latest
.PHONY: run
# Run latest docker container
run:
docker run -it dotfiles:latest /bin/bash

View File

@@ -1,7 +1,11 @@
# .local
export PATH="$HOME/.local/bin:$PATH"
# pyenv
export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
export PATH="$PYENV_ROOT/shims:$PATH"
# 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:
#
# i. Run in new bash shell.
# i. Run script.
#
# $ bash bootstrap.sh
# $ bash /path/to/bootstrap.sh
# $ 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 /path/to/bootstrap.sh
@@ -33,7 +39,7 @@
# @default "install.sh"
#
# $FAST_MODE - whether to skip git (and speed up install steps)
# @defualt unset
# @defualt unset, i.e. false
#
#
set -o pipefail
@@ -41,26 +47,31 @@ echo "setting up..."
# Variables: $REPOSITORY
if [ -z "$REPOSITORY" ]; then
REPOSITORY="andrejusk/dotfiles"
export REPOSITORY="andrejusk/dotfiles"
fi
readonly repository_url="git@github.com:$REPOSITORY.git"
export repository_url="https://github.com/$REPOSITORY.git"
echo "using repository: $repository_url"
# Variables: $WORKSPACE
if [ -z "$WORKSPACE" ]; then
WORKSPACE="$HOME/workspace"
export WORKSPACE="$HOME/workspace"
fi
readonly dotfiles_dir="$WORKSPACE/dotfiles"
export dotfiles_dir="$WORKSPACE/dotfiles"
echo "using dir: $dotfiles_dir"
# Variables: $INSTALLER
if [ -z "$INSTALLER" ]; then INSTALLER="install.sh"; fi
readonly installer="$dotfiles_dir/$INSTALLER"
if [ -z "$INSTALLER" ]; then
export INSTALLER="install.sh";
fi
export installer="$dotfiles_dir/$INSTALLER"
echo "using installer: $installer"
# Pull latest git if not skipped
if [ -z "$FAST_MODE" ]; then
# Set to falsy variable
export FAST_MODE=false
# Ensure git is installed
if ! [ -x "$(command -v git)" ]; then
echo "installing git..."
@@ -81,6 +92,8 @@ if [ -z "$FAST_MODE" ]; then
fi
# Install dotfiles
echo "installing..."
cd "$dotfiles_dir"
source "$installer"
chmod +x "$installer"
"$installer"
echo "done!"

View File

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

View File

@@ -24,7 +24,7 @@ fi
touch "$install_lock_file" # Requires clean
# 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
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}"
# Run and indent output
source "$script" | indent
chmod +x "$script"
source "$HOME/.bashrc" && "$script" | indent
printf "${C_NC}"
# Clean up if fails

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

@@ -5,15 +5,16 @@
# Install list of packages in ./00-apt-pkglist
#
# apt update, upgrade if not fast
# pre clean
clean
# apt update, upgrade
update
if [ -z "$FAST_MODE" ]; then
upgrade
fi
# Package installs
readonly package_list_file="$install_dir/00-apt-pkglist"
install_file $package_list_file
package_list_file="$install_dir/00-apt-pkglist"
install_file "$package_list_file"
# Log version
cat /etc/os-release

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

@@ -5,7 +5,7 @@
#
# 1. bash dotfiles are symlinked
readonly bash_source="$dotfiles_dir/bash"
readonly bash_target="$HOME"
bash_source="$dotfiles_dir/bash"
bash_target="$HOME"
link_folder "$bash_source" "$bash_target"
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
# 2. fish shell is default login shell
# 3. fish dotfiles are symlinked
# 4. fisher is installed
#
# 1. fish shell is installed
@@ -12,24 +13,22 @@ if not_installed "fish"; then
printf "Installing fish...\n"
# Add fish repository
app_ppa "fish-shell/release-3"
add_ppa "fish-shell/release-3"
update
# 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
printf "fish is installed\n"
fish --version
# 2. fish shell is default login shell
readonly fish_path="$(which fish)"
if [ "$SHELL" != fish_path ]; then
current_shell="$(getent passwd $USER | cut -d: -f7)"
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
sudo chsh -s "$fish_path" "$USER"
@@ -39,7 +38,24 @@ fi
printf "fish is default login shell\n"
# 3. fish dotfiles are symlinked
readonly fish_source="$dotfiles_dir/fish"
readonly fish_target="$HOME/.config/fish"
fish_source="$dotfiles_dir/fish"
fish_target="$HOME/.config/fish"
link_folder "$fish_source" "$fish_target"
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
readonly ssh_target="$HOME/.ssh"
readonly ssh_key="$ssh_target/id_rsa"
readonly ssh_pub="$ssh_key.pub"
ssh_target="$HOME/.ssh"
ssh_key="$ssh_target/id_rsa"
ssh_pub="$ssh_key.pub"
if [ ! -f "$ssh_key" ]; then
printf "generating ssh key...\n"
ssh-keygen -t rsa -b 4096 -f "$ssh_key"
@@ -16,7 +16,7 @@ fi
printf "ssh key exists\n"
# 2. ssh dotfiles are symlinked
readonly ssh_source="$dotfiles_dir/ssh"
ssh_source="$dotfiles_dir/ssh"
link_folder "$ssh_source" "$ssh_target"
printf "ssh dotfiles are symlinked\n"
cat "$ssh_pub"

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

@@ -5,8 +5,8 @@
#
# 1. git dotfiles are symlinked
readonly git_source="$dotfiles_dir/git"
readonly git_target="$HOME"
git_source="$dotfiles_dir/git"
git_target="$HOME"
link_folder "$git_source" "$git_target"
printf "git dotfiles linked\n"
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
export PYENV_ROOT="$HOME/.pyenv"
if not_installed "pyenv"; then
printf "Installing pyenv...\n"
# Install pyenv prerequisites
# see https://github.com/pyenv/pyenv/wiki/common-build-problems
install make build-essential libssl-dev zlib1g-dev libbz2-dev \
libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev \
xz-utils tk-dev libffi-dev liblzma-dev python-openssl git
# Add to install path
add_path "$HOME/.pyenv/bin"
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"
refresh
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
fi
printf "pyenv is installed, upgrading...\n"
readonly pyenv_root=$(pyenv root)
git --git-dir="$pyenv_root" pull
git --git-dir="$PYENV_ROOT/.git" pull
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 global 3.7.0
pyenv local 3.7.0
fi
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,10 +8,14 @@
#
# 1. docker is installed
DOCKER_FOLDER="$HOME/.docker"
if not_installed "docker"; then
printf "Installing docker...\n"
# Create folder
mkdir -p "$DOCKER_FOLDER"
# Requirements
install apt-transport-https ca-certificates curl gnupg-agent \
software-properties-common
@@ -28,8 +32,8 @@ if not_installed "docker"; then
install docker-ce
# Chown
sudo chown "$USER":"$USER" "$HOME/.docker" -R
sudo chmod g+rwx "$HOME/.docker" -R
sudo chown "$USER":"$USER" "$DOCKER_FOLDER" -R
sudo chmod g+rwx "$DOCKER_FOLDER" -R
fi
printf "docker is installed\n"
@@ -43,7 +47,6 @@ if not_installed "docker-compose"; then
# Docker-compose
pip3 install --user docker-compose
fi
printf "docker-compose is installed, upgrading\n"
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
# Clean up
sudo apt-get -y autoremove
sudo apt-get -y autoclean
# post clean
clean

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