aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/SuckIt
blob: 7ed0bf6b200d369b6bffdc7d59ba00a170e23039 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/bin/bash

TIMEFORMAT="    took %lR using %P%% CPU"
time {
pushd /opt/nyaw

rm -fr Foswiki/*
cp -r /opt/nyaw_EMPTY/Foswiki .
rm -fr PmWiki/*
cp -r /opt/nyaw_EMPTY/PmWiki .
rm -fr unsorted
mkdir -p unsorted
rm -fr users/*
#mkdir -p users
cp -r /opt/nyaw_EMPTY/users .

# Copy across things like images that where uploaded.
mkdir -p /opt/nyaw/Foswiki/pub/
# TODO - Should rsync this instead.
cp -r /opt/Foswiki/pub/Main /opt/nyaw/Foswiki/pub/
filter="
 -name _default -prune -o \
 -name _empty -prune -o \
 -name System -prune -o \
 -name Trash -prune -o \
 -name TWiki -prune -o \
"
ogURL="https://fos.wiki.devuan.org"
ogWiki="Foswiki"
time find /opt/Foswiki/data  ${filter} \
-name "*.txt" -type f,l -printf "%P\n" | while read line
do
    base=`echo "${line}" | cut -d '/' -f 1`
    file=`echo "${line}" | cut -d '/' -f 2- | rev | cut -b 5- | rev`
    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
	realURL=${ogWiki}/${base}/${file}
	time=`date --rfc-3339=seconds -ur /opt/Foswiki/data/${base}/${file}.txt | cut -d '+' -f 1`
	mkdir -p ${ogWiki}/${base}
	mkdir -p ${ogWiki}/${base}/`dirname ${file}`
	echo -e "ogWiki=${ogWiki}\nogURL=${ogURL}\nrealURL=${realURL}\nogBase=${base}\nogFile=${file}\ntimestamp=${time}\n" > ${ogWiki}/${base}/${file}.md.md
	echo "downloading ${ogURL}/${base}/${file}?cover=print"
	# 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.
	curl --silent --no-progress-meter ${ogURL}/${base}/${file}?cover=print -o ${ogWiki}/${base}/${file}.HTM
	# Attempt to separate user profiles from user content.  Doesn't work when people turn their profiles into content.
	dest=""
	if [[ "${base}" ==  "Main" ]]; then
	    dest="unsorted"
	    if [ -L users/${file}_fos.md ]; then
		dest='users'
	    fi
	    mkdir -p `dirname users/${file}`
	    sed -i -E ${ogWiki}/${base}/${file}.HTM -e "s%<a href=\"/System/UserForm\">UserForm</a>%%w users/${file}_fos.SED"
	    if [ -s users/${file}_fos.SED ]; then
		dest="users"
	    fi
	    rm users/${file}_fos.SED >/dev/null 2>&1
	    rm -d `dirname users/${file}` >/dev/null 2>&1
	fi
	# "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.
	#						Skipping anything with "<a href="/Main/UnknownUser">UnknownUser</a></span></div>".
	if [[ "${base}" ==  "Sandbox" ]]; then
	    dest="unsorted"
	    mkdir -p `dirname users/${file}`
	    sed -i -E ${ogWiki}/${base}/${file}.HTM -e "s%<a href=\"/Main/UnknownUser\">UnknownUser</a></span></div>%%w users/${file}_fos.SED"
	    if [ -s users/${file}_fos.SED ]; then
		dest=""
	    fi
	    rm users/${file}_fos.SED >/dev/null 2>&1
	    rm -d `dirname users/${file}` >/dev/null 2>&1
	fi

	if [[ "${dest}" != "" ]]; then
	    mkdir -p `dirname ${dest}/${file}`
	    realURL=${dest}/${file}
	    echo -e "ogWiki=${ogWiki}\nogURL=${ogURL}\nrealURL=${realURL}_fos\nogBase=${base}\nogFile=${file}\ntimestamp=${time}\n" > ${ogWiki}/${base}/${file}.md.md
	    touch   ${ogWiki}/${base}/${file}.md
	    ln -sfr ${ogWiki}/${base}/${file}.md ${dest}/${file}_fos.md
	    ln -sfr ${ogWiki}/${base}/${file}.md.md ${dest}/${file}_fos.md.md
	    rm      ${ogWiki}/${base}/${file}.md
	fi
    fi
done


# Copy across things like images that where uploaded.
cp -r /opt/pmwiki/uploads /opt/nyaw/PmWiki/
filter="
 -not -name "*~" -a \
 -not -name ".flock" -a \
 -not -name ".htaccess" -a \
 -not -name ".lastmod" -a \
 -not -name ".pageindex" -a \
"
ogURL="https://wiki.devuan.org"
ogWiki="PmWiki"
time find /opt/pmwiki/wiki.d  ${filter} \
-name "*.*" -type f,l -printf "%P\n" | while read line
do
    base=`echo "${line}" | cut -d '.' -f 1`
    file=`echo "${line}" | cut -d '.' -f 2`
    if [[ "${base}" !=  "Site" ]]; then
	realURL=${ogWiki}/${base}/${file}
	time=`date --rfc-3339=seconds -ur /opt/pmwiki/wiki.d/${base}.${file} | cut -d '+' -f 1`
	mkdir -p ${ogWiki}/${base}
	echo -e "ogWiki=${ogWiki}\nogURL=${ogURL}\nrealURL=${realURL}\nogBase=${base}\nogFile=${file}\ntimestamp=${time}\n" > ${ogWiki}/${base}/${file}.md.md
#	echo "downloading ${ogURL}/?n=${base}.${file}?action=markdown"
#	curl --no-progress-meter ${ogURL}/?n=${base}.${file}?action=markdown -o ${ogWiki}/${base}/${file}.MARKDOWN
	echo "downloading ${ogURL}/?n=${base}.${file}?action=print"
	curl --no-progress-meter ${ogURL}/?n=${base}.${file}?action=print -o ${ogWiki}/${base}/${file}.HTM
	# 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.
	if [[ "${base}" ==  "Profiles" ]]; then
	    dest="unsorted"
	    if [ -L users/${file}_pm.md ]; then
		dest='users'
	    fi
	    realURL=${dest}/${file}
	    echo -e "ogWiki=${ogWiki}\nogURL=${ogURL}\nrealURL=${realURL}_pm\nogBase=${base}\nogFile=${file}\ntimestamp=${time}\n" > ${ogWiki}/${base}/${file}.md.md
	    touch   ${ogWiki}/${base}/${file}.md
	    ln -sfr ${ogWiki}/${base}/${file}.md ${dest}/${file}_pm.md
	    ln -sfr ${ogWiki}/${base}/${file}.md.md ${dest}/${file}_pm.md.md
	    rm      ${ogWiki}/${base}/${file}.md
	fi

# TODO - groups are PmWiki/Onefang and PmWiki/Tiki

#    	pandoc -f markdown -t commonmark_x --self-contained ${ogWiki}//${base}/${file}.MD >${ogWiki}/${base}/${file}.md
#    	pandoc -f html -t commonmark_x --self-contained ${ogWiki}//${base}/${file}.HTM >${ogWiki}/${base}/${file}.md
    fi
done


time notYetAnotherWiki.lua

popd
}