File dokuwiki_cleanup.sh of Package dokuwiki

#!/bin/bash

CONFIG_FILE='/etc/sysconfig/dokuwiki'

function cleanup()
{
    local data_path="$1"        # full path to data directory of wiki
    local retention_days="$2"   # number of days after which old files are to be removed
 
    # purge files older than ${retention_days} days from attic and media_attic (old revisions)
    find "${data_path}"/{media_,}attic/ -type f -mtime +${retention_days} -delete
 
    # remove stale lock files (files which are 1-2 days old)
    find "${data_path}"/locks/ -name '*.lock' -type f -mtime +1 -delete
 
    # remove empty directories
    find "${data_path}"/{attic,cache,index,locks,media,media_attic,media_meta,meta,pages,tmp}/ \
        -mindepth 1 -type d -empty -delete
 
    # remove files older than ${retention_days} days from the cache
    if [ -e "${data_path}/cache/?/" ]
    then
        find "${data_path}"/cache/?/ -type f -mtime +${retention_days} -delete
    fi
}

if [ -r "$CONFIG_FILE" ]; then
   source /etc/sysconfig/dokuwiki
else
   echo "error: could not source $CONFIG_FILE"
   exit 1
fi

# cleanup DokuWiki installations (path to datadir, number of days)
# some examples:

for dir in $DOKUWIKI_DATA_PATH ; do
   if ! ( [ -d "$dir" ] && [ -r "$dir" ] ); then
      echo "error: $dir is not a directory. Skipping."
   elif ! [[ "$DOKUWIKI_REMOVE_OLDER_THAN_DAYS" =~ ^[0-9][0-9]*$ ]] ; then
      echo "error: DOKUWIKI_REMOVE_OLDER_THAN_DAYS is not a number."
      exit 1
   else
      cleanup $DOKUWIKI_DATA_PATH $DOKUWIKI_REMOVE_OLDER_THAN_DAYS
   fi
done
openSUSE Build Service is sponsored by