Commit 1324b953 authored by Andreas Klöckner's avatar Andreas Klöckner
Browse files

Fix backup-codimd-docs.sh

parent 80207d0b
Loading
Loading
Loading
Loading
+34 −23
Original line number Diff line number Diff line
@@ -16,15 +16,24 @@ fi

export CODIMD_SERVER='https://codimd.tiker.net'
$CODIMD login --email inform+codibackup@tiker.net "$CODIMD_PASSWORD"
while read -r DOCID FILEPATH; do

# read will not return the last line if there isn't a newline :facepalm:
DONE=false
until $DONE; do
    DOCID=""
    read -r DOCID FILEPATH || DONE=true
    if test "$DOCID" != ""; then
        echo "Reading note $DOCID into $FILEPATH"
    echo "**DO NOT EDIT**" > "$FILEPATH"
    echo "This file will be automatically overwritten. " >> "$FILEPATH"
    echo "Instead, edit the file at ${CODIMD_SERVER}/${DOCID} " >> "$FILEPATH"
    echo "**DO NOT EDIT**" >> "$FILEPATH"
    echo "" >> "$FILEPATH"
    $CODIMD export --md "$DOCID" "-" >> "$FILEPATH"
        {
                echo "**DO NOT EDIT**"
                echo "This file will be automatically overwritten. "
                echo "Instead, edit the file at ${CODIMD_SERVER}/${DOCID} "
                echo "**DO NOT EDIT**"
                echo ""
                $CODIMD export --md "$DOCID" "-"
        } > "$FILEPATH"
        git add "$FILEPATH"
    fi
done < .codimd-backup.txt

if [[ `git status --porcelain --untracked-files=no ` ]]; then
@@ -41,3 +50,5 @@ if [[ `git status --porcelain --untracked-files=no ` ]]; then
    echo -e "Host gitlab.tiker.net\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config
    git push git@gitlab.tiker.net:${CI_PROJECT_PATH}.git master
fi

# vim: sw=4