]>
apps.delaporte.us Git - dotfiles.git/blob - bin/dot
dc3e8fa2e8114be4a85f5115f8d013bdd6efc47b
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
12 read -d '' HELP
<< EOF
13 dot - a (mostly) one script dotfiles manager
15 Copyright 2026 Edward Delaporte V
16 Licensed under AGPLv3 and later.
19 install ansible CLI to $ANSIBLE
22 updates ~/dot.HOSTNAME.yaml
23 to include a symlink from ~/dotfiles/files/FILE to ~/.FILE
26 check setup against ~/backup/dot.HOSTNAME.yaml
29 apply config in ~/backup/dot.HOSTNAME.yaml
32 setup - more information on setup
33 all - additional features
36 read -d '' SETUP_HELP
<< EOF
39 1. Install this file on your path
40 2. Clone your (or my) 'dotfiles' repository to ~/dotfiles
41 3. Run 'dot help' to get started.
46 read -d '' EXTRA_HELP
<< EOF
49 updates ~/dot.HOSTNAME.yaml
50 to run ~/dotfiles/SCRIPT.sh if it has not yet been run
51 creates ~/dot/SCRIPT.installed after SCRIPT has been run
54 create Python environment ~/envs/ENV based on ~/dotfiles/reqs/ENV.txt
59 if [ ! -n "$1" ] || [ "$1" == "help" ]; then
62 if [ "$1" == "help" ] && [ "$2" == "all" ]; then
68 if [ "$1" == "help" ] && [ "$2" == "setup" ]; then
77 read -d '' EMPTY_TASKFILE
<< EOF
79 - name: Set up dotfiles on $HOSTNAME
85 - name: Check on $TASKFILE
90 if [[ ! -f "$TASKFILE" ]]; then
91 echo "Creating empty $TASKFILE"
92 mkdir -p "$HOME/backup"
93 echo "$EMPTY_TASKFILE" >> $TASKFILE
96 if [ "$1" == "setup" ]; then
97 if [[ ! -f "$ANSIBLE" ]]; then
99 echo "Setting up Ansible in ~/envs/ansible"
100 cd $HOME/envs
; python3
-m venv ansible
101 $HOME/envs
/ansible
/bin
/pip
install ansible jinja2
103 if [[ -f "$ANSIBLE" ]]; then
104 echo "[ ok ]: Ansible setup at $ANSIBLE"
106 if [[ -f "$TASKFILE" ]]; then
107 echo "[ ok ]: dot config at $TASKFILE"
111 if [ "$1" == "reset" ]; then
112 read -n1 -p "Reset $TASKFILE? [y,N]" input
113 if [[ ! $input == "Y" && ! $input == "y" ]]; then
114 echo "Aborted by user"
117 echo "$EMPTY_TASKFILE" > $TASKFILE
122 if [ "$1" == "check" ]; then
123 $ANSIBLE $TASKFILE --check --diff
126 if [ "$1" == "link" ]; then
127 if [ ! -n "$2" ]; then
128 echo "Can symlink: (from $LINKFILES)"
134 read -d '' LINK_THIS_FILE
<< EOF
137 ansible.builtin.file:
143 if [[ "$2" == *"."* ]];then
144 # File already contains a dot
145 read -d '' LINK_THIS_FILE
<< EOF
148 ansible.builtin.file:
157 echo " $LINK_THIS_FILE" >> $TASKFILE
158 echo "$2 added to symlinks in $TASKFILE"
159 echo "Run 'dot apply' to create all configured symlinks"
162 if [ "$1" == "apply" ]; then
163 if [[ ! -f "$TASKFILE" ]]; then
164 echo "$TASKFILE is missing. Run 'dot setup'"
170 if [ "$1" == "install" ]; then
171 if [ ! -n "$2" ]; then
172 echo "Can install: (.sh scripts in $INSTALLS)"
174 ls -p | grep -v / | grep .sh
177 if [[ ! -f "$INSTALLS/$2.sh" ]]; then
178 echo "No such install script $INSTALLS/$2.sh"
179 echo "Run dot install with no params to list scripts."
184 read -d '' RUN_INSTALL
<< EOF
187 path: "$DOT/$2.installed"
188 register: $2_installed
190 ansible.builtin.shell: |
192 touch "$DOT/$2.installed"
193 when: not $2_installed.stat.exists
194 - name: verify $2 is installed
195 ansible.builtin.debug:
196 msg: "$2 is installed."
197 when: $2_installed.stat.exists
199 echo " $RUN_INSTALL" >> $TASKFILE
200 echo "Run 'dot apply' to run the install"
204 if [ "$1" == "env" ]; then
205 if [ ! -n "$2" ]; then
206 echo "Can create: (.txt files in $REQS)"
208 ls -p | grep -v / | grep .txt
211 if [[ ! -f "$REQS/$2.txt" ]]; then
212 echo "No such requirements file script $REQS/$2.txt"
213 echo "Run dot env with no params to list files."
217 read -d '' ADD_ENV
<< EOF
223 ansible.builtin.shell: |
226 $ENVS/$2/bin/python -m pip install -r $REQS/$2.txt
227 when: not $2_path.stat.exists
228 - name: verify env $2 exists
229 ansible.builtin.debug:
231 when: $2_path.stat.exists
233 echo " $ADD_ENV" >> $TASKFILE
234 echo "Run 'dot apply' to run the install"