diff options
Diffstat (limited to 'SuckIt')
-rwxr-xr-x | SuckIt | 162 |
1 files changed, 162 insertions, 0 deletions
@@ -0,0 +1,162 @@ | |||
1 | #!/bin/bash | ||
2 | |||
3 | TIMEFORMAT=" took %lR using %P%% CPU" | ||
4 | time { | ||
5 | pushd /opt/nyaw | ||
6 | |||
7 | #rm -fr Foswiki/* | ||
8 | cp -r /opt/nyaw_EMPTY/Foswiki . | ||
9 | #rm -fr PmWiki/* | ||
10 | cp -r /opt/nyaw_EMPTY/PmWiki . | ||
11 | #rm -fr unsorted | ||
12 | mkdir -p unsorted | ||
13 | cp -r /opt/nyaw_EMPTY/unsorted . | ||
14 | #rm -fr users/* | ||
15 | mkdir -p users | ||
16 | cp -r /opt/nyaw_EMPTY/users . | ||
17 | |||
18 | # Copy across things like images that where uploaded. | ||
19 | mkdir -p /opt/nyaw/Foswiki/pub/ | ||
20 | # TODO - Should rsync this instead. | ||
21 | cp -r /opt/Foswiki/pub/Main /opt/nyaw/Foswiki/pub/ | ||
22 | filter=" | ||
23 | -name _default -prune -o \ | ||
24 | -name _empty -prune -o \ | ||
25 | -name System -prune -o \ | ||
26 | -name Trash -prune -o \ | ||
27 | -name TWiki -prune -o \ | ||
28 | " | ||
29 | ogURL="https://fos.wiki.devuan.org" | ||
30 | ogWiki="Foswiki" | ||
31 | time find /opt/Foswiki/data ${filter} \ | ||
32 | -name "*.txt" -type f,l -printf "%P\n" | while read line | ||
33 | do | ||
34 | base=`echo "${line}" | cut -d '/' -f 1` | ||
35 | file=`echo "${line}" | cut -d '/' -f 2- | rev | cut -b 5- | rev` | ||
36 | if [[ ! ${file} =~ (AdminGroup|AdminUser|AdminUserLeftBar|CommentPluginExamples|EditorGroup|GroupTemplate|GroupViewTemplate|NobodyGroup|PatternSkinUserViewTemplate|ProjectContributor|RegistrationAgent|SitePreferences|UnprocessedRegistrations|UnprocessedRegistrationsLog|UserHomepageHeader|UserList|UserListByDateJoined|UserListByLocation|UserList|UserListHeader|WebAtom|WebChanges|WebCreateNewTopic|WebHome|WebIndex|WebLeftBar|WebLeftBarExample|WebNotify|WebPreferences|WebRss|WebSearch|WebSearchAdvanced|WebTopicList|WikiGroups|WikiUsers)$ ]]; then | ||
37 | doit='false' | ||
38 | if [ ! -s ${ogWiki}/${base}/${file}.HTM ]; then | ||
39 | echo "NEW /opt/Foswiki/data/${base}/${file}.txt" | ||
40 | doit='true' | ||
41 | elif [ /opt/Foswiki/data/${base}/${file}.txt -nt ${ogWiki}/${base}/${file}.HTM ]; then | ||
42 | echo "NEWER /opt/Foswiki/data/${base}/${file}.txt" | ||
43 | date --rfc-3339=seconds -ur /opt/Foswiki/data/${base}/${file}.txt | ||
44 | date --rfc-3339=seconds -ur ${ogWiki}/${base}/${file}.HTM | ||
45 | doit='true' | ||
46 | fi | ||
47 | if [[ ${doit} == "true" ]]; then | ||
48 | realURL=${ogWiki}/${base}/${file} | ||
49 | time=`date --rfc-3339=seconds -ur /opt/Foswiki/data/${base}/${file}.txt | cut -d '+' -f 1` | ||
50 | mkdir -p ${ogWiki}/${base} | ||
51 | mkdir -p ${ogWiki}/${base}/`dirname ${file}` | ||
52 | echo -e "ogWiki=${ogWiki}\nogURL=${ogURL}\nrealURL=${realURL}\nogBase=${base}\nogFile=${file}\ntimestamp=${time}\n" > ${ogWiki}/${base}/${file}.md.md | ||
53 | echo "downloading ${ogURL}/${base}/${file}?cover=print" | ||
54 | # Doesn't help with redownloads, coz natch a dynamic site isn't cached. But I can at least comment out the curl command during testing to save time. | ||
55 | curl --silent --no-progress-meter ${ogURL}/${base}/${file}?cover=print -o ${ogWiki}/${base}/${file}.HTM | ||
56 | # Attempt to separate user profiles from user content. Doesn't work when people turn their profiles into content. | ||
57 | dest="" | ||
58 | if [[ "${base}" == "Main" ]]; then | ||
59 | dest="unsorted" | ||
60 | if [ -L users/${file}_fos.md ]; then | ||
61 | dest='users' | ||
62 | fi | ||
63 | mkdir -p `dirname users/${file}` | ||
64 | sed -i -E ${ogWiki}/${base}/${file}.HTM -e "s%<a href=\"/System/UserForm\">UserForm</a>%%w users/${file}_fos.SED" | ||
65 | if [ -s users/${file}_fos.SED ]; then | ||
66 | dest="users" | ||
67 | fi | ||
68 | rm users/${file}_fos.SED >/dev/null 2>&1 | ||
69 | rm -d `dirname users/${file}` >/dev/null 2>&1 | ||
70 | fi | ||
71 | # "Devuan" is only two pages that get sorted. "Sandbox" is a mixture of standard examples, stuff that was copied to PmWiki, and other things that should get unsorted. | ||
72 | # Skipping anything with "<a href="/Main/UnknownUser">UnknownUser</a></span></div>". | ||
73 | if [[ "${base}" == "Sandbox" ]]; then | ||
74 | dest="unsorted" | ||
75 | mkdir -p `dirname users/${file}` | ||
76 | sed -i -E ${ogWiki}/${base}/${file}.HTM -e "s%<a href=\"/Main/UnknownUser\">UnknownUser</a></span></div>%%w users/${file}_fos.SED" | ||
77 | if [ -s users/${file}_fos.SED ]; then | ||
78 | dest="" | ||
79 | fi | ||
80 | rm users/${file}_fos.SED >/dev/null 2>&1 | ||
81 | rm -d `dirname users/${file}` >/dev/null 2>&1 | ||
82 | fi | ||
83 | |||
84 | if [[ "${dest}" != "" ]]; then | ||
85 | mkdir -p `dirname ${dest}/${file}` | ||
86 | realURL=${dest}/${file} | ||
87 | echo -e "ogWiki=${ogWiki}\nogURL=${ogURL}\nrealURL=${realURL}_fos\nogBase=${base}\nogFile=${file}\ntimestamp=${time}\n" > ${ogWiki}/${base}/${file}.md.md | ||
88 | touch ${ogWiki}/${base}/${file}.md | ||
89 | ln -sfr ${ogWiki}/${base}/${file}.md ${dest}/${file}_fos.md | ||
90 | ln -sfr ${ogWiki}/${base}/${file}.md.md ${dest}/${file}_fos.md.md | ||
91 | rm ${ogWiki}/${base}/${file}.md | ||
92 | fi | ||
93 | fi | ||
94 | fi | ||
95 | done | ||
96 | |||
97 | |||
98 | # Copy across things like images that where uploaded. | ||
99 | cp -r /opt/pmwiki/uploads /opt/nyaw/PmWiki/ | ||
100 | filter=" | ||
101 | -not -name "*~" -a \ | ||
102 | -not -name ".flock" -a \ | ||
103 | -not -name ".htaccess" -a \ | ||
104 | -not -name ".lastmod" -a \ | ||
105 | -not -name ".pageindex" -a \ | ||
106 | " | ||
107 | ogURL="https://wiki.devuan.org" | ||
108 | ogWiki="PmWiki" | ||
109 | time find /opt/pmwiki/wiki.d ${filter} \ | ||
110 | -name "*.*" -type f,l -printf "%P\n" | while read line | ||
111 | do | ||
112 | base=`echo "${line}" | cut -d '.' -f 1` | ||
113 | file=`echo "${line}" | cut -d '.' -f 2` | ||
114 | if [[ "${base}" != "Site" ]]; then | ||
115 | doit='false' | ||
116 | if [ ! -s ${ogWiki}/${base}/${file}.HTM ]; then | ||
117 | echo "NEW /opt/pmwiki/wiki.d/${base}.${file} ${ogWiki}/${base}/${file}.HTM" | ||
118 | doit='true' | ||
119 | elif [ /opt/pmwiki/wiki.d/${base}.${file} -nt ${ogWiki}/${base}/${file}.HTM ]; then | ||
120 | echo "NEWER /opt/pmwiki/wiki.d/${base}.${file}" | ||
121 | date --rfc-3339=seconds -ur /opt/pmwiki/wiki.d/${base}.${file} | ||
122 | date --rfc-3339=seconds -ur ${ogWiki}/${base}/${file}.HTM | ||
123 | doit='true' | ||
124 | fi | ||
125 | if [[ ${doit} == "true" ]]; then | ||
126 | realURL=${ogWiki}/${base}/${file} | ||
127 | time=`date --rfc-3339=seconds -ur /opt/pmwiki/wiki.d/${base}.${file} | cut -d '+' -f 1` | ||
128 | mkdir -p ${ogWiki}/${base} | ||
129 | echo -e "ogWiki=${ogWiki}\nogURL=${ogURL}\nrealURL=${realURL}\nogBase=${base}\nogFile=${file}\ntimestamp=${time}\n" > ${ogWiki}/${base}/${file}.md.md | ||
130 | # echo "downloading ${ogURL}/?n=${base}.${file}?action=markdown" | ||
131 | # curl --no-progress-meter ${ogURL}/?n=${base}.${file}?action=markdown -o ${ogWiki}/${base}/${file}.MARKDOWN | ||
132 | echo "downloading ${ogURL}/?n=${base}.${file}?action=print" | ||
133 | curl --no-progress-meter ${ogURL}/?n=${base}.${file}?action=print -o ${ogWiki}/${base}/${file}.HTM | ||
134 | # Seems there's no way to tell user profiles apart from user content. Unless I can find a list of users somewhere. Don't think there is one. | ||
135 | if [[ "${base}" == "Profiles" ]]; then | ||
136 | dest="unsorted" | ||
137 | if [ -L users/${file}_pm.md ]; then | ||
138 | dest='users' | ||
139 | fi | ||
140 | realURL=${dest}/${file} | ||
141 | echo -e "ogWiki=${ogWiki}\nogURL=${ogURL}\nrealURL=${realURL}_pm\nogBase=${base}\nogFile=${file}\ntimestamp=${time}\n" > ${ogWiki}/${base}/${file}.md.md | ||
142 | touch ${ogWiki}/${base}/${file}.md | ||
143 | ln -sfr ${ogWiki}/${base}/${file}.md ${dest}/${file}_pm.md | ||
144 | ln -sfr ${ogWiki}/${base}/${file}.md.md ${dest}/${file}_pm.md.md | ||
145 | rm ${ogWiki}/${base}/${file}.md | ||
146 | fi | ||
147 | fi | ||
148 | |||
149 | # TODO - groups are PmWiki/Onefang and PmWiki/Tiki | ||
150 | |||
151 | # pandoc -f markdown -t commonmark_x --self-contained ${ogWiki}//${base}/${file}.MD >${ogWiki}/${base}/${file}.md | ||
152 | # pandoc -f html -t commonmark_x --self-contained ${ogWiki}//${base}/${file}.HTM >${ogWiki}/${base}/${file}.md | ||
153 | fi | ||
154 | done | ||
155 | |||
156 | |||
157 | time notYetAnotherWiki.lua | ||
158 | # No idea why yet, but needs a second run to sort out everything. Shouldn't take long anyway. | ||
159 | time notYetAnotherWiki.lua | ||
160 | |||
161 | popd | ||
162 | } | ||