#!/usr/bin/env bash working_dir="$(dirname $(realpath $0))" conf_file="${working_dir}/conf/cleanup_drupal_cache_watchdog.conf" log_file="$(mktemp)" #--------------------------------------- #----------------------------- # Base Function(s) #----------------------------- #--------------------------------------- clean_up() { # Perform program exit housekeeping rm -f $log_file exit $1 } echononl(){ if $terminal ; then echo X\\c > /tmp/shprompt$$ if [ `wc -c /tmp/shprompt$$ | awk '{print $1}'` -eq 1 ]; then echo -e -n "$*\\c" 1>&2 else echo -e -n "$*" 1>&2 fi rm /tmp/shprompt$$ fi } fatal (){ echo "" echo "" if $terminal ; then echo -e "\t[ \033[31m\033[1mFatal\033[m ]: \033[37m\033[1m$*\033[m" echo "" echo -e "\t\033[31m\033[1m Firewall Script will be interrupted..\033[m\033[m" else echo " [ Fatal ]: $*" echo "" echo " Script was terminated...." fi rm -f $log_file echo "" clean_up 1 } error(){ echo "" if $terminal ; then echo -e "\t[ \033[31m\033[1mFehler\033[m ]: $*" else echo "Error: $*" fi echo "" } warn (){ echo "" if $terminal ; then echo -e "\t[ \033[33m\033[1mWarning\033[m ]: $*" else echo "Warning: $*" fi echo "" } info (){ echo "" if $terminal ; then echo -e "\t[ \033[32m\033[1mInfo\033[m ]: $*" else echo "Info: $*" fi echo "" } echo_done() { if $terminal ; then echo -e "\033[75G[ \033[32mdone\033[m ]" else if $LOGGING ; then echo " [ done ]" fi fi } echo_ok() { if $terminal ; then echo -e "\033[75G[ \033[32mok\033[m ]" else if $LOGGING ; then echo " [ ok ]" fi fi } echo_warning() { if $terminal ; then echo -e "\033[75G[ \033[33m\033[1mwarn\033[m ]" else if $LOGGING ; then echo " [ warning ]" fi fi } echo_failed(){ if $terminal ; then echo -e "\033[75G[ \033[1;31mfailed\033[m ]" else if $LOGGING ; then echo ' [ failed! ]' fi fi } echo_skipped() { if $terminal ; then echo -e "\033[75G[ \033[37mskipped\033[m ]" else if $LOGGING ; then echo " [ skipped ]" fi fi } # - Running in a terminal? # - if [[ -t 1 ]] ; then terminal=true LOGGING=true else terminal=false LOGGING=false fi if $LOGGING ; then echo "" fi echononl " Load configuration file.." if [[ ! -f "$conf_file" ]]; then echo_failed fatal "Configuration file \033[37m\033[1m$(basename ${conf_file})\033[m not found!" else source "${conf_file}" > $log_file 2>&1 if [[ $? -eq 0 ]]; then echo_ok else echo_failed fatal "$(cat $log_file)" fi fi if [[ -z "$DRUPAL_ROOT_DIR" ]]; then fatal "No drupal root dir given (DRUPAL_ROOT_DIR)" fi for _drupal_dir in $DRUPAL_ROOT_DIR ; do cd $_drupal_dir ## - Cleanup ALL cache ## - echononl " Cleaning up ALL cache.." drush cc all > $log_file 2>&1 if [[ $? -eq 0 ]]; then echo_ok else echo_failed error "$(cat $log_file)" fi ## - Delete all watchdog table-entries ## - echononl " Deleting all watchdog table-entries.." drush -y watchdog-delete all > $log_file 2>&1 if [[ $? -eq 0 ]]; then echo_ok else echo_failed error "$(cat $log_file)" fi done if $LOGGING ; then echo "" fi clean_up