mirror of https://github.com/Chizi123/Dotfiles.git

Joel Grunbaum
2021-12-24 49cbc019d66d408db17986a5c09b2b7d7a976576
Single dependency install, POSIX sourcing, overwrite checking, force install
1 files modified
54 ■■■■ changed files
INSTALL.sh 54 ●●●● patch | view | raw | blame | history
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