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