]>
us-delaporte.pagekite.me Git - dotfiles.git/blob - bin/dot
009f9aa03d769ac5d2d5ed468473263379265d56
2 ENVS
="$HOME/envs" # Python environments - including required Ansible
3 ANSIBLE
="$ENVS/ansible/bin/ansible-playbook" # Core command
4 TASKFILE
="$HOME/backup/dot.$HOSTNAME.yaml" # Backup of localhost config
5 DOTFILES
="$HOME/dotfiles" # Where to find dotfiles
7 LINKFILES
="$DOTFILES/files" # Files to symlink
8 INSTALLS
="$DOTFILES/install" # Install scripts
9 DOT
="$HOME/.dot" # Touched files go here to track installs
10 REQS
="$DOTFILES/reqs" # Python env requirements.txt files
14 read -d '' HELP
<< EOF
15 dot - a (mostly) one script dotfiles manager
17 Copyright 2026 Edward Delaporte V
18 Licensed under AGPLv3 and later.
21 install ansible CLI to $ANSIBLE
24 updates ~/dot.HOSTNAME.yaml
25 to include a symlink from ~/dotfiles/files/FILE to ~/.FILE
28 check setup against ~/backup/dot.HOSTNAME.yaml
31 apply config in ~/backup/dot.HOSTNAME.yaml
34 setup - more information on setup
35 all - additional features
38 read -d '' SETUP_HELP
<< EOF
41 1. Install this file on your path
42 2. Clone your (or my) 'dotfiles' repository to ~/dotfiles
43 3. Run 'dot help' to get started.
48 read -d '' EXTRA_HELP
<< EOF
51 updates ~/dot.HOSTNAME.yaml
52 to run ~/dotfiles/SCRIPT.sh if it has not yet been run
53 creates ~/dot/SCRIPT.installed after SCRIPT has been run
56 create Python environment ~/envs/ENV based on ~/dotfiles/reqs/ENV.txt
61 if [ ! -n "$1" ] || [ "$1" == "help" ]; then
64 if [ "$1" == "help" ] && [ "$2" == "all" ]; then
70 if [ "$1" == "help" ] && [ "$2" == "setup" ]; then
79 read -d '' EMPTY_TASKFILE
<< EOF
81 - name: Set up dotfiles on $HOSTNAME
87 - name: Check on $TASKFILE
92 if [[ ! -f "$TASKFILE" ]]; then
93 echo "Creating empty $TASKFILE"
94 mkdir -p "$HOME/backup"
95 echo "$EMPTY_TASKFILE" >> $TASKFILE
98 if [ "$1" == "setup" ]; then
99 if [[ ! -f "$ANSIBLE" ]]; then
101 echo "Setting up Ansible in ~/envs/ansible"
102 cd $HOME/envs
; python3
-m venv ansible
103 $HOME/envs
/ansible
/bin
/pip
install ansible jinja2
105 if [[ -f "$ANSIBLE" ]]; then
106 echo "[ ok ]: Ansible setup at $ANSIBLE"
108 if [[ -f "$TASKFILE" ]]; then
109 echo "[ ok ]: dot config at $TASKFILE"
113 if [ "$1" == "reset" ]; then
114 read -n1 -p "Reset $TASKFILE? [y,N]" input
115 if [[ ! $input == "Y" && ! $input == "y" ]]; then
116 echo "Aborted by user"
119 echo "$EMPTY_TASKFILE" > $TASKFILE
124 if [ "$1" == "check" ]; then
125 $ANSIBLE $TASKFILE --check --diff
128 if [ "$1" == "link" ]; then
129 if [ ! -n "$2" ]; then
130 echo "Can symlink: (from $LINKFILES)"
136 read -d '' LINK_THIS_FILE
<< EOF
139 ansible.builtin.file:
145 if [[ "$2" == *"."* ]];then
146 # File already contains a dot
147 read -d '' LINK_THIS_FILE
<< EOF
150 ansible.builtin.file:
159 echo " $LINK_THIS_FILE" >> $TASKFILE
160 echo "$2 added to symlinks in $TASKFILE"
161 echo "Run 'dot apply' to create all configured symlinks"
164 if [ "$1" == "apply" ]; then
165 if [[ ! -f "$TASKFILE" ]]; then
166 echo "$TASKFILE is missing. Run 'dot setup'"
169 $ANSIBLE -v $TASKFILE
172 if [ "$1" == "install" ]; then
173 if [ ! -n "$2" ]; then
174 echo "Can install: (.sh scripts in $INSTALLS)"
176 ls -p | grep -v / | grep .sh
179 if [[ ! -f "$INSTALLS/$2.sh" ]]; then
180 echo "No such install script $INSTALLS/$2.sh"
181 echo "Run dot install with no params to list scripts."
186 read -d '' RUN_INSTALL
<< EOF
189 path: "$DOT/$2.installed"
190 register: $2_installed
192 ansible.builtin.shell: |
193 "$INSTALLS/$2.sh" && touch "$DOT/$2.installed"
196 ("Error" in ret.stdout) or
197 (ret.stderr != '') or
199 when: not $2_installed.stat.exists
200 - name: verify $2 is installed
201 ansible.builtin.debug:
202 msg: "$2 is installed."
203 when: $2_installed.stat.exists
205 echo " $RUN_INSTALL" >> $TASKFILE
206 echo "Run 'dot apply' to run the install"
210 if [ "$1" == "env" ]; then
211 if [ ! -n "$2" ]; then
212 echo "Can create: (.txt files in $REQS)"
214 ls -p | grep -v / | grep .txt
217 if [[ ! -f "$REQS/$2.txt" ]]; then
218 echo "No such requirements file script $REQS/$2.txt"
219 echo "Run dot env with no params to list files."
223 read -d '' ADD_ENV
<< EOF
229 ansible.builtin.shell: |
232 $ENVS/$2/bin/python -m pip install -r $REQS/$2.txt
233 when: not $2_path.stat.exists
234 - name: verify env $2 exists
235 ansible.builtin.debug:
237 when: $2_path.stat.exists
239 echo " $ADD_ENV" >> $TASKFILE
240 echo "Run 'dot apply' to run the install"