From f4047bf3c3827792b14f500305fb296e330f07f5 Mon Sep 17 00:00:00 2001 From: mapperr Date: Sun, 27 Oct 2019 12:55:06 +0100 Subject: [PATCH] Fix self update feature --- dfl | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/dfl b/dfl index 6015869..c0349e4 100755 --- a/dfl +++ b/dfl @@ -33,6 +33,7 @@ dotfiles_dir_abs="$dfl_user_dir_abs/$dotfiles_dir" track_file_abs="$dfl_user_dir_abs/$track_filename" untrack_file_abs="$dfl_user_dir_abs/.untrack" +update_scriptpath_abs="$dfl_user_dir_name/update_dfl.sh" backup_suffix="-dflbak" logd() { @@ -40,6 +41,21 @@ logd() { test "$debug" = "true" && echo "$msg" } +write_update_script() { + cat > "$update_scriptpath_abs" << EOF +#!/bin/bash +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" +EOF +} + take_file() { local file="$1" local profile="$2" @@ -341,16 +357,8 @@ elif [ "$command" = "l" ] || [ "$command" = "link" ]; then 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" + write_update_script + exec /bin/bash "$update_scriptpath_abs" else helpmsg -- 2.45.2