diff --git a/add-autogen-crons.sh b/add-autogen-crons.sh new file mode 100755 index 0000000..a3b3f78 --- /dev/null +++ b/add-autogen-crons.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +CRON_FILE="/pfrm2.0/etc/crontabs/root" + +bash remove-autogen-crons.sh + +bash gen-cron-line.sh |tee -a "${CRON_FILE}" >/dev/null diff --git a/block-list-dst-domain-url b/block-list-dst-domain-url index 1e62d48..e16ff1d 100644 --- a/block-list-dst-domain-url +++ b/block-list-dst-domain-url @@ -1 +1 @@ -https://raw.githubusercontent.com/elico/cp-tls-inspection-application-update-cron/master/020-BlockList.dstdom +http://gogs.ngtech.home/elicro/cp-tls-inspection-application-update-cron/raw/master/020-BlockList.dstdom diff --git a/gen-cron-line.sh b/gen-cron-line.sh index ee44db0..87afc6d 100755 --- a/gen-cron-line.sh +++ b/gen-cron-line.sh @@ -1,47 +1,104 @@ #!/usr/bin/env bash -SCRIPT_MD5_SUM=$(md5sum cron-example-with-diff-dstdom.sh|awk '{print $1}') -SCRIPT_URL="https://raw.githubusercontent.com/elico/cp-tls-inspection-application-update-cron/master/cron-example-with-diff-dstdom.sh" -DST_DOMAIN_LIST_URL=$(head -1 dst-domain-url) -APP_NAME="NgTechBypassDstDomain" -SCRIPT_PATH="/storage/cron-example-with-diff-dstdom.sh" +function printTopHeader() { + echo "####### NFGW Auto Genereated CRONS START MARK $(date)" +} -export CA_CERT_BUNDLE_PATH="/pfrm2.0/opt/fw1/bin/ca-bundle.crt" -export SSL_CERT_FILE="${CA_CERT_BUNDLE_PATH}" -#alias curl_cli="curl_cli --cacert ${CA_CERT_BUNDLE_PATH}" +function printButtomHeader() { + echo "####### NFGW Auto Genereated CRONS END MARK $(date)" +} +CA_CERT_BUNDLE_PATH="/pfrm2.0/opt/fw1/bin/ca-bundle.crt" +SSL_CERT_FILE="${CA_CERT_BUNDLE_PATH}" -echo "####" -echo +export CA_CERT_BUNDLE_PATH +export SSL_CERT_FILE -SCRIPT_TMP_PATH="/tmp/cron-example-with-diff-dstdom.sh_73ffe3f6-b85a-46ed-9e11-07865339759c" -echo "*/5 * * * * (/usr/bin/md5sum ${SCRIPT_PATH} | /bin/grep \"^${SCRIPT_MD5_SUM} \") || (curl_cli --cacert ${CA_CERT_BUNDLE_PATH} -s ${SCRIPT_URL} -o ${SCRIPT_TMP_PATH} >/dev/null 2>&1 && /usr/bin/md5sum ${SCRIPT_TMP_PATH} |/bin/grep \"^${SCRIPT_MD5_SUM} \" && mv ${SCRIPT_TMP_PATH} ${SCRIPT_PATH} )" +GOGS_GIT_PREFIX=$( cat gogs_url_prefix ) +GITHUB_GIT_PREFIX=$( cat github_url_prefix ) +GIT_PREFIX="" +if [ -f "use-gogs" ];then + GIT_PREFIX="${GOGS_GIT_PREFIX}" +else + GIT_PREFIX="${GITHUB_GIT_PREFIX}" +fi -echo "####" -echo -echo "*/5 * * * * su - admin -c \"/bin/bash ${SCRIPT_PATH} ${APP_NAME} ${DST_DOMAIN_LIST_URL} >/dev/null 2>&1\"" +DST_DOM_SCRIPT_URL="${GIT_PREFIX}/cron-example-with-diff-dstdom.sh" +DST_DOM_SCRIPT_MD5_SUM=$(md5sum cron-example-with-diff-dstdom.sh|awk '{print $1}') +DST_DOM_SCRIPT_PATH="/storage/cron-example-with-diff-dstdom.sh" +DST_SCRIPT_TMP_PATH="/tmp/cron-example-with-diff-dstdom.sh_73ffe3f6-b85a-46ed-9e11-07865339759c" -echo "####" -echo +function createScriptUpdateCron() { + SCRIPT_PATH="$1" + SCRIPT_MD5_SUM="$2" + SCRIPT_URL="$3" + SCRIPT_TMP_PATH="$4" + echo "#### Update Cron for the script: \"${SCRIPT_PATH}\"" + echo -DST_DOMAIN_LIST_URL=$(head -1 block-list-dst-domain-url) -APP_NAME="NgTechBlockListDstDomain" -echo "*/1 * * * * su - admin -c \"/bin/bash ${SCRIPT_PATH} ${APP_NAME} ${DST_DOMAIN_LIST_URL} >/dev/null 2>&1\"" + echo "*/5 * * * * (/usr/bin/md5sum ${SCRIPT_PATH} | /bin/grep \"^${SCRIPT_MD5_SUM} \") || (curl_cli --cacert ${CA_CERT_BUNDLE_PATH} -s ${SCRIPT_URL} -o ${SCRIPT_TMP_PATH} >/dev/null 2>&1 && /usr/bin/md5sum ${SCRIPT_TMP_PATH} |/bin/grep \"^${SCRIPT_MD5_SUM} \" && mv ${SCRIPT_TMP_PATH} ${SCRIPT_PATH} )" + echo + echo "####" + echo +} -SCRIPT_MD5_SUM=$(md5sum collect-clish-scripts.sh|awk '{print $1}') -SCRIPT_URL="https://raw.githubusercontent.com/elico/cp-tls-inspection-application-update-cron/master/collect-clish-scripts.sh" -SCRIPT_PATH="/storage/collect-clish-scripts.sh" -SCRIPT_TMP_PATH="/tmp/collect-clish-scripts.sh_73ffe3f6-b85a-46ed-9e11-07865339759c" +function createListUpdateCron() { + SCRIPT_PATH="$1" + APP_NAME="$2" + DST_DOMAIN_LIST_URL="$3" -echo "####" -echo + echo "#### Update Cron for the FW APP: \"${APP_NAME}\"" + echo -echo "*/5 * * * * (/usr/bin/md5sum ${SCRIPT_PATH} | /bin/grep \"^${SCRIPT_MD5_SUM} \") || (curl_cli --cacert ${CA_CERT_BUNDLE_PATH} -s ${SCRIPT_URL} -o ${SCRIPT_TMP_PATH} >/dev/null 2>&1 && /usr/bin/md5sum ${SCRIPT_TMP_PATH} |/bin/grep \"^${SCRIPT_MD5_SUM} \" && mv ${SCRIPT_TMP_PATH} ${SCRIPT_PATH} )" + echo "*/5 * * * * su - admin -c \"/bin/bash ${SCRIPT_PATH} ${APP_NAME} ${DST_DOMAIN_LIST_URL} >/dev/null 2>&1\"" -echo "####" -echo + echo + echo "####" + echo +} -echo "*/30 * * * * su - admin -c \"/bin/bash ${SCRIPT_PATH} >/dev/null 2>&1\"" +function createRunScriptAsCron() { + USER="$1" + SCRIPT_PATH="$2" + ALLOW_STDOUT="$3" + + echo "#### Run Cron AS USER: ${USER}" + echo + + if [ "${ALLOW_STDOUT}" -gt "0" ];then + echo "*/30 * * * * su - ${USER} -c \"/bin/bash ${SCRIPT_PATH} >/dev/null 2>&1\"" + else + echo "*/30 * * * * su - ${USER} -c \"/bin/bash ${SCRIPT_PATH}\"" + fi + + echo + echo "####" + echo +} + +printTopHeader + +createScriptUpdateCron "${DST_DOM_SCRIPT_PATH}" "${DST_DOM_SCRIPT_MD5_SUM}" "${DST_DOM_SCRIPT_URL}" "${DST_SCRIPT_TMP_PATH}" + +COLLECT_CLISH_SCRIPT_PATH="/storage/collect-clish-scripts.sh" +COLLECT_CLISH_SCRIPT_MD5_SUM=$(md5sum collect-clish-scripts.sh|awk '{print $1}') + +COLLECT_CLISH_SCRIPT_URL="${GIT_PREFIX}collect-clish-scripts.sh" +COLLECT_CLISH_SCRIPT_TMP_PATH="/tmp/collect-clish-scripts.sh_73ffe3f6-b85a-46ed-9e11-07865339759c" + +createScriptUpdateCron "${COLLECT_CLISH_SCRIPT_PATH}" "${COLLECT_CLISH_SCRIPT_MD5_SUM}" "${COLLECT_CLISH_SCRIPT_URL}" "${COLLECT_CLISH_SCRIPT_TMP_PATH}" + +NgTechBypassDstDomain_APP_NAME="NgTechBypassDstDomain" +NgTechBypassDstDomain_LIST_URL=$( head -1 ngtech-bypass-dstdomains-list-url ) + +createListUpdateCron "${DST_DOM_SCRIPT_PATH}" "${NgTechBypassDstDomain_APP_NAME}" "${NgTechBypassDstDomain_LIST_URL}" + +NgTechBlockListDstDomain_APP_NAME="NgTechBlockListDstDomain" +NgTechBlockListDstDomain_LIST_URL=$(head -1 block-list-dst-domain-url) + +createListUpdateCron "${DST_DOM_SCRIPT_PATH}" "${NgTechBlockListDstDomain_APP_NAME}" "${NgTechBlockListDstDomain_LIST_URL}" + +printButtomHeader diff --git a/gen-userscipt.sh b/gen-userscipt.sh index 6ae04c0..3b286b8 100755 --- a/gen-userscipt.sh +++ b/gen-userscipt.sh @@ -1,7 +1,16 @@ #!/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" + +GOGS_GIT_PREFIX=$( cat gogs_url_prefix ) +GITHUB_GIT_PREFIX=$( github_url_prefix ) + +if [ -f "use-gogs" ];then + SCRIPT_URL="${GOGS_GIT_PREFIX}collect-clish-scripts-daemon.sh" +else + SCRIPT_URL="${GITHUB_GIT_PREFIX}collect-clish-scripts-daemon.sh" +fi + SCRIPT_PATH="/storage/collect-clish-scripts-daemon.sh" USERSCRIPT_PATH="/pfrm2.0/etc/userScript" LOCK_FILE="/tmp/clish-scripts-collector-cron-lockfile" diff --git a/github_url_prefix b/github_url_prefix new file mode 100644 index 0000000..2f309c7 --- /dev/null +++ b/github_url_prefix @@ -0,0 +1 @@ +https://raw.githubusercontent.com/elico/cp-tls-inspection-application-update-cron/master/ diff --git a/gogs_url_prefix b/gogs_url_prefix new file mode 100644 index 0000000..1f48740 --- /dev/null +++ b/gogs_url_prefix @@ -0,0 +1 @@ +http://gogs.ngtech.home/elicro/cp-tls-inspection-application-update-cron/raw/master/ diff --git a/ngtech-bypass-dstdomains-list-url b/ngtech-bypass-dstdomains-list-url new file mode 100644 index 0000000..139c1bc --- /dev/null +++ b/ngtech-bypass-dstdomains-list-url @@ -0,0 +1 @@ +http://gogs.ngtech.home/elicro/cp-tls-inspection-application-update-cron/raw/master/010-GeneralTLSInspectionBypass.dstdom diff --git a/remove-autogen-crons.sh b/remove-autogen-crons.sh new file mode 100755 index 0000000..e43f165 --- /dev/null +++ b/remove-autogen-crons.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +CRON_FILE="/pfrm2.0/etc/crontabs/root" + +sed -i -n '/^####### NFGW Auto Genereated CRONS START MARK/{p; :a; N; /####### NFGW Auto Genereated CRONS END MARK/!ba; s/.*\n//}; p' |sed -e "s@^####### NFGW Auto Genereated CRONS START MARK.*@@g" -e "s@^####### NFGW Auto Genereated CRONS END MARK.*@@g" "${CRON_FILE}" diff --git a/use-gogs b/use-gogs new file mode 100644 index 0000000..e69de29