]> git.proxmox.com Git - pve-docs.git/blob - pve-docs-mediawiki-import.in
4a2736c366c35f7de83ffd9267f0e235e8fe73b7
[pve-docs.git] / pve-docs-mediawiki-import.in
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5 use Data::Dumper;
6
7 use IO::File;
8 use File::Basename;
9 use MediaWiki::API;
10
11 use JSON;
12
13 my $data_str = "";
14 while (<main::DATA>) { $data_str .= $_; }
15
16 my $fileinfo = decode_json($data_str);
17
18 my $config_fn = "/root/.pve-docs"; # format 'username:pw'
19
20 my $fh = IO::File->new("$config_fn") ||
21 die "Please configure the mediawiki user/passswd in '$config_fn'\n";
22
23 my $api_url = "http://localhost/mediawiki/api.php";
24
25 my $config = <$fh>;
26 chomp $config;
27
28 my ($username, $passwd) = split(':', $config, 2);
29
30 my $mw = MediaWiki::API->new();
31 $mw->{config}->{api_url} = $api_url;
32
33 # log in to the wiki
34 $mw->login({ lgname => $username, lgpassword => $passwd })
35 || die $mw->{error}->{code} . ': ' . $mw->{error}->{details};
36
37 sub update_page {
38 my ($pagename, $include, $category) = @_;
39
40 print "update mediawiki page: $pagename\n";
41
42 my $ref = $mw->get_page( { title => $pagename } );
43 my $page = $ref->{'*'} || '';
44
45 if ($page !~ m/^\{\{#pvedocs:.*\}\}\s*$/m) {
46 $page = "{{#pvedocs:$include}}\n$page";
47 } else {
48 $page =~ s/^\{\{#pvedocs:.*\}\}\s*$/\{\{#pvedocs:$include\}\}\n/m;
49 }
50
51 if ($category) {
52 my $catstr = "Category:$category";
53
54 if ($page !~ m/^\[\[$catstr\]\]\s*$/m) {
55 $page .= "\n[[$catstr]]\n";
56 }
57 }
58
59 my $timestamp = $ref->{timestamp};
60 my $wcmd = {
61 action => 'edit',
62 title => $pagename,
63 basetimestamp => $timestamp, # to avoid edit conflicts
64 text => $page,
65 };
66
67 $mw->edit($wcmd) ||
68 die $mw->{error}->{code} . ': ' . $mw->{error}->{details};
69 }
70
71 my $cat_refdoc = "Reference Documentation";
72
73 my $docs_old = {
74 'ha-manager-plain.html' => {
75 title => "High Availability",
76 category => $cat_refdoc,
77 },
78 'pve-installation-plain.html' => {
79 title => "Installation",
80 category => $cat_refdoc,
81 },
82 'pve-usbstick-plain.html' => {
83 title => "Install from USB Stick",
84 category => $cat_refdoc,
85 },
86 'pve-system-requirements-plain.html' => {
87 title => "System Requirements",
88 category => $cat_refdoc,
89 },
90 'getting-help-plain.html' => {
91 title => "Getting Help",
92 category => $cat_refdoc,
93 },
94 'pve-network-plain.html' => {
95 title => "Network Configuration",
96 category => $cat_refdoc,
97 },
98 'pve-disk-health-monitoring-plain.html' => {
99 title => "Disk Health Monitoring",
100 category => $cat_refdoc,
101 },
102 'local-lvm-plain.html' => {
103 title => "Logical Volume Manager (LVM)",
104 category => $cat_refdoc,
105 },
106 'pve-package-repos-plain.html' => {
107 title => "Package Repositories",
108 category => $cat_refdoc,
109 },
110 'system-software-updates-plain.html' => {
111 title => "System Software Updates",
112 category => $cat_refdoc,
113 },
114 'sysadmin-plain.html' => {
115 title => "Host System Administration",
116 category => $cat_refdoc,
117 },
118 'pct-plain.html' => {
119 title => "Linux Container",
120 category => $cat_refdoc,
121 },
122 'pmxcfs-plain.html' => {
123 title => "Proxmox Cluster File System (pmxcfs)",
124 category => $cat_refdoc,
125 },
126 'pve-bibliography-plain.html' => {
127 title => "Bibliography",
128 category => $cat_refdoc,
129 },
130 'pvecm-plain.html' => {
131 title => "Cluster Manager",
132 category => $cat_refdoc,
133 },
134 'pve-faq-plain.html' => {
135 title => "FAQ",
136 category => $cat_refdoc,
137 },
138 'pve-firewall-plain.html' => {
139 title => "Firewall",
140 category => $cat_refdoc,
141 },
142 'pvesm-plain.html' => {
143 title => "Storage",
144 category => $cat_refdoc,
145 },
146 'pveum-plain.html' => {
147 title => "User Management",
148 category => $cat_refdoc,
149 },
150 'qm-plain.html' => {
151 title => "Qemu/KVM Virtual Machines",
152 category => $cat_refdoc,
153 },
154 'vzdump-plain.html' => {
155 title => "Backup and Restore",
156 category => $cat_refdoc,
157 },
158 'qm.conf.5-plain.html' => {
159 title => "Manual: vm.conf",
160 category => $cat_refdoc,
161 },
162 'pct.conf.5-plain.html' => {
163 title => "Manual: pct.conf",
164 category => $cat_refdoc,
165 },
166 'datacenter.cfg.5-plain.html' => {
167 title => "Manual: datacenter.cfg",
168 category => $cat_refdoc,
169 },
170 # Storage Plugins
171 'pve-storage-dir-plain.html' => {
172 title => "Storage: Directory",
173 category => $cat_refdoc,
174 },
175 'pve-storage-glusterfs-plain.html' => {
176 title => "Storage: GlusterFS",
177 category => $cat_refdoc,
178 },
179 'pve-storage-iscsidirect-plain.html' => {
180 title => "Storage: User Mode iSCSI",
181 category => $cat_refdoc,
182 },
183 'pve-storage-iscsi-plain.html' => {
184 title => "Storage: iSCSI",
185 category => $cat_refdoc,
186 },
187 'pve-storage-lvm-plain.html' => {
188 title => "Storage: LVM",
189 category => $cat_refdoc,
190 },
191 'pve-storage-lvmthin-plain.html' => {
192 title => "Storage: LVM Thin",
193 category => $cat_refdoc,
194 },
195 'pve-storage-nfs-plain.html' => {
196 title => "Storage: NFS",
197 category => $cat_refdoc,
198 },
199 'pve-storage-rbd-plain.html' => {
200 title => "Storage: RBD",
201 category => $cat_refdoc,
202 },
203 'pve-storage-zfspool-plain.html' => {
204 title => "Storage: ZFS",
205 category => $cat_refdoc,
206 },
207 };
208
209 my $wiki_man5_pages = {
210 'datacenter.cfg.adoc' => 1,
211 'qm.conf.adoc' => 1,
212 'pct.conf.adoc' => 1,
213 };
214
215 my $docs = {};
216 foreach my $source (sort keys %{$fileinfo->{toplevel}->{wiki}}) {
217 my $title = $fileinfo->{titles}->{wiki}->{$source};
218 my $doctype = $fileinfo->{doctype}->{wiki}->{$source};
219
220 my $suffix = $wiki_man5_pages->{$source} ? '.5-plain.html' : '-plain.html';
221 my $filename = $source;
222 $filename =~ s/\.adoc//;
223 $filename .= $suffix;
224
225 my $path = "/usr/share/pve-docs/$filename";
226 die "no such file '$path'" if ! -f $path;
227
228 update_page($title, $filename, category => $cat_refdoc);
229 }
230
231 # also update 'Get support' page, because this is used since a long
232 # time and is referenced from outside
233 update_page("Get support", 'getting-help-plain.html', 'HOWTO');
234
235 __END__