diff options
author | Aaron LI <aly@aaronly.me> | 2018-03-10 19:40:38 +0800 |
---|---|---|
committer | Aaron LI <aly@aaronly.me> | 2018-03-10 19:40:38 +0800 |
commit | 6b974479e6e52e1da360faf98602521ef62d17dd (patch) | |
tree | 405cd992fd79214de7e6e498c82646dc71bb697e | |
parent | 1d36cf530b77105d1b844b5b2ca28525576a86ef (diff) | |
download | dfly-update-6b974479e6e52e1da360faf98602521ef62d17dd.tar.bz2 |
Add functions get_branch_filename() and is_master_branch()
-rwxr-xr-x | dfly-update | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/dfly-update b/dfly-update index beb9f8a..5e2ff5e 100755 --- a/dfly-update +++ b/dfly-update @@ -36,6 +36,9 @@ URL_DEVELOPMENT="${URL_BASE}/snapshots/x86_64/images" URL_RELEASE="${URL_BASE}/iso-images" # Default to track the same branch as the installed system +# * MASTER (i.e., the DEVELOPMENT branch) +# * RELEASE +# * (empty) - same as the local installed branch UPDATE_BRANCH= @@ -63,6 +66,42 @@ check_os() { fi } +# contains(string, substring) +# +# Returns 0 if the specified string contains the specified substring, +# otherwise returns 1. +# +# Credit: https://stackoverflow.com/a/8811800 +contains() { + local string="$1" + local substring="$2" + if [ "${string#*$substring}" != "$string" ]; then + return 0 # $substring is in $string + else + return 1 # $substring is not in $string + fi +} + +# Determine the branch from the image filename +get_branch_filename() { + if contains "$1" "-DEV-"; then + echo "MASTER" + else + echo "RELEASE" + fi +} + +# Determine whether the given name refers to the master branch? +is_master_branch() { + case "$1" in + master|MASTER|[dD][eE][vV]*) + return 0 + ;; + *) + return 1 + ;; + esac +} # Get the branch of the installed system # * DEVELOPMENT |