Ajout du script
This commit is contained in:
commit
2dc57efd00
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
data
|
||||
lol-wiki
|
5
README.md
Normal file
5
README.md
Normal file
@ -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`.
|
94
migrate.sh
Executable file
94
migrate.sh
Executable file
@ -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"
|
Loading…
Reference in New Issue
Block a user