From 49cbc019d66d408db17986a5c09b2b7d7a976576 Mon Sep 17 00:00:00 2001
From: Joel Grunbaum <joelgrun@gmail.com>
Date: Fri, 24 Dec 2021 03:39:05 +0000
Subject: [PATCH] Single dependency install, POSIX sourcing, overwrite checking, force install
---
INSTALL.sh | 54 ++++++++++++++++++++++++++++++++++++++++++++++--------
1 files changed, 46 insertions(+), 8 deletions(-)
diff --git a/INSTALL.sh b/INSTALL.sh
index 90ee445..72f1af1 100755
--- a/INSTALL.sh
+++ b/INSTALL.sh
@@ -1,14 +1,36 @@
#!/bin/sh
install_links() {
- source ./DICT
+ . ./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"
+ while [ 1 ]; do
+ CHOICE="overwrite"
+ if [ -a "$loc" ] && [ "$FORCE" = "0" ]; then
+ echo "WARNING: \"$loc\" exists, (overwrite, change, nothing): "
+ read CHOICE
+ fi
+ case "$CHOICE" in
+ o|overwrite)
+ dir=$(dirname "$loc")
+ mkdir -p "$dir"
+ ln -sf "$(pwd)/$file" "$loc"; break;;
+ c|change)
+ tmpfile=$(mktemp)
+ echo "$loc" >> $tmpfile
+ $EDITOR "$tmpfile"
+ loc=$(cat $tmpfile)
+ rm $tmpfile
+ unset tmpfile;;
+ n|nothing)
+ break;;
+ *)
+ echo "INVALID CHOICE \"$CHOICE\", (overwrite, change, nothing)"
+ read CHOICE
+ esac
+ done
done
fi
if [ -n "$SUDO_FILES" ]; then
@@ -26,7 +48,7 @@
}
remove_links() {
- source ./DICT
+ . ./DICT
if [ -n "$FILES" ]; then
for i in `seq 1 $(echo $FILES | wc -w)`; do
loc=$(echo "$LOCATIONS" | cut -d' ' -f $i)
@@ -60,8 +82,11 @@
unset DEPS
eval $(grep "DEPS=" $1/DICT)
for i in $DEPS; do
- (handle_package $i $2)
+ if ! grep -q "$i" "$PACKAGE_CACHE"; then
+ (handle_package $i $2)
+ fi
done
+ echo "$1" >> "$PACKAGE_CACHE"
(cd "$1"; $2)
else
echo "No configuration found for $i"
@@ -73,20 +98,31 @@
echo "Usage with -h|--help"
echo "Install with -i|--install (default)"
echo "Remove with -r|--remove"
+ echo "Force install with -f|--force"
echo "Directories have the configurations for their programs/use cases"
echo "List all configurations to be installed in the command line"
+ echo "If there is a file at the install location, you will be prompted to change it"
echo "Example usage: $0 -i bash zsh"
}
INSTALL=1
-PACKAGES=""
-FUNCTION=""
+FORCE=0
+PACKAGE_CACHE=$(mktemp)
+DOTFILES_PATH="$(dirname $0)"
+
+cd $DOTFILES_PATH
+
+if [ -z "$1" ]; then
+ usage
+ exit
+fi
while [ -n "$1" ]; do
case "$1" in
-h|--help|"") usage; exit;;
-i|--install) INSTALL=1;;
-r|--remove) INSTALL=0;;
+ -f|--force) FORCE=1;;
--) shift; break;;
-*) echo "Invalid argument"; usage; exit;;
*) handle_package "$1" "$([ \"$INSTALL\" = \"1\" ] && echo install || echo remove)_links";;
@@ -97,3 +133,5 @@
while [ -n "$1" ]; do
handle_package "$1" "$([ \"$INSTALL\" = \"1\" ] && echo install || echo remove)_links"
done
+
+rm $PACKAGE_CACHE
--
Gitblit v1.10.0