From 1810d48b1a99a3a51317420af6974f4f314360bc Mon Sep 17 00:00:00 2001 From: mapperr Date: Fri, 25 Oct 2019 12:19:52 +0200 Subject: [PATCH] Add self update capability --- dfl | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/dfl b/dfl index 2df63ff..d0e29c2 100755 --- a/dfl +++ b/dfl @@ -8,7 +8,6 @@ # optionals: # - git - # https://stackoverflow.com/a/246128/1407614 SOURCE="${BASH_SOURCE[0]}" while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink @@ -18,6 +17,8 @@ while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symli done SCRIPT_DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )" +script_name="dfl" +script_url="https://raw.githubusercontent.com/mapperr/dfl/master/dfl" dotfiles_dir="dotfiles" default_profile_name="default" @@ -189,6 +190,9 @@ helpmsg() { d prints the dotfiles directory absolute path + u, up, update + self update from [$script_url] + Options: -v - activate verbose mode " @@ -274,6 +278,19 @@ elif [ "$command" = "l" ] || [ "$command" = "link" ]; then cd - >/dev/null process_deleted_files $profile +elif [ "$command" = "u" ] || [ "$command" = "up" ] || [ "$command" = "update" ]; then + + script_path_abs="$SCRIPT_DIR/$script_name" + if hash curl; then + curl -o "$script_path_abs" "$script_url" + if [ $? -ne 0 ]; then + echo "ERROR: cannot update myself" + exit 1 + fi + fi + + echo "Updated" + else helpmsg fi -- 2.45.2