Rewritten main function to be as general as it can be

This commit is contained in:
fedora 2019-06-27 02:07:46 +02:00
parent 30b4a2716f
commit e5a90c6df0
Signed by: wanderer
GPG Key ID: 7B28D8DC28BD2388

@ -3,24 +3,39 @@
if [ $# -ne 1 ]; then
printf "createarchive\n"
printf "usage: createarchive <folder to be archived>\n"
printf "warning: the archive will be moved to pwd (`pwd`)\n"
printf "warning: the archive will be moved to "backups" directory (`echo $dest`)\n"
exit 1
fi
# what this does in short: tar, compress, timestamp, shred the tar, mv .xz to pwd and display it
logdate="$(date +%Y%m%dT%H%M%S)"
basedir="$1"
tmpdir=$(mktemp -d "${TMPDIR:-/tmp/}$(basename $0).XXXXXXXXXX")
#/run/user/$(id -u) tmpfs 0700 perms
f="`cd $basedir; pwd | tr '/' ' ' | sed 's/^.* / /' | cut -c2-`" > /dev/null
g="$logdate-$f.tar"
dest=~/MEGAsync/backups
f=$1
thisfunc() {
tar cfv $f.tar $f && xz -vzk9e $f.tar -S .`date +%Y%m%d%H%M%S`.xz && shred -zuv $f.tar && mv $f.tar.xz . && ls -latr | tail -1
doathing() {
cd $basedir/..
tar cfv "$tmpdir/$g" "$f" && \
xz -vzk9e "$tmpdir/$g" -S .xz && \
rsync -avP "$tmpdir/$g.xz" "$dest" && \
shred -zuv "$tmpdir/$g" "$tmpdir/$g.xz" && \
printf "\n"
ls -latr "$dest/$g.xz"
}
thisfunc
if [ `echo $?` -eq 0 ]; then
printf "done\n"
exit 0
if [ ! -d $1 ]; then
echo "$1 is not a directory"
exit 1
else
printf "there were some errors\n"
exit 1
echo `pwd`
echo "$f"
echo "$1"
doathing
trap "rm -rfv $tmpdir" 0 1 3 15
exit $?
fi