commit 2dc57efd00ab21db0b1e459b88862b9245149756 Author: EpicKiwi Date: Tue Oct 29 21:07:45 2024 +0100 Ajout du script diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0a067f9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +data +lol-wiki \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..121b39b --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +# Migration d'un wiki GIT vers dokuwiki + +Le script [`migrate.sh`](migrate.sh) permet de convertir un wiki sous forme de fichiers markdown (`mdwn`) dans un repository git vers une scructure de fichiers compatible avec la base de donnees de DokuWiki. + +Par defaut, le repository est dans `lol-wiki` et la sortie dans `output`. \ No newline at end of file diff --git a/migrate.sh b/migrate.sh new file mode 100755 index 0000000..eb50b2d --- /dev/null +++ b/migrate.sh @@ -0,0 +1,94 @@ +#!/bin/bash + +OUT_DIR="output" +NAMESPACE="vintage/" + +rm -rf "$OUT_DIR" +mkdir "$OUT_DIR" +mkdir "$OUT_DIR/pages" +mkdir "$OUT_DIR/attic" +mkdir "$OUT_DIR/meta" +mkdir "$OUT_DIR/media" +mkdir "$OUT_DIR/media_attic" + +SOURCE_DIR="$(pwd)/lol-wiki" +export GIT_DIR="$SOURCE_DIR/.git" + +baseref=master +lastref=$baseref + +git checkout $baseref > /dev/null + +for page in $(cd $SOURCE_DIR && find ./ -not -path "./.git/*" -type f); do + extension="${page##*.}" + + if [ "$extension" == "mdwn" ]; then + mkdir -p "$OUT_DIR/pages/$NAMESPACE$(dirname "$page")" + pandoc --from=markdown --to=dokuwiki "$SOURCE_DIR/$page" -o "$OUT_DIR/pages/$NAMESPACE${page%.$extension}.txt" + echo PAGE "$page" + else + mkdir -p "$OUT_DIR/media/$NAMESPACE$(dirname "$page")" + cp "$SOURCE_DIR/$page" "$OUT_DIR/media/$NAMESPACE$page" + echo MEDIA "$page" + fi +done + +for ref in $(git rev-list $baseref); do + date="$(git show --no-patch --format=%ct "$ref")" + subject="$(git show --no-patch --format=%s "$ref")" + commiter="$(git show --no-patch --format=%cn "$ref")" + + files=$(git -c "core.quotePath=false" diff --compact-summary --stat=999999 --no-renames $lastref $ref | head -n -1) + + IFS=$'\n' + for line in $files; do + + fileState=$(echo "$line" | cut -d'|' -f1 | awk '{$1=$1};1') + fileChanges=$(echo "$line" | cut -d'|' -f2 | awk '{$1=$1};1' | cut -d' ' -f1) + + page=$(echo "$fileState" | rev | cut -d" " -f2- | rev) + status=$(echo "$fileState" | rev | cut -d" " -f1 | rev) + + filename="$(basename "$page")" + extension="${filename##*.}" + + if [ "$status" != "(gone)" ]; then + + if [ "$extension" == "mdwn" ]; then + + namespace=$(echo "$NAMESPACE${page%.$extension}" | tr "/" ":") + changesFile="$OUT_DIR/meta/$NAMESPACE${page%.$extension}.changes" + + mkdir -p "$OUT_DIR/attic/$NAMESPACE$(dirname "$page")" + mkdir -p "$OUT_DIR/meta/$NAMESPACE$(dirname "$page")" + + git show "$ref:$page" | pandoc --from=markdown --to=dokuwiki - -o - | gzip -c > "$OUT_DIR/attic/$NAMESPACE${page%.$extension}.$date.txt.gz" + + touch "$changesFile" + if [ "$status" == "(new)" ]; then + printf '%s\n%s\n' "$date 127.0.0.1 C ${namespace} $subject $fileChanges $commiter" "$(cat "$changesFile")" > "$changesFile" + else + printf '%s\n%s\n' "$date 127.0.0.1 E ${namespace} $subject $fileChanges $commiter" "$(cat "$changesFile")" > "$changesFile" + fi + + echo ATTIC PAGE "$page" from $ref "($subject)" + else + namespace=$(echo "$NAMESPACE${page}" | tr "/" ":") + changesFile="$OUT_DIR/media_meta/$NAMESPACE${page}.changes" + + mkdir -p "$OUT_DIR/media_attic/$NAMESPACE$(dirname "$page")" + git show "$ref:$page" | gzip -c > "$OUT_DIR/media_attic/$NAMESPACE${page%.$extension}.$date.$extension.gz" + echo ATTIC MEDIA "$page" from $ref "($subject)" + + mkdir -p "$OUT_DIR/media_meta/$NAMESPACE$(dirname "$page")" + touch "$changesFile" + printf '%s\n%s\n' "$date 127.0.0.1 E ${namespace} $subject $fileChanges $commiter" "$(cat "$changesFile")" > "$changesFile" + fi + fi + + done + + lastref=$ref +done + +find "$OUT_DIR/meta/" -name '*.changes' ! -name '_media.changes' -exec cat {} + | sort -u > "$OUT_DIR/meta/_dokuwiki.changes" \ No newline at end of file