Finishing touches

This commit is contained in:
2020-02-25 23:13:21 +00:00
committed by Andrejus
parent c4ce39b965
commit fc5ba9f99d
17 changed files with 157 additions and 121 deletions

1
.gitignore vendored
View File

@@ -1 +1,2 @@
.dotlock .dotlock
*.deb

View File

@@ -6,43 +6,38 @@
# `source path/to/bootstrap.sh` # `source path/to/bootstrap.sh`
# `source <(wget path/to/bootstrap.sh)` # `source <(wget path/to/bootstrap.sh)`
# #
set -euo pipefail set -o pipefail
echo "setting up..."
# Set up variables and imports # Variables: git
readonly repository="andrejusk/dotfiles" if [ -z "$REPOSITORY" ]; then
readonly repository_url="https://github.com/$repository.git" export REPOSITORY="andrejusk/dotfiles"
readonly workspace_dir="$HOME/workspace" fi
readonly dotfiles_dir="$workspace_dir/dotfiles" readonly repository_url="https://github.com/$REPOSITORY.git"
readonly install_dir="$dotfiles_dir/install" echo "using repository: $repository_url"
readonly lock_file="$dotfiles_dir/.dotlock"
source "$dotfiles_dir/utils.sh"
# Log execution # Variables: workspace
printf "Setting up ${C_CYAN}$repository${C_NC} with:\n" if [ -z "$WORKSPACE" ]; then
printf " repository:\t ${C_YELLOW}$repository${C_NC}\n" export WORKSPACE="$HOME/workspace"
printf " repository_url: ${C_YELLOW}$repository_url${C_NC}\n" fi
printf " workspace_dir: ${C_YELLOW}$workspace_dir${C_NC}\n" readonly dotfiles_dir="$WORKSPACE/dotfiles"
printf " dotfiles_dir:\t ${C_YELLOW}$dotfiles_dir${C_NC}\n" echo "using dir: $dotfiles_dir"
printf " install_dir:\t ${C_YELLOW}$install_dir${C_NC}\n"
printf " lock_file:\t ${C_YELLOW}$lock_file${C_NC}\n\n"
# Ensure git is installed # Ensure git is installed
if ! hash git 2>/dev/null if ! [ -x "$(command -v git)" ]; then
then echo "installing git..."
sudo apt-get update -yqq sudo apt-get update -qqy
sudo apt-get install -yqq git sudo apt-get install git -qqy
fi
# Ensure repository is cloned
if [[ ! -d "$dotfiles_dir" ]]
then
mkdir -p "$workspace_dir"
git clone -q "$repository_url" "$dotfiles_dir"
fi fi
# Ensure repository is up to date # Ensure repository is up to date
cd "$dotfiles_dir" echo "pulling latest..."
git pull -q origin master || true if [[ ! -d $dotfiles_dir ]]; then
mkdir -p "$dotfiles_dir"
git clone -q "$repository_url" "$dotfiles_dir"
else
git --git-dir="$dotfiles_dir/.git" pull -q origin master || true
fi
# Install dotfiles # Install dotfiles
source "$dotfiles_dir/install.sh" source "$dotfiles_dir/install.sh"

View File

@@ -1 +0,0 @@
/home/andrejus/.config/fish

12
fish/config.fish Normal file
View File

@@ -0,0 +1,12 @@
# Ensure fisher is installed
if not functions -q 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
end
# Poetry
set -gx PATH $HOME/.poetry/bin $PATH
# Wipe greeting
set fish_greeting

View File

@@ -1 +0,0 @@
/home/andrejus/.config/fish

2
fish/fishfile Normal file
View File

@@ -0,0 +1,2 @@
rafaelrinaldi/pure
jorgebucaran/fish-nvm

View File

@@ -0,0 +1 @@
node_modules

View File

@@ -2,32 +2,32 @@
# #
# Invokes all install scripts. # Invokes all install scripts.
# #
set -euo pipefail
# Log execution source "$dotfiles_dir/utils.sh"
printf "Installing ${C_CYAN}$repository${C_NC}" printf "Installing ${C_CYAN}$REPOSITORY${C_NC}"
printf " as ${C_YELLOW}$USER${C_NC}\n\n" printf " as ${C_YELLOW}$USER${C_NC}\n\n"
# Prevent running as root # Prevent running as root
if [ "$USER" == "root" ] if [[ $USER == root ]]; then
then
printf "Failed: ${C_RED}Running as root${C_NC}\n" printf "Failed: ${C_RED}Running as root${C_NC}\n"
printf "Please run as user, not ${C_YELLOW}sudo${C_NC}\n" printf "Please run as user, not ${C_YELLOW}sudo${C_NC}\n"
exit 1 exit 1
fi fi
# Prevent concurrent scripts # Prevent concurrent runs
if [ -f "$lock_file" ] readonly install_lock_file="$dotfiles_dir/.dotlock"
then if [ -f $install_lock_file ]; then
printf "Failed: ${C_RED}Script already running${C_NC}\n" printf "Failed: ${C_RED}Script already running${C_NC}\n"
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 "$lock_file" # Requires clean touch "$install_lock_file" # Requires clean
# Run all install scripts # Run all install scripts
script_filter="$install_dir/*.sh" readonly install_dir="$dotfiles_dir/install"
for script in $script_filter readonly script_filter="$install_dir/*.sh"
do for script in $script_filter; do
# Avoid pattern matching self # Avoid pattern matching self
[ -e "$script" ] || continue [ -e "$script" ] || continue
@@ -38,7 +38,7 @@ do
# Run and indent output # Run and indent output
source "$script" | indent source "$script" | indent
printf "${C_NC}\n" printf "${C_NC}"
done done

View File

@@ -1,14 +1,15 @@
#!/bin/bash #!/bin/bash
# #
# Always updates apt, upgrades apt, and installes 00-apt-pkglist # apt update and upgrade
# #
# Install list of packages in ./00-apt-pkglist
#
readonly package_list_file="00-apt-pkglist"
# apt update and upgrade non-interactively # apt update and upgrade non-interactively
sudo apt-get update -y update
DEBIAN_FRONTEND=noninteractive sudo apt-get \ upgrade
-o Dpkg::Options::="--force-confdef" \
-o Dpkg::Options::="--force-confold" upgrade -y
# Package installs # Package installs
readonly apt_pkglist=$(cat $install_dir/00-apt-pkglist) readonly package_list=$(cat $install_dir/$package_list_file)
sudo apt-get install -y $apt_pkglist install -y "$package_list"

View File

@@ -7,36 +7,33 @@
# #
# 1. fish shell is installed # 1. fish shell is installed
if [ is_missing fish ] 2>/dev/null if not_installed "fish"; then
then
printf "Installing fish...\n" printf "Installing fish...\n"
# Add fish repository # Add fish repository
sudo apt-add-repository -y ppa:fish-shell/release-3 app_ppa fish-shell/release-3
sudo apt-get -y update update
# Install fish # Install fish
sudo apt-get -y install fish install fish
fi fi
printf "fish is installed\n" printf "fish is installed\n"
fish --version
# 2. fish shell is default login shell # 2. fish shell is default login shell
readonly fish_path=$(which fish) readonly fish_path=$(which fish)
if [ $SHELL != fish_path ] if [ "$SHELL" != fish_path ]; then
then
printf "Setting fish as default...\n"
# Update default login shell # Update default login shell
usermod -s $fish_path $USER usermod -s "$fish_path" "$USER"
fi 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/*" readonly fish_source="$dotfiles_dir/fish"
readonly fish_target="$HOME/.config/fish" readonly 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"

View File

@@ -5,7 +5,7 @@
# #
# 1. git dotfiles are symlinked # 1. git dotfiles are symlinked
readonly git_source="$dotfiles_dir/git/*" readonly git_source="$dotfiles_dir/git"
readonly git_target="$HOME" readonly 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"

View File

@@ -5,14 +5,15 @@
# #
# 1.keybase is installed # 1.keybase is installed
if [ ! hash keybase ] 2>/dev/null if not_installed "keybase"; then
then
printf "Installing keybase...\n" printf "Installing keybase...\n"
curl --remote-name https://prerelease.keybase.io/keybase_amd64.deb curl --remote-name https://prerelease.keybase.io/keybase_amd64.deb
sudo apt-get install -y ./keybase_amd64.deb install ./keybase_amd64.deb
run_keybase rm ./keybase_amd64.deb
fi fi
printf "keybase is installed\n" printf "keybase is installed\n"
run_keybase
keybase --version

View File

@@ -8,13 +8,12 @@
# #
# 1. docker is installed # 1. docker is installed
if ! hash docker 2>/dev/null if not_installed "docker"; then
then
printf "Installing docker...\n" printf "Installing docker...\n"
# Requirements # Requirements
sudo apt-get -y install \ install \
apt-transport-https \ apt-transport-https \
ca-certificates \ ca-certificates \
curl \ curl \
@@ -22,41 +21,42 @@ then
software-properties-common software-properties-common
# Add repository # Add repository
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - add_key https://download.docker.com/linux/ubuntu/gpg
sudo add-apt-repository -y \ sudo add-apt-repository -y \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \ "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \ $(lsb_release -cs) \
stable" stable"
sudo apt-get -y update update
# Install
install docker-ce
fi fi
printf "docker is installed\n" printf "docker is installed\n"
docker --version
# 2. docker-compose if installed # 2. docker-compose if installed
if ! hash docker-compose 2>/dev/null if not_installed "docker-compose"; then
then
printf "Installing docker-compose...\n" printf "Installing docker-compose...\n"
# Docker-compose # Docker-compose
curl -L https://github.com/docker/compose/releases/download/1.21.2/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose curl -L https://github.com/docker/compose/releases/download/1.21.2/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose sudo chmod +x /usr/local/bin/docker-compose
docker-compose --version
fi fi
printf "docker-compose is installed\n" printf "docker-compose is installed\n"
docker-compose --version
# 3. docker group exists # 3. docker group exists
readonly docker_group='docker' readonly docker_group='docker'
if ! grep -q $docker_group /etc/group if ! grep -q "$docker_group" /etc/group; then
then sudo groupadd "$docker_group"
sudo groupadd $docker_group
fi fi
printf "group '$docker_group' is created\n" printf "group '$docker_group' is created\n"
# 4. user is in docker group # 4. user is in docker group
if ! groups $USER | grep -q "\b$docker_group\b" if ! groups $USER | grep -q "\b$docker_group\b"; then
then sudo usermod -aG docker "$USER"
sudo usermod -aG docker $USER
fi fi
printf "user '$USER' is in '$docker_group' group\n" printf "user '$USER' is in '$docker_group' group\n"

View File

@@ -5,20 +5,22 @@
# #
# 1. pyenv is installed # 1. pyenv is installed
if ! hash pyenv 2>/dev/null if not_installed "pyenv"; then
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
sudo apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev \ install make build-essential libssl-dev zlib1g-dev libbz2-dev \
libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev \ libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev \
xz-utils tk-dev libffi-dev liblzma-dev python-openssl git xz-utils tk-dev libffi-dev liblzma-dev python-openssl git
# Install pyenv # Install pyenv
# see https://github.com/pyenv/pyenv-installer # see https://github.com/pyenv/pyenv-installer
curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash run https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer bash
# Add to install path
export PATH="$HOME/.pyenv/bin:$PATH"
fi fi
printf "pyenv is installed\n" printf "pyenv is installed\n"

View File

@@ -5,8 +5,7 @@
# #
# 1. python is installed # 1. python is installed
if ! hash python 2>/dev/null if not_installed "python"; then
then
printf "Installing python...\n" printf "Installing python...\n"

View File

@@ -5,13 +5,12 @@
# #
# 1. poetry is installed # 1. poetry is installed
if ! hash poetry 2>/dev/null if not_installed "poetry"; then
then
printf "Installing poetry...\n" printf "Installing poetry...\n"
# Install poetry # Install poetry
curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python3 run https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py python3
fi fi
printf "poetry is installed\n" printf "poetry is installed\n"

View File

@@ -1,5 +1,5 @@
#!/bin/bash #!/bin/bash
# Clean up # Clean up
sudo apt-get -y autoremove sudo apt-get -qqy autoremove
sudo apt-get -y autoclean sudo apt-get -qqy autoclean

View File

@@ -1,29 +1,57 @@
indent() { sed 's/^/ /'; } #!/bin/bash
#
# Alias commands and utilities.
#
update() {
sudo apt-get update -y
}
# Non-interactive upgrade
upgrade() {
DEBIAN_FRONTEND=noninteractive \
sudo apt-get upgrade -y \
-o Dpkg::Options::="--force-confdef" \
-o Dpkg::Options::="--force-confold"
}
# @arg $1 packages to install
install() {
sudo apt-get install -y $1
}
# @arg $1 repository to add
app_ppa() {
sudo add-apt-repository -y ppa:"$1" &>/dev/null
}
# @arg $1 url to add
add_key() {
curl -fsSL $1 | sudo apt-key add -
}
# @arg $1 URL to run
# @arg $2 binary to use
run() {
curl -fsSL $1 | $2
}
# Symlink contents of source folder to target # Symlink contents of source folder to target
# #
# @arg $1 source # @arg $1 source folder
# @arg $2 target # @arg $2 target folder
# link_folder() {
link_folder () { cp -srf $1 $2
source=$1
target=$2
for file in $(ls -d $source)
do
rel_path=$(realpath --relative-to="$target" "$file")
printf "Linking $file to $target as $rel_path...\n"
ln -sf $target $rel_path
done
} }
# Return if specified binary is not in PATH indent() { sed 's/^/ /'; }
is_missing () {
return ! hash $1 # @arg $1 binary to test
not_installed() {
! [ -x "$(command -v $1)" ]
} }
# Colors
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'