From 6b974479e6e52e1da360faf98602521ef62d17dd Mon Sep 17 00:00:00 2001
From: Aaron LI <aly@aaronly.me>
Date: Sat, 10 Mar 2018 19:40:38 +0800
Subject: Add functions get_branch_filename() and is_master_branch()

---
 dfly-update | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

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
-- 
cgit v1.2.2