From f86690f5bd27074a1784c65fffaaa7974c214e3d Mon Sep 17 00:00:00 2001
From: Joel Grunbaum <joelgrun@gmail.com>
Date: Thu, 23 Dec 2021 04:09:56 +0000
Subject: [PATCH] Shift from make and stow to shell script to install

---
 INSTALL.sh |  117 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 117 insertions(+), 0 deletions(-)

diff --git a/INSTALL.sh b/INSTALL.sh
new file mode 100755
index 0000000..0aaa4a2
--- /dev/null
+++ b/INSTALL.sh
@@ -0,0 +1,117 @@
+#!/bin/sh
+
+install_links() {
+    source ./DICT
+    if [ -n "$FILES" ]; then
+	for i in `seq 1 $(echo "$FILES" | wc -w)`; do
+	    file=$(echo "$FILES" | cut -d' ' -f $i)
+	    loc=$(echo "$LOCATIONS" | cut -d' ' -f $i)
+	    dir=$(echo "$loc" | rev | cut -d'/' -f2- | rev)
+	    mkdir -p "$dir"
+	    ln -sf "$(pwd)/$file" "$loc"
+	done
+    fi
+    if [ -n "$SUDO_FILES" ]; then
+	for i in `seq 1 $(echo "$SUDO_FILES" | wc -w)`; do
+	    file=$(echo "$SUDO_FILES" | cut -d' ' -f $i)
+	    loc=$(echo "$SUDO_LOCATIONS" | cut -d' ' -f $i)
+	    dir=$(echo "$loc" | rev | cut -d'/' -f2- | rev)
+	    sudo mkdir -p "$dir"
+	    sudo ln -sf "$(pwd)/$file" "$loc"
+	done
+    fi
+    if [ "$(type -t custom)" = "function" ]; then
+	custom install
+    fi
+}
+
+remove_links() {
+    source ./DICT
+    if [ -n "$FILES" ]; then
+	for i in `seq 1 $(echo $FILES | wc -w)`; do
+	    loc=$(echo "$LOCATIONS" | cut -d' ' -f $i)
+	    rm "$loc" 2>/dev/null
+	    loc=$(echo "$loc" | rev | cut -d'/' -f2- | rev)
+	    while [ -z "$(ls -A $loc)" ]; do
+		rm -r "$loc"
+		loc=$(echo "$loc" | rev | cut -d'/' -f2- | rev)
+	    done 2>/dev/null
+	done
+    fi
+    if [ -n "$SUDO_FILES" ]; then
+	for i in `seq 1 $(echo $SUDO_FILES | wc -w)`; do
+	    loc=$(echo "$SUDO_LOCATIONS" | cut -d' ' -f $i)
+	    sudo rm "$loc" 2>/dev/null
+	    loc=$(echo "$loc" | rev | cut -d'/' -f2- | rev)
+	    while [ -z "ls -A $loc" ]; do
+		sudo rm -r "$loc"
+		loc=$(echo "$loc" | rev | cut -d'/' -f2- | rev)
+	    done 2>/dev/null
+	done
+    fi
+    if [ "$(type -t custom)" = "function" ]; then
+	custom remove
+    fi
+}
+
+handle_package() {
+if [ -d "$1" ]; then
+	(cd "$1"; $2)
+    else
+	echo "No configuration found for $i"
+    fi
+}
+usage() {
+    echo "Install dotfiles with symlinks"
+    echo "Usage with -h|--help"
+    echo "Install with -i|--install (default)"
+    echo "Remove with -r|--remove"
+    echo "Directories have the configurations for their programs/use cases"
+    echo "List all configurations to be installed in the command line"
+    echo "Example usage: $0 -i bash zsh"
+}
+
+INSTALL=1
+PACKAGES=""
+FUNCTION=""
+
+while [ -n "$1" ]; do
+      case "$1" in
+	  -h|--help|"") usage; exit;;
+	  -i|--install) INSTALL=1;;
+	  -r|--remove) INSTALL=0;;
+	  --) shift; break;;
+	  -*) echo "Invalid argument"; usage; exit;;
+	  *) handle_package "$1" "$([ \"$INSTALL\" = \"1\" ] && echo install || echo remove)_links";;
+      esac
+      shift
+done
+
+# case "$1" in
+#     -*) echo "Only one argument allowed"; exit;;
+# esac
+
+# while [ -n "$1" ]; do
+#     PACKAGES="$PACKAGES $1"
+#     shift
+# done
+
+# if [ "$INSTALL" = "1" ] && [ "$REMOVE" = "0" ]; then
+#     FUNCTION="install_links"
+# elif [ "$INSTALL" = "0" ] && [ "$REMOVE" = "1" ]; then
+#     FUNCTION="remove_links"
+# else
+#     echo "Need to specify install or removal of configs"
+#     exit 1
+# fi
+
+# for i in $PACKAGES; do
+#     if [ -d "$i" ]; then
+# 	(cd "$i"; $FUNCTION)
+#     else
+# 	echo "No configuration found for $i"
+#     fi
+# done
+
+# (cd $1; install_links)
+# (cd $1; remove_links)

--
Gitblit v1.9.3