]>
us-delaporte.pagekite.me Git - dotfiles.git/blob - bin/dot
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 display the contents of $TASKFILE
54 updates ~/dot.HOSTNAME.yaml
55 to run ~/dotfiles/SCRIPT.sh if it has not yet been run
56 creates ~/dot/SCRIPT.installed after SCRIPT has been run
59 create Python environment ~/envs/ENV based on ~/dotfiles/reqs/ENV.txt
64 if [ ! -n "$1" ] || [ "$1" == "help" ]; then
67 if [ "$1" == "help" ] && [ "$2" == "all" ]; then
73 if [ "$1" == "help" ] && [ "$2" == "setup" ]; then
82 read -d '' EMPTY_TASKFILE
<< EOF
84 - name: Set up dotfiles on $HOSTNAME
90 - name: Check on $TASKFILE
95 if [[ ! -f "$TASKFILE" ]]; then
96 echo "Creating empty $TASKFILE"
97 mkdir -p "$HOME/backup"
98 echo "$EMPTY_TASKFILE" >> $TASKFILE
101 if [ "$1" == "list" ]; then
106 if [ "$1" == "setup" ]; then
107 if [[ ! -f "$ANSIBLE" ]]; then
109 echo "Setting up Ansible in ~/envs/ansible"
110 cd $HOME/envs
; python3
-m venv ansible
111 $HOME/envs
/ansible
/bin
/pip
install ansible jinja2
113 if [[ -f "$ANSIBLE" ]]; then
114 echo "[ ok ]: Ansible setup at $ANSIBLE"
116 if [[ -f "$TASKFILE" ]]; then
117 echo "[ ok ]: dot config at $TASKFILE"
121 if [ "$1" == "reset" ]; then
122 read -n1 -p "Reset $TASKFILE? [y,N]" input
123 if [[ ! $input == "Y" && ! $input == "y" ]]; then
124 echo "Aborted by user"
127 echo "$EMPTY_TASKFILE" > $TASKFILE
132 if [ "$1" == "check" ]; then
133 $ANSIBLE $TASKFILE --check --diff
136 if [ "$1" == "link" ]; then
137 if [ ! -n "$2" ]; then
138 echo "Can symlink: (from $LINKFILES)"
144 read -d '' LINK_THIS_FILE
<< EOF
147 ansible.builtin.file:
153 if [[ "$2" == *"."* ]];then
154 # File already contains a dot
155 read -d '' LINK_THIS_FILE
<< EOF
158 ansible.builtin.file:
167 echo " $LINK_THIS_FILE" >> $TASKFILE
168 echo "$2 added to symlinks in $TASKFILE"
169 echo "Run 'dot apply' to create all configured symlinks"
172 if [ "$1" == "apply" ]; then
173 if [[ ! -f "$TASKFILE" ]]; then
174 echo "$TASKFILE is missing. Run 'dot setup'"
177 $ANSIBLE -v $TASKFILE
180 if [ "$1" == "install" ]; then
181 if [ ! -n "$2" ]; then
182 echo "Can install: (.sh scripts in $INSTALLS)"
184 ls -p | grep -v / | grep .sh
187 if [[ ! -f "$INSTALLS/$2.sh" ]]; then
188 echo "No such install script $INSTALLS/$2.sh"
189 echo "Run dot install with no params to list scripts."
194 read -d '' RUN_INSTALL
<< EOF
197 path: "$DOT/$2.installed"
198 register: $2_installed
200 ansible.builtin.shell: |
201 "$INSTALLS/$2.sh" && touch "$DOT/$2.installed"
204 ("Error" in ret.stdout) or
205 ("Error" in ret.stderr) or
207 when: not $2_installed.stat.exists
208 - name: verify $2 is installed
209 ansible.builtin.debug:
210 msg: "$2 is installed."
211 when: $2_installed.stat.exists
213 echo " $RUN_INSTALL" >> $TASKFILE
214 echo "Run 'dot apply' to run the install"
218 if [ "$1" == "env" ]; then
219 if [ ! -n "$2" ]; then
220 echo "Can create: (.txt files in $REQS)"
222 ls -p | grep -v / | grep .txt
225 if [[ ! -f "$REQS/$2.txt" ]]; then
226 echo "No such requirements file script $REQS/$2.txt"
227 echo "Run dot env with no params to list files."
231 read -d '' ADD_ENV
<< EOF
237 ansible.builtin.shell: |
240 $ENVS/$2/bin/python -m pip install -r $REQS/$2.txt
241 when: not $2_path.stat.exists
242 - name: verify env $2 exists
243 ansible.builtin.debug:
245 when: $2_path.stat.exists
247 echo " $ADD_ENV" >> $TASKFILE
248 echo "Run 'dot apply' to run the install"