snippets/hedgebak
2022-12-09 20:53:17 +01:00

50 lines
1015 B
Bash
Executable File

#!/bin/bash
# uses https://github.com/hedgedoc/cli to download notes as markdown and commit them to a
# git repo
#
# mandatory files in pwd:
# .hedgeserver - the URL of the hedgedoc instance
# .hedgebak - note IDs to back up
# optional:
# .hedgecookie - cookie to use (e.g. for owner-accessible notes)
set -eu
ID_FILE=.hedgebak
SERVER_FILE=.hedgeserver
COOKIE_FILE=.hedgecookie
if [ ! -d ".git" ]; then
echo "not a git repo, exiting"
exit -1
fi
if [ ! -f "$SERVER_FILE" ]; then
echo "$SERVER_FILE does not exist, exiting"
exit -1
fi
SERVER=`cat "$SERVER_FILE"`
if [ ! -f "$COOKIE_FILE" ]; then
$COOKIE_FILE=""
fi
if [ ! -f "$ID_FILE" ]; then
echo "$ID_FILE does not exist, exiting"
exit -1
fi
while read id; do
outfile=`HEDGEDOC_SERVER="$SERVER" HEDGEDOC_COOKIES_FILE="$COOKIE_FILE" hedgedoc export --md "$id"`
if [ "$?" == "0" ]; then
echo "$outfile"
git add "$outfile"
fi
done < "$ID_FILE"
DATE=`date --utc +"%Y%m%d_%H%M"`
git commit -m "note backup $DATE (utc)"
git push