Skip to content

Instantly share code, notes, and snippets.

@Marwe
Created November 16, 2021 01:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Marwe/66c6eef9568b2b949707d10a28e0c495 to your computer and use it in GitHub Desktop.
Save Marwe/66c6eef9568b2b949707d10a28e0c495 to your computer and use it in GitHub Desktop.
hedgedoc zip backup postprocessing
#!/bin/bash
trgd="./hedgedocpads/"
usage(){
echo "$0 path/to/archive.zip [targetdir (default: $trgd)"
echo "Download archive.zip from hedgedoc, see dropdown on login name, URL is https://hedgedocdomain.tld/me/export"
}
fd2nbin=$(which filedate2nameprefix.sh)
if [ -z "$fd2nbin" ] ; then
fd2nbin="$(dirname $0)/filedate2nameprefix.sh"
if [ ! -x "$fd2nbin" ] ; then
echo "error: filedate2nameprefix.sh not found in \$PATH or $fd2nbin"
exit 1
fi
fi
if [ -z "$1" ] ; then
usage
exit 1
fi
if [ -n "$2" ] ; then
trgd="$2"
fi
mkdir -p "$trgd"
if [ ! -d "$trgd" ] ; then
echo "error: target dir $trgd does not exist"
usage
exit 1
fi
pushd "$trgd"
tmpd=$(mktemp -d --tmpdir pads_hedgedoc.XXXX)
echo "working in $tmpd"
if [ -f "$1" ] ; then
unzip -d "$tmpd" "$1"
else
"$1 file does not exist"
exit 1
fi
pushd "$tmpd"
detox -- *
find . -empty -delete
filedate2nameprefix.sh *
popd
cp -u -- "$tmpd"/* .
read -p "download images from uploads? [y/N]" ans
if [ "$ans" == "y" ] ; then
mkdir -p uploads
grep -h -o 'https*://[^/]*/uploads/upload_[a-z0-9]*\....' *.md | xargs -r wget -c --directory-prefix=uploads
sed -i -e 's#https*://[^/]*/uploads/#uploads/#g' *.md
fi
echo "the following filenames are the same (apart from date), you may possibly want to merge them:"
for i in $(ls | sed -e 's/^[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}_//'| sort | uniq -d)
do
echo "---"
ls *"$i"
done
popd
echo "results in $trgd"
@Marwe
Copy link
Author

Marwe commented Nov 16, 2021

filedate2nameprefix.sh is a separate script:
https://gist.github.com/Marwe/25e67c0cd5b4b849f90e40cca8cce68e

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment