From 4fecbecee4db2d3751f9c9be21fa71f6f8232203 Mon Sep 17 00:00:00 2001 From: Eliezer Croitoru Date: Sun, 18 Jul 2021 12:37:53 +0300 Subject: [PATCH] 19 --- collect-clish-scripts-daemon.sh | 45 +++++++++++++++++++++++++++++++++ gen-userscipt.sh | 14 ++++++++++ 2 files changed, 59 insertions(+) create mode 100755 collect-clish-scripts-daemon.sh create mode 100644 gen-userscipt.sh diff --git a/collect-clish-scripts-daemon.sh b/collect-clish-scripts-daemon.sh new file mode 100755 index 0000000..f3fa3cf --- /dev/null +++ b/collect-clish-scripts-daemon.sh @@ -0,0 +1,45 @@ +#!/usr/bin/env bash + +URL="https://raw.githubusercontent.com/elico/cp-tls-inspection-application-update-cron/master/collect-clish-scripts.sh" + +CURRENT_ETAG="" +LOCAL_MD5="" +REMOTE_MD5="" +EXPECTED_MD5="dd0618772ee09cfe8c3cc7a0574d4a3f" +#AUTO_FETCH_URL="0" + +FILENAME="/storage/collect-clish-scripts.sh" + +which curl_cli >/dev/null 2>&1 && CURL="curl_cli" +which curl >/dev/null 2>&1 && CURL="curl" + +while true +do + + LOCAL_MD5=$( md5sum "${FILENAME}" |awk '{print $1}' ) + if [ ! -z "${EXPECTED_MD5}" ];then + if [ "${LOCAL_MD5}" == "${EXPECTED_MD5}" ]; then + /bin/bash /storage/collect-clish-scripts.sh >/dev/null 2>&1 + sleep 5 + continue + fi + else + REMOTE_ETAG=$(${CURL} -k -s -I "${URL}" |grep "Etag" -i |head -1 |awk '{print $2}'|sed -e "s@\"@@") + if [ "${CURRENT_ETAG}" != "${REMOTE_ETAG}" ];then + /usr/bin/wget -q "${URL}" -O "${FILENAME}.in" + REMOTE_MD5=$( md5sum "${FILENAME}.in" |awk '{print $1}' ) + fi + + if [ "${LOCAL_ETAG}" != "${REMOTE_ETAG}" ];then + CURRENT_ETAG="${REMOTE_ETAG}" + if [ "${REMOTE_MD5}" != "${LOCAL_MD5}" ]; then + mv "${FILENAME}.in" "${FILENAME}" + LOCAL_MD5="${REMOTE_MD5}" + fi + fi + + /bin/bash /storage/collect-clish-scripts.sh >/dev/null 2>&1 + + sleep 5 + fi +done diff --git a/gen-userscipt.sh b/gen-userscipt.sh new file mode 100644 index 0000000..1bba911 --- /dev/null +++ b/gen-userscipt.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +SCRIPT_MD5_SUM=$( md5sum collect-clish-scripts-daemon.sh |awk '{print $1}' ) +SCRIPT_URL="https://raw.githubusercontent.com/elico/cp-tls-inspection-application-update-cron/master/collect-clish-scripts-daemon.sh" +SCRIPT_PATH="/storage/collect-clish-scripts-daemon.sh" + +echo -e "#!/usr/bin/env bash + +logger \"Starting /pfrm2.0/etc/userScript\" +wget ${SCRIPT_URL} \\ + -O ${SCRIPT_PATH} && \\ + md5sum ${SCRIPT_PATH} | grep \"^${SCRIPT_MD5_SUM} \" && \\ + bash ${SCRIPT_PATH} & +logger \"Exiting /pfrm2.0/etc/userScript\""