]> apps.delaporte.us Git - dotfiles.git/blobdiff - bin/dot
Add dot apply command
[dotfiles.git] / bin / dot
diff --git a/bin/dot b/bin/dot
index 16e366ef6e566eb37029d9b82c35a8300c01b7d4..06d0db4640ad8c658f1d5c50850a6261aaf021ce 100755 (executable)
--- a/bin/dot
+++ b/bin/dot
 # dot setup
 #              install the necessary tools to $HOME/envs/dot
 #
-# dot list
-#   list available roles
+# dot link FILE
+#   updates ~/dot.HOSTNAME.yaml
+#   to include a symlink from ~/dotfiles/files/FILE to ~/.FILE
 #
 # dot check
-#   check setup vs expected
-#
-# dot add ROLE
-#   add ROLE to localhost
+#              check setup against ~/dot.HOSTNAME.yaml
 #
 # dot apply
-#              apply all added ROLES
+#              apply config in ~/dot.HOSTNAME.yaml
 
 # set -v
 
 ENVS="$HOME/envs"
 ANSIBLE="$ENVS/ansible/bin/ansible-playbook"
 TASKFILE="$HOME/dot.$HOSTNAME.yaml"
+LINKFILES="$HOME/dotfiles/files"
 
 read -d '' EMPTY_TASKFILE << EOF
 ---
@@ -36,8 +35,9 @@ read -d '' EMPTY_TASKFILE << EOF
   connection: local
 
   tasks:
-     - name: Do nothing
-       ansible.builtin.shell: echo "Nothing to do."
+    - name: Check on $TASKFILE
+      ansible.builtin.stat:
+        path: $TASKFILE
 EOF
 
 
@@ -60,40 +60,50 @@ if [ "$1" == "setup" ]; then
        fi
 fi
 
-if [ "$1" == "check" ]; then
-       $ANSIBLE $TASKFILE --check --diff
-fi
-
-if [ "$1" == "list" ]; then
-  echo "May symlink:"
-       cd $HOME/dotfiles/files
-       ls -p | grep -v /
+if [ "$1" == "reset" ]; then
+       read -n1 -p "Reset $TASKFILE? [y,N]" input
+       if [[ ! $input == "Y" && ! $input == "y" ]]; then
+               echo "Aborted by user"
+               exit 1
+       fi
+       echo "$EMPTY_TASKFILE" > $TASKFILE
+       echo ""
 fi
 
 
+if [ "$1" == "check" ]; then
+       $ANSIBLE $TASKFILE --check --diff
+fi
 
 if [ "$1" == "link" ]; then
-       echo "wait"
-fi
+       if [ ! -n "$2" ]; then
+               echo "May symlink:"
+               cd $LINKFILES
+               ls -p | grep -v /
+               exit 1
+       fi
 
-echo << EOF
-- name: Create a symbolic link
-  ansible.builtin.file:
-    src: /file/to/link/to
-    dest: /path/to/symlink
-    owner: foo
-    group: foo
-    state: link
+read -d '' LINK_THIS_FILE << EOF
+
+    - name: symlink $2
+      ansible.builtin.file:
+        src: "$LINKFILES/$2"
+        dest: "$HOME/.$2"
+        state: "link"
 EOF
 
-echo "heh"
+       echo "    $LINK_THIS_FILE" >> $TASKFILE
+       echo "$2 added to symlinks in $TASKFILE"
+       echo "Run 'dot apply' to create all configured symlinks"
+fi
 
 
-if [ "$1" == "reset" ]; then
-       read -n1 -p "Reset $TASKFILE? [y,N]" input
-       if [[ ! $input == "Y" && ! $input == "y" ]]; then
-               echo "Aborted by user"
+if [ "$1" == "apply" ]; then
+  if [[ ! -f "$TASKFILE" ]]; then
+               echo "$TASKFILE is missing. Run 'dot setup'"
                exit 1
        fi
-       echo "$EMPTY_TASKFILE" > $TASKFILE
+       $ANSIBLE $TASKFILE
 fi
+
+