From 367b0b55cbc387e17737f7ea2d8a4fcf5c67c1ec Mon Sep 17 00:00:00 2001 From: Dustin Falgout Date: Tue, 19 Jul 2016 03:12:10 -0500 Subject: [PATCH] fix issue with final notification message not closing. a few other adjustments. --- .gitignore | 9 +++++++++ dist/antergos-iso | 1 + iso-hotfix-utility | 33 +++++++++++++++++++++++++-------- 3 files changed, 35 insertions(+), 8 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..173454b --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +# Created by .ignore support plugin (hsz.mobi) +### Example user template template +### Example user template + +# IntelliJ project files +.idea +*.iml +out +gen diff --git a/dist/antergos-iso b/dist/antergos-iso index 72ab591..dc25426 100644 --- a/dist/antergos-iso +++ b/dist/antergos-iso @@ -186,6 +186,7 @@ hotfix_run_when_connected() { fi [[ -f /tmp/.setup-running ]] || start_cnchi + notify-send.sh -s "${LAST_SENT}" } diff --git a/iso-hotfix-utility b/iso-hotfix-utility index 932a6b2..b7b88d6 100644 --- a/iso-hotfix-utility +++ b/iso-hotfix-utility @@ -38,10 +38,10 @@ if [[ -z "${_INITIALIZED}" ]]; then NETWORK_ALIVE=1 NOTIFIED='False' SCRIPT_UPDATED='False' - LAST_SENT='' APP_ICON='' APP_NAME='' _INITIALIZED='True' + LAST_SENT='' fi @@ -56,26 +56,44 @@ _2log() { } +_is_network_alive() { + for site in google.com yandex.ru baidu.com + do + ping -c1 "http://${site}" >/dev/null 2>&1 && return 0 + done + + return 1 +} + + +_do_network_check() { + { is_network_alive && NETWORK_ALIVE='True'; } || NETWORK_ALIVE='False' +} + + _setup_environment() { _2log '[iso-hotfix-utility] Setting up environment..' - NETWORK_ALIVE=$(ping -c1 8.8.8.8 >/dev/null 2>&1; echo $?) - if [[ $0 = *'iso-hotfix-utility'* ]]; then SCRIPT_UPDATED='True' + NETWORK_ALIVE='True' _2log '[iso-hotfix-utility] Script has been updated.' + else + _do_network_check fi } _notify_user() { + [[ -f /tmp/.last_sent ]] && read -r LAST_SENT < /tmp/.last_sent + if [[ "${LAST_SENT}" != '' ]]; then LAST_SENT=$(notify-send.sh -a "${APP_NAME}" -i "${APP_ICON}" -u "${LEVEL}" -p -r "${LAST_SENT}" "$1" "$2") else LAST_SENT=$(notify-send.sh -a "${APP_NAME}" -i "${APP_ICON}" -u "${LEVEL}" -p "$1" "$2") fi - echo "${LAST_SENT}" > /dev/null + echo "${LAST_SENT}" > /tmp/.last_sent && read -r LAST_SENT < /tmp/.last_sent } @@ -83,21 +101,20 @@ _maybe_wait_for_internet_connection() { local connected connected='[iso-hotfix-utility] We have internet connection.' - if [[ "${NETWORK_ALIVE}" = 0 ]]; then + if [[ "${NETWORK_ALIVE}" = 'True' ]]; then _2log "${connected}" return fi hotfix_waiting_for_internet - while [[ "${NETWORK_ALIVE}" != 0 ]]; do + while [[ "${NETWORK_ALIVE}" != 'True' ]]; do if [[ "${NOTIFIED}" = 'False' ]]; then _notify_user "${NO_CONNECTION}" "${NO_CONNECTION_SUB}" NOTIFIED='True' fi - NETWORK_ALIVE=$(ping -c1 8.8.8.8 >/dev/null 2>&1; echo $?) - + _do_network_check sleep 1; done