瀏覽代碼

[Update] Check mulitple IPs

andryyy 5 年之前
父節點
當前提交
7c40943e3f
共有 1 個文件被更改,包括 12 次插入3 次删除
  1. 12 3
      update.sh

+ 12 - 3
update.sh

@@ -41,7 +41,17 @@ export LC_ALL=C
 DATE=$(date +%Y-%m-%d_%H_%M_%S)
 DATE=$(date +%Y-%m-%d_%H_%M_%S)
 BRANCH=$(git rev-parse --abbrev-ref HEAD)
 BRANCH=$(git rev-parse --abbrev-ref HEAD)
 
 
-function prefetch_images() {
+check_online_status() {
+  CHECK_ONLINE_IPS=(1.1.1.1 9.9.9.9 8.8.8.8)
+  for ip in "${CHECK_ONLINE_IPS[@]}"; do
+    if timeout 3 ping -c 1 ${ip} > /dev/null; then
+      return 0
+    fi
+  done
+  return 1
+}
+
+prefetch_images() {
   [[ -z ${BRANCH} ]] && { echo -e "\e[33m\nUnknown branch...\e[0m"; exit 1; }
   [[ -z ${BRANCH} ]] && { echo -e "\e[33m\nUnknown branch...\e[0m"; exit 1; }
   git fetch origin #${BRANCH}
   git fetch origin #${BRANCH}
   while read image; do
   while read image; do
@@ -363,8 +373,7 @@ for option in ${CONFIG_ARRAY[@]}; do
 done
 done
 
 
 echo -en "Checking internet connection... "
 echo -en "Checking internet connection... "
-timeout 3 ping -c 1 9.9.9.9 > /dev/null
-if [[ $? != 0 ]]; then
+if ! check_online_status; then
   echo -e "\e[31mfailed\e[0m"
   echo -e "\e[31mfailed\e[0m"
   exit 1
   exit 1
 else
 else