]> git.proxmox.com Git - pve-docs.git/blame - pve-docs-mediawiki-import.in
new file pve-docs-mediawiki-import.in
[pve-docs.git] / pve-docs-mediawiki-import.in
CommitLineData
cfabc2e9
DM
1#!/usr/bin/perl
2
3use strict;
4use warnings;
5use Data::Dumper;
6
7use IO::File;
8use File::Basename;
9use MediaWiki::API;
10
b489b02c
DM
11use JSON;
12
13my $data_str = "";
14while (<main::DATA>) { $data_str .= $_; }
15
16my $fileinfo = decode_json($data_str);
17
cfabc2e9
DM
18my $config_fn = "/root/.pve-docs"; # format 'username:pw'
19
20my $fh = IO::File->new("$config_fn") ||
21 die "Please configure the mediawiki user/passswd in '$config_fn'\n";
22
a45b098f 23my $api_url = "http://localhost/mediawiki/api.php";
cfabc2e9
DM
24
25my $config = <$fh>;
26chomp $config;
27
28my ($username, $passwd) = split(':', $config, 2);
29
30my $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
37sub 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
71my $cat_refdoc = "Reference Documentation";
72
b489b02c
DM
73my $docs_old = {
74 'ha-manager-plain.html' => {
cfabc2e9
DM
75 title => "High Availability",
76 category => $cat_refdoc,
77 },
b489b02c 78 'pve-installation-plain.html' => {
5c6cf7ac
DM
79 title => "Installation",
80 category => $cat_refdoc,
81 },
b489b02c 82 'pve-usbstick-plain.html' => {
5c6cf7ac
DM
83 title => "Install from USB Stick",
84 category => $cat_refdoc,
85 },
b489b02c 86 'pve-system-requirements-plain.html' => {
bc1c71d4
DM
87 title => "System Requirements",
88 category => $cat_refdoc,
89 },
b489b02c 90 'getting-help-plain.html' => {
8c80c3fc
DM
91 title => "Getting Help",
92 category => $cat_refdoc,
93 },
b489b02c 94 'pve-network-plain.html' => {
8c80c3fc
DM
95 title => "Network Configuration",
96 category => $cat_refdoc,
97 },
b489b02c 98 'pve-disk-health-monitoring-plain.html' => {
e2c8ae0f 99 title => "Disk Health Monitoring",
8c80c3fc
DM
100 category => $cat_refdoc,
101 },
b489b02c 102 'local-lvm-plain.html' => {
8b849dc3
DM
103 title => "Logical Volume Manager (LVM)",
104 category => $cat_refdoc,
8c80c3fc 105 },
b489b02c 106 'pve-package-repos-plain.html' => {
8c80c3fc
DM
107 title => "Package Repositories",
108 category => $cat_refdoc,
109 },
b489b02c 110 'system-software-updates-plain.html' => {
8c80c3fc
DM
111 title => "System Software Updates",
112 category => $cat_refdoc,
113 },
b489b02c 114 'sysadmin-plain.html' => {
cfabc2e9
DM
115 title => "Host System Administration",
116 category => $cat_refdoc,
117 },
b489b02c 118 'pct-plain.html' => {
cfabc2e9
DM
119 title => "Linux Container",
120 category => $cat_refdoc,
121 },
b489b02c 122 'pmxcfs-plain.html' => {
cfabc2e9
DM
123 title => "Proxmox Cluster File System (pmxcfs)",
124 category => $cat_refdoc,
125 },
b489b02c 126 'pve-bibliography-plain.html' => {
cfabc2e9
DM
127 title => "Bibliography",
128 category => $cat_refdoc,
129 },
b489b02c 130 'pvecm-plain.html' => {
cfabc2e9
DM
131 title => "Cluster Manager",
132 category => $cat_refdoc,
133 },
b489b02c 134 'pve-faq-plain.html' => {
cfabc2e9
DM
135 title => "FAQ",
136 category => $cat_refdoc,
137 },
b489b02c 138 'pve-firewall-plain.html' => {
cfabc2e9
DM
139 title => "Firewall",
140 category => $cat_refdoc,
141 },
b489b02c 142 'pvesm-plain.html' => {
cfabc2e9
DM
143 title => "Storage",
144 category => $cat_refdoc,
145 },
b489b02c 146 'pveum-plain.html' => {
cfabc2e9
DM
147 title => "User Management",
148 category => $cat_refdoc,
149 },
b489b02c 150 'qm-plain.html' => {
cfabc2e9
DM
151 title => "Qemu/KVM Virtual Machines",
152 category => $cat_refdoc,
153 },
b489b02c 154 'vzdump-plain.html' => {
cfabc2e9
DM
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,
f9599fd5 190 },
cfabc2e9
DM
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
b489b02c
DM
209my $wiki_man5_pages = {
210 'datacenter.cfg.adoc' => 1,
211 'qm.conf.adoc' => 1,
212 'pct.conf.adoc' => 1,
213};
214
215my $docs = {};
216foreach 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;
cfabc2e9 224
cfabc2e9
DM
225 my $path = "/usr/share/pve-docs/$filename";
226 die "no such file '$path'" if ! -f $path;
b489b02c
DM
227
228 update_page($title, $filename, category => $cat_refdoc);
cfabc2e9 229}
11e7e157
DM
230
231# also update 'Get support' page, because this is used since a long
232# time and is referenced from outside
b489b02c
DM
233update_page("Get support", 'getting-help-plain.html', 'HOWTO');
234
235__END__