]>
Commit | Line | Data |
---|---|---|
cfabc2e9 DM |
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 | my $config_fn = "/root/.pve-docs"; # format 'username:pw' | |
12 | ||
13 | my $fh = IO::File->new("$config_fn") || | |
14 | die "Please configure the mediawiki user/passswd in '$config_fn'\n"; | |
15 | ||
a45b098f | 16 | my $api_url = "http://localhost/mediawiki/api.php"; |
cfabc2e9 DM |
17 | |
18 | my $config = <$fh>; | |
19 | chomp $config; | |
20 | ||
21 | my ($username, $passwd) = split(':', $config, 2); | |
22 | ||
23 | my $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 | ||
30 | sub 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 | ||
64 | my $cat_refdoc = "Reference Documentation"; | |
65 | ||
66 | my $docs = { | |
67 | 'chapter-ha-manager-plain.html' => { | |
68 | title => "High Availability", | |
69 | category => $cat_refdoc, | |
70 | }, | |
8c80c3fc DM |
71 | 'sysadmin-getting-help-plain.html' => { |
72 | title => "Getting Help", | |
73 | category => $cat_refdoc, | |
74 | }, | |
75 | 'sysadmin-pve-network-plain.html' => { | |
76 | title => "Network Configuration", | |
77 | category => $cat_refdoc, | |
78 | }, | |
79 | 'sysadmin-local-zfs-plain.html' => { | |
80 | title => "ZFS on Linux", | |
81 | category => $cat_refdoc, | |
82 | }, | |
8b849dc3 DM |
83 | 'sysadmin-local-lvm-plain.html' => { |
84 | title => "Logical Volume Manager (LVM)", | |
85 | category => $cat_refdoc, | |
86 | }, | |
8c80c3fc DM |
87 | 'sysadmin-pve-installation-plain.html' => { |
88 | title => "Installation", | |
89 | category => $cat_refdoc, | |
90 | }, | |
91 | 'sysadmin-pve-package-repos-plain.html' => { | |
92 | title => "Package Repositories", | |
93 | category => $cat_refdoc, | |
94 | }, | |
95 | 'sysadmin-system-software-updates-plain.html' => { | |
96 | title => "System Software Updates", | |
97 | category => $cat_refdoc, | |
98 | }, | |
cfabc2e9 DM |
99 | 'chapter-sysadmin-plain.html' => { |
100 | title => "Host System Administration", | |
101 | category => $cat_refdoc, | |
102 | }, | |
103 | 'chapter-pct-plain.html' => { | |
104 | title => "Linux Container", | |
105 | category => $cat_refdoc, | |
106 | }, | |
107 | 'chapter-pmxcfs-plain.html' => { | |
108 | title => "Proxmox Cluster File System (pmxcfs)", | |
109 | category => $cat_refdoc, | |
110 | }, | |
111 | 'chapter-pve-bibliography-plain.html' => { | |
112 | title => "Bibliography", | |
113 | category => $cat_refdoc, | |
114 | }, | |
115 | 'chapter-pvecm-plain.html' => { | |
116 | title => "Cluster Manager", | |
117 | category => $cat_refdoc, | |
118 | }, | |
119 | 'chapter-pve-faq-plain.html' => { | |
120 | title => "FAQ", | |
121 | category => $cat_refdoc, | |
122 | }, | |
123 | 'chapter-pve-firewall-plain.html' => { | |
124 | title => "Firewall", | |
125 | category => $cat_refdoc, | |
126 | }, | |
127 | 'chapter-pvesm-plain.html' => { | |
128 | title => "Storage", | |
129 | category => $cat_refdoc, | |
130 | }, | |
131 | 'chapter-pveum-plain.html' => { | |
132 | title => "User Management", | |
133 | category => $cat_refdoc, | |
134 | }, | |
135 | 'chapter-qm-plain.html' => { | |
136 | title => "Qemu/KVM Virtual Machines", | |
137 | category => $cat_refdoc, | |
138 | }, | |
139 | 'chapter-vzdump-plain.html' => { | |
140 | title => "Backup and Restore", | |
141 | category => $cat_refdoc, | |
142 | }, | |
143 | 'qm.conf.5-plain.html' => { | |
144 | title => "Manual: vm.conf", | |
145 | category => $cat_refdoc, | |
146 | }, | |
147 | 'pct.conf.5-plain.html' => { | |
148 | title => "Manual: pct.conf", | |
149 | category => $cat_refdoc, | |
150 | }, | |
151 | 'datacenter.cfg.5-plain.html' => { | |
152 | title => "Manual: datacenter.cfg", | |
153 | category => $cat_refdoc, | |
154 | }, | |
155 | # Storage Plugins | |
156 | 'pve-storage-dir-plain.html' => { | |
157 | title => "Storage: Directory", | |
158 | category => $cat_refdoc, | |
159 | }, | |
160 | 'pve-storage-glusterfs-plain.html' => { | |
161 | title => "Storage: GlusterFS", | |
162 | category => $cat_refdoc, | |
163 | }, | |
164 | 'pve-storage-iscsidirect-plain.html' => { | |
165 | title => "Storage: User Mode iSCSI", | |
166 | category => $cat_refdoc, | |
167 | }, | |
168 | 'pve-storage-iscsi-plain.html' => { | |
169 | title => "Storage: iSCSI", | |
170 | category => $cat_refdoc, | |
171 | }, | |
172 | 'pve-storage-lvm-plain.html' => { | |
173 | title => "Storage: LVM", | |
174 | category => $cat_refdoc, | |
175 | },q | |
176 | 'pve-storage-lvmthin-plain.html' => { | |
177 | title => "Storage: LVM Thin", | |
178 | category => $cat_refdoc, | |
179 | }, | |
180 | 'pve-storage-nfs-plain.html' => { | |
181 | title => "Storage: NFS", | |
182 | category => $cat_refdoc, | |
183 | }, | |
184 | 'pve-storage-rbd-plain.html' => { | |
185 | title => "Storage: RBD", | |
186 | category => $cat_refdoc, | |
187 | }, | |
188 | 'pve-storage-zfspool-plain.html' => { | |
189 | title => "Storage: ZFS", | |
190 | category => $cat_refdoc, | |
191 | }, | |
192 | }; | |
193 | ||
194 | #update_page("testpage1", $filename, $d->{category}); | |
195 | ||
196 | foreach my $filename (keys %$docs) { | |
197 | my $path = "/usr/share/pve-docs/$filename"; | |
198 | die "no such file '$path'" if ! -f $path; | |
199 | my $d = $docs->{$filename}; | |
200 | update_page($d->{title}, $filename, $d->{category}); | |
201 | } |