37
This commit is contained in:
parent
0b7995bb9c
commit
3fbd791dfb
@ -25,12 +25,9 @@ fi
|
|||||||
|
|
||||||
FILENAME="/storage/collect-clish-scripts.sh"
|
FILENAME="/storage/collect-clish-scripts.sh"
|
||||||
|
|
||||||
which curl_cli >/dev/null 2>&1 && CURL="curl_cli"
|
CA_CERT_BUNDLE_PATH="/pfrm2.0/opt/fw1/bin/ca-bundle.crt"
|
||||||
which curl >/dev/null 2>&1 && CURL="curl"
|
SSL_CERT_FILE="${CA_CERT_BUNDLE_PATH}"
|
||||||
|
|
||||||
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 collect() {
|
function collect() {
|
||||||
START_EXECUTION_TIME=$( date +"%Y_%m_%d_%H_%M_%SS" )
|
START_EXECUTION_TIME=$( date +"%Y_%m_%d_%H_%M_%SS" )
|
||||||
@ -86,7 +83,7 @@ function collect() {
|
|||||||
|
|
||||||
echo "Starting to work on: \"${file}\" at: $( date +"%Y_%m_%d_%H_%M_%SS" ) , Execution count: ${count}" |tee -a "${ARCHIVE_PATH}/${START_EXECUTION_DATE}/execution.log"
|
echo "Starting to work on: \"${file}\" at: $( date +"%Y_%m_%d_%H_%M_%SS" ) , Execution count: ${count}" |tee -a "${ARCHIVE_PATH}/${START_EXECUTION_DATE}/execution.log"
|
||||||
echo "Starting to work on: \"${file}\" at: $( date +"%Y_%m_%d_%H_%M_%SS" ) , Execution count: ${count}" |logger
|
echo "Starting to work on: \"${file}\" at: $( date +"%Y_%m_%d_%H_%M_%SS" ) , Execution count: ${count}" |logger
|
||||||
clish -f "${file}"
|
su - "admin" -c "/pfrm2.0/bin/clish -f \"${file}\""
|
||||||
mv -v "${file}" "${ARCHIVE_PATH}/${START_EXECUTION_DATE}/${count}.clish_${START_EXECUTION_TIME}"
|
mv -v "${file}" "${ARCHIVE_PATH}/${START_EXECUTION_DATE}/${count}.clish_${START_EXECUTION_TIME}"
|
||||||
echo "Finished working on: \"${file}\" , Exit Code: $? , at: $( date +"%Y_%m_%d_%H_%M_%SS" ) , Execution count: ${count}" |tee -a "${ARCHIVE_PATH}/${START_EXECUTION_DATE}/execution.log"
|
echo "Finished working on: \"${file}\" , Exit Code: $? , at: $( date +"%Y_%m_%d_%H_%M_%SS" ) , Execution count: ${count}" |tee -a "${ARCHIVE_PATH}/${START_EXECUTION_DATE}/execution.log"
|
||||||
echo "Finished working on: \"${file}\" , Exit Code: $? , at: $( date +"%Y_%m_%d_%H_%M_%SS" ) , Execution count: ${count}" |logger
|
echo "Finished working on: \"${file}\" , Exit Code: $? , at: $( date +"%Y_%m_%d_%H_%M_%SS" ) , Execution count: ${count}" |logger
|
||||||
@ -111,16 +108,16 @@ do
|
|||||||
if [ "${RUN_AS_A_FUNCTION}" -eq "1" ];then
|
if [ "${RUN_AS_A_FUNCTION}" -eq "1" ];then
|
||||||
collect
|
collect
|
||||||
else
|
else
|
||||||
/bin/bash /storage/collect-clish-scripts.sh >/dev/null 2>&1
|
su - admin -c "/bin/bash /storage/collect-clish-scripts.sh >/dev/null 2>&1"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
sleep 5
|
sleep 5
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
REMOTE_ETAG=$(${CURL} -s -I "${URL}" |grep "Etag" -i |head -1 |awk '{print $2}'|sed -e "s@\"@@")
|
REMOTE_ETAG=$( curl_cli -s --cacert "${SSL_CERT_FILE}" -I "${URL}" |grep "Etag" -i |head -1 |awk '{print $2}'|sed -e "s@\"@@" )
|
||||||
if [ "${CURRENT_ETAG}" != "${REMOTE_ETAG}" ];then
|
if [ "${CURRENT_ETAG}" != "${REMOTE_ETAG}" ];then
|
||||||
${CURL} -s "${URL}" -o "${TMP_REMOTE_IN_FILE}"
|
curl_cli -s --cacert "${SSL_CERT_FILE}""${URL}" -o "${TMP_REMOTE_IN_FILE}"
|
||||||
REMOTE_MD5=$( md5sum "${TMP_REMOTE_IN_FILE}" |awk '{print $1}' )
|
REMOTE_MD5=$( md5sum "${TMP_REMOTE_IN_FILE}" |awk '{print $1}' )
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -134,7 +131,7 @@ do
|
|||||||
if [ "${RUN_AS_A_FUNCTION}" -eq "1" ];then
|
if [ "${RUN_AS_A_FUNCTION}" -eq "1" ];then
|
||||||
collect
|
collect
|
||||||
else
|
else
|
||||||
/bin/bash /storage/collect-clish-scripts.sh >/dev/null 2>&1
|
su - admin -c "/bin/bash /storage/collect-clish-scripts.sh >/dev/null 2>&1"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
sleep 5
|
sleep 5
|
||||||
|
@ -1,6 +1,25 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
FORCE_ADMIN_USER="1"
|
||||||
|
|
||||||
|
if [ "${FORCE_ADMIN_USER}" -eq "1" ];then
|
||||||
|
if [ "${USER}" != "admin" ]; then
|
||||||
|
echo "Switching to admin user"
|
||||||
|
exec su "admin" "$0" -- "$@"
|
||||||
|
exit $?
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
FLAGS_PREFIX="/tmp/dst-dom-script-flag_"
|
FLAGS_PREFIX="/tmp/dst-dom-script-flag_"
|
||||||
|
WORK_DIR="/tmp/dst-dom-script"
|
||||||
|
|
||||||
|
mkdir -vp "${WORK_DIR}"
|
||||||
|
cd "${WORK_DIR}"
|
||||||
|
|
||||||
|
export CPDIR=/opt/fw1
|
||||||
|
export FWDIR=${CPDIR}
|
||||||
|
export SUROOT=/var/suroot
|
||||||
|
. /pfrm2.0/etc/bashrc
|
||||||
|
|
||||||
if [ -f "${FLAGS_PREFIX}unsetx" ];then
|
if [ -f "${FLAGS_PREFIX}unsetx" ];then
|
||||||
set -x
|
set -x
|
||||||
@ -13,12 +32,11 @@ REGEX_FLAG_ENABLED="0"
|
|||||||
LOCK_FILE="/tmp/dst-domain-cron-lockfile"
|
LOCK_FILE="/tmp/dst-domain-cron-lockfile"
|
||||||
DUMP_ENV="/tmp/env_cd5fecd5-7123-4a21-bd02-242f1d695a6d"
|
DUMP_ENV="/tmp/env_cd5fecd5-7123-4a21-bd02-242f1d695a6d"
|
||||||
|
|
||||||
export CA_CERT_BUNDLE_PATH="/pfrm2.0/opt/fw1/bin/ca-bundle.crt"
|
CA_CERT_BUNDLE_PATH="/pfrm2.0/opt/fw1/bin/ca-bundle.crt"
|
||||||
export SSL_CERT_FILE="${CA_CERT_BUNDLE_PATH}"
|
SSL_CERT_FILE="${CA_CERT_BUNDLE_PATH}"
|
||||||
#alias curl_cli="curl_cli --cacert ${CA_CERT_BUNDLE_PATH}"
|
|
||||||
|
|
||||||
if [ -f "${LOCK_FILE}" ];then
|
if [ -f "${LOCK_FILE}" ];then
|
||||||
echo "Lockfile exits, stopping update"
|
echo "Lockfile \"${LOCK_FILE}\" exits, stopping update"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -30,6 +48,7 @@ fi
|
|||||||
|
|
||||||
if [ -f "${FLAGS_PREFIX}dry-run" ];then
|
if [ -f "${FLAGS_PREFIX}dry-run" ];then
|
||||||
DRY_RUN="1"
|
DRY_RUN="1"
|
||||||
|
echo "Runnning dry run"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -f "${FLAGS_PREFIX}cleanup-after" ];then
|
if [ -f "${FLAGS_PREFIX}cleanup-after" ];then
|
||||||
@ -121,9 +140,8 @@ fi
|
|||||||
|
|
||||||
TMP_DOWNLOAD_FILE=$(mktemp)
|
TMP_DOWNLOAD_FILE=$(mktemp)
|
||||||
|
|
||||||
/opt/fw1/bin/curl_cli --cacert "${CA_CERT_BUNDLE_PATH}" -s "${URL}" -o "${TMP_DOWNLOAD_FILE}"
|
/opt/fw1/bin/curl_cli -s --cacert "${SSL_CERT_FILE}" "${URL}" -o "${TMP_DOWNLOAD_FILE}" >> /tmp/log.1
|
||||||
RES=$?
|
RES="$?"
|
||||||
|
|
||||||
if [ "${RES}" -gt "0" ];then
|
if [ "${RES}" -gt "0" ];then
|
||||||
echo "Error Downloading file from URL: \"${URL}\""
|
echo "Error Downloading file from URL: \"${URL}\""
|
||||||
logger "Error Downloading file from URL: \"${URL}\""
|
logger "Error Downloading file from URL: \"${URL}\""
|
||||||
@ -140,11 +158,13 @@ TMP_CLISH_TRANSACTION_FILE=$( mktemp )
|
|||||||
|
|
||||||
TMP_DIFF_FILE=$( mktemp )
|
TMP_DIFF_FILE=$( mktemp )
|
||||||
|
|
||||||
#clish -c "show configuration"|egrep "^set application application-name \"${APP_NAME}\"" > ${TMP_CURRENT_CONFIG_FILE}
|
|
||||||
|
|
||||||
TMP_CURRENT_APP_CONTENT_FILE=$( mktemp )
|
TMP_CURRENT_APP_CONTENT_FILE=$( mktemp )
|
||||||
|
|
||||||
clish -c "show application application-name \"${APP_NAME}\"" | sed -e "s@^description.*@@g" \
|
APP_DETAILS=$( clish -c "show application application-name ${APP_NAME}" )
|
||||||
|
echo "$? exit code from clish -c \"show application application-name ${APP_NAME}\""
|
||||||
|
|
||||||
|
echo "${APP_DETAILS}" | sed -e "s@^description.*@@g" \
|
||||||
|
-e "s@.*Role\ is\ not\ assigned\ to\ user.*@@g" \
|
||||||
-e "s@^application\-name\:.*@@g" \
|
-e "s@^application\-name\:.*@@g" \
|
||||||
-e "s@^application\-id\:.*@@g" \
|
-e "s@^application\-id\:.*@@g" \
|
||||||
-e "s@^Categories\:.*@@g" \
|
-e "s@^Categories\:.*@@g" \
|
||||||
@ -152,8 +172,12 @@ clish -c "show application application-name \"${APP_NAME}\"" | sed -e "s@^descri
|
|||||||
-e 's@^[ \t]\+@@g' \
|
-e 's@^[ \t]\+@@g' \
|
||||||
-e '/^$/ d' > ${TMP_CURRENT_APP_CONTENT_FILE}
|
-e '/^$/ d' > ${TMP_CURRENT_APP_CONTENT_FILE}
|
||||||
|
|
||||||
CURRENT_APP_CONTENT_REGEX=$( cat ${TMP_CURRENT_APP_CONTENT_FILE} |sort )
|
CURRENT_APP_CONTENT_REGEX=$( cat "${TMP_CURRENT_APP_CONTENT_FILE}" |sort )
|
||||||
REMOTE_APP_CONTENT_REGEX=$( mktemp )
|
REMOTE_APP_CONTENT_REGEX=$( mktemp )
|
||||||
|
echo "${CURRENT_APP_CONTENT_REGEX}" > "${TMP_CURRENT_APP_CONTENT_FILE}"
|
||||||
|
|
||||||
|
comp_start=`date +%s`
|
||||||
|
echo "Compiling APP_REGEX started at: ${comp_start}"
|
||||||
|
|
||||||
while IFS= read -r line
|
while IFS= read -r line
|
||||||
do
|
do
|
||||||
@ -167,7 +191,12 @@ do
|
|||||||
|
|
||||||
done < ${TMP_DOWNLOAD_FILE}
|
done < ${TMP_DOWNLOAD_FILE}
|
||||||
|
|
||||||
SORTED_REMOTE_APP_CONTENT_REGEX=$( cat ${REMOTE_APP_CONTENT_REGEX}| sort| uniq )
|
comp_end=`date +%s`
|
||||||
|
comp_runtime=$( echo "$comp_end - $comp_start" | bc -l )
|
||||||
|
|
||||||
|
echo "FINISHED Compiling APP_REGEX finished at: ${comp_end} , Took: ${comp_runtime} Seconds"
|
||||||
|
|
||||||
|
SORTED_REMOTE_APP_CONTENT_REGEX=$( cat "${REMOTE_APP_CONTENT_REGEX}" | sort| uniq )
|
||||||
echo "${SORTED_REMOTE_APP_CONTENT_REGEX}" > "${REMOTE_APP_CONTENT_REGEX}"
|
echo "${SORTED_REMOTE_APP_CONTENT_REGEX}" > "${REMOTE_APP_CONTENT_REGEX}"
|
||||||
|
|
||||||
DIFF=$( diff "${TMP_CURRENT_APP_CONTENT_FILE}" "${REMOTE_APP_CONTENT_REGEX}" |sed -e "1,3d;" )
|
DIFF=$( diff "${TMP_CURRENT_APP_CONTENT_FILE}" "${REMOTE_APP_CONTENT_REGEX}" |sed -e "1,3d;" )
|
||||||
@ -191,6 +220,9 @@ sed -i -e 's@\\@\\\\\\@g' "${TMP_CLISH_TRANSACTION_FILE}"
|
|||||||
|
|
||||||
if [ "${DRY_RUN}" -eq "0" ];then
|
if [ "${DRY_RUN}" -eq "0" ];then
|
||||||
clish -f "${TMP_CLISH_TRANSACTION_FILE}"
|
clish -f "${TMP_CLISH_TRANSACTION_FILE}"
|
||||||
|
echo "$? exit code from clish -f"
|
||||||
|
else
|
||||||
|
echo "Running in DRY-RUN MODE"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Finished Transaction"
|
echo "Finished Transaction"
|
||||||
|
Loading…
Reference in New Issue
Block a user