#!/bin/bash # Bootstrap for: bash -c "$(curl -fsSL dot.djmonta.me)" trap 'e_error "Abort the command that is in progress"; exit 1' INT trap 'e_error "Some error has occurred"; exit 1' ERR set -e set -u cat <<-'EOT' __ __ ____ _ __ ____/ /____ / /_ / __/(_)/ /___ _____ / __ // __ \ / __// /_ / // // _ \ / ___/ / /_/ // /_/ // /_ / __// // // __/(__ ) \__,_/ \____/ \__//_/ /_//_/ \___//____/ *** WHAT'S INSIDE? *** 1. Clone or update https://github.com/djmonta/dotfiles.git 2. Install Determinate Nix if missing (optional) 3. Apply nix-darwin + home-manager (macOS), or home-manager only 4. Run etc/init/* (optional: bash -c "$(curl ...)" init) See the README for documentation. https://github.com/djmonta/dotfiles Copyright (c) 2015 "Sachiko Miyamoto" aka @djmonta Licensed under the MIT license. EOT e_newline() { printf "\n"; } e_header() { printf "\n\033[1m%s\033[0m\n" "$*"; } e_success() { printf " \033[1;32m✔\033[0m %s\n" "$*"; } e_error() { printf " \033[1;31m✖\033[0m %s\n" "$*" 1>&2; } e_arrow() { printf " \033[1;34m➜\033[0m %s\n" "$*"; } is_exist() { command -v "$1" >/dev/null 2>&1; } DOTFILES=$HOME/dotfiles export DOTFILES REPO_URL='https://github.com/djmonta/dotfiles.git' load_nix() { if [[ -e /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh ]]; then # shellcheck disable=SC1091 . /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh fi } clone_or_update() { e_header 'Downloading dotfiles...' if [[ -d "$DOTFILES/.git" ]]; then e_arrow "$DOTFILES already exists, pulling..." git -C "$DOTFILES" pull --ff-only elif [[ -d "$DOTFILES" ]]; then e_error "$DOTFILES exists and is not a git repository" return 1 elif is_exist git; then git clone --recursive "$REPO_URL" "$DOTFILES" else zip_url='https://github.com/djmonta/dotfiles/archive/master.zip' mkdir -p /tmp/$$ && cd /tmp/$$ if is_exist curl; then curl -L -o dotfiles.zip "$zip_url" elif is_exist wget; then wget -O dotfiles.zip "$zip_url" else e_error 'not found downloader' return 1 fi unzip dotfiles.zip mv dotfiles-master "$DOTFILES" fi e_success 'done' } ensure_nix() { load_nix if is_exist nix; then return 0 fi e_header 'Installing Nix...' bash "$DOTFILES/etc/init/install_nix.sh" load_nix } deploy() { cd "$DOTFILES" e_header 'Deploying dotfiles...' if ! is_exist nix; then e_error 'nix not found; falling back to symlinks' if make deploy; then e_success 'done (symlinks)' fi return fi if [[ "$(uname)" == Darwin ]]; then if make darwin; then e_success 'done (nix-darwin + home-manager)' return 0 fi e_error 'nix-darwin failed; falling back to home-manager' fi if make hm; then e_success 'done (home-manager)' return 0 fi e_error 'home-manager failed; falling back to symlinks' if make deploy; then e_success 'done (symlinks)' fi } maybe_init() { if [[ "${1:-}" != 'init' ]]; then return 0 fi e_header 'Initializing...' if make init; then e_success 'done' fi } installing_dotfiles() { clone_or_update ensure_nix deploy maybe_init "${1:-}" e_newline e_arrow 'Restarting your shell...' exec "${SHELL:-/bin/zsh}" } # Refuse a raw `./etc/install` unless called as `./etc/install directly`. # The README one-liner (`bash -c "$(curl ...)"`) does not hit this. if [[ "${0}" = "${BASH_SOURCE:-}" ]]; then e_error 'WARNING!!' e_error 'You should NOT run directly from the command line' e_error 'For more info, see https://github.com/djmonta/dotfiles' e_newline if [[ "${1:-}" != 'directly' ]]; then exit 1 fi shift fi installing_dotfiles "${1:-}" e_success 'All done'