Further tidying and making

This commit is contained in:
2020-02-25 21:09:30 +00:00
committed by Andrejus
parent 549d6ce88d
commit c4ce39b965
15 changed files with 101 additions and 68 deletions

2
.gitignore vendored
View File

@@ -1 +1 @@
*.dotlock
.dotlock

View File

@@ -1,3 +1,7 @@
.PHONY: clean
clean:
rm -f .dotlock
.PHONY: run
run:
bash bootstrap.sh

View File

@@ -6,31 +6,43 @@
# `source path/to/bootstrap.sh`
# `source <(wget path/to/bootstrap.sh)`
#
set -euf -o pipefail
set -euo pipefail
# Set up variables and imports
repository="andrejusk/dotfiles"
repository_url="https://github.com/$repository.git"
workspace_dir="$HOME/workspace"
dotfiles_dir="$workspace_dir/dotfiles"
lock_extension="dotlock"
source "${dotfiles_dir}/utils.sh"
readonly repository="andrejusk/dotfiles"
readonly repository_url="https://github.com/$repository.git"
readonly workspace_dir="$HOME/workspace"
readonly dotfiles_dir="$workspace_dir/dotfiles"
readonly install_dir="$dotfiles_dir/install"
readonly lock_file="$dotfiles_dir/.dotlock"
source "$dotfiles_dir/utils.sh"
# Log execution
printf "Setting up ${C_CYAN}$repository${C_NC} with:\n"
printf " repository:\t ${C_YELLOW}$repository${C_NC}\n"
printf " repository_url: ${C_YELLOW}$repository_url${C_NC}\n"
printf " workspace_dir: ${C_YELLOW}$workspace_dir${C_NC}\n"
printf " dotfiles_dir:\t ${C_YELLOW}$dotfiles_dir${C_NC}\n"
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
if ! hash git 2>/dev/null; then
if ! hash git 2>/dev/null
then
sudo apt-get update -yqq
sudo apt-get install -yqq git
fi
# Ensure repository is cloned
if [[ ! -d $dotfiles_dir ]]; then
mkdir -p $workspace_dir
git clone $repository_url $dotfiles_dir
if [[ ! -d "$dotfiles_dir" ]]
then
mkdir -p "$workspace_dir"
git clone -q "$repository_url" "$dotfiles_dir"
fi
# Ensure repository is up to date
cd $dotfiles_dir
# git pull origin master
cd "$dotfiles_dir"
git pull -q origin master || true
# Install dotfiles
source $dotfiles_dir/install.sh
source "$dotfiles_dir/install.sh"

View File

@@ -1,12 +0,0 @@
# 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

1
fish/config.fish Symbolic link
View File

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

View File

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

1
fish/fishfile Symbolic link
View File

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

View File

@@ -8,25 +8,26 @@ printf "Installing ${C_CYAN}$repository${C_NC}"
printf " as ${C_YELLOW}$USER${C_NC}\n\n"
# Prevent running as root
if [ "$USER" == "root" ]; then
printf "Failed: ${C_RED}Running as $USER${C_NC}\n"
if [ "$USER" == "root" ]
then
printf "Failed: ${C_RED}Running as root${C_NC}\n"
printf "Please run as user, not ${C_YELLOW}sudo${C_NC}\n"
exit 1
fi
# Prevent concurrent scripts
lock_file="$dotfiles_dir/.$lock_extension"
if [ -f "$lock_file" ]; then
if [ -f "$lock_file" ]
then
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"
exit 1
fi
touch $lock_file # Requires clear
touch "$lock_file" # Requires clean
# Run all install scripts
for script in "$dotfiles_dir/install/*.sh"; do
printf "$script\n\n"
script_filter="$install_dir/*.sh"
for script in $script_filter
do
# Avoid pattern matching self
[ -e "$script" ] || continue

View File

@@ -10,5 +10,5 @@ DEBIAN_FRONTEND=noninteractive sudo apt-get \
-o Dpkg::Options::="--force-confold" upgrade -y
# Package installs
pkglist=$(cat $install_dir/00-apt-pkglist)
sudo apt-get install -y $pkglist
readonly apt_pkglist=$(cat $install_dir/00-apt-pkglist)
sudo apt-get install -y $apt_pkglist

View File

@@ -7,7 +7,8 @@
#
# 1. fish shell is installed
if [ ! hash fish ] 2>/dev/null; then
if [ is_missing fish ] 2>/dev/null
then
printf "Installing fish...\n"
@@ -22,23 +23,20 @@ fi
printf "fish is installed\n"
# 2. fish shell is default login shell
fish_path=$(which fish)
if [ $SHELL != fish_path ]; then
readonly fish_path=$(which fish)
if [ $SHELL != fish_path ]
then
printf "Setting fish as default...\n"
# Update default login shell
chsh -s $fish_path $USER
usermod -s $fish_path $USER
fi
printf "fish is default login shell\n"
# 3. fish dotfiles are symlinked
target="$HOME/.config/fish"
for file in $(ls -d $script_dir/fish/*); do
rel_path=$(realpath --relative-to="$target" "$file")
printf "Linking $file to $target as $rel_path...\n"
ln -sv $rel_path $target
done
readonly fish_source="$dotfiles_dir/fish/*"
readonly fish_target="$HOME/.config/fish"
link_folder "$fish_source" "$fish_target"
printf "fish dotfiles linked\n"

View File

@@ -5,10 +5,7 @@
#
# 1. git dotfiles are symlinked
target="$HOME"
for file in $(ls -d $script_dir/git/*); do
rel_path=$(realpath --relative-to="$target" "$file")
printf "Linking $file to $target as $rel_path...\n"
ln -sv $rel_path $target
done
readonly git_source="$dotfiles_dir/git/*"
readonly git_target="$HOME"
link_folder $git_source $git_target
printf "git dotfiles linked\n"

View File

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

View File

@@ -8,7 +8,8 @@
#
# 1. docker is installed
if ! hash docker 2>/dev/null; then
if ! hash docker 2>/dev/null
then
printf "Installing docker...\n"
@@ -32,7 +33,8 @@ fi
printf "docker is installed\n"
# 2. docker-compose if installed
if ! hash docker-compose 2>/dev/null; then
if ! hash docker-compose 2>/dev/null
then
printf "Installing docker-compose...\n"
@@ -45,14 +47,16 @@ fi
printf "docker-compose is installed\n"
# 3. docker group exists
group='docker'
if ! grep -q $group /etc/group; then
sudo groupadd docker
readonly docker_group='docker'
if ! grep -q $docker_group /etc/group
then
sudo groupadd $docker_group
fi
printf "group '$group' is created\n"
printf "group '$docker_group' is created\n"
# 4. user is in docker group
if ! groups $USER | grep -q "\b$group\b"; then
if ! groups $USER | grep -q "\b$docker_group\b"
then
sudo usermod -aG docker $USER
fi
printf "user '$USER' is in '$group' group\n"
printf "user '$USER' is in '$docker_group' group\n"

View File

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

View File

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

View File

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

View File

@@ -1,5 +1,29 @@
indent() { sed 's/^/ /'; }
# Symlink contents of source folder to target
#
# @arg $1 source
# @arg $2 target
#
link_folder () {
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
is_missing () {
return ! hash $1
}
C_BLACK='\033[0;30m'
C_DGRAY='\033[1;30m'
C_RED='\033[0;31m'