From 3d5c9c2e308123a9d37e7cbab33b854a304bb381 Mon Sep 17 00:00:00 2001 From: Christian Goll Date: Fri, 6 Dec 2019 16:42:28 +0100 Subject: [PATCH 1/2] added of download_js --- download_js.sh | 126 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100755 download_js.sh diff --git a/download_js.sh b/download_js.sh new file mode 100755 index 0000000..67e26fd --- /dev/null +++ b/download_js.sh @@ -0,0 +1,126 @@ +#!/bin/bash +CONFFILE="/srv/www/htdocs/ganglia-web/conf_default.php" +SAVEDIR='/srv/www/htdocs/ganglia-web' +PHPCONFDIR='/etc/apache2/conf.d/' +PHPCONFNAME='conf.php' +TARBALL='/tmp/ajax_ganglia.tar.gz' +RESCRIPT='/tmp/download_js.sh' +SUFFIX='ajax_libs' +TMPDIR='/tmp' + +function get_conf() { +declare -f -F conf_stor > /dev/null +if [ $? -eq 0 ] ; then + conf_stor +else + cat ${CONFFILE} +fi +} + +function usage() { +cat < /dev/null + if [ $? -eq 0 ] ; then + echo "This script was recreated so could not recreate it." + exit 1 + fi + cat << EOF > $RESCRIPT +#!/bin/bash +# this file was recreated on $(uname -n) at $(date) +function conf_stor() { +cat <> $RESCRIPT + cat << EOF >> $RESCRIPT + +ENDCONF +} +EOF + cat $0 | sed -e 's@#!/bin/bash@@' \ + -e 's@usage_set=1@usage_set=0@' \ + -e 's@tarball=0@tarball=1@' >> $RESCRIPT + echo "wrote $RESCRIPT" + exit 0 +fi + + +which curl &> /dev/null || echo "need curl to download ajax libraries" +which curl &> /dev/null || exit 1 + +if [ $tarball -eq 1 ] ; then + test -d ${TMPDIR}/${SUFFIX} || mkdir -vp ${TMPDIR}/${SUFFIX} + PHPCONFFILELOC=${TMPDIR}/${SUFFIX}/${PHPCONFNAME} + cd ${TMPDIR} +else + test -d ${SAVEDIR}/${SUFFIX} || mkdir -vp ${SAVEDIR}/${SUFFIX} + PHPCONFFILELOC=${PHPCONFDIR}/${PHPCONFNAME} + cd ${SAVEDIR} +fi + +for lib_line in $(get_conf | grep -e '^$conf.* = \"https://cdnjs' | tr ' ' '@') ; do + conf_line=$(echo $lib_line | cut -f 1 -d '@') + url=$(echo $lib_line | cut -f 3 -d '@' |tr -d '"' | tr -d ';') + file_name=$(basename $url) + echo -n "getting ${file_name}: " + curl -# $url -o ${SUFFIX}/$file_name + echo "$conf_line = \"${SAVEDIR}/${SUFFIX}/${file_name}\";" >> ${PHPCONFFILELOC} +done +if [ $tarball -eq 1 ] ; then + tar czf ${TARBALL} ${SUFFIX} + echo "created ${TARBALL} , which also contains ${PHPCONFNAME}" +fi +cd - > /dev/null + -- 2.16.4