From 57fa030b8f20ca0c267864811611c904b2eef873 Mon Sep 17 00:00:00 2001 From: Anthony Perkins Date: Thu, 3 Oct 2019 11:50:19 +0100 Subject: [PATCH] Move from dotfiles to roles-based playbooks --- main.yml | 8 ++ roles/distro/tasks/debian.yml | 42 ++++++ roles/distro/tasks/main.yml | 4 + roles/distro/tasks/modules.yml | 13 ++ roles/home/files/Xresources | 67 +++++++++ roles/home/files/bash_profile | 4 + roles/home/files/bashrc | 4 + roles/home/files/fonts.conf | 50 +++++++ roles/home/files/gitconfig | 26 ++++ roles/home/files/hushlogin | 0 roles/home/files/inputrc | 1 + roles/home/files/mate-acp.layout | 69 ++++++++++ roles/home/files/profile | 16 +++ roles/home/files/shrc | 228 +++++++++++++++++++++++++++++++ roles/home/files/tmux.conf | 12 ++ roles/home/files/zshrc | 3 + roles/home/tasks/emacs.yml | 38 ++++++ roles/home/tasks/main.yml | 6 + roles/home/tasks/mate.yml | 6 + roles/home/tasks/repos.yml | 5 + roles/home/tasks/shell.yml | 21 +++ roles/home/tasks/vim.yml | 25 ++++ 22 files changed, 648 insertions(+) create mode 100644 main.yml create mode 100644 roles/distro/tasks/debian.yml create mode 100644 roles/distro/tasks/main.yml create mode 100644 roles/distro/tasks/modules.yml create mode 100644 roles/home/files/Xresources create mode 100644 roles/home/files/bash_profile create mode 100644 roles/home/files/bashrc create mode 100644 roles/home/files/fonts.conf create mode 100644 roles/home/files/gitconfig create mode 100644 roles/home/files/hushlogin create mode 100644 roles/home/files/inputrc create mode 100644 roles/home/files/mate-acp.layout create mode 100644 roles/home/files/profile create mode 100644 roles/home/files/shrc create mode 100644 roles/home/files/tmux.conf create mode 100644 roles/home/files/zshrc create mode 100644 roles/home/tasks/emacs.yml create mode 100644 roles/home/tasks/main.yml create mode 100644 roles/home/tasks/mate.yml create mode 100644 roles/home/tasks/repos.yml create mode 100644 roles/home/tasks/shell.yml create mode 100644 roles/home/tasks/vim.yml diff --git a/main.yml b/main.yml new file mode 100644 index 0000000..f019649 --- /dev/null +++ b/main.yml @@ -0,0 +1,8 @@ +--- +- name: Setup + hosts: localhost + tasks: + - include_role: + name: distro + - include_role: + name: home diff --git a/roles/distro/tasks/debian.yml b/roles/distro/tasks/debian.yml new file mode 100644 index 0000000..51aeb65 --- /dev/null +++ b/roles/distro/tasks/debian.yml @@ -0,0 +1,42 @@ +--- +- name: Install packages + become: true + apt: + name: '{{ packages }}' + state: present + force_apt_get: yes + vars: + packages: + - apt-file + - asciidoctor + - caja-open-terminal + - dc + - desktop-base + - dnsutils + - emacs + - evolution + - galculator + - git + - git-gui + - mc + - mpv + - nextcloud-desktop + - nmap + - packagekit + - python3 + - realmd + - redshift-gtk + - remmina + - rxvt-unicode + - seahorse + - sqlite3 + - sssd + - sudo + - task-british-desktop + - task-mate-desktop + - tlp + - tmux + - vim-gtk + - xinput + - xterm + - zsh diff --git a/roles/distro/tasks/main.yml b/roles/distro/tasks/main.yml new file mode 100644 index 0000000..83f12a2 --- /dev/null +++ b/roles/distro/tasks/main.yml @@ -0,0 +1,4 @@ +--- +- include: debian.yml + when: ansible_distribution == 'Debian' +- include: modules.yml diff --git a/roles/distro/tasks/modules.yml b/roles/distro/tasks/modules.yml new file mode 100644 index 0000000..c3e93e4 --- /dev/null +++ b/roles/distro/tasks/modules.yml @@ -0,0 +1,13 @@ +--- +- name: Blacklist pcspkr module + become: true + lineinfile: + path: /etc/modprobe.d/blacklist.conf + line: blacklist pcspkr + create: yes +- name: Blacklist dvb_usb_rtl28xxu module + become: true + lineinfile: + path: /etc/modprobe.d/blacklist.conf + line: blacklist dvb_usb_rtl28xxu + create: yes diff --git a/roles/home/files/Xresources b/roles/home/files/Xresources new file mode 100644 index 0000000..c11ded2 --- /dev/null +++ b/roles/home/files/Xresources @@ -0,0 +1,67 @@ +*color: true +URxvt*background: #111111 +URxvt*color0: #1e1e1e +URxvt*color1: #cc0000 +URxvt*color2: #4e9a06 +URxvt*color3: #c4a000 +URxvt*color4: #3465a4 +URxvt*color5: #75507b +URxvt*color6: #0b939b +URxvt*color7: #d3d7cf +URxvt*color8: #555753 +URxvt*color9: #ef2929 +URxvt*color10: #8ae234 +URxvt*color11: #fce94f +URxvt*color12: #729fcf +URxvt*color13: #ad7fa8 +URxvt*color14: #00f5e9 +URxvt*color15: #eeeeec +URxvt*font: xft:Monospace:Regular:size=10 +URxvt*foreground: #c0c0c0 +URxvt*letterSpace: -1 +URxvt*locale: true +URxvt*metaSendsEscape: true +URxvt*perl-ext: -searchable-scrollback +URxvt*scrollBar_right: true +URxvt*termName: rxvt-unicode +XClock*hourColor: black +XClock*majorColor: red +XClock*minorColor: black +XClock*minuteColor: black +XClock*render: true +XClock*secondColor: red +XClock*update: 1 +Xft.hintstyle: hintfull +Xft.rgba: none +xterm*background: #111111 +xterm*color0: #1e1e1e +xterm*color1: #cc0000 +xterm*color2: #4e9a06 +xterm*color3: #c4a000 +xterm*color4: #3465a4 +xterm*color5: #75507b +xterm*color6: #0b939b +xterm*color7: #d3d7cf +xterm*color8: #555753 +xterm*color9: #ef2929 +xterm*color10: #8ae234 +xterm*color11: #fce94f +xterm*color12: #729fcf +xterm*color13: #ad7fa8 +xterm*color14: #00f5e9 +xterm*color15: #eeeeec +xterm*faceName: xft:Monospace:Regular:size=10 +xterm*faceSize1: 4 +xterm*faceSize2: 6 +xterm*faceSize3: 8 +xterm*faceSize4: 12 +xterm*faceSize5: 14 +xterm*faceSize6: 16 +xterm*faceSize: 9 +xterm*foreground: #c0c0c0 +xterm*locale: true +xterm*metaSendsEscape: true +xterm*scrollBar: true +xterm*utf8: always +xterm*utf8Fonts: always +xterm*utf8Title: true diff --git a/roles/home/files/bash_profile b/roles/home/files/bash_profile new file mode 100644 index 0000000..c71bf23 --- /dev/null +++ b/roles/home/files/bash_profile @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +if [ -r $HOME/.profile ]; then + . $HOME/.profile +fi diff --git a/roles/home/files/bashrc b/roles/home/files/bashrc new file mode 100644 index 0000000..605d5f4 --- /dev/null +++ b/roles/home/files/bashrc @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +if [ -r $HOME/.shrc ]; then + . $HOME/.shrc +fi diff --git a/roles/home/files/fonts.conf b/roles/home/files/fonts.conf new file mode 100644 index 0000000..f01857c --- /dev/null +++ b/roles/home/files/fonts.conf @@ -0,0 +1,50 @@ + + + + + + + + rgb + + + true + + + hintslight + + + true + + + lcddefault + + + + + + + Times + + + Liberation Serif + + + + + Helvetica + + + Liberation Sans + + + + + Courier + + + Liberation Mono + + + + diff --git a/roles/home/files/gitconfig b/roles/home/files/gitconfig new file mode 100644 index 0000000..98743d5 --- /dev/null +++ b/roles/home/files/gitconfig @@ -0,0 +1,26 @@ +[pull] + rebase = true +[push] + default = simple +[color] + ui = auto +[credential] + helper = store +[alias] + ci = commit + co = checkout + ff = merge --ff-only + graph = log --graph --oneline --all + l1 = log --pretty=oneline + last = log -1 HEAD --pretty=fuller + unstage = reset HEAD -- + up = pull --rebase +[gui] + encoding = utf-8 + recentrepo = /home/acp/data/he + +[guitool "Rebase"] + cmd = rebase +[user] + name = Anthony Perkins + email = anthony@acperkins.com diff --git a/roles/home/files/hushlogin b/roles/home/files/hushlogin new file mode 100644 index 0000000..e69de29 diff --git a/roles/home/files/inputrc b/roles/home/files/inputrc new file mode 100644 index 0000000..ac81a39 --- /dev/null +++ b/roles/home/files/inputrc @@ -0,0 +1 @@ +set bell-style none diff --git a/roles/home/files/mate-acp.layout b/roles/home/files/mate-acp.layout new file mode 100644 index 0000000..5c6970d --- /dev/null +++ b/roles/home/files/mate-acp.layout @@ -0,0 +1,69 @@ +[Toplevel top] +expand=true +orientation=top +size=32 + +[Object menu] +object-type=menu +toplevel-id=top +position=0 +locked=true + +[Object terminal] +object-type=launcher +launcher-location=/usr/share/applications/mate-terminal.desktop +toplevel-id=top +position=10 +locked=true + +[Object file-browser] +object-type=launcher +launcher-location=/usr/share/applications/caja-browser.desktop +toplevel-id=top +position=20 +locked=true + +[Object text-editor] +object-type=launcher +launcher-location=/usr/share/applications/gvim.desktop +toplevel-id=top +position=30 +locked=true + +[Object web-browser] +object-type=launcher +launcher-location=/usr/share/applications/firefox-esr.desktop +toplevel-id=top +position=40 +locked=true + +[Object window-list] +object-type=applet +applet-iid=WnckletFactory::WindowListApplet +toplevel-id=top +position=50 +locked=true + +[Object workspace-switcher] +object-type=applet +applet-iid=WnckletFactory::WorkspaceSwitcherApplet +toplevel-id=top +position=20 +panel-right-stick=true +locked=true + +[Object notification-area] +object-type=applet +applet-iid=NotificationAreaAppletFactory::NotificationArea +toplevel-id=top +position=10 +panel-right-stick=true +locked=true + +[Object clock] +object-type=applet +applet-iid=ClockAppletFactory::ClockApplet +toplevel-id=top +position=0 +panel-right-stick=true +locked=true diff --git a/roles/home/files/profile b/roles/home/files/profile new file mode 100644 index 0000000..c0487ca --- /dev/null +++ b/roles/home/files/profile @@ -0,0 +1,16 @@ +#!/bin/sh + +if [ -r /etc/profile ]; then + . /etc/profile +fi + +export BASH_ENV="$HOME/.bashrc" +export BLOCKSIZE="K" +export EDITOR="vi" +export ENV="$HOME/.shrc" +export LANG="en_GB.UTF-8" +export PAGER="less" + +if [ -r $HOME/.profile.$(hostname -s) ]; then + . $HOME/.profile.$(hostname -s) +fi diff --git a/roles/home/files/shrc b/roles/home/files/shrc new file mode 100644 index 0000000..57fca6d --- /dev/null +++ b/roles/home/files/shrc @@ -0,0 +1,228 @@ +#!/bin/sh + +umask 0022 + +set -o emacs +set -o noclobber + +# Locale and language. +export LC_ALL= +export LANG="en_GB.UTF-8" +export LANGUAGE="en_GB:en" +export LC_ADDRESS="en_GB.UTF-8" +export LC_COLLATE="en_GB.UTF-8" +export LC_CTYPE="en_GB.UTF-8" +export LC_IDENTIFICATION="en_GB.UTF-8" +export LC_MEASUREMENT="en_GB.UTF-8" +export LC_MESSAGES="en_GB.UTF-8" +export LC_MONETARY="en_GB.UTF-8" +export LC_NAME="en_GB.UTF-8" +export LC_NUMERIC="en_GB.UTF-8" +export LC_PAPER="en_GB.UTF-8" +export LC_TELEPHONE="en_GB.UTF-8" +export LC_TIME="en_GB.UTF-8" +export PAPERSIZE="a4" +export TIME_STYLE="long-iso" + +# Other exports. +export EDITOR=vi +export PYTHONWARNINGS="ignore::UserWarning" + +if [ "$SHELL" = "/bin/sh" ]; then + export PS1='\$ ' +else + export PS1='${SSH_TTY:+[$(id -un)@$(hostname -s)]}\$ ' +fi + +if [ "$BASH" ]; then + shopt -s histappend + bind '"\e[1;5C": forward-word' + bind '"\e[1;5D": backward-word' + bind '"\e[A": history-search-backward' + bind '"\e[B": history-search-forward' +fi + +if [ "$ZSH_VERSION" ]; then + # Command history. + autoload -U history-search-end + zle -N history-beginning-search-backward-end history-search-end + zle -N history-beginning-search-forward-end history-search-end + bindkey "^[[A" history-beginning-search-backward-end + bindkey "^[[B" history-beginning-search-forward-end + bindkey "^[OA" history-beginning-search-backward-end + bindkey "^[OB" history-beginning-search-forward-end + + bindkey "^[[1;5C" forward-word # Ctrl-Right + bindkey "^[[1;5D" backward-word # Ctrl-Left + bindkey "^[[3;5~" delete-char # Ctrl-Del + bindkey "^[[3~" delete-char # Del + export HISTFILE=$HOME/.zsh_history + export HISTSIZE=1000000 + export SAVEHIST=1000000 + setopt EXTENDED_HISTORY + setopt HIST_IGNORE_ALL_DUPS + setopt HIST_IGNORE_SPACE + setopt PROMPT_SUBST + setopt SHARE_HISTORY +fi + +LSOPTIONS="-F" +if ls --color=auto /dev/null 2>/dev/null 1>/dev/null; then + LSOPTIONS="$LSOPTIONS --color=auto" +fi +if [ "$(uname -s)" = "FreeBSD" ]; then + LSOPTIONS="$LSOPTIONS -G" +fi + +alias adoc="asciidoctor -a stylesheet=$HOME/.asciidoctor.css" +alias cal="ncal -w" +alias df="df -x squashfs" +alias ec="emacsclient -c" +alias en="emacsclient -nw" +alias f="fossil" +alias ll="/bin/ls -l" +alias ls="/bin/ls $LSOPTIONS" +alias now="date +%Y%m%dT%H%M%S%z" +alias nowu="date -u +%Y%m%dT%H%M%SZ" +alias ta="$HOME/opt/textadept/textadept" +alias tm="tmux -2 attach-session || tmux -2 new-session" +alias wg="wordgrinder" +alias ytmp3="youtube-dl -q -x --audio-format=mp3" + +if [ ! -d "$HOME/.local/bin" ]; then + /bin/mkdir -p "$HOME/.local/bin" +fi + +# Alias vi to vim if it is installed +if [ -x /usr/bin/vim ] || [ -x /usr/local/bin/vim ]; then + alias vi="vim" +fi + +# Set up GOPATH +export GOPATH="$HOME/data/go" +if [ -x /usr/bin/go ] || [ -x /usr/local/bin/go ]; then + if [ ! -d "$GOPATH" ]; then + /bin/mkdir -p "$GOPATH/bin" + /bin/mkdir -p "$GOPATH/pkg" + /bin/mkdir -p "$GOPATH/src" + fi +fi + +# Useful aliases for Podman and Docker +alias prun="podman run --rm -it" +alias prunx="podman run -v /tmp/.X11-unix:/tmp/.X11-unix:ro -e DISPLAY=\"unix\$DISPLAY\"" +alias drun="sudo docker run --rm -it" +alias drunx="sudo docker run -v /tmp/.X11-unix:/tmp/.X11-unix:ro -e DISPLAY=\"unix\$DISPLAY\"" + +PATH="/usr/bin:/bin" +for dir in $HOME/.local/bin \ + $HOME/bin \ + /app/bin \ + /snap/bin \ + /sbin \ + /usr/sbin \ + /usr/X11R6/bin \ + /usr/X11R7/bin \ + /usr/local/bin \ + /usr/local/sbin \ + /usr/pkg/bin \ + /usr/pkg/sbin \ + /usr/games \ + /usr/local/heirloom-doctools/bin \ + /var/lib/snapd/snap/bin \ + $GOPATH/bin \ + $HOME/.cargo/bin \ + ; do + if [ -d "$dir" ]; then + PATH="$PATH:$dir" + fi +done +export PATH + +MANPATH="/usr/share/man" +for dir in $HOME/.local/share/man \ + /usr/X11R6/man \ + /usr/X11R7/man \ + /usr/local/man \ + /usr/pkg/man \ + /usr/local/share/man \ + /usr/local/heirloom-doctools/man \ + ; do + if [ -d "$dir" ]; then + MANPATH="$MANPATH:$dir" + fi +done +export MANPATH + +mkcd () { + if [ $# -ne 1 ]; then + echo "mkcd: incorrect arguments (one directory required)." >&2 + return 1 + else + mkdir -p "$1" + cd "$1" + fi +} + +termtitle () { + echo -en "\033]0;$1\007" +} + +linapm () { + cat /sys/class/power_supply/BAT0/{status,capacity} +} + +cman () { + # md: start bold + # us: start underline + # ue: end underline + # me: end bold, blink, and underline + env MANPAGER=less \ + LESS_TERMCAP_md=$'\e[1;36m' \ + LESS_TERMCAP_me=$'\e[0m' \ + LESS_TERMCAP_us=$'\e[4;32m' \ + LESS_TERMCAP_ue=$'\e[0m' \ + /usr/bin/man "$1" +} + +xa () { + OUT=$(xrandr --listactivemonitors | awk 'NR!=1{print " "$NF" "}') + for monitor in "${OUT}"; do + m=$(echo $monitor | sed 's/ //g') + xrandr --output $m --auto + done +} + +if [ -x /usr/bin/yum ] && [ ! -x /usr/bin/dnf ]; then + alias dnf='yum' +fi + +if [ -x /usr/bin/svnlite ] && [ ! -x /usr/local/bin/svn ]; then + alias svn='svnlite' + alias svnadmin='svnliteadmin' + alias svndumpfilter='svnlitedumpfilter' + alias svnlook='svnlitelook' + alias svnmucc='svnlitemucc' + alias svnrdump='svnliterdump' + alias svnserve='svnliteserve' + alias svnsync='svnlitesync' + alias svnversion='svnliteversion' +fi + +case $- in + *i*) + # Shell is interactive + printf "\033[7m" + uname -sr + printf "\033[0m" + if [ -r /etc/os-release ]; then + echo " $(. /etc/os-release; echo $PRETTY_NAME)" + fi + ;; + *) + ;; +esac + +if [ -r $HOME/.shrc.$(hostname -s) ]; then + . $HOME/.shrc.$(hostname -s) +fi diff --git a/roles/home/files/tmux.conf b/roles/home/files/tmux.conf new file mode 100644 index 0000000..81626a3 --- /dev/null +++ b/roles/home/files/tmux.conf @@ -0,0 +1,12 @@ +bind-key C command-prompt -p "Execute:" "new-window '%1'" +bind-key M-'"' command-prompt -p "Execute:" "split-window '%1'" +bind-key M-% command-prompt -p "Execute:" "split-window -h '%1'" +bind-key R source-file "${HOME}/.tmux.conf" +bind-key S command-prompt -p "Move to:" "swap-pane -s. -t%1 \; select-pane -t%1" +set -g base-index 1 +set -g default-command "$SHELL" +set -g default-terminal "screen-256color" +set -g display-panes-time 5000 +set -g pane-base-index 1 +set -g status-right '' +set-window-option -g xterm-keys on diff --git a/roles/home/files/zshrc b/roles/home/files/zshrc new file mode 100644 index 0000000..6157cec --- /dev/null +++ b/roles/home/files/zshrc @@ -0,0 +1,3 @@ +if [ -r $HOME/.shrc ]; then + . $HOME/.shrc +fi diff --git a/roles/home/tasks/emacs.yml b/roles/home/tasks/emacs.yml new file mode 100644 index 0000000..8a1ef74 --- /dev/null +++ b/roles/home/tasks/emacs.yml @@ -0,0 +1,38 @@ +--- +- name: Clone emacs settings + git: + repo: https://git.acperkins.com/acp/emacs.d.git + dest: "{{ ansible_env.HOME }}/.emacs.d" +- name: Find emacs service definition + find: + paths: /usr/share/emacs + patterns: 'emacs.service' + recurse: yes + depth: 3 + register: emacs_service_files +- name: Create systemd user directory + file: + path: "{{ ansible_env.HOME }}/.config/systemd/user" + state: directory +- name: Create emacs user service + copy: + src: '{{ item.path }}' + dest: "{{ ansible_env.HOME }}/.config/systemd/user/emacs.service" + remote_src: yes + loop: '{{ emacs_service_files.files }}' +- name: Start emacs user service + systemd: + name: emacs.service + scope: user + daemon_reload: yes + enabled: yes + state: started +- name: Create user applications directory + file: + path: "{{ ansible_env.HOME }}/.local/share/applications" + state: directory +- name: Create emacs client launcher + copy: + src: "{{ ansible_env.HOME }}/.emacs.d/emacs-client.desktop" + dest: "{{ ansible_env.HOME }}/.local/share/applications/emacs-client.desktop" + remote_src: yes diff --git a/roles/home/tasks/main.yml b/roles/home/tasks/main.yml new file mode 100644 index 0000000..88ef387 --- /dev/null +++ b/roles/home/tasks/main.yml @@ -0,0 +1,6 @@ +--- +- include: repos.yml +- include: vim.yml +- include: shell.yml +- include: emacs.yml +- include: mate.yml diff --git a/roles/home/tasks/mate.yml b/roles/home/tasks/mate.yml new file mode 100644 index 0000000..3b431b3 --- /dev/null +++ b/roles/home/tasks/mate.yml @@ -0,0 +1,6 @@ +--- +- name: Copy MATE panel layout + become: true + copy: + src: mate-acp.layout + dest: /usr/share/mate-panel/layouts/acp.layout diff --git a/roles/home/tasks/repos.yml b/roles/home/tasks/repos.yml new file mode 100644 index 0000000..8cda961 --- /dev/null +++ b/roles/home/tasks/repos.yml @@ -0,0 +1,5 @@ +--- +- name: Clone vim settings + git: + repo: https://git.acperkins.com/acp/vimfiles.git + dest: "{{ ansible_env.HOME }}/.vim" diff --git a/roles/home/tasks/shell.yml b/roles/home/tasks/shell.yml new file mode 100644 index 0000000..83ed8f0 --- /dev/null +++ b/roles/home/tasks/shell.yml @@ -0,0 +1,21 @@ +--- +- name: Copy .bashrc + copy: + src: bashrc + dest: "{{ ansible_env.HOME }}/.bashrc" +- name: Copy .bash_profile + copy: + src: bash_profile + dest: "{{ ansible_env.HOME }}/.bash_profile" +- name: Copy .profile + copy: + src: profile + dest: "{{ ansible_env.HOME }}/.profile" +- name: Copy .shrc + copy: + src: shrc + dest: "{{ ansible_env.HOME }}/.shrc" +- name: Copy .zshrc + copy: + src: zshrc + dest: "{{ ansible_env.HOME }}/.zshrc" diff --git a/roles/home/tasks/vim.yml b/roles/home/tasks/vim.yml new file mode 100644 index 0000000..a476dc4 --- /dev/null +++ b/roles/home/tasks/vim.yml @@ -0,0 +1,25 @@ +--- +- name: Copy .Xresources + copy: + src: Xresources + dest: "{{ ansible_env.HOME }}/.Xresources" +- name: Copy .fonts.conf + copy: + src: fonts.conf + dest: "{{ ansible_env.HOME }}/.fonts.conf" +- name: Copy .gitconfig + copy: + src: gitconfig + dest: "{{ ansible_env.HOME }}/.gitconfig" +- name: Copy .inputrc + copy: + src: inputrc + dest: "{{ ansible_env.HOME }}/.inputrc" +- name: Copy .tmux.conf + copy: + src: tmux.conf + dest: "{{ ansible_env.HOME }}/.tmux.conf" +- name: Copy .hushlogin + copy: + src: hushlogin + dest: "{{ ansible_env.HOME }}/.hushlogin"