1 | #!/usr/bin/env php |
---|
2 | <?php |
---|
3 | class lambdaModule |
---|
4 | { |
---|
5 | private $deb; |
---|
6 | private $type; |
---|
7 | private $today; |
---|
8 | |
---|
9 | private $id; |
---|
10 | private $package_name; |
---|
11 | private $name; |
---|
12 | private $desc; |
---|
13 | private $author; |
---|
14 | private $version; |
---|
15 | |
---|
16 | public function __construct($module,$type) |
---|
17 | { |
---|
18 | if ($type != 'plugin' && $type != 'theme') { |
---|
19 | throw new Exception('Invalid module type'); |
---|
20 | } |
---|
21 | $this->type = $type; |
---|
22 | |
---|
23 | if (!$module || !is_dir($module)) { |
---|
24 | throw new Exception(sprintf('Module %s does not exist',$module)); |
---|
25 | } |
---|
26 | |
---|
27 | $mod_define = $module.'/_define.php'; |
---|
28 | |
---|
29 | if (!is_file($mod_define)) { |
---|
30 | throw new Exception(sprintf('Module %s does not have _define.php file',$module)); |
---|
31 | } |
---|
32 | |
---|
33 | if (is_dir($module.'/debian')) { |
---|
34 | throw new Exception(sprintf('Module %s already have a debian directory',$module)); |
---|
35 | } |
---|
36 | |
---|
37 | include $mod_define; |
---|
38 | $this->id = strtolower(basename(realpath($module))); |
---|
39 | $this->package_name = 'libdotclear-'.$this->type.'-'.$this->id; |
---|
40 | |
---|
41 | # Creating debian directory |
---|
42 | $this->deb = $module.'/debian'; |
---|
43 | mkdir($this->deb); |
---|
44 | |
---|
45 | $this->createFile('changelog',$this->changelogTPL()); |
---|
46 | $this->createFile('compat',"4\n"); |
---|
47 | $this->createFile('control',$this->controlTPL()); |
---|
48 | $this->createFile('copyright',$this->copyrightTPL()); |
---|
49 | $this->createFile('dirs',$this->dirsTPL()); |
---|
50 | $this->createFile('rules',$this->rulesTPL()); |
---|
51 | chmod($this->deb.'/rules',0755); |
---|
52 | } |
---|
53 | |
---|
54 | private function registerModule($name,$desc,$author,$version) |
---|
55 | { |
---|
56 | $this->name = $name; |
---|
57 | $this->desc = $desc; |
---|
58 | $this->author = $author; |
---|
59 | $this->version = $version; |
---|
60 | } |
---|
61 | |
---|
62 | private function createFile($name,$content='') |
---|
63 | { |
---|
64 | $fp = fopen($this->deb.'/'.$name,'wb'); |
---|
65 | fwrite($fp,$content); |
---|
66 | fclose($fp); |
---|
67 | } |
---|
68 | |
---|
69 | private function changelogTPL() |
---|
70 | { |
---|
71 | return |
---|
72 | $this->package_name.' ('.$this->version.') unstable; urgency=low'."\n". |
---|
73 | "\n". |
---|
74 | " Initial upstream release\n". |
---|
75 | "\n". |
---|
76 | " -- ".$this->author." <email@example.com> ".date('r')."\n\n"; |
---|
77 | } |
---|
78 | |
---|
79 | private function controlTPL() |
---|
80 | { |
---|
81 | return |
---|
82 | "Source: ".$this->package_name."\n". |
---|
83 | "Section: web\n". |
---|
84 | "Priority: optional\n". |
---|
85 | "Maintainer: ".$this->author." <email@example.com>\n". |
---|
86 | "Build-Depends: debhelper (>= 4.0.0), php5-cli\n". |
---|
87 | "Standards-Version: 3.6.1\n". |
---|
88 | "\n". |
---|
89 | "Package: ".$this->package_name."\n". |
---|
90 | "Architecture: all\n". |
---|
91 | 'Depends: ${misc:Depends}, dotclear'."\n". |
---|
92 | "Description: Dotclear ".$this->name." Module \n". |
---|
93 | " DotClear is a bloging tool.\n". |
---|
94 | " .\n". |
---|
95 | " ".$this->desc."\n". |
---|
96 | "\n"; |
---|
97 | } |
---|
98 | |
---|
99 | private function copyrightTPL() |
---|
100 | { |
---|
101 | return |
---|
102 | "This is Dotclear ".$this->name." Module, written and maintained by ".$this->author."\n". |
---|
103 | "on ".date('r').".\n". |
---|
104 | "\n". |
---|
105 | "Copyright (C) ".date('Y')." ".$this->author."\n". |
---|
106 | "\n". |
---|
107 | "License:\n". |
---|
108 | "\n". |
---|
109 | " This program is free software; you can redistribute it and/or modify\n". |
---|
110 | " it under the terms of the GNU General Public License as published by\n". |
---|
111 | " the Free Software Foundation; either version 2 of the License, or\n". |
---|
112 | " (at your option) any later version.\n". |
---|
113 | "\n". |
---|
114 | " This program is distributed in the hope that it will be useful,\n". |
---|
115 | " but WITHOUT ANY WARRANTY; without even the implied warranty of\n". |
---|
116 | " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n". |
---|
117 | " GNU General Public License for more details.\n". |
---|
118 | "\n". |
---|
119 | " You should have received a copy of the GNU General Public License\n". |
---|
120 | " along with this package; if not, write to the Free Software\n". |
---|
121 | " Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA\n". |
---|
122 | " 02111-1307, USA.\n". |
---|
123 | "\n". |
---|
124 | "On Debian systems, the complete text of the GNU General\n". |
---|
125 | "Public License can be found in `/usr/share/common-licenses/GPL'.". |
---|
126 | "\n"; |
---|
127 | } |
---|
128 | |
---|
129 | private function dirsTPL() |
---|
130 | { |
---|
131 | return |
---|
132 | '/usr/share/dotclear/'.$this->type.'s/'.$this->id."\n"; |
---|
133 | } |
---|
134 | |
---|
135 | private function rulesTPL() |
---|
136 | { |
---|
137 | return |
---|
138 | "#!/usr/bin/make -f\n". |
---|
139 | "# -*- makefile -*-\n". |
---|
140 | "\n". |
---|
141 | "DEST=debian/".$this->package_name."/usr/share/dotclear/".$this->type.'s/'.$this->id."\n". |
---|
142 | "\n". |
---|
143 | "configure: configure-stamp\n". |
---|
144 | "configure-stamp:\n". |
---|
145 | " dh_testdir\n". |
---|
146 | " # Add here commands to configure the package.\n". |
---|
147 | "\n". |
---|
148 | " touch configure-stamp\n". |
---|
149 | "\n". |
---|
150 | "build: build-stamp\n". |
---|
151 | "\n". |
---|
152 | "build-stamp: configure-stamp\n". |
---|
153 | " dh_testdir\n". |
---|
154 | "\n". |
---|
155 | " # Add here commands to compile the package.\n". |
---|
156 | ' test -f Makefile && $(MAKE) config || echo "No Makefile"'."\n". |
---|
157 | " touch build-stamp\n". |
---|
158 | "\n". |
---|
159 | "clean:\n". |
---|
160 | " dh_testdir\n". |
---|
161 | " dh_testroot\n". |
---|
162 | " rm -f build-stamp configure-stamp\n". |
---|
163 | "\n". |
---|
164 | " # Add here commands to clean up after the build process.\n". |
---|
165 | ' test -f Makefile && $(MAKE) clean || echo "No Makefile"'."\n". |
---|
166 | "\n". |
---|
167 | " dh_clean\n". |
---|
168 | "\n". |
---|
169 | "install: build\n". |
---|
170 | " dh_testdir\n". |
---|
171 | " dh_testroot\n". |
---|
172 | " dh_clean -k\n". |
---|
173 | " dh_installdirs\n". |
---|
174 | "\n". |
---|
175 | " test -d _dist/module \\\n". |
---|
176 | ' && cp -af _dist/module ./$(DEST) \\'."\n". |
---|
177 | " || ( \\\n". |
---|
178 | " find ./ -mindepth 1 -type d -not -regex '.*.svn.*' \\\n". |
---|
179 | " -not -regex '.*debian.*' -exec mkdir ./\$(DEST)/\{\} \; \\\n". |
---|
180 | " && find ./ -type f -not -regex '.*.svn.*' -not -regex '.*debian.*' \\\n". |
---|
181 | " -not -name 'Makefile' -not -name 'configure-stamp' \\\n". |
---|
182 | " -not -name 'build-stamp' -exec cp -f \{\} ./\$(DEST) \; \\\n". |
---|
183 | " )\n". |
---|
184 | "\n". |
---|
185 | "# Build architecture-independent files here.\n". |
---|
186 | "binary-indep: build install\n". |
---|
187 | "# We have nothing to do by default.\n". |
---|
188 | "\n". |
---|
189 | "# Build architecture-dependent files here.\n". |
---|
190 | "binary-arch: build install\n". |
---|
191 | " dh_testdir\n". |
---|
192 | " dh_testroot\n". |
---|
193 | " dh_installchangelogs\n". |
---|
194 | " dh_installdocs\n". |
---|
195 | " dh_installexamples\n". |
---|
196 | " dh_installman\n". |
---|
197 | " dh_link\n". |
---|
198 | " dh_strip\n". |
---|
199 | " dh_compress\n". |
---|
200 | " dh_fixperms\n". |
---|
201 | " dh_installdeb\n". |
---|
202 | " dh_gencontrol\n". |
---|
203 | " dh_md5sums\n". |
---|
204 | " dh_builddeb\n". |
---|
205 | "\n". |
---|
206 | "binary: binary-indep binary-arch\n". |
---|
207 | ".PHONY: build clean binary-indep binary-arch binary install configure\n". |
---|
208 | "\n"; |
---|
209 | } |
---|
210 | } |
---|
211 | |
---|
212 | # Main |
---|
213 | try |
---|
214 | { |
---|
215 | $module = !empty($_SERVER['argv'][1]) ? $_SERVER['argv'][1] : '.'; |
---|
216 | $type = !empty($_SERVER['argv'][2]) ? $_SERVER['argv'][2] : 'plugin'; |
---|
217 | $m = new lambdaModule($module,$type); |
---|
218 | } |
---|
219 | catch (Exception $e) |
---|
220 | { |
---|
221 | fwrite(STDERR,$e->getMessage()."\n"); |
---|
222 | exit(1); |
---|
223 | } |
---|
224 | ?> |
---|