From 16eae64a973956a95bc6f2388aa8f5af75556db3 Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Sat, 10 Mar 2018 23:43:58 +0800 Subject: Implement fly command for one-command upgrade procedure :) XXX: Use global variables shared between cmd_status() and cmd_fly() --- dfly-update | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'dfly-update') diff --git a/dfly-update b/dfly-update index 9c8f171..b492196 100755 --- a/dfly-update +++ b/dfly-update @@ -77,6 +77,14 @@ BAK_SUF="__bak__" NEW_SUF="__new__" +# +# XXX: Variables share across two or more functions +# +_FILENAME= # The latest remote system image filename +_MD5= +_HAS_UPDATE= + + # # Helper Functions # @@ -581,6 +589,8 @@ Usage: Install the new kernel, world, and config files cleanup Clean up obsolete files, umount and remove image file + fly + Synthetic command to upgrade the system! _EOF_ echo cmd_version @@ -620,6 +630,11 @@ _EOF_ else echo "??? Your DragonFly is newer than remote ???" fi + + # XXX: set the global variables for use in `cmd_fly()` + _FILENAME="${_filename}" + _MD5=${_md5} + _HAS_UPDATE=${has_update} } # Download the given image and check aginst the given MD5 @@ -691,6 +706,21 @@ cmd_cleanup() { postupgrade } +# Integrate all the upgrading steps -> fly :-) +cmd_fly() { + [ $# -eq 0 ] || \ + error ${EC_ARGS} "cmd_fly: invalid arguments: $@" + echo "Checking status ..." + cmd_status + if [ ${_HAS_UPDATE} -eq 1 ]; then + local file="${CACHE_DIR}/${_FILENAME}" + cmd_download "${_FILENAME}" ${_MD5} + cmd_mount ${file} + cmd_backup + cmd_upgrade + cmd_cleanup + fi +} # # Main @@ -707,7 +737,7 @@ case "${COMMAND}" in ;; status) shift - cmd_status "$@" + cmd_status ;; download) shift @@ -729,6 +759,10 @@ case "${COMMAND}" in shift cmd_cleanup ;; + fly|go) + shift + cmd_fly + ;; help|--help|-h|*) cmd_usage ;; -- cgit v1.2.2