From 08c918b3c06ceb28d10ec23e1073664e06c3875d Mon Sep 17 00:00:00 2001 From: Thomas Forgione Date: Mon, 3 Jun 2019 17:10:42 +0200 Subject: [PATCH] Better kill even though still not perfect --- bin/update | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/bin/update b/bin/update index 7248817..b2ac714 100755 --- a/bin/update +++ b/bin/update @@ -1,5 +1,18 @@ #!/usr/bin/env bash +running=0 + +_check_running() { + if [ $running -ne 0 ]; then + _unlock + exit $running + fi +} + +_onkill() { + running=1 +} + _lock() { if [ -f ~/.config/dotfiles/.data/update_lock ]; then return 1 @@ -356,28 +369,37 @@ main() { echo -e "\033[32;1m=== Starting full update ===\033[0m" # Update the system + _check_running update-system # Update rust and rust packages + _check_running update-rust # Update npm and npm packages + _check_running update-npm # Update the dotfiles + _check_running update-dotfiles # Update the neovim packages + _check_running update-neovim + _check_running update-postpone + _check_running seconds=$((`date +%s` - $start )) formatted=`date -ud "@$seconds" +'%H hours %M minutes %S seconds'` echo -e "\033[32;1m=== Update finished in $formatted ===\033[0m" + _check_running _check_date_if_format force + _check_running _unlock else @@ -402,6 +424,7 @@ main() { fi for part in $@; do + _check_running partial-update $part done @@ -411,5 +434,6 @@ main() { fi } +trap _onkill 2 3 main $@