49 lines
1.0 KiB
Plaintext
49 lines
1.0 KiB
Plaintext
|
#!/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"`
|
||
|
|
||
|
HEDGEDOC_COOKIES_FILE=""
|
||
|
if [ -f "$COOKIE_FILE" ]; then
|
||
|
HEDGEDOC_COOKIES_FILE="$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="$HEDGEDOC_COOKIES_FILE" hedgedoc export --md "$id"`
|
||
|
echo "$outfile"
|
||
|
git add "$outfile"
|
||
|
done < "$ID_FILE"
|
||
|
|
||
|
DATE=`date --utc +"%Y%m%d_%H%M"`
|
||
|
git commit -m "note backup $DATE (utc)"
|
||
|
git push
|