#!/bin/bash
#
# Name: hs-dump-crontab
# Author: Michael Hierweck
# Contributors: Michael Hierweck
# License: GNU General Public License (GPL) version 2 or later
# Language: bash
# Dependencies: stat, tar, gzip, secat
# Initial Release: 2011-10-15
# Lastest Release: 2011-10-15
#
# hs-dump-crontab dumps crontabs.
# The crontabs are dumped into the .bak directory of the corresponding package.
#

if [ $(ls /home/pacs | wc -l) -gt 0 ]; then
stat --format="%n" /home/pacs/* \
|cut --delimiter="/" --fields=4 \
|sort \
|while read PAC; do
    TAR="/home/pacs/${PAC}/.bak/crontabs.tar.gz"
    (stat --format="%n" "/var/spool/cron/crontabs" "/var/spool/cron/crontabs/${PAC}"*) 2>/dev/null \
    |tar --create --absolute-names --no-recursion --ignore-failed-read --files-from=- \
    |gzip --best \
    |secat --user=${PAC} --group=${PAC} --umask=007 --output=${TAR}
done
fi
