OSDN Git Service

[update] : Use exit code to check channel
authorhayao <hayao@fascode.net>
Mon, 15 Mar 2021 14:09:32 +0000 (23:09 +0900)
committerhayao <hayao@fascode.net>
Mon, 15 Mar 2021 14:09:32 +0000 (23:09 +0900)
build.sh
tools/channel.sh

index 7ec1078..365dafd 100755 (executable)
--- a/build.sh
+++ b/build.sh
@@ -539,7 +539,9 @@ prepare_build() {
     check_bool boot_splash cleaning noconfirm nodepend customized_username customized_password noloopmod nochname tarball noiso noaur customized_syslinux norescue_entry debug bash_debug nocolor msgdebug noefi nosigcheck
 
     # Check architecture for each channel
-    if [[ ! "$(bash "${tools_dir}/channel.sh" --version "${alteriso_version}" -a ${arch} -n -b check "${channel_name}")" = "correct" ]]; then
+    local _exit=0
+    bash "${tools_dir}/channel.sh" --version "${alteriso_version}" -a ${arch} -n -b check "${channel_name}" || _exit="${?}"
+    if (( "${_exit}" != 0 )) && (( "${_exit}" != 1 )); then
         msg_error "${channel_name} channel does not support current architecture (${arch})." "1"
     fi
 
@@ -1305,15 +1307,15 @@ if [[ "${bash_debug}" = true ]]; then set -x -v; fi
 
 # Check for a valid channel name
 if [[ -n "${1+SET}" ]]; then
-    case "$(bash "${tools_dir}/channel.sh" --version "${alteriso_version}" -n check "${1}")" in
-        "incorrect")
+    case "$(bash "${tools_dir}/channel.sh" --version "${alteriso_version}" -n check "${1}"; printf "${?}")" in
+        "2")
             msg_error "Invalid channel ${1}" "1"
             ;;
-        "directory")
+        "1")
             channel_dir="${1}"
             channel_name="$(basename "${1%/}")"
             ;;
-        "correct")
+        "0")
             channel_dir="${script_path}/channels/${1}"
             channel_name="${1}"
             ;;
index 4b02ae3..9e5d716 100755 (executable)
@@ -38,6 +38,12 @@ _help() {
     echo "    -h | --help               This help message"
     echo
     echo "         --nocheck            Do not check the channel with desc command.This option helps speed up."
+    echo
+    echo " check command exit code"
+    echo "    0 (correct)               Normal available channel"
+    echo "    1 (directory)             Channel outside the channel directory"
+    echo "    2 (incorrect)             Unavailable channel"
+    echo "    3                         Other error"
 }
 
 gen_channel_list() {
@@ -111,19 +117,23 @@ check() {
     gen_channel_list
     if [[ ! "${#}" = "1" ]]; then
         _help
-        exit 1
+        exit 3
     fi
     if [[ $(printf '%s\n' "${channellist[@]}" | grep -qx "${1}"; echo -n ${?} ) -eq 0 ]]; then
-        echo "correct"
+        #echo "correct"
+        exit 0
     elif [[ -d "${1}" ]] && [[ -n $(ls "${1}") ]]; then
         local _channel_name="$(basename "${1%/}")"
         if ! check_alteriso_version "${_channel}" || [[ "${opt_nochkver}" = true ]]; then
-            echo "directory"
+            #echo "directory"
+            exit 1
         else
-            echo "incorrect"
+            #echo "incorrect"
+            exit 2
         fi
     else
-        echo "incorrect"
+        #echo "incorrect"
+        exit 2
     fi
 }
 
@@ -133,7 +143,7 @@ desc() {
         _help
         exit 1
     fi
-    if [[ "${opt_nocheck}" = false ]] && [[ ! "$(bash "${script_path}/tools/channel.sh" -a ${arch} -n -b check "${1}")" = "correct" ]]; then
+    if [[ "${opt_nocheck}" = false ]] && ! bash "${script_path}/tools/channel.sh" -a ${arch} -n -b check "${1}"; then
         exit 1
     fi
     local _channel