Add base for CI/CD setup tasks and otherwise.
[SquirrelJME.git] / .circleci / squirreljme-wikify-user-guide.sh
blob089229e2275d07923fd703cea8733390d44153c3
1 #!/bin/sh
2 # ---------------------------------------------------------------------------
3 # Multi-Phasic Applications: SquirrelJME
4 # Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 # Copyright (C) Multi-Phasic Applications <multiphasicapps.net>
6 # ---------------------------------------------------------------------------
7 # SquirrelJME is under the GNU General Public License v3+, or later.
8 # See license.mkd for licensing and copyright information.
9 # ---------------------------------------------------------------------------
10 # DESCRIPTION: Wikifies SquirrelJME for GitHub, since GitHub uses a different
11 # format for their Wikis...
13 # Must be valid!
14 if [ "$#" -lt "2" ]
15 then
16 echo "Usage: $0 [repo] [wiki-git-repo]"
17 exit 1
20 # These are directories
21 __foss="$1/assets/user-guide"
22 __gith="$2"
24 # These both must be directories
25 if [ ! -d "$__foss" ] || [ ! -d "$__gith" ]
26 then
27 echo "Both arguments must be directories."
28 exit 1
31 # Target must be a Git repo
32 if [ ! -d "$__gith/.git" ]
33 then
34 echo "Target not a Git repository."
35 exit 1
38 # Convert to GitHub name
39 __toGitHubName()
41 __srcName="$1"
43 if [ "$__srcName" = "readme.mkd" ]
44 then
45 echo "Home.markdown"
46 else
47 echo "$__srcName" | sed 's/\.mkd$/\.markdown/'
51 # Convert to Fossil name
52 __toFossilName()
54 __srcName="$1"
56 if [ "$__srcName" = "Home.markdown" ]
57 then
58 echo "readme.mkd"
59 else
60 echo "$__srcName" | sed 's/\.markdown$/\.mkd/'
64 # Remove any other old files
65 find "$__gith" -type f | grep -e '\.mkd$' -e '\.md$' | while read __githFile
67 echo "Removing old file $__githFile..."
68 (cd "$__gith" && git rm -f "$__githFile")
69 done
71 # Remove any files which are missing
72 find "$__gith" -type f | grep '\.markdown$' | while read __githFile
74 __baseGith="$(basename "$__githFile")"
75 __baseFoss="$(__toFossilName "$__baseGith")"
77 # The file may be in the root of the project or elsewhere...
78 if ! find "$__foss/" -type f | grep "$__baseFoss" > /dev/null
79 then
80 echo "Removing file $__githFile (aka $__baseFoss)..."
82 (cd "$__gith" && git rm -f "$__githFile")
84 done
86 # Copy and convert the files for GitHub's Wiki
87 find "$__foss" -type f | grep '\.mkd$' | while read __fossFile
89 __baseFoss="$(basename "$__fossFile")"
90 __baseGith="$(__toGitHubName "$__baseFoss")"
92 echo "Converting $__baseFoss to $__baseGith..."
94 # Links need to be properly converted or they will be lost
95 sed 's/(readme\.mkd)/(Home)/g' < "$__fossFile" | \
96 sed 's/(\([^.]*\)\.mkd)/(\1)/g' > "$__gith/$__baseGith"
97 (cd "$__gith" && git add "$__gith/$__baseGith")
98 done