Created
July 18, 2023 14:01
-
-
Save randria/a9d0fb48712ac058f8e4e625ccd8ff6e to your computer and use it in GitHub Desktop.
Backup CodiMD Content
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
# OSX is not a Linux! But bash works on both ;-) | |
if [ $(uname -s) != "Darwin" ]; then | |
echo "** I know you should run this on a Mac :) But it's a bash, so you can adapt it on your risk! **" | |
exit 1 | |
fi | |
# check if it's a git repo | |
if [ ! -d '.git' ]; then | |
echo "** Hey dude! Should this command in a git repo... **" | |
exit 1 | |
fi | |
git stash | |
git pull | |
export HEDGEDOC_SERVER=https://codimd.math.cnrs.fr | |
# attention à bien mettre à jour le fichier des cookies avant d'exécuter le script ! | |
export HEDGEDOC_COOKIES_FILE=${HEDGEDOC_COOKIES_FILE:-./cookies.txt} | |
unset HEDGEDOC | |
hash hedgedoc || exit 1 | |
export HEDGEDOC=$(which hedgedoc) | |
export SHA1SUM=./sha1sum.txt | |
export TEMPFILE="$(mktemp).md" | |
[ ! -f $SHA1SUM ] && find . -type f -iname '*.md' -print0 | xargs -0 shasum -a 1 > $SHA1SUM | |
N=0 | |
for note in $(hedgedoc history --json | jq -r '.history[].id') | |
do | |
title=$(hedgedoc history --json | jq -r ".history[] | select(.id==\"${note}\") | .text" | sed -e 's/ /_/g' -e 's#/#_#g') | |
$HEDGEDOC export --md "$note" "$TEMPFILE" &>/dev/null | |
if [ -f "$TEMPFILE" ]; then | |
A=$(shasum "$TEMPFILE" | awk '{print $1}') | |
grep -q "^$A " $SHA1SUM 2>/dev/null && continue | |
echo "== changed == ${title}" | |
cat "$TEMPFILE" > "${title}".md | |
git add "${title}".md | |
N=$(( N + 1 )) | |
fi | |
done | |
if [ $N -ne 0 ]; then | |
git commit -m "$N files changed" | |
find . -type f -iname "*.md" -print0 | xargs -0 shasum -a 1 > $SHA1SUM | |
git add $SHA1SUM | |
git commit -m "$(shasum -a 1 $SHA1SUM)" | |
git push | |
exit $? | |
else | |
echo "Great! Nothing have been changed on the pad." | |
exit 0 | |
fi | |
rm -f $TEMPFILE 2>/dev/null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Backup Codimd en api
Outils pré-requis
Configuration codimd au PLM
L'authentification est de type oauth2
Il faut utiliser hedgedoc et une authentification par cookies sur le browser.
Un exemple fait par Romain THERON