summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Ilvokhin <d@ilvokhin.com>2024-02-24 18:36:32 +0000
committerDmitry Ilvokhin <d@ilvokhin.com>2024-02-24 18:36:32 +0000
commit2b29e812468ae2f33a4d37e2e280b7080f11ee86 (patch)
tree15826a929d63c05081399d970e8caaf6d0ecdc23
parent505d0e3202677729f9c5a9c03cb5ddfd9faf6d78 (diff)
downloadinfra-2b29e812468ae2f33a4d37e2e280b7080f11ee86.tar.gz
infra-2b29e812468ae2f33a4d37e2e280b7080f11ee86.tar.bz2
infra-2b29e812468ae2f33a4d37e2e280b7080f11ee86.zip
Add simple dotfiles management playbook
-rw-r--r--dotfiles.yml4
-rw-r--r--misc/dotfiles/bash_profile9
-rw-r--r--misc/dotfiles/bashrc.j222
-rw-r--r--misc/dotfiles/gdbinit2
-rw-r--r--misc/dotfiles/gitconfig3
-rw-r--r--misc/dotfiles/muttrc25
-rw-r--r--misc/dotfiles/screenrc.j249
-rw-r--r--misc/dotfiles/ssh/config.j229
-rwxr-xr-xmisc/dotfiles/ssh/rc20
-rw-r--r--misc/dotfiles/templates/template.cpp23
-rw-r--r--misc/dotfiles/templates/template.py10
-rw-r--r--misc/dotfiles/vimrc25
-rw-r--r--roles/dotfiles/defaults/main.yml2
-rw-r--r--roles/dotfiles/tasks/main.yml163
14 files changed, 386 insertions, 0 deletions
diff --git a/dotfiles.yml b/dotfiles.yml
new file mode 100644
index 0000000..5074dbe
--- /dev/null
+++ b/dotfiles.yml
@@ -0,0 +1,4 @@
+- name: Copy necessary dotfiles
+ hosts: localhost
+ roles:
+ - { role: dotfiles }
diff --git a/misc/dotfiles/bash_profile b/misc/dotfiles/bash_profile
new file mode 100644
index 0000000..7bbee3f
--- /dev/null
+++ b/misc/dotfiles/bash_profile
@@ -0,0 +1,9 @@
+export LC_ALL=en_US.UTF-8
+export LANG=en_US.UTF-8
+
+export EDITOR=vim
+export PATH="$HOME/bin:/usr/local/sbin:$PATH"
+
+if [ -f $HOME/.bashrc ]; then
+ . $HOME/.bashrc
+fi
diff --git a/misc/dotfiles/bashrc.j2 b/misc/dotfiles/bashrc.j2
new file mode 100644
index 0000000..4a872fc
--- /dev/null
+++ b/misc/dotfiles/bashrc.j2
@@ -0,0 +1,22 @@
+# Source system-wide settings of there are any.
+if [ -f /etc/bashrc ]; then
+ . /etc/bashrc
+fi
+
+{% if ansible_facts['os_family'] == "Darwin" %}
+# Specific settings for macOS.
+if [[ "$OSTYPE" == "darwin"* ]]; then
+
+# Silence bash deprecation warning.
+export BASH_SILENCE_DEPRECATION_WARNING=1
+
+# Enable colors for `ls` output.
+export CLICOLOR=1
+
+# Get GitHub token from keychain to avoid homebrew rate limiting on GitHub
+# side.
+export HOMEBREW_GITHUB_API_TOKEN=`security \
+ find-generic-password -s "Homebrew GitHub Token" -w`
+
+fi
+{% endif %}
diff --git a/misc/dotfiles/gdbinit b/misc/dotfiles/gdbinit
new file mode 100644
index 0000000..eeb5e28
--- /dev/null
+++ b/misc/dotfiles/gdbinit
@@ -0,0 +1,2 @@
+set history save on
+set history filename ~/.gdb_history
diff --git a/misc/dotfiles/gitconfig b/misc/dotfiles/gitconfig
new file mode 100644
index 0000000..4ac77b1
--- /dev/null
+++ b/misc/dotfiles/gitconfig
@@ -0,0 +1,3 @@
+[user]
+ name = Dmitry Ilvokhin
+ email = d@ilvokhin.com
diff --git a/misc/dotfiles/muttrc b/misc/dotfiles/muttrc
new file mode 100644
index 0000000..2f5b7f1
--- /dev/null
+++ b/misc/dotfiles/muttrc
@@ -0,0 +1,25 @@
+# imap
+set imap_user = d@ilvokhin.com
+set folder = imaps://mail.ilvokhin.com
+set spoolfile = +INBOX
+set record = +INBOX/Sent
+set postponed = +INBOX/Drafts
+set mbox = +INBOX/All
+
+# smtp
+set smtp_url = smtps://$imap_user@mail.ilvokhin.com
+set smtp_pass = $imap_pass
+set ssl_force_tls = yes
+
+# composition
+set editor = `echo \$EDITOR`
+set edit_headers = yes
+set charset = UTF-8
+unset use_domain
+set realname = "Dmitry Ilvokhin"
+set from = "d@ilvokhin.com"
+set use_from = yes
+
+set sort=threads
+set sort_browser=date
+set sort_aux=reverse-last-date-received
diff --git a/misc/dotfiles/screenrc.j2 b/misc/dotfiles/screenrc.j2
new file mode 100644
index 0000000..acc934a
--- /dev/null
+++ b/misc/dotfiles/screenrc.j2
@@ -0,0 +1,49 @@
+# Automatically detach screen on hangup.
+autodetach on
+
+# Change escape key to Ctrl + b.
+escape ^bb
+
+# Increase size of the scrollback buffer.
+defscrollback 32768
+
+# Disable copyright notice during startup.
+startup_message off
+
+# Set `$TERM` value for xterm instead of screen.
+term xterm
+
+# Enable "alternate screen" terminal capability. Screen will behave like
+# regular terminal. For example, after vim was closed, shell history will be
+# displayed instead of contents of the file just closed.
+altscreen on
+
+# Always display windows captions with the following format.
+# %{Wb}: bright white letters on blue background.
+# %H: hostname of the system.
+# %c: current time HH:MM in 24h format.
+# %{wk}: white letter on black background.
+# %-w: all window numbers and names up to the current window.
+# %{kw}: black letters on white background.
+# [%n %t]: window number and window title.
+# %{-}: restores the attributes and colors that were set before the last change
+# was made.
+# %+w: all window numbers and names starting with the window after the current
+# one.
+caption always "%{Wb} %H - %c %{wk} %-w%{kw}[%n %t]%{-}%+w"
+
+# Enable visual bell.
+vbell off
+
+# Use bright colors for bold text (most terminal emulators do this already).
+attrcolor b ".I"
+
+# Change background-color-erase setting. If ‘bce’ is set to on, all characters
+# cleared by an erase/insert/scroll/clear operation will be displayed in the
+# current background color.
+defbce "on"
+
+{% if jumphost %}
+# Make ssh-agent forwarding work with screen.
+setenv SSH_AUTH_SOCK $HOME/.ssh/ssh_auth_sock
+{% endif %}
diff --git a/misc/dotfiles/ssh/config.j2 b/misc/dotfiles/ssh/config.j2
new file mode 100644
index 0000000..d56f1d0
--- /dev/null
+++ b/misc/dotfiles/ssh/config.j2
@@ -0,0 +1,29 @@
+Host *
+ User d
+{% if ansible_facts['os_family'] == "Darwin" %}
+ # macOS specific settings.
+ UseKeychain yes
+ AddKeysToAgent yes
+{% endif %}
+
+Host gate
+ Hostname gate.ilvokhin.com
+ ForwardAgent yes
+
+Host sun
+ Hostname sun.ilvokhin.com
+
+Host mail
+ Hostname mail.ilvokhin.com
+ User root
+
+# Moscow machines behind NAT.
+Host water
+ ProxyJump gate
+ Hostname 10.9.8.2
+ ForwardAgent yes
+
+Host flame
+ ProxyJump gate
+ Hostname 10.9.9.2
+ ForwardAgent yes
diff --git a/misc/dotfiles/ssh/rc b/misc/dotfiles/ssh/rc
new file mode 100755
index 0000000..c129eb8
--- /dev/null
+++ b/misc/dotfiles/ssh/rc
@@ -0,0 +1,20 @@
+#! /usr/bin/env bash
+
+# Credits: https://gist.github.com/martijnvermaat/8070533
+
+# Fix SSH auth socket location so agent forwarding works with screen.
+if test "$SSH_AUTH_SOCK" ; then
+ ln -sf $SSH_AUTH_SOCK ~/.ssh/ssh_auth_sock
+fi
+
+# Taken from the sshd(8) manpage.
+if read proto cookie && [ -n "$DISPLAY" ]; then
+ if [ `echo $DISPLAY | cut -c1-10` = 'localhost:' ]; then
+ # X11UseLocalhost=yes
+ echo add unix:`echo $DISPLAY |
+ cut -c11-` $proto $cookie
+ else
+ # X11UseLocalhost=no
+ echo add $DISPLAY $proto $cookie
+ fi | xauth -q -
+fi
diff --git a/misc/dotfiles/templates/template.cpp b/misc/dotfiles/templates/template.cpp
new file mode 100644
index 0000000..16f3e15
--- /dev/null
+++ b/misc/dotfiles/templates/template.cpp
@@ -0,0 +1,23 @@
+#include <algorithm>
+#include <iterator>
+#include <iostream>
+#include <iomanip>
+#include <cassert>
+#include <utility>
+#include <string>
+#include <vector>
+#include <limits>
+#include <queue>
+#include <cmath>
+#include <map>
+#include <set>
+
+using namespace std;
+
+using ll = long long;
+
+int main()
+{
+
+ return 0;
+}
diff --git a/misc/dotfiles/templates/template.py b/misc/dotfiles/templates/template.py
new file mode 100644
index 0000000..e35598b
--- /dev/null
+++ b/misc/dotfiles/templates/template.py
@@ -0,0 +1,10 @@
+#! /usr/bin/env python3
+# -*- coding: utf-8 -*
+
+
+def main():
+ pass
+
+
+if __name__ == "__main__":
+ main()
diff --git a/misc/dotfiles/vimrc b/misc/dotfiles/vimrc
new file mode 100644
index 0000000..9e3afc2
--- /dev/null
+++ b/misc/dotfiles/vimrc
@@ -0,0 +1,25 @@
+" Enable ruler (will display line number and column number by default).
+set ruler
+
+" Enable syntax highlight.
+syntax on
+
+" Expand tabs to spaces.
+set expandtab
+
+" Use four-space indentation.
+set tabstop=4
+set softtabstop=4
+set shiftwidth=4
+
+" Limit text width.
+set textwidth=79
+
+" Disable incremental search.
+set noincsearch
+
+" Disable highlighting of the search results.
+set nohlsearch
+
+" Disable incremental search.
+set noincsearch
diff --git a/roles/dotfiles/defaults/main.yml b/roles/dotfiles/defaults/main.yml
new file mode 100644
index 0000000..27bf5a5
--- /dev/null
+++ b/roles/dotfiles/defaults/main.yml
@@ -0,0 +1,2 @@
+user: d
+jumphost: false
diff --git a/roles/dotfiles/tasks/main.yml b/roles/dotfiles/tasks/main.yml
new file mode 100644
index 0000000..85879a2
--- /dev/null
+++ b/roles/dotfiles/tasks/main.yml
@@ -0,0 +1,163 @@
+# This role is a little bit different from others, because it is supposed to
+# run mostly from localhost to make and copy dotfiles that might be useful on
+# this particular machine. There is maybe not enough permissions to install
+# software, so we are taking unusual approach here: check if software is
+# installed and then bring relevant dotfiles for it.
+
+- name: Configure bash if installed
+ block:
+ - name: Check if bash is installed
+ ansible.builtin.command: bash --version
+ changed_when: false
+ failed_when: false
+ register: has_bash
+
+ - name: Copy bash_profile to home directory
+ ansible.builtin.copy:
+ src: misc/dotfiles/bash_profile
+ dest: "~{{ user }}/.bash_profile"
+ when: has_bash.rc == 0
+
+ - name: Template bashrc to home directory
+ ansible.builtin.template:
+ src: misc/dotfiles/bashrc.j2
+ dest: "~{{ user }}/.bashrc"
+ when: has_bash.rc == 0
+
+- name: Configure vim if installed
+ block:
+ - name: Check if vim is installed
+ ansible.builtin.command: vim --version
+ changed_when: false
+ failed_when: false
+ register: has_vim
+
+ - name: Copy vimrc to home directory
+ ansible.builtin.copy:
+ src: misc/dotfiles/vimrc
+ dest: "~{{ user }}/.vimrc"
+ when: has_vim.rc == 0
+
+- name: Configure screen if installed
+ block:
+ - name: Check if screen is installed
+ ansible.builtin.command: screen --version
+ changed_when: false
+ failed_when: false
+ register: has_screen
+
+ - name: Template screenrc to home directory
+ ansible.builtin.template:
+ src: misc/dotfiles/screenrc.j2
+ dest: "~{{ user }}/.screenrc"
+ # For some reason screen's exit status is 1 for --version.
+ when: has_screen.rc == 1
+
+- name: Configure ssh if installed
+ block:
+ - name: Check if ssh is installed
+ ansible.builtin.command: ssh -V
+ changed_when: false
+ failed_when: false
+ register: has_ssh
+
+ - name: Setup ssh directory
+ ansible.builtin.file:
+ path: "~{{ user }}/.ssh"
+ state: directory
+ owner: "{{ user }}"
+ mode: u+rw,g-rw,o-rw
+ when: has_ssh.rc == 0
+
+ - name: Template ssh config to home directory
+ ansible.builtin.template:
+ src: misc/dotfiles/ssh/config.j2
+ dest: "~{{ user }}/.ssh/config"
+ owner: "{{ user }}"
+ mode: u+rw,g-rw,o-rw
+ when: has_ssh.rc == 0
+
+ - name: Copy ssh rc to home directory
+ ansible.builtin.copy:
+ src: misc/dotfiles/ssh/rc
+ dest: "~{{ user }}/.ssh/rc"
+ owner: "{{ user }}"
+ mode: u+rwx,g-rw,o-rw
+ when:
+ - has_ssh.rc == 0
+ - jumphost
+
+- name: Configure git if installed
+ block:
+ - name: Check if git is installed
+ ansible.builtin.command: git --version
+ changed_when: false
+ failed_when: false
+ register: has_git
+
+ - name: Copy gitconfig to home directory
+ ansible.builtin.copy:
+ src: misc/dotfiles/gitconfig
+ dest: "~{{ user }}/.gitconfig"
+ when: has_git.rc == 0
+
+- name: Configure gdb if installed
+ block:
+ - name: Check if gdb is installed
+ ansible.builtin.command: gdb --version
+ changed_when: false
+ failed_when: false
+ register: has_gdb
+
+ - name: Copy gdbinit to home directory
+ ansible.builtin.copy:
+ src: misc/dotfiles/gdbinit
+ dest: "~{{ user }}/.gdbinit"
+ when: has_gdb.rc == 0
+
+- name: Configure mutt if installed
+ block:
+ - name: Check if mutt is installed
+ ansible.builtin.command: mutt -v
+ changed_when: false
+ failed_when: false
+ register: has_mutt
+
+ - name: Copy muttrc to home directory
+ ansible.builtin.copy:
+ src: misc/dotfiles/muttrc
+ dest: "~{{ user }}/.muttrc"
+ when: has_mutt.rc == 0
+
+- name: Copy templates files if necessary
+ block:
+ - name: Check if C++ compiler is installed
+ ansible.builtin.command: c++ --version
+ changed_when: false
+ failed_when: false
+ register: has_cpp
+
+ - name: Check if Python is installed
+ ansible.builtin.command: python --version
+ changed_when: false
+ failed_when: false
+ register: has_python
+
+ - name: Setup templates directory
+ ansible.builtin.file:
+ path: "~{{ user }}/.templates"
+ state: directory
+ owner: "{{ user }}"
+ when: has_cpp.rc == 0 or has_python.rc == 0
+
+ - name: Copy template.cpp to home directory
+ ansible.builtin.copy:
+ src: misc/dotfiles/templates/template.cpp
+ dest: "~{{ user }}/.templates/template.cpp"
+ when: has_cpp.rc == 0
+
+ - name: Copy template.py to home directory
+ ansible.builtin.copy:
+ src: misc/dotfiles/templates/template.py
+ dest: "~{{ user }}/.templates/template.py"
+ when: has_python.rc == 0