From b16ca6a6261e257930b85d50a0ffc93679a319ce Mon Sep 17 00:00:00 2001 From: Fernando Schauenburg Date: Sun, 3 Jan 2021 17:24:48 +0100 Subject: [PATCH] replace ansible with bootstrap script --- ansible.cfg | 6 - {roles/dotfiles/files/bin => bin}/colorman | 0 {roles/dotfiles/files/bin => bin}/colortest | 0 .../dotfiles/files/bin => bin}/colortest256 | 0 {roles/dotfiles/files/bin => bin}/git-churn | 0 .../git-what-the-hell-just-happened | 0 {roles/dotfiles/files/bin => bin}/git-wtf | 0 {roles/dotfiles/files/bin => bin}/solarize | 0 {roles/dotfiles/files/bin => bin}/styletest | 0 {roles/dotfiles/files/bin => bin}/vboxmount | 0 bootstrap | 198 ++++++++++++++++++ .../dircolors => dircolors}/solarized-dark | 0 .../dircolors => dircolors}/solarized-light | 0 {roles/dotfiles/files => files}/alacritty.yml | 0 {roles/dotfiles/files => files}/bashrc | 0 {roles/dotfiles/files => files}/gitconfig | 0 {roles/dotfiles/files => files}/gitignore | 0 {roles/dotfiles/files => files}/inputrc | 0 {roles/dotfiles/files => files}/minttyrc | 0 {roles/dotfiles/files => files}/plug.vim | 0 .../files => files}/python-startup.py | 0 {roles/dotfiles/files => files}/ssh_config | Bin .../dotfiles/files => files}/tmux-colors.conf | 0 {roles/dotfiles/files => files}/tmux.conf | 0 {roles/dotfiles/files => files}/vimrc | 0 inventory | 5 - local.yml | 15 -- roles/dotfiles/tasks/main.yml | 112 ---------- roles/dotfiles/templates/gitconfig.host.j2 | 19 -- roles/packages/tasks/main.yml | 74 ------- 30 files changed, 198 insertions(+), 231 deletions(-) delete mode 100644 ansible.cfg rename {roles/dotfiles/files/bin => bin}/colorman (100%) rename {roles/dotfiles/files/bin => bin}/colortest (100%) rename {roles/dotfiles/files/bin => bin}/colortest256 (100%) rename {roles/dotfiles/files/bin => bin}/git-churn (100%) rename {roles/dotfiles/files/bin => bin}/git-what-the-hell-just-happened (100%) rename {roles/dotfiles/files/bin => bin}/git-wtf (100%) rename {roles/dotfiles/files/bin => bin}/solarize (100%) rename {roles/dotfiles/files/bin => bin}/styletest (100%) rename {roles/dotfiles/files/bin => bin}/vboxmount (100%) create mode 100755 bootstrap rename {roles/dotfiles/files/dircolors => dircolors}/solarized-dark (100%) rename {roles/dotfiles/files/dircolors => dircolors}/solarized-light (100%) rename {roles/dotfiles/files => files}/alacritty.yml (100%) rename {roles/dotfiles/files => files}/bashrc (100%) rename {roles/dotfiles/files => files}/gitconfig (100%) rename {roles/dotfiles/files => files}/gitignore (100%) rename {roles/dotfiles/files => files}/inputrc (100%) rename {roles/dotfiles/files => files}/minttyrc (100%) rename {roles/dotfiles/files => files}/plug.vim (100%) rename {roles/dotfiles/files => files}/python-startup.py (100%) rename {roles/dotfiles/files => files}/ssh_config (100%) rename {roles/dotfiles/files => files}/tmux-colors.conf (100%) rename {roles/dotfiles/files => files}/tmux.conf (100%) rename {roles/dotfiles/files => files}/vimrc (100%) delete mode 100644 inventory delete mode 100644 local.yml delete mode 100644 roles/dotfiles/tasks/main.yml delete mode 100644 roles/dotfiles/templates/gitconfig.host.j2 delete mode 100644 roles/packages/tasks/main.yml diff --git a/ansible.cfg b/ansible.cfg deleted file mode 100644 index 313fa92..0000000 --- a/ansible.cfg +++ /dev/null @@ -1,6 +0,0 @@ -[defaults] -interpreter_python = auto_silent -inventory = ./inventory -nocows = True -roles_path = ./roles - diff --git a/roles/dotfiles/files/bin/colorman b/bin/colorman similarity index 100% rename from roles/dotfiles/files/bin/colorman rename to bin/colorman diff --git a/roles/dotfiles/files/bin/colortest b/bin/colortest similarity index 100% rename from roles/dotfiles/files/bin/colortest rename to bin/colortest diff --git a/roles/dotfiles/files/bin/colortest256 b/bin/colortest256 similarity index 100% rename from roles/dotfiles/files/bin/colortest256 rename to bin/colortest256 diff --git a/roles/dotfiles/files/bin/git-churn b/bin/git-churn similarity index 100% rename from roles/dotfiles/files/bin/git-churn rename to bin/git-churn diff --git a/roles/dotfiles/files/bin/git-what-the-hell-just-happened b/bin/git-what-the-hell-just-happened similarity index 100% rename from roles/dotfiles/files/bin/git-what-the-hell-just-happened rename to bin/git-what-the-hell-just-happened diff --git a/roles/dotfiles/files/bin/git-wtf b/bin/git-wtf similarity index 100% rename from roles/dotfiles/files/bin/git-wtf rename to bin/git-wtf diff --git a/roles/dotfiles/files/bin/solarize b/bin/solarize similarity index 100% rename from roles/dotfiles/files/bin/solarize rename to bin/solarize diff --git a/roles/dotfiles/files/bin/styletest b/bin/styletest similarity index 100% rename from roles/dotfiles/files/bin/styletest rename to bin/styletest diff --git a/roles/dotfiles/files/bin/vboxmount b/bin/vboxmount similarity index 100% rename from roles/dotfiles/files/bin/vboxmount rename to bin/vboxmount diff --git a/bootstrap b/bootstrap new file mode 100755 index 0000000..fdcd972 --- /dev/null +++ b/bootstrap @@ -0,0 +1,198 @@ +#!/bin/sh +set -eu + +DRY_RUN=false +DEFAULT_GIT_USER="Fernando Schauenburg" +DEFAULT_GIT_EMAIL="fernando@schauenburg.me" + +XDG_CACHE_HOME="${XDG_CACHE_HOME:-$HOME/.cache}" +XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$XDG_CONFIG_HOME}" +XDG_DATA_HOME="${XDG_DATA_HOME:-$home/.local/share}" + +DIRS=$(cat < $target" + $DRY_RUN || ln -sf "$target" "$1" + fi +} + +file_content() { # Ensure $1 and $2 contents are equal, updating $1 if needed. + if diff "$1" "$2" >/dev/null 2>&1; then + info "OK: $1" + else + warn "overwriting $1 with $2:" + cat "$2" + $DRY_RUN || cp -f "$2" "$1" + fi +} + +task_gather_user_info() { + heading "Gather user information" + printf 'git name [%s]: ' "$DEFAULT_GIT_USER" + read -r git_user + printf 'git e-mail [%s]: ' "$DEFAULT_GIT_EMAIL" + read -r git_email +} + +task_remove_bash_profile() { + heading "Remove pre-installed bash profile" + for f in .bash_logout .profile; do + file_absent "$HOME/$f" + done +} + +task_ensure_directories() { + heading "Ensure existence of directories used by dotfiles" + echo "$DIRS" | while read -r d; do directory_present "$d"; done +} + +task_link_dotfiles() { + heading "Link dotfiles" + echo "$DOTFILES" | while read -r dest src; do + file_link "$src" "$dest" + done +} + +task_deploy_templates() { + heading "Deploy templates" + temp_git="$(mktemp)" + cat >"$temp_git" </dev/null 2>&1; then + warn "Installing vim plugins" + $DRY_RUN || vim -nes -u "$XDG_CONFIG_HOME/vim/vimrc" -c 'PlugInstall | qall!' + else + error "vim is not installed; skipping plugin installation..." + fi +} + +main() { + task_gather_user_info + task_remove_bash_profile + task_ensure_directories + task_link_dotfiles + task_deploy_templates + task_link_local_commands + task_link_dircolors + task_make_logins_silent + task_install_vim_plugins +} + +main + diff --git a/roles/dotfiles/files/dircolors/solarized-dark b/dircolors/solarized-dark similarity index 100% rename from roles/dotfiles/files/dircolors/solarized-dark rename to dircolors/solarized-dark diff --git a/roles/dotfiles/files/dircolors/solarized-light b/dircolors/solarized-light similarity index 100% rename from roles/dotfiles/files/dircolors/solarized-light rename to dircolors/solarized-light diff --git a/roles/dotfiles/files/alacritty.yml b/files/alacritty.yml similarity index 100% rename from roles/dotfiles/files/alacritty.yml rename to files/alacritty.yml diff --git a/roles/dotfiles/files/bashrc b/files/bashrc similarity index 100% rename from roles/dotfiles/files/bashrc rename to files/bashrc diff --git a/roles/dotfiles/files/gitconfig b/files/gitconfig similarity index 100% rename from roles/dotfiles/files/gitconfig rename to files/gitconfig diff --git a/roles/dotfiles/files/gitignore b/files/gitignore similarity index 100% rename from roles/dotfiles/files/gitignore rename to files/gitignore diff --git a/roles/dotfiles/files/inputrc b/files/inputrc similarity index 100% rename from roles/dotfiles/files/inputrc rename to files/inputrc diff --git a/roles/dotfiles/files/minttyrc b/files/minttyrc similarity index 100% rename from roles/dotfiles/files/minttyrc rename to files/minttyrc diff --git a/roles/dotfiles/files/plug.vim b/files/plug.vim similarity index 100% rename from roles/dotfiles/files/plug.vim rename to files/plug.vim diff --git a/roles/dotfiles/files/python-startup.py b/files/python-startup.py similarity index 100% rename from roles/dotfiles/files/python-startup.py rename to files/python-startup.py diff --git a/roles/dotfiles/files/ssh_config b/files/ssh_config similarity index 100% rename from roles/dotfiles/files/ssh_config rename to files/ssh_config diff --git a/roles/dotfiles/files/tmux-colors.conf b/files/tmux-colors.conf similarity index 100% rename from roles/dotfiles/files/tmux-colors.conf rename to files/tmux-colors.conf diff --git a/roles/dotfiles/files/tmux.conf b/files/tmux.conf similarity index 100% rename from roles/dotfiles/files/tmux.conf rename to files/tmux.conf diff --git a/roles/dotfiles/files/vimrc b/files/vimrc similarity index 100% rename from roles/dotfiles/files/vimrc rename to files/vimrc diff --git a/inventory b/inventory deleted file mode 100644 index c3a73cd..0000000 --- a/inventory +++ /dev/null @@ -1,5 +0,0 @@ -localhost - -[all:vars] -ansible_connection=local - diff --git a/local.yml b/local.yml deleted file mode 100644 index 1c19a3e..0000000 --- a/local.yml +++ /dev/null @@ -1,15 +0,0 @@ -- name: Make myself at home :) - hosts: all - - vars_prompt: - - name: git_user - private: no - default: Fernando Schauenburg - - name: git_email - private: no - default: fernando@schauenburg.me - - roles: - - dotfiles - - packages - diff --git a/roles/dotfiles/tasks/main.yml b/roles/dotfiles/tasks/main.yml deleted file mode 100644 index 3b5f1b6..0000000 --- a/roles/dotfiles/tasks/main.yml +++ /dev/null @@ -1,112 +0,0 @@ ---- -- name: remove pre-installed bash profile - file: - path: "{{ item }}" - state: absent - loop: - - ~/.bash_logout - - ~/.profile - - -- name: ensure existence of directories used by dotfiles - file: - path: "{{ item }}" - state: directory - loop: - - ~/.config/alacritty - - ~/.config/dircolors - - ~/.config/git - - ~/.config/mintty - - ~/.config/python - - ~/.config/readline - - ~/.config/tmux - - ~/.config/vim - - ~/.config/vim/autoload # vim plugin manager - - ~/.local/bin # local commands - - ~/.local/etc/git # local git config - - ~/.local/share/bash # for bash history - - ~/.local/share/bash-completion/completions # custom bash completions - - ~/.local/share/less # less history - - ~/.local/share/python # python history - - ~/.local/share/vim # viminfo - - ~/.local/share/vim/plugged # vim plugins - - ~/.ssh - - -- name: link dotfiles - file: - src: "{{ role_path }}/files/{{ item.src }}" - dest: "{{ item.dest }}" - state: link - force: yes - loop: - - { src: alacritty.yml, dest: ~/.config/alacritty/alacritty.yml } - - { src: bashrc, dest: ~/.bash_profile } - - { src: bashrc, dest: ~/.bashrc } - - { src: gitconfig, dest: ~/.config/git/config } - - { src: gitignore, dest: ~/.config/git/ignore } - - { src: inputrc, dest: ~/.config/readline/inputrc } - - { src: minttyrc, dest: ~/.config/mintty/config } - - { src: plug.vim, dest: ~/.config/vim/autoload/plug.vim } - - { src: python-startup.py, dest: ~/.config/python/startup.py } - - { src: ssh_config, dest: ~/.ssh/config } - - { src: tmux-colors.conf, dest: ~/.config/tmux/tmux-colors.conf } - - { src: tmux.conf, dest: ~/.config/tmux/tmux.conf } - - { src: vimrc, dest: ~/.config/vim/vimrc } - - -- name: deploy templates - template: - src: "{{ item.src }}" - dest: "{{ item.dest }}" - loop: - - src: gitconfig.host.j2 - dest: ~/.local/etc/git/config.host - - -- name: link local commands - file: - src: "{{ item }}" - dest: ~/.local/bin/{{ item | basename }} - state: link - force: yes - with_fileglob: - - "{{ role_path }}/files/bin/*" - - -- name: link dircolors - file: - src: "{{ item }}" - dest: ~/.config/dircolors/{{ item | basename }} - state: link - force: yes - with_fileglob: - - "{{ role_path }}/files/dircolors/*" - - -- block: - - name: hushlogin exists? - stat: - path: ~/.hushlogin - register: hush - - - name: create hushlogin - when: hush.stat.exists == false - file: - path: ~/.hushlogin - state: touch - - -- block: - - name: vim plugins installed? - find: - paths: ~/.local/share/vim/plugged - file_type: directory - register: vim_plugins - - - name: install vim plugins - when: vim_plugins.matched|int == 0 - shell: vim -nes -u ~/.config/vim/vimrc -c 'PlugInstall | qall!' - register: result_vim_plugins - failed_when: result_vim_plugins.rc != 0 - diff --git a/roles/dotfiles/templates/gitconfig.host.j2 b/roles/dotfiles/templates/gitconfig.host.j2 deleted file mode 100644 index ac06b53..0000000 --- a/roles/dotfiles/templates/gitconfig.host.j2 +++ /dev/null @@ -1,19 +0,0 @@ -# ************************************* -# * DO NOT EDIT THIS FILE * -# ************************************* -# -# This file was generated by Ansible and any changes will be overwritten the -# next time the playbook is run. For local settings, use this instead: -# -# ~/.local/etc/git/config -# - -[user] - name = {{ git_user }} - email = {{ git_email }} - -{% if ansible_os_family == 'Darwin' %} -[credential] - helper = osxkeychain -{% endif %} - diff --git a/roles/packages/tasks/main.yml b/roles/packages/tasks/main.yml deleted file mode 100644 index 40656a1..0000000 --- a/roles/packages/tasks/main.yml +++ /dev/null @@ -1,74 +0,0 @@ ---- -- name: install apt packages - when: ansible_facts['os_family']|lower == "debian" - become: yes - apt: - state: latest - update_cache: yes - name: - - bash - - bash-completion - - curl - - exa - - exuberant-ctags - - ffmpeg - - git - - git-crypt - - git-lfs - - gpg - - htop - - nmap - - psmisc - - python3 - - python3-pip - - shellcheck - - sqlite - - stow - - tmux - - tree - - vifm - - vim - - wget - - youtube-dl - - -- name: install homebrew packages - when: ansible_facts['os_family']|lower == "darwin" - homebrew: - state: latest - update_homebrew: yes - name: - - bash - - bash-completion - - coreutils - - ctags - - curl - - exa - - exiftool - - ffmpeg - - findutils - - git - - git-crypt - - git-lfs - - gnu-sed - - gpg - - grep - - gzip - - htop - - imagemagick - - jupyter - - make - - nmap - - pstree - - python3 - - reattach-to-user-namespace - - shellcheck - - sqlite - - stow - - tmux - - tree - - vifm - - vim - - wget - - youtube-dl -