refactor: migrate to role-based variable management and blockinfile config
This commit is contained in:
11
bootstrap.sh
11
bootstrap.sh
@@ -1,6 +1,9 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
|
ARCHSETUP_REPO="${ARCHSETUP_REPO:-https://github.com/YOUR_USERNAME/archsetup}"
|
||||||
|
ARCHSETUP_DIR="${ARCHSETUP_DIR:-$HOME/archsetup}"
|
||||||
|
|
||||||
echo "=== Arch Linux Hyprland Setup Bootstrap ==="
|
echo "=== Arch Linux Hyprland Setup Bootstrap ==="
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
@@ -25,18 +28,18 @@ sudo pacman -Sy --noconfirm git ansible
|
|||||||
|
|
||||||
# Step 3: Clone or update the repo
|
# Step 3: Clone or update the repo
|
||||||
echo "[3/4] Setting up archsetup..."
|
echo "[3/4] Setting up archsetup..."
|
||||||
if [ -d "$HOME/archsetup/.git" ]; then
|
if [ -d "$ARCHSETUP_DIR/.git" ]; then
|
||||||
echo "Updating archsetup..."
|
echo "Updating archsetup..."
|
||||||
cd "$HOME/archsetup"
|
cd "$ARCHSETUP_DIR"
|
||||||
git pull
|
git pull
|
||||||
else
|
else
|
||||||
echo "Cloning archsetup..."
|
echo "Cloning archsetup..."
|
||||||
git clone https://github.com/YOUR_USERNAME/archsetup.git "$HOME/archsetup"
|
git clone "$ARCHSETUP_REPO" "$ARCHSETUP_DIR"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Step 4: Run the playbook
|
# Step 4: Run the playbook
|
||||||
echo "[4/4] Running Ansible playbook..."
|
echo "[4/4] Running Ansible playbook..."
|
||||||
cd "$HOME/archsetup"
|
cd "$ARCHSETUP_DIR"
|
||||||
ansible-playbook site.yml
|
ansible-playbook site.yml
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
|
|||||||
@@ -1,24 +0,0 @@
|
|||||||
$formatters
|
|
||||||
format = """
|
|
||||||
[─](bold green)
|
|
||||||
[❯](bold green) """
|
|
||||||
add_newline = true
|
|
||||||
|
|
||||||
[character]
|
|
||||||
success_symbol = "[❯](bold green)"
|
|
||||||
error_symbol = "[❯](bold red)"
|
|
||||||
|
|
||||||
[directory]
|
|
||||||
home_symbol = "~"
|
|
||||||
truncation_length = 3
|
|
||||||
truncate_to_repo = true
|
|
||||||
|
|
||||||
[git]
|
|
||||||
branch_symbol = " "
|
|
||||||
stash_count_symbol = " "
|
|
||||||
format = "on [$symbol$branch]($style)$completions"
|
|
||||||
style = "bold purple"
|
|
||||||
|
|
||||||
[docker_context]
|
|
||||||
format = "via [$symbol$context]($style) "
|
|
||||||
style = "blue bold"
|
|
||||||
6
roles/common/defaults/main.yml
Normal file
6
roles/common/defaults/main.yml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
archsetup_user: "{{ ansible_user_id }}"
|
||||||
|
archsetup_repo: "{{ lookup('env', 'ARCHSETUP_REPO', default='https://github.com/YOUR_USERNAME/archsetup') }}"
|
||||||
|
archsetup_user_home: "{{ lookup('env', 'HOME') }}"
|
||||||
|
archsetup_dir: "{{ archsetup_user_home }}/archsetup"
|
||||||
|
aur_helper: paru
|
||||||
3
roles/common/handlers/main.yml
Normal file
3
roles/common/handlers/main.yml
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
- name: Update font cache
|
||||||
|
become: true
|
||||||
|
command: fc-cache -fv
|
||||||
@@ -1,4 +1,21 @@
|
|||||||
# tasks file for common
|
# tasks file for common
|
||||||
|
- name: Check for legacy zshrc content
|
||||||
|
shell: |
|
||||||
|
if grep -q "^# ~/.zshrc" "{{ archsetup_user_home }}/.zshrc" 2>/dev/null; then
|
||||||
|
echo "1"
|
||||||
|
else
|
||||||
|
echo "0"
|
||||||
|
fi
|
||||||
|
register: legacy_check
|
||||||
|
changed_when: false
|
||||||
|
|
||||||
|
- name: Clean legacy zshrc content
|
||||||
|
replace:
|
||||||
|
path: "{{ archsetup_user_home }}/.zshrc"
|
||||||
|
regexp: '^# ~/.zshrc.*\n'
|
||||||
|
replace: ''
|
||||||
|
when: legacy_check.stdout | int > 0
|
||||||
|
|
||||||
- name: Install base development tools
|
- name: Install base development tools
|
||||||
become: true
|
become: true
|
||||||
pacman:
|
pacman:
|
||||||
@@ -57,7 +74,7 @@
|
|||||||
- name: Ensure ttf-joypixels is installed from AUR
|
- name: Ensure ttf-joypixels is installed from AUR
|
||||||
kewlfft.aur.aur:
|
kewlfft.aur.aur:
|
||||||
name: ttf-joypixels
|
name: ttf-joypixels
|
||||||
use: paru
|
use: "{{ aur_helper | default('paru') }}"
|
||||||
state: present
|
state: present
|
||||||
notify: Update font cache
|
notify: Update font cache
|
||||||
|
|
||||||
@@ -85,24 +102,22 @@
|
|||||||
become: true
|
become: true
|
||||||
getent:
|
getent:
|
||||||
database: passwd
|
database: passwd
|
||||||
key: "{{ user }}"
|
key: "{{ archsetup_user }}"
|
||||||
register: user_info
|
register: user_info
|
||||||
changed_when: false
|
changed_when: false
|
||||||
|
|
||||||
- name: Set zsh as default shell
|
- name: Set zsh as default shell
|
||||||
become: true
|
become: true
|
||||||
shell: chsh -s /bin/zsh {{ user }}
|
command: chsh -s /bin/zsh {{ archsetup_user }}
|
||||||
when: user_info.ansible_facts.getent_passwd[user][-1] != '/bin/zsh'
|
when: user_info.ansible_facts.getent_passwd[archsetup_user][-1] != '/bin/zsh'
|
||||||
|
|
||||||
- name: Setup shell profile configuration
|
- name: Setup shell profile configuration
|
||||||
blockinfile:
|
blockinfile:
|
||||||
path: "{{ lookup('env', 'HOME') }}/.profile"
|
path: "{{ archsetup_user_home }}/.profile"
|
||||||
marker: "# {mark} ANSIBLE MANAGED BLOCK"
|
marker: "# {mark} ANSIBLE MANAGED BLOCK"
|
||||||
create: yes
|
create: yes
|
||||||
mode: '0644'
|
mode: '0644'
|
||||||
content: |
|
block: |
|
||||||
# ~/.profile - POSIX compatible environment
|
|
||||||
|
|
||||||
# Rust and cargo binaries
|
# Rust and cargo binaries
|
||||||
export PATH="$HOME/.cargo/bin:$HOME/.local/bin:$PATH"
|
export PATH="$HOME/.cargo/bin:$HOME/.local/bin:$PATH"
|
||||||
|
|
||||||
@@ -113,26 +128,68 @@
|
|||||||
|
|
||||||
export EDITOR="emacs -nw"
|
export EDITOR="emacs -nw"
|
||||||
|
|
||||||
- name: Setup zprofile for Zsh compatibility
|
- name: Deploy zshrc base config
|
||||||
copy:
|
|
||||||
dest: "{{ lookup('env', 'HOME') }}/.zprofile"
|
|
||||||
content: |
|
|
||||||
# ~/.zprofile - Sourced by Zsh for login shells
|
|
||||||
# Source .profile for POSIX-compatible environment
|
|
||||||
emulate sh -c 'source ~/.profile'
|
|
||||||
|
|
||||||
# Initialize zoxide for smart cd
|
|
||||||
eval "$(zoxide init zsh)"
|
|
||||||
|
|
||||||
# Initialize atuin for shell history
|
|
||||||
eval "$(atuin init zsh)"
|
|
||||||
owner: "{{ lookup('env', 'USER') }}"
|
|
||||||
mode: '0644'
|
|
||||||
|
|
||||||
- name: Setup shell plugins in zshrc
|
|
||||||
blockinfile:
|
blockinfile:
|
||||||
path: "{{ lookup('env', 'HOME') }}/.zshrc"
|
path: "{{ archsetup_user_home }}/.zshrc"
|
||||||
marker: "# {mark} ANSIBLE MANAGED BLOCK"
|
marker: "# {mark} ANSIBLE MANAGED - BASE"
|
||||||
content: |
|
block: |
|
||||||
# Source .zprofile for login shell environment
|
# Source .zprofile for login shell environment
|
||||||
[[ -f ~/.zprofile ]] && emulate sh -c 'source ~/.zprofile'
|
[[ -f ~/.zprofile ]] && emulate sh -c 'source ~/.zprofile'
|
||||||
|
|
||||||
|
# Enable oh-my-zsh
|
||||||
|
export ZSH="$HOME/.oh-my-zsh"
|
||||||
|
ZSH_THEME="agnoster"
|
||||||
|
|
||||||
|
# Plugins
|
||||||
|
plugins=(
|
||||||
|
git
|
||||||
|
history
|
||||||
|
z
|
||||||
|
)
|
||||||
|
|
||||||
|
source $ZSH/oh-my-zsh.sh
|
||||||
|
|
||||||
|
# Initialize starship (must be after oh-my-zsh)
|
||||||
|
eval "$(starship init zsh)"
|
||||||
|
#
|
||||||
|
# Initialize zoxide (must be after oh-my-zsh)
|
||||||
|
eval "$(zoxide init zsh)"
|
||||||
|
|
||||||
|
# Initialize atuin (must be after oh-my-zsh)
|
||||||
|
eval "$(atuin init zsh)"
|
||||||
|
|
||||||
|
- name: Deploy zshrc history config
|
||||||
|
blockinfile:
|
||||||
|
path: "{{ archsetup_user_home }}/.zshrc"
|
||||||
|
marker: "# {mark} ANSIBLE MANAGED - HISTORY"
|
||||||
|
block: |
|
||||||
|
# History
|
||||||
|
export HISTSIZE=50000
|
||||||
|
export SAVEHIST=50000
|
||||||
|
export HISTTIMEFORMAT="[%F %T] "
|
||||||
|
|
||||||
|
setopt INC_APPEND_HISTORY
|
||||||
|
setopt EXTENDED_HISTORY
|
||||||
|
setopt HIST_EXPIRE_DUPS_FIRST
|
||||||
|
setopt HIST_IGNORE_DUPS
|
||||||
|
setopt HIST_IGNORE_ALL_DUPS
|
||||||
|
setopt HIST_FIND_NO_DUPS
|
||||||
|
setopt HIST_IGNORE_SPACE
|
||||||
|
setopt HIST_SAVE_NO_DUPS
|
||||||
|
setopt SHARE_HISTORY
|
||||||
|
|
||||||
|
- name: Deploy zshrc common aliases
|
||||||
|
blockinfile:
|
||||||
|
path: "{{ archsetup_user_home }}/.zshrc"
|
||||||
|
marker: "# {mark} ANSIBLE MANAGED - COMMON ALIASES"
|
||||||
|
block: |
|
||||||
|
# Common aliases
|
||||||
|
alias q="exit"
|
||||||
|
alias vim="nvim"
|
||||||
|
alias cat="bat"
|
||||||
|
alias ls="eza --icons"
|
||||||
|
alias ll="eza -l --icons"
|
||||||
|
alias la="eza -la --icons"
|
||||||
|
alias lt="eza --tree --level=2 --icons"
|
||||||
|
alias df="df -h"
|
||||||
|
alias wttr="curl wttr.in/Essen"
|
||||||
|
|||||||
@@ -38,16 +38,12 @@
|
|||||||
creates: ~/.emacs.d
|
creates: ~/.emacs.d
|
||||||
|
|
||||||
- name: Setup shell aliases
|
- name: Setup shell aliases
|
||||||
lineinfile:
|
blockinfile:
|
||||||
path: "{{ lookup('env', 'HOME') }}/.zshrc"
|
path: "{{ archsetup_user_home }}/.zshrc"
|
||||||
line: "{{ item }}"
|
marker: "# {mark} ANSIBLE MANAGED - CS STUDENT"
|
||||||
create: yes
|
block: |
|
||||||
loop:
|
# CS student aliases
|
||||||
- alias ls='eza --icons --group-directories-first'
|
alias find='fd'
|
||||||
- alias ll='eza -la --icons --group-directories-first'
|
alias top='btm'
|
||||||
- alias cat='bat --style=auto'
|
alias tre='broot --sizes'
|
||||||
- alias find='fd'
|
alias e='emacs -nw'
|
||||||
- alias top='btm'
|
|
||||||
- alias tre='broot --sizes'
|
|
||||||
- alias e='emacs -nw'
|
|
||||||
- alias vim='nvim'
|
|
||||||
|
|||||||
1
roles/devops/defaults/main.yml
Normal file
1
roles/devops/defaults/main.yml
Normal file
@@ -0,0 +1 @@
|
|||||||
|
---
|
||||||
@@ -13,12 +13,12 @@
|
|||||||
- kubectx
|
- kubectx
|
||||||
state: present
|
state: present
|
||||||
|
|
||||||
- name: Setup shell aliases
|
- name: Deploy DevOps aliases
|
||||||
lineinfile:
|
blockinfile:
|
||||||
path: "{{ lookup('env', 'HOME') }}/.zshrc"
|
path: "{{ archsetup_user_home }}/.zshrc"
|
||||||
line: "{{ item }}"
|
marker: "# {mark} ANSIBLE MANAGED DEVOPS"
|
||||||
create: yes
|
block: |
|
||||||
loop:
|
# DevOps aliases
|
||||||
- alias kc='kubectl'
|
alias kc="kubectl"
|
||||||
- alias kctx='kubectx'
|
alias kctx="kubectx"
|
||||||
- alias kns='kubens'
|
alias kns="kubens"
|
||||||
|
|||||||
4
roles/dotfiles/defaults/main.yml
Normal file
4
roles/dotfiles/defaults/main.yml
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
---
|
||||||
|
dotfiles_stow_packages:
|
||||||
|
- hypr
|
||||||
|
- zellij
|
||||||
@@ -7,17 +7,15 @@
|
|||||||
state: present
|
state: present
|
||||||
|
|
||||||
- name: Remove existing config files before stowing
|
- name: Remove existing config files before stowing
|
||||||
shell: |
|
file:
|
||||||
[ -L ~/.config/hypr/hyprland.conf ] || rm -f ~/.config/hypr/hyprland.conf
|
path: "{{ archsetup_user_home }}/.config/{{ item }}"
|
||||||
[ -L ~/.config/starship ] || rm -rf ~/.config/starship
|
state: absent
|
||||||
[ -L ~/.config/zellij ] || rm -rf ~/.config/zellij
|
loop:
|
||||||
changed_when: false
|
- hypr
|
||||||
|
- zellij
|
||||||
|
|
||||||
- name: Create symlinks with stow
|
- name: Create symlinks with stow
|
||||||
shell: |
|
command: stow --target={{ archsetup_user_home }} {{ dotfiles_stow_packages | join(' ') }}
|
||||||
cd {{ lookup('env', 'HOME') }}/archsetup/dotfiles
|
|
||||||
stow -t ~ hypr starship zellij
|
|
||||||
args:
|
args:
|
||||||
executable: /bin/bash
|
creates: "{{ archsetup_user_home }}/.config/hypr"
|
||||||
creates: "{{ lookup('env', 'HOME') }}/.config/starship"
|
chdir: "{{ archsetup_dir }}/dotfiles"
|
||||||
chdir: "{{ lookup('env', 'HOME') }}/archsetup/dotfiles"
|
|
||||||
|
|||||||
@@ -76,6 +76,6 @@
|
|||||||
- name: Add user to docker group
|
- name: Add user to docker group
|
||||||
become: true
|
become: true
|
||||||
user:
|
user:
|
||||||
name: "{{ user }}"
|
name: "{{ archsetup_user }}"
|
||||||
groups: docker
|
groups: docker
|
||||||
append: yes
|
append: yes
|
||||||
|
|||||||
11
roles/multimedia/tasks/main.yml
Normal file
11
roles/multimedia/tasks/main.yml
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
# tasks file for multimedia
|
||||||
|
- name: Install multimedia packages
|
||||||
|
become: true
|
||||||
|
pacman:
|
||||||
|
name:
|
||||||
|
- vlc
|
||||||
|
- ffmpeg
|
||||||
|
- imagemagick
|
||||||
|
- ghostscript
|
||||||
|
- mpv
|
||||||
|
state: present
|
||||||
4
site.yml
4
site.yml
@@ -1,9 +1,6 @@
|
|||||||
---
|
---
|
||||||
- hosts: localhost
|
- hosts: localhost
|
||||||
connection: local
|
connection: local
|
||||||
vars:
|
|
||||||
aur_helper: paru
|
|
||||||
user: "{{ ansible_user_id }}"
|
|
||||||
|
|
||||||
roles:
|
roles:
|
||||||
- { role: common, tags: ['common'] }
|
- { role: common, tags: ['common'] }
|
||||||
@@ -11,5 +8,6 @@
|
|||||||
- { role: cs_student, tags: ['cs_student'] }
|
- { role: cs_student, tags: ['cs_student'] }
|
||||||
- { role: devops, tags: ['devops'] }
|
- { role: devops, tags: ['devops'] }
|
||||||
- { role: ctf, tags: ['ctf'] }
|
- { role: ctf, tags: ['ctf'] }
|
||||||
|
- { role: multimedia, tags: ['multimedia'] }
|
||||||
- { role: hyprland, tags: ['hyprland'] }
|
- { role: hyprland, tags: ['hyprland'] }
|
||||||
- { role: ai, tags: ['ai'] }
|
- { role: ai, tags: ['ai'] }
|
||||||
|
|||||||
Reference in New Issue
Block a user