]> apps.delaporte.us Git - dotfiles.git/blob - bin/dot
Add help text to dot link
[dotfiles.git] / bin / dot
1 #!/bin/bash
2 # dot - a (mostly) one script dotfiles manager
3 #
4 # Copyright 2026 Edward Delaporte V
5 # Licensed under AGPLv3 and later.
6 #
7 # Features
8 # symlinks - any file in $HOME/dotfiles/files may be symlinked
9 #
10 # dot setup
11 # install the necessary tools to $HOME/envs/dot
12 #
13 # dot list
14 # list available roles
15 #
16 # dot check
17 # check setup vs expected
18 #
19 # dot add ROLE
20 # add ROLE to localhost
21 #
22 # dot apply
23 # apply all added ROLES
24
25 # set -v
26
27 ENVS="$HOME/envs"
28 ANSIBLE="$ENVS/ansible/bin/ansible-playbook"
29 TASKFILE="$HOME/dot.$HOSTNAME.yaml"
30
31 read -d '' EMPTY_TASKFILE << EOF
32 ---
33 - name: Set up dotfiles on $HOSTNAME
34 gather_facts: no
35 hosts: localhost
36 connection: local
37
38 tasks:
39 - name: Do nothing
40 ansible.builtin.shell: echo "Nothing to do."
41 EOF
42
43
44 if [ "$1" == "setup" ]; then
45 if [[ ! -f "$ANSIBLE" ]]; then
46 mkdir -p "$ENVS"
47 echo "Setting up Ansible in ~/envs/ansible"
48 cd $HOME/envs; python3 -m venv ansible
49 $HOME/envs/ansible/bin/pip install ansible jinja2
50 fi
51 if [[ -f "$ANSIBLE" ]]; then
52 echo "[ ok ]: Ansible setup at $ANSIBLE"
53 fi
54 if [[ ! -f "$TASKFILE" ]]; then
55 echo "Creating $TASKFILE"
56 echo "$EMPTY_TASKFILE" >> $TASKFILE
57 fi
58 if [[ -f "$TASKFILE" ]]; then
59 echo "[ ok ]: dot config at $TASKFILE"
60 fi
61 fi
62
63 if [ "$1" == "reset" ]; then
64 read -n1 -p "Reset $TASKFILE? [y,N]" input
65 if [[ ! $input == "Y" && ! $input == "y" ]]; then
66 echo "Aborted by user"
67 exit 1
68 fi
69 echo "$EMPTY_TASKFILE" > $TASKFILE
70 fi
71
72
73 if [ "$1" == "check" ]; then
74 $ANSIBLE $TASKFILE --check --diff
75 fi
76
77 if [ "$1" == "list" ]; then
78 echo "May symlink:"
79 cd $HOME/dotfiles/files
80 ls -p | grep -v /
81 fi
82
83
84
85
86
87 if [ "$1" == "link" ]; then
88 if [ ! -n "$2" ]; then
89 echo "May symlink:"
90 cd $HOME/dotfiles/files
91 ls -p | grep -v /
92 fi
93
94 read -d '' LINK_FILE << EOF
95 ---
96 tasks:
97 - name: Create a symbolic link
98 ansible.builtin.file:
99 src: /file/to/link/to
100 dest: /path/to/symlink
101 owner: foo
102 group: foo
103 state: link
104 EOF
105
106 fi
107