diff --git a/.gitignore b/.gitignore index 86bcc74..cf7e053 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1 @@ -*.dotlock +.dotlock diff --git a/Makefile b/Makefile index 729b793..9ef3353 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,7 @@ .PHONY: clean clean: rm -f .dotlock + +.PHONY: run +run: + bash bootstrap.sh \ No newline at end of file diff --git a/bootstrap.sh b/bootstrap.sh index 8f57c53..6edfc09 100644 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -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" diff --git a/fish/config.fish b/fish/config.fish deleted file mode 100644 index e127afe..0000000 --- a/fish/config.fish +++ /dev/null @@ -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 diff --git a/fish/config.fish b/fish/config.fish new file mode 120000 index 0000000..b3a41f0 --- /dev/null +++ b/fish/config.fish @@ -0,0 +1 @@ +/home/andrejus/.config/fish \ No newline at end of file diff --git a/fish/fishfile b/fish/fishfile deleted file mode 100644 index 69245b2..0000000 --- a/fish/fishfile +++ /dev/null @@ -1,2 +0,0 @@ -rafaelrinaldi/pure -jorgebucaran/fish-nvm diff --git a/fish/fishfile b/fish/fishfile new file mode 120000 index 0000000..b3a41f0 --- /dev/null +++ b/fish/fishfile @@ -0,0 +1 @@ +/home/andrejus/.config/fish \ No newline at end of file diff --git a/install.sh b/install.sh index 28c4f29..49f1b7b 100755 --- a/install.sh +++ b/install.sh @@ -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 diff --git a/install/00-apt.sh b/install/00-apt.sh index c1065f2..1a1b8f8 100644 --- a/install/00-apt.sh +++ b/install/00-apt.sh @@ -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 diff --git a/install/01-fish.sh b/install/01-fish.sh index 5900987..a85abaa 100644 --- a/install/01-fish.sh +++ b/install/01-fish.sh @@ -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" diff --git a/install/10-git.sh b/install/10-git.sh index 93707c4..3a4d6a8 100644 --- a/install/10-git.sh +++ b/install/10-git.sh @@ -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" diff --git a/install/11-keybase.sh b/install/11-keybase.sh index e01f0a4..1fbc5f8 100644 --- a/install/11-keybase.sh +++ b/install/11-keybase.sh @@ -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" diff --git a/install/12-docker.sh b/install/12-docker.sh index 2e7ac66..341fdcd 100644 --- a/install/12-docker.sh +++ b/install/12-docker.sh @@ -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" diff --git a/install/20-pyenv.sh b/install/20-pyenv.sh index 453b39c..2eb1267 100644 --- a/install/20-pyenv.sh +++ b/install/20-pyenv.sh @@ -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" diff --git a/install/21-python.sh b/install/21-python.sh index 2999081..458c9b5 100644 --- a/install/21-python.sh +++ b/install/21-python.sh @@ -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" diff --git a/install/22-poetry.sh b/install/22-poetry.sh index 2a5fcd7..44576e8 100644 --- a/install/22-poetry.sh +++ b/install/22-poetry.sh @@ -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" diff --git a/utils.sh b/utils.sh index 202085c..188c660 100644 --- a/utils.sh +++ b/utils.sh @@ -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'