#!/bin/bash unset DISPLAY; unset LUI; if [ -z "${LOGONROOT}" ]; then echo "parse: unable to determine \$LOGONROOT directory; exit."; exit 1; fi # # include a shared set of shell functions and global parameters, including the # architecture identifier .LOGONOS. # . ${LOGONROOT}/etc/library.bash; tsdb="$LOGONROOT/bin/tsdb" source="--source"; while [ $# -gt 0 -a "${1#-}" != "$1" ]; do case ${1} in --binary) source=""; shift 1; ;; --source) source="--source"; shift 1; ;; -c|--compress) action="compress"; shift 1; ;; -t|--thin) action="thin"; shift 1; ;; --drop) action="drop"; gold=${2}; shift 2; ;; --cat) cat="--cat"; shift 1; ;; *) echo "usage: itsdb { -c | -t } directory; exit."; exit 1; esac done if [ -z "${action}" ]; then echo "usage: itsdb { -c | -t } directory; exit."; exit 1; fi if [ ! -d ${1} ]; then echo "itsdb: invalid or missing directory \`${1}'; exit."; exit 1; fi directory="${1}"; if [ -z "${LOGONLOG}" ]; then LOGONLOG=${LOGONROOT}/log; fi LOG=${LOGONLOG}/itsdb.${date}.log; case "${action}" in compress) tmp="/tmp/.itsdb.tmp.${USER}.$$" find ${directory} -name relations | sed 's@/relations@@g' > ${tmp}.dbs while read i; do ${tsdb} -home "${i}" -query "info relations" \ | egrep '^[a-zA-Z0-9_-]+:$' | sed 's@:$@@g' > ${tmp}.files for j in $(cat ${tmp}.files); do file="${i}/${j}"; if [ -s "${file}" ]; then echo -n "compressing \`${file}' ... "; gzip -f -9 "${file}"; echo "done"; fi done done < ${tmp}.dbs /bin/rm -f ${tmp}.dbs ${tmp}.files ;; drop) tmp="/tmp/.itsdb.tmp.${USER}.$$" ${tsdb} -home "${directory}" -query "info relations" \ | egrep '^[a-zA-Z0-9_-]+:$' | sed 's@:$@@g' > ${tmp} for j in $(cat ${tmp}); do file="${directory}/${j}"; if [ -s ${file}.gz ]; then cat ${file}.gz > ${gold}/${j}.gz; elif [ -f ${file} ]; then cat ${file} > ${gold}/${j}; else echo "itsdb: missing or invalid relation file for \`${j}'; exit." exit 1; fi done /bin/rm -f ${tmp} ;; esac