From 489adc762e23363077154794dcda0e4f1f1353e5 Mon Sep 17 00:00:00 2001
From: Santiago Lo Coco <santilococo.01@gmail.com>
Date: Wed, 5 Jan 2022 14:25:32 -0300
Subject: [PATCH] Distinguish between oneshot and simple services

---
 install.sh | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/install.sh b/install.sh
index 74c16e3..220e129 100755
--- a/install.sh
+++ b/install.sh
@@ -376,7 +376,7 @@ updateMirrors() {
         countriesFmt=$(echo "$countries" | sed -r 's/" "/,/g')
         reflector --country \"${countriesFmt//\"/}\" --protocol https --sort rate --save /etc/pacman.d/mirrorlist 2>&1 | debug
     else
-        checkForSystemdUnit "mirrors update" "reflector.service"
+        checkForSystemdUnit "mirrors update" "reflector.service" "oneshot"
     fi
 }
 
@@ -454,15 +454,21 @@ getDotfiles() {
 
 checkForSystemdUnit() {
     trap 'systemctl stop ${2}; forceExit=true' INT
-    systemctl is-active --quiet ${2}
-    [ $? -eq 0 ] && return
     forceExit=false
     calcWidthAndRun "whiptail --infobox \"Waiting for the ${1} to finish. Please wait.\" 7 WIDTH"
-    systemctl is-active --quiet ${2}
-    while [ $? -ne 0 ] && [ $forceExit = false ]; do
-        sleep 1
+    if [ "${3}" = "oneshot" ]; then
         systemctl is-active --quiet ${2}
-    done
+        while [ $? -ne 0 ] && [ $forceExit = false ]; do
+            sleep 1
+            systemctl is-active --quiet ${2}
+        done
+    else
+        while [ $forceExit = false ]; do
+            result=$(systemctl show -p ActiveState --value ${2})
+            [ "$result" = "activating" ] && break
+            sleep 1
+        done
+    fi
     trap - INT
 }