2022-12-04 22:47:16 +01:00
|
|
|
#!/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"`
|
|
|
|
|
2022-12-04 23:33:05 +01:00
|
|
|
if [ ! -f "$COOKIE_FILE" ]; then
|
|
|
|
$COOKIE_FILE=""
|
2022-12-04 22:47:16 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -f "$ID_FILE" ]; then
|
|
|
|
echo "$ID_FILE does not exist, exiting"
|
|
|
|
exit -1
|
|
|
|
fi
|
|
|
|
|
|
|
|
while read id; do
|
2022-12-04 23:33:05 +01:00
|
|
|
outfile=`HEDGEDOC_SERVER="$SERVER" HEDGEDOC_COOKIES_FILE="$COOKIE_FILE" hedgedoc export --md "$id"`
|
2022-12-09 20:53:17 +01:00
|
|
|
if [ "$?" == "0" ]; then
|
|
|
|
echo "$outfile"
|
|
|
|
git add "$outfile"
|
|
|
|
fi
|
2022-12-04 22:47:16 +01:00
|
|
|
done < "$ID_FILE"
|
|
|
|
|
|
|
|
DATE=`date --utc +"%Y%m%d_%H%M"`
|
|
|
|
git commit -m "note backup $DATE (utc)"
|
|
|
|
git push
|