PageRenderTime 59ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 1ms

/m0n0dev.php

https://github.com/Siliconsoul/m0n0dev
PHP | 1276 lines | 545 code | 140 blank | 591 comment | 13 complexity | 435b940671536619385207b829b81d5f MD5 | raw file
  1. #!/usr/local/bin/php -f
  2. <?php
  3. /*
  4. m0n0dev.php (http://www.askozia.com/m0n0wall/m0n0dev.php)
  5. Copyright (C) 2007 IKT <http://www.itison-ikt.de>
  6. All rights reserved.
  7. Authors:
  8. Michael Iedema <michael@askozia.com>.
  9. Redistribution and use in source and binary forms, with or without
  10. modification, are permitted provided that the following conditions are met:
  11. 1. Redistributions of source code must retain the above copyright notice,
  12. this list of conditions and the following disclaimer.
  13. 2. Redistributions in binary form must reproduce the above copyright
  14. notice, this list of conditions and the following disclaimer in the
  15. documentation and/or other materials provided with the distribution.
  16. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
  17. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  18. AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  19. AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
  20. OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  21. SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  22. INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  23. CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  24. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  25. POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. // Please set me to the path you checked out the m0n0wall FreeBSD 6 branch to.
  28. $dirs['mwroot'] = "/root/m0n0wall"; // no trailing slash please!
  29. // --[ package versions ]------------------------------------------------------
  30. $php_version = "php-4.4.7";
  31. $radius_version = "radius-1.2.5";
  32. $mini_httpd_version = "mini_httpd-1.19";
  33. $wol_version = "wol-0.7.1";
  34. $ez_ipupdate_version = "ez-ipupdate-3.0.11b8";
  35. $bpalogin_version = "bpalogin-2.0.2";
  36. $ucd_snmp_version = "ucd-snmp-4.2.7";
  37. $mpd_version = "mpd-3.18";
  38. $ipsec_tools_version = "ipsec-tools-0.7";
  39. $siproxd_version = "siproxd-0.6.0";
  40. $ataidle_version = "ataidle-2.3";
  41. // --[ image sizes ]-----------------------------------------------------------
  42. $mfsroot_pad = 2304; // this gives roughly 15MB and matches official >=1.3b3
  43. $image_pad = 1024;
  44. // --[ possible platforms and kernels ]----------------------------------------
  45. $platform_list = "net45xx net48xx wrap generic-pc generic-pc-cdrom";//generic-pc-smp";
  46. $platforms = explode(" ", $platform_list);
  47. // --[ sanity checks and env info ]--------------------------------------------
  48. $dirs['pwd'] = rtrim(shell_exec("pwd"), "\n");
  49. $dirs['boot'] = $dirs['mwroot'] . "/build/boot";
  50. $dirs['kernelconfigs'] = $dirs['mwroot'] . "/build/kernelconfigs";
  51. $dirs['minibsd'] = $dirs['mwroot'] . "/build/minibsd";
  52. $dirs['patches'] = $dirs['mwroot'] . "/build/patches";
  53. $dirs['tools'] = $dirs['mwroot'] . "/build/tools";
  54. $dirs['captiveportal'] = $dirs['mwroot'] . "/captiveportal";
  55. $dirs['etc'] = $dirs['mwroot'] . "/etc";
  56. $dirs['phpconf'] = $dirs['mwroot'] . "/phpconf";
  57. $dirs['webgui'] = $dirs['mwroot'] . "/webgui";
  58. $dirs['files'] = $dirs['pwd'] . "/files";
  59. // check to make sure that the directories we expect are there
  60. foreach($dirs as $expected_dir) {
  61. if(!file_exists($expected_dir)) {
  62. _log("FATAL: missing directory ($expected_dir)\n".
  63. "Did you set the \"mwroot\" at the top of this script to the correct path?");
  64. exit(1);
  65. }
  66. }
  67. // create the work directory
  68. if(!file_exists("work")) {
  69. mkdir("work");
  70. }
  71. // ...and subdirectories
  72. $dirs['packages'] = $dirs['pwd']."/work/packages";
  73. $dirs['images'] = $dirs['pwd']."/work/images";
  74. $dirs['mfsroots'] = $dirs['pwd']."/work/mfsroots";
  75. foreach($dirs as $dir) {
  76. if(!file_exists($dir)) {
  77. mkdir($dir);
  78. }
  79. }
  80. // --[ the functions! ]--------------------------------------------------------
  81. $h["patch kernel"] = "patches the kernel sources with any changes needed by m0n0wall";
  82. function patch_kernel() {
  83. global $dirs;
  84. _exec("cd /usr/src; patch -p0 < ". $dirs['patches'] ."/kernel/kernel-6.patch");
  85. _log("patched kernel");
  86. _exec("cd /usr/src/sys; patch -p0 < ". $dirs['patches'] ."/kernel/racoon-nattraversal-freebsd6.patch");
  87. _log("patched racoon nat-traversal");
  88. }
  89. $h["patch syslog"] = "patches circular logging support into syslog";
  90. function patch_syslogd() {
  91. global $dirs;
  92. _exec("cd /usr/src; patch < ". $dirs['patches'] ."/user/syslogd.c.patch");
  93. _exec("cd /usr/src/usr.sbin; tar xfvz ". $dirs['patches'] ."/user/clog-1.0.1.tar.gz");
  94. _log("patched syslogd");
  95. }
  96. $h["patch bootloader"] = "patches the bootloader to fix some problems with terminal output";
  97. function patch_bootloader() {
  98. global $dirs;
  99. _exec("cd /sys/boot/i386/libi386; patch < ". $dirs['files'] ."/libi386.patch");
  100. _log("patched bootloader");
  101. }
  102. $h["patch hostapd"] = "patches hostapd to add PID support";
  103. function patch_hostapd() {
  104. global $dirs;
  105. _exec("cd /usr/src; patch < ". $dirs['patches'] ."/user/hostapd.patch");
  106. _log("patched hostapd");
  107. }
  108. $h["patch everything"] = "patches the bootloader, kernel and syslogd";
  109. function patch_everything() {
  110. patch_kernel();
  111. patch_syslogd();
  112. patch_bootloader();
  113. patch_hostapd();
  114. }
  115. $h["build kernel"] = "(re)builds and compresses the specified platform's kernel ($platform_list)";
  116. function build_kernel($platform) {
  117. global $dirs;
  118. $kernel = _platform_to_kernel($platform);
  119. _exec("cp ". $dirs['kernelconfigs'] ."/M0N0WALL_* /sys/i386/conf/");
  120. _exec("cp ". $dirs['files'] ."/M0N0WALL_GENERIC_SMP* /sys/i386/conf/");
  121. if(file_exists("/sys/i386/compile/$kernel")) {
  122. _exec("rm -rf /sys/i386/compile/$kernel");
  123. }
  124. _exec("cd /sys/i386/conf/; config $kernel");
  125. _exec("cd /sys/i386/compile/$kernel; make cleandepend; make depend; make");
  126. _exec("gzip -9 /sys/i386/compile/$kernel/kernel");
  127. _log("built kernel for $platform");
  128. }
  129. $h["build kernels"] = "(re)builds and compresses all kernels";
  130. function build_kernels() {
  131. global $platforms;
  132. foreach($platforms as $platform) {
  133. if($platform == "generic-pc-cdrom") {
  134. continue;
  135. }
  136. build_kernel($platform);
  137. }
  138. }
  139. $h["build syslogd"] = "(re)builds syslogd";
  140. function build_syslogd() {
  141. _exec("cd /usr/src/usr.sbin/syslogd; make clean; make");
  142. _log("built syslogd");
  143. }
  144. $h["build clog"] = "(re)builds the circular logging binary which optimizes logging on devices with limited memory";
  145. function build_clog() {
  146. _exec("cd /usr/src/usr.sbin/clog; make clean; make obj; make");
  147. _log("built clog");
  148. }
  149. $h["build hostapd"] = "(re)builds the hostapd binary";
  150. function build_hostapd() {
  151. _exec("cd /usr/src/usr.sbin/wpa/hostapd; make clean; make; make install");
  152. _log("built hostapd");
  153. }
  154. $h["build php"] = "(re)builds php and radius extension, also installs and configures autoconf if not already present";
  155. function build_php() {
  156. global $dirs, $php_version, $radius_version;
  157. if(!file_exists("/usr/local/bin/autoconf")) {
  158. _exec("cd /usr/ports/devel/autoconf213; make install clean");
  159. _exec("ln -s /usr/local/bin/autoconf213 /usr/local/bin/autoconf");
  160. _exec("ln -s /usr/local/bin/autoheader213 /usr/local/bin/autoheader");
  161. _log("installed autoconf");
  162. }
  163. if(!file_exists($dirs['packages'] ."/$php_version.tar.gz")) {
  164. _exec("cd ". $dirs['packages'] ."; ".
  165. "fetch http://br.php.net/distributions/$php_version.tar.gz");
  166. _log("fetched $php_version");
  167. }
  168. if (!is_dir($dirs['packages'] ."/$php_version")) {
  169. _exec("cd ". $dirs['packages'] ."; ".
  170. "tar zxf $php_version.tar.gz");
  171. _log("untarred $php_version");
  172. if (!file_exists($dirs['packages'] ."/$php_version/ext/$radius_version.tgz")) {
  173. _exec("cd ". $dirs['packages'] ."/$php_version/ext; ".
  174. "fetch http://m0n0.ch/wall/downloads/freebsd-4.11/$radius_version.tgz");
  175. _log("fetched $radius_version");
  176. }
  177. if (!is_dir($dirs['packages'] ."/$php_version/ext/radius")) {
  178. _exec("cd ". $dirs['packages'] ."/$php_version/ext; ".
  179. "tar zxf $radius_version.tgz; ".
  180. "mv $radius_version radius");
  181. _log("untarred $radius_version");
  182. }
  183. }
  184. _exec("cd ". $dirs['packages'] ."/$php_version; ".
  185. "rm configure; ".
  186. "./buildconf --force; ".
  187. "./configure --without-mysql --with-pear --with-openssl --enable-discard-path --enable-radius --enable-sockets --enable-bcmath; ".
  188. "make");
  189. _log("built php");
  190. }
  191. $h["build minihttpd"] = "(re)builds and patches mini_httpd";
  192. function build_minihttpd() {
  193. global $dirs, $mini_httpd_version;
  194. if(!file_exists($dirs['packages'] ."/$mini_httpd_version.tar.gz")) {
  195. _exec("cd ". $dirs['packages'] ."; ".
  196. "fetch http://www.acme.com/software/mini_httpd/$mini_httpd_version.tar.gz");
  197. _log("fetched $mini_httpd_version");
  198. }
  199. if (!is_dir($dirs['packages'] ."/$mini_httpd_version")) {
  200. _exec("cd ". $dirs['packages'] ."; ".
  201. "tar zxf $mini_httpd_version.tar.gz");
  202. _log("untarred $mini_httpd_version");
  203. }
  204. if(!_is_patched($mini_httpd_version)) {
  205. _exec("cd ". $dirs['packages'] ."/$mini_httpd_version; patch < ". $dirs['patches'] . "/packages/mini_httpd.patch");
  206. _stamp_package_as_patched($mini_httpd_version);
  207. }
  208. _exec("cd ". $dirs['packages'] ."/$mini_httpd_version; make clean; make");
  209. _log("built minihttpd");
  210. }
  211. $h["build dhcpserver"] = "(re)builds the ISC DHCP server (NOTE: dialog must be confirmed)";
  212. function build_dhcpserver() {
  213. /* TODO: automate compile */
  214. _prompt("After the screen appears, press TAB and then ENTER. (it's on the TODO list...)", 5);
  215. _exec("cd /usr/ports/net/isc-dhcp3-server; make clean; make WITHOUT_DHCP_LDAP_SSL=YES WITHOUT_DHCP_PARANOIA=YES WITHOUT_DHCP_JAIL=YES");
  216. _log("built dhcp server");
  217. }
  218. $h["build dhcprelay"] = "(re)builds the ISC DHCP relay";
  219. function build_dhcprelay() {
  220. _exec("cd /usr/ports/net/isc-dhcp3-relay; make clean; make");
  221. _log("built dhcp relay");
  222. }
  223. $h["build dnsmasq"] = "(re)builds Dnsmasq (DNS forwarder for NAT firewalls) (NOTE: dialog must be confirmed)";
  224. function build_dnsmasq() {
  225. /* TODO: automate compile */
  226. _prompt("After the screen appears, press TAB and then ENTER. (it's on the TODO list...)", 5);
  227. _exec("cd /usr/ports/dns/dnsmasq; make clean; make");
  228. _log("built dnsmasq");
  229. }
  230. $h["build msntp"] = "(re)builds msntp (NTP client)";
  231. function build_msntp() {
  232. _exec("cd /usr/ports/net/msntp; make clean; make");
  233. _log("built msntp");
  234. }
  235. $h["build wol"] = "(re)builds wol (wake-on-lan client)";
  236. function build_wol() {
  237. global $dirs, $wol_version;
  238. if(!file_exists($dirs['packages'] ."/$wol_version.tar.gz")) {
  239. _exec("cd ". $dirs['packages'] ."; ".
  240. "fetch http://heanet.dl.sourceforge.net/sourceforge/ahh/$wol_version.tar.gz");
  241. _log("fetched $wol_version");
  242. }
  243. if (!is_dir($dirs['packages'] ."/$wol_version")) {
  244. _exec("cd ". $dirs['packages'] ."; ".
  245. "tar zxf $wol_version.tar.gz");
  246. _log("untarred $wol_version");
  247. }
  248. _exec("cd ". $dirs['packages'] ."/$wol_version; ".
  249. "./configure --disable-nls; ".
  250. "make");
  251. _log("built wol");
  252. }
  253. $h["build ezipupdate"] = "(re)builds and patches ez-ipupdate (dynamic dns update client)";
  254. function build_ezipupdate() {
  255. global $dirs, $ez_ipupdate_version;
  256. if (!file_exists($dirs['packages'] ."/$ez_ipupdate_version.tar.gz")) {
  257. _exec("cd ". $dirs['packages'] ."; ".
  258. "fetch http://dyn.pl/client/UNIX/ez-ipupdate/$ez_ipupdate_version.tar.gz");
  259. _log("fetched $ez_ipupdate_version");
  260. }
  261. if (!is_dir($dirs['packages'] ."/$ez_ipupdate_version")) {
  262. _exec("cd ". $dirs['packages'] ."; ".
  263. "tar zxf $ez_ipupdate_version.tar.gz");
  264. _log("untarred $ez_ipupdate_version");
  265. }
  266. if(!_is_patched($ez_ipupdate_version)) {
  267. _exec("cd ". $dirs['packages'] ."/$ez_ipupdate_version; ".
  268. "patch < ". $dirs['patches'] ."/packages/ez-ipupdate.c.patch");
  269. _stamp_package_as_patched($ez_ipupdate_version);
  270. }
  271. _exec("cd ". $dirs['packages'] ."/$ez_ipupdate_version; ".
  272. "./configure; ".
  273. "make");
  274. _log("built ez-ipupdate");
  275. }
  276. $h["build bpalogin"] = "(re)builds BPALogin (Big Pond client)";
  277. function build_bpalogin() {
  278. global $dirs, $bpalogin_version;
  279. if(!file_exists($dirs['packages'] ."/$bpalogin_version.tar.gz")) {
  280. _exec("cd ". $dirs['packages'] ."; ".
  281. "fetch http://bpalogin.sourceforge.net/download/$bpalogin_version.tar.gz");
  282. _log("fetched $bpalogin_version");
  283. }
  284. if (!is_dir($dirs['packages'] ."/$bpalogin_version")) {
  285. _exec("cd ". $dirs['packages'] ."; ".
  286. "tar zxf $bpalogin_version.tar.gz");
  287. _log("untarred $bpalogin_version");
  288. }
  289. _exec("cd ". $dirs['packages'] ."/$bpalogin_version; ".
  290. "./configure; ".
  291. "make");
  292. _log("built bpalogin");
  293. }
  294. $h["build racoon"] = "(re)builds and patches the ipsec-tools version of racoon";
  295. function build_racoon() {
  296. global $dirs, $ipsec_tools_version;
  297. // TODO: mklibs.pl fails on this because the library has already been added by hand
  298. // hacked to install lib temporarily
  299. // TODO: ugly ugly ugly...make clean, make, make clean, make install!!
  300. /* TODO: automate compile */
  301. _prompt("After the screen appears, press TAB and then ENTER. (it's on the TODO list...)", 5);
  302. _exec("cd /usr/ports/security/ipsec-tools; patch < ". $dirs['files'] ."/ipsec-tools-makefile.patch");
  303. _exec("cd /usr/ports/security/ipsec-tools; make clean; make");
  304. /*_exec("cd /usr/ports/security/ipsec-tools/work/$ipsec_tools_version; ".
  305. "patch < ". $dirs['patches'] ."/packages/ipsec-tools-0.6.6.patch");*/
  306. _exec("cd /usr/ports/security/ipsec-tools/work/$ipsec_tools_version; make clean; make install");
  307. _log("built and patched racoon (albeit hackily)");
  308. }
  309. $h["build mpd"] = "(re)builds and patches MPD (Multi-link PPP daemon)";
  310. function build_mpd() {
  311. global $dirs, $mpd_version;
  312. // TODO: ugly...still need to better judge the port status
  313. _exec("cd /usr/ports/net/mpd; make clean; make");
  314. _exec("cd /usr/ports/net/mpd/work/$mpd_version; patch < ". $dirs['patches'] ."/packages/mpd.patch");
  315. _exec("cd /usr/ports/net/mpd/work/$mpd_version; make");
  316. _log("built and patched MPD");
  317. }
  318. $h["build ataidle"] = "(re)builds ataidle";
  319. function build_ataidle() {
  320. _exec("cd /usr/ports/sysutils/ataidle; make clean; make");
  321. _log("built ataidle");
  322. }
  323. $h["build ucdsnmp"] = "(re)builds and patches UCD-SNMP";
  324. function build_ucdsnmp() {
  325. global $dirs, $ucd_snmp_version;
  326. if (!file_exists($dirs['packages'] ."/$ucd_snmp_version.tar.gz")) {
  327. _exec("cd ". $dirs['packages'] ."; ".
  328. "fetch http://kent.dl.sourceforge.net/sourceforge/net-snmp/$ucd_snmp_version.tar.gz");
  329. _log("fetched $ucd_snmp_version");
  330. }
  331. if (!is_dir($dirs['packages'] ."/$ucd_snmp_version")) {
  332. _exec("cd ". $dirs['packages'] ."; tar zxf $ucd_snmp_version.tar.gz");
  333. _log("untarred $ucd_snmp_version");
  334. }
  335. if(!_is_patched("$ucd_snmp_version")) {
  336. _exec("cd ". $dirs['packages'] ."/$ucd_snmp_version; ".
  337. "patch < ". $dirs['patches'] ."/packages/ucd-snmp.patch");
  338. _stamp_package_as_patched("$ucd_snmp_version");
  339. }
  340. _prompt("All of the following prompts can all be answered with their default values.", 5);
  341. _exec("cd ". $dirs['packages'] ."/$ucd_snmp_version; ".
  342. "./configure --without-openssl --disable-debugging --enable-static --enable-mini-agent --disable-privacy --disable-testing-code --disable-shared-version --disable-shared --disable-ipv6 '--with-out-transports=TCP Unix' '--with-mib-modules=mibII/interfaces mibII/var_route ucd-snmp/vmstat_freebsd2'");
  343. _exec("cd ". $dirs['packages'] ."/$ucd_snmp_version; ".
  344. "patch < ". $dirs['files'] ."/ucd-snmp-config.h.patch");
  345. _exec("cd ". $dirs['packages'] ."/$ucd_snmp_version; make");
  346. _log("built UCD-SNMP");
  347. }
  348. $h["build siproxd"] = "(re)builds siproxd and installs libosip2 library if not found";
  349. function build_siproxd() {
  350. global $dirs, $siproxd_version;
  351. if (!file_exists("/usr/local/lib/libosip2.so.3")) {
  352. _exec("cd /usr/ports/net/libosip2; make clean; make install clean");
  353. _log("built libosip2 library");
  354. }
  355. if (!file_exists($dirs['packages'] ."/$siproxd_version.tar.gz")) {
  356. _exec("cd ". $dirs['packages'] ."; ".
  357. "fetch http://downloads.sourceforge.net/siproxd/$siproxd_version.tar.gz;");
  358. _log("fetched $siproxd_version");
  359. }
  360. if (!is_dir($dirs['packages'] ."/$siproxd_version")) {
  361. _exec("cd ". $dirs['packages'] ."; ".
  362. "tar zxf $siproxd_version.tar.gz; " .
  363. "patch < ". $dirs['patches'] ."/user/siproxd.patch");
  364. _log("untarred and patched $siproxd_version");
  365. }
  366. _exec("cd ". $dirs['packages'] ."/$siproxd_version; ".
  367. "./configure; make");
  368. _log("built siproxd");
  369. }
  370. $h["build tools"] = "(re)builds the little \"helper tools\" that m0n0wall needs (choparp, stats.cgi, minicron, verifysig)";
  371. function build_tools() {
  372. global $dirs;
  373. _exec("cd ". $dirs['tools'] ."; gcc -o choparp choparp.c");
  374. _log("built choparp");
  375. _exec("cd ". $dirs['tools'] ."; gcc -o stats.cgi stats.c");
  376. _log("built stats.cgi");
  377. _exec("cd ". $dirs['tools'] ."; gcc -o minicron minicron.c");
  378. _log("built minicron");
  379. _exec("cd ". $dirs['tools'] ."; gcc -o verifysig -lcrypto verifysig.c");
  380. _log("built verifysig");
  381. _exec("cd ". $dirs['tools'] ."; gcc -o wrapresetbtn wrapresetbtn.c");
  382. _log("built wrapresetbtn");
  383. _exec("cd ". $dirs['tools'] ."; gcc -o voucher -lcrypto -O2 voucher.c");
  384. _log("built voucher");
  385. }
  386. $h["build bootloader"] = "(re)builds the bootloader files";
  387. function build_bootloader() {
  388. _exec("cd /sys/boot; make clean; make obj; make");
  389. _log("compiled boot loader");
  390. }
  391. $h["build packages"] = "(re)builds all necessary packages";
  392. function build_packages() {
  393. build_php();
  394. build_minihttpd();
  395. build_wol();
  396. build_ezipupdate();
  397. build_bpalogin();
  398. build_ucdsnmp();
  399. }
  400. $h["build ports"] = "(re)builds all necessary ports";
  401. function build_ports() {
  402. build_dnsmasq();
  403. build_msntp();
  404. build_dhcpserver();
  405. build_dhcprelay();
  406. build_racoon();
  407. build_mpd();
  408. build_ataidle();
  409. build_siproxd();
  410. }
  411. $h["build everything"] = "(re)builds all packages, kernels and the bootloader";
  412. function build_everything() {
  413. build_syslogd();
  414. build_clog();
  415. build_hostapd();
  416. build_packages();
  417. build_ports();
  418. build_tools();
  419. build_kernels();
  420. build_bootloader();
  421. }
  422. $h["create"] = "creates the directory structure for the given \"image_name\"";
  423. function create($image_name) {
  424. global $dirs;
  425. if (file_exists($image_name)) {
  426. _exec("rm -rf $image_name");
  427. _exec("rm -rf {$dirs['images']}/*$image_name.img");
  428. _exec("rm -rf {$dirs['mfsroots']}/*$image_name.gz");
  429. }
  430. _exec("mkdir $image_name");
  431. _exec("cd $image_name; mkdir lib bin cf conf.default dev etc ftmp mnt libexec proc root sbin tmp usr var");
  432. _exec("cd $image_name; mkdir etc/inc");
  433. _exec("cd $image_name; ln -s /cf/conf conf");
  434. _exec("cd $image_name/usr; mkdir bin lib libexec local sbin share");
  435. _exec("cd $image_name/usr/local; mkdir bin captiveportal lib sbin www");
  436. _exec("cd $image_name/usr/local; ln -s /var/run/htpasswd www/.htpasswd");
  437. _log("created directory structure");
  438. }
  439. $h["populate base"] = "populates the base system binaries for the given \"image_name\"";
  440. function populate_base($image_name) {
  441. global $dirs;
  442. _exec("perl ". $dirs['minibsd'] ."/mkmini.pl ". $dirs['minibsd'] ."/m0n0wall.files / $image_name");
  443. _log("added base system binaries");
  444. }
  445. $h["populate etc"] = "populates /etc and appropriately links /etc/resolv.conf and /etc/hosts for the given \"image_name\"";
  446. function populate_etc($image_name) {
  447. global $dirs;
  448. _exec("cp -p ". $dirs['files'] ."/etc/* $image_name/etc/"); // etc stuff not in svn
  449. _exec("cp -p ". $dirs['etc'] ."/rc* $image_name/etc/");
  450. _exec("cp ". $dirs['etc'] ."/pubkey.pem $image_name/etc/");
  451. _log("added etc");
  452. _exec("ln -sf /var/etc/resolv.conf $image_name/etc/resolv.conf");
  453. _exec("ln -sf /var/etc/hosts $image_name/etc/hosts");
  454. _log("added resolv.conf and hosts symlinks");
  455. }
  456. $h["populate defaultconf"] = "adds the default xml configuration file to the given \"image_name\"";
  457. function populate_defaultconf($image_name) {
  458. global $dirs;
  459. _exec("cp ". $dirs['phpconf'] ."/config.xml $image_name/conf.default/");
  460. _log("added default config.xml");
  461. }
  462. $h["populate zoneinfo"] = "adds timezone info to the given \"image_name\"";
  463. function populate_zoneinfo($image_name) {
  464. global $dirs;
  465. _exec("cp ". $dirs['files'] ."/zoneinfo.tgz $image_name/usr/share/");
  466. _log("added zoneinfo.tgz");
  467. }
  468. $h["populate syslogd"] = "adds syslogd to the given \"image_name\"";
  469. function populate_syslogd($image_name) {
  470. global $dirs;
  471. _exec("cd /usr/src/usr.sbin/syslogd; ".
  472. "install -s /usr/obj/usr/src/usr.sbin/syslogd/syslogd $image_name/usr/sbin");
  473. _log("added syslogd");
  474. }
  475. $h["populate clog"] = "adds circular logging to the given \"image_name\"";
  476. function populate_clog($image_name) {
  477. global $dirs;
  478. _exec("cd /usr/src/usr.sbin/clog; ".
  479. "install -s /usr/obj/usr/src/usr.sbin/clog/clog $image_name/usr/sbin");
  480. _log("added clog");
  481. }
  482. $h["populate php"] = "adds the php interpreter to the given \"image_name\"";
  483. function populate_php($image_name) {
  484. global $dirs, $php_version;
  485. _exec("cd ". $dirs['packages'] ."/$php_version/; install -s sapi/cgi/php $image_name/usr/local/bin");
  486. _exec("cp ". $dirs['files'] ."/php.ini $image_name/usr/local/lib/");
  487. _log("added php");
  488. }
  489. $h["populate minihttpd"] = "adds the mini-httpd server to the given \"image_name\"";
  490. function populate_minihttpd($image_name) {
  491. global $dirs, $mini_httpd_version;
  492. _exec("cd ". $dirs['packages'] ."/$mini_httpd_version; ".
  493. "install -s mini_httpd $image_name/usr/local/sbin");
  494. _log("added mini_httpd");
  495. }
  496. $h["populate dhclient"] = "adds the ISC DHCP client to the given \"image_name\"";
  497. function populate_dhclient($image_name) {
  498. global $dirs;
  499. _exec("cp /sbin/dhclient $image_name/sbin/");
  500. _exec("cp ". $dirs['tools'] ."/dhclient-script $image_name/sbin/");
  501. _exec("chmod a+rx $image_name/sbin/dhclient-script");
  502. _log("added dhclient");
  503. }
  504. $h["populate dhcpserver"] = "adds the ISC DHCP server to the given \"image_name\"";
  505. function populate_dhcpserver($image_name) {
  506. global $dirs;
  507. _exec("cd /usr/ports/net/isc-dhcp3-server; ".
  508. "install -s work/dhcp-*/work.freebsd/server/dhcpd $image_name/usr/local/sbin");
  509. _log("added dhcp server");
  510. }
  511. $h["populate dhcprelay"] = "adds the ISC DHCP relay to the given \"image_name\"";
  512. function populate_dhcprelay($image_name) {
  513. global $dirs;
  514. _exec("cd /usr/ports/net/isc-dhcp3-relay; ".
  515. "install -s work/dhcp-*/work.freebsd/relay/dhcrelay $image_name/usr/local/sbin");
  516. _log("added dhcp relay");
  517. }
  518. $h["populate dnsmasq"] = "adds Dnsmasq (DNS forwarder) to the given \"image_name\"";
  519. function populate_dnsmasq($image_name) {
  520. global $dirs;
  521. _exec("cd /usr/ports/dns/dnsmasq; ".
  522. "install -s work/dnsmasq-*/src/dnsmasq $image_name/usr/local/sbin");
  523. _log("added dnsmasq");
  524. }
  525. $h["populate msntp"] = "adds msntp (NTP client) to the given \"image_name\"";
  526. function populate_msntp($image_name) {
  527. global $dirs;
  528. _exec("cd /usr/ports/net/msntp; ".
  529. "install -s work/msntp-*/msntp $image_name/usr/local/bin");
  530. _log("added msntp");
  531. }
  532. $h["populate wol"] = "adds wol (wake on lan client) to the given \"image_name\"";
  533. function populate_wol($image_name) {
  534. global $dirs, $wol_version;
  535. _exec("cd ". $dirs['packages'] ."/$wol_version; ".
  536. "install -s src/wol $image_name/usr/local/bin");
  537. _log("added wol");
  538. }
  539. $h["populate ezipupdate"] = "adds ez-ipupdate (dynamic dns client) to the given \"image_name\"";
  540. function populate_ezipupdate($image_name) {
  541. global $dirs, $ez_ipupdate_version;
  542. _exec("cd ". $dirs['packages'] ."/$ez_ipupdate_version; ".
  543. "install -s ez-ipupdate $image_name/usr/local/bin");
  544. _log("added ez-ipupdate");
  545. }
  546. $h["populate bpalogin"] = "adds bpalogin (Big Pond client) to the given \"image_name\"";
  547. function populate_bpalogin($image_name) {
  548. global $dirs, $bpalogin_version;
  549. _exec("cd ". $dirs['packages'] ."/$bpalogin_version; ".
  550. "install -s bpalogin $image_name/usr/local/sbin");
  551. _log("added bpalogin");
  552. }
  553. $h["populate mpd"] = "adds MPD (Multi-link PPP daemon) to the given \"image_name\"";
  554. function populate_mpd($image_name) {
  555. global $dirs;
  556. _exec("cd /usr/ports/net/mpd; install -s work/mpd-*/src/mpd $image_name/usr/local/sbin");
  557. _log("added mpd");
  558. }
  559. $h["populate racoon"] = "adds racoon to the given \"image_name\"";
  560. function populate_racoon($image_name) {
  561. global $dirs, $ipsec_tools_version;
  562. _exec("cd /usr/ports/security/ipsec-tools; ".
  563. "install -s work/$ipsec_tools_version/src/racoon/.libs/racoon $image_name/usr/local/sbin; ".
  564. "install -s work/$ipsec_tools_version/src/libipsec/.libs/libipsec.so.0 $image_name/usr/local/lib");
  565. _exec("cp /usr/ports/security/ipsec-tools/work/$ipsec_tools_version/src/setkey/setkey $image_name/usr/local/sbin/");
  566. _log("added racoon");
  567. }
  568. $h["populate ucdsnmp"] = "adds UCD-SNMP to the given \"image_name\"";
  569. function populate_ucdsnmp($image_name) {
  570. global $dirs, $ucd_snmp_version;
  571. _exec("cd ". $dirs['packages'] ."/$ucd_snmp_version; ".
  572. "install -s agent/snmpd $image_name/usr/local/sbin");
  573. _log("added ucd-snmp");
  574. }
  575. $h["populate siproxd"] = "adds the siproxd to the given \"image_name\"";
  576. function populate_siproxd($image_name) {
  577. global $dirs, $siproxd_version;
  578. _exec("cd ". $dirs['packages'] ."/$siproxd_version; ".
  579. "install -s src/siproxd $image_name/usr/local/sbin");
  580. _log("added siprxod");
  581. }
  582. $h["populate tools"] = "adds the m0n0wall \"helper tools\" to the given \"image_name\"";
  583. function populate_tools($image_name) {
  584. global $dirs;
  585. _exec("cd ". $dirs['tools'] ."; ".
  586. "install -s choparp $image_name/usr/local/sbin; ".
  587. "install -s stats.cgi $image_name/usr/local/www; ".
  588. "install -s minicron $image_name/usr/local/bin; ".
  589. "install -s verifysig $image_name/usr/local/bin; ".
  590. "install runmsntp.sh $image_name/usr/local/bin; ".
  591. "install wrapresetbtn $image_name/usr/local/sbin; ".
  592. "install -s voucher $image_name/usr/local/bin; ".
  593. "install ppp-linkup vpn-linkdown vpn-linkup $image_name/usr/local/sbin");
  594. }
  595. $h["populate phpconf"] = "adds the php configuration system to the given \"image_name\"";
  596. function populate_phpconf($image_name) {
  597. global $dirs;
  598. _exec("cp ". $dirs['phpconf'] ."/rc* $image_name/etc/");
  599. _exec("cp ". $dirs['phpconf'] ."/inc/* $image_name/etc/inc/");
  600. _log("added php conf scripts");
  601. }
  602. $h["populate webgui"] = "adds the php webgui files to the given \"image_name\"";
  603. function populate_webgui($image_name) {
  604. global $dirs;
  605. _exec("cp ". $dirs['webgui'] ."/* $image_name/usr/local/www/");
  606. _log("added webgui");
  607. }
  608. $h["populate captiveportal"] = "adds the captiveportal scripts to the given \"image_name\"";
  609. function populate_captiveportal($image_name) {
  610. global $dirs;
  611. _exec("cp ". $dirs['captiveportal'] ."/* $image_name/usr/local/captiveportal/");
  612. _log("added captiveportal");
  613. }
  614. $h["populate libs"] = "adds the required libraries (using mklibs.pl) to the given \"image_name\"";
  615. function populate_libs($image_name) {
  616. global $dirs;
  617. _exec("perl ". $dirs['minibsd'] ."/mklibs.pl $image_name > $image_name/tmp.libs");
  618. _exec("perl ". $dirs['minibsd'] ."/mkmini.pl $image_name/tmp.libs / $image_name");
  619. _exec("rm $image_name/tmp.libs");
  620. _log("added libraries");
  621. }
  622. $h["populate ataidle"] = "adds ataidle to the given \"image_name\"";
  623. function populate_ataidle($image_name) {
  624. _exec("cd /usr/ports/sysutils/ataidle/work/$ataidle_version/; ".
  625. "install -s ataidle $image_name/usr/local/sbin");
  626. _log("added ataidle");
  627. }
  628. $h["populate everything"] = "adds all packages, scripts and config files to the given \"image_name\"";
  629. function populate_everything($image_name) {
  630. populate_base($image_name);
  631. populate_etc($image_name);
  632. populate_defaultconf($image_name);
  633. populate_zoneinfo($image_name);
  634. populate_syslogd($image_name);
  635. populate_clog($image_name);
  636. populate_php($image_name);
  637. populate_minihttpd($image_name);
  638. populate_msntp($image_name);
  639. populate_ataidle($image_name);
  640. populate_bpalogin($image_name);
  641. populate_dhclient($image_name);
  642. populate_dhcprelay($image_name);
  643. populate_dhcpserver($image_name);
  644. populate_dnsmasq($image_name);
  645. populate_ezipupdate($image_name);
  646. populate_mpd($image_name);
  647. populate_racoon($image_name);
  648. populate_ucdsnmp($image_name);
  649. populate_wol($image_name);
  650. populate_siproxd($image_name);
  651. populate_tools($image_name);
  652. populate_phpconf($image_name);
  653. populate_webgui($image_name);
  654. populate_captiveportal($image_name);
  655. populate_libs($image_name);
  656. }
  657. // TODO: this is quite large and ugly
  658. $h["package"] = "package the specified image directory into an .img for the specified platform (i.e. package generic-pc testimage)";
  659. function package($platform, $image_name) {
  660. global $dirs;
  661. global $mfsroot_pad, $image_pad;
  662. _set_permissions($image_name);
  663. if(!file_exists("tmp")) {
  664. _exec("mkdir -p tmp");
  665. _exec("mkdir -p tmp/mnt");
  666. _exec("mkdir -p tmp/stage");
  667. }
  668. $kernel = _platform_to_kernel($platform);
  669. // mfsroot
  670. // add rootfs
  671. _exec("cd tmp/stage; tar -cf - -C $image_name ./ | tar -xpf -");
  672. // ...system modules
  673. _exec("mkdir -p tmp/stage/boot");
  674. _exec("mkdir -p tmp/stage/boot/kernel");
  675. if ($platform == "generic-pc" ||
  676. $platform == "generic-pc-cdrom") {
  677. _exec("cp /sys/i386/compile/$kernel/modules/usr/src/sys/modules/acpi/acpi/acpi.ko tmp/stage/boot/kernel/");
  678. }
  679. // ...stamps
  680. _exec("echo \"". basename($image_name) ."\" > tmp/stage/etc/version");
  681. _exec("echo `date` > tmp/stage/etc/version.buildtime");
  682. _exec("echo $platform > tmp/stage/etc/platform");
  683. // get size and package mfsroot
  684. $mfsroot_size = _get_dir_size("tmp/stage") + $mfsroot_pad;
  685. _exec("dd if=/dev/zero of=tmp/mfsroot bs=1k count=$mfsroot_size");
  686. _exec("mdconfig -a -t vnode -f tmp/mfsroot -u 0");
  687. _exec("bsdlabel -rw md0 auto");
  688. _exec("newfs -O 1 -b 8192 -f 1024 -o space -m 0 /dev/md0c");
  689. _exec("mount /dev/md0c tmp/mnt");
  690. _exec("cd tmp/mnt; tar -cf - -C ../stage ./ | tar -xpf -");
  691. // dummynet.ko and ipfw.ko reside in mfsroot/boot/kernel
  692. _exec("mkdir -p tmp/mnt/boot/kernel");
  693. _exec("cp /sys/i386/compile/$kernel/modules/usr/src/sys/modules/dummynet/dummynet.ko tmp/mnt/boot/kernel/");
  694. _exec("cp /sys/i386/compile/$kernel/modules/usr/src/sys/modules/ipfw/ipfw.ko tmp/mnt/boot/kernel/");
  695. _log("---- $platform - " . basename($image_name) . " - mfsroot ----");
  696. _exec("df tmp/mnt");
  697. _exec("umount tmp/mnt");
  698. _exec("rm -rf tmp/stage/*");
  699. _exec("mdconfig -d -u 0");
  700. _exec("gzip -9 tmp/mfsroot");
  701. _exec("mv tmp/mfsroot.gz {$dirs['mfsroots']}/$platform-". basename($image_name) .".gz");
  702. // .img
  703. if ($platform != "generic-pc-cdrom") {
  704. // add mfsroot
  705. _exec("cp {$dirs['mfsroots']}/$platform-". basename($image_name) .".gz ".
  706. "tmp/stage/mfsroot.gz");
  707. // ...boot
  708. _exec("mkdir -p tmp/stage/boot");
  709. _exec("mkdir -p tmp/stage/boot/kernel");
  710. _exec("cp /usr/obj/usr/src/sys/boot/i386/loader/loader tmp/stage/boot/");
  711. _exec("cp {$dirs['boot']}/$platform/loader.rc tmp/stage/boot/");
  712. // ...conf
  713. _exec("mkdir -p tmp/stage/conf");
  714. _exec("cp {$dirs['phpconf']}/config.xml tmp/stage/conf");
  715. _exec("cp /sys/i386/compile/$kernel/kernel.gz tmp/stage/kernel.gz");
  716. // get size and populate
  717. $image_size = _get_dir_size("tmp/stage") + $asterisk_size + $image_pad;
  718. $image_size += 16 - ($image_size % 16);
  719. _exec("dd if=/dev/zero of=tmp/image.bin bs=1k count=$image_size");
  720. _exec("mdconfig -a -t vnode -f tmp/image.bin -u 0");
  721. _exec("bsdlabel -Brw -b /usr/obj/usr/src/sys/boot/i386/boot2/boot md0 auto");
  722. _exec("newfs -O 1 -b 8192 -f 1024 -o space -m 0 /dev/md0a");
  723. _exec("mount /dev/md0a tmp/mnt");
  724. _exec("cd tmp/mnt; tar -cf - -C ../stage ./ | tar -xpf -");
  725. _log("---- $platform - " . basename($image_name) . " - system partition ----");
  726. _exec("df tmp/mnt");
  727. _exec("umount tmp/mnt");
  728. // cleanup
  729. _exec("mdconfig -d -u 0");
  730. _exec("gzip -9 tmp/image.bin");
  731. _exec("mv tmp/image.bin.gz {$dirs['images']}/m0n0wall-$platform-". basename($image_name) .".img");
  732. // .iso
  733. } else if($platform == "generic-pc-cdrom" && !file_exists($dirs['images'] ."/$platform-$version-". basename($image_name) .".iso")) {
  734. _exec("mkdir -p tmp/cdroot");
  735. _exec("cp ". $dirs['mfsroots'] ."/$platform-". basename($image_name) .".gz tmp/cdroot/mfsroot.gz");
  736. _exec("cp /sys/i386/compile/$kernel/kernel.gz tmp/cdroot/kernel.gz");
  737. _exec("mkdir -p tmp/cdroot/boot");
  738. _exec("cp /usr/obj/usr/src/sys/boot/i386/cdboot/cdboot tmp/cdroot/boot/");
  739. _exec("cp /usr/obj/usr/src/sys/boot/i386/loader/loader tmp/cdroot/boot/");
  740. _exec("cp ". $dirs['boot'] ."/$platform/loader.rc tmp/cdroot/boot/");
  741. _exec("cp /usr/obj/usr/src/sys/boot/i386/boot2/boot tmp/cdroot/boot/");
  742. _exec("mkisofs -b \"boot/cdboot\" -no-emul-boot -A \"m0n0wall CD-ROM image\" ".
  743. "-c \"boot/boot.catalog\" -d -r -publisher \"m0n0.ch\" ".
  744. "-p \"Your Name\" -V \"m0n0wall_cd\" -o \"m0n0wall.iso\" tmp/cdroot/");
  745. _exec("mv m0n0wall.iso ". $dirs['images'] ."/m0n0wall-cdrom-". basename($image_name) .".iso");
  746. }
  747. _exec("rm -rf tmp");
  748. }
  749. function _set_permissions($image_name) {
  750. _exec("chmod 755 $image_name/etc/rc*");
  751. _exec("chmod 644 $image_name/etc/pubkey.pem");
  752. _exec("chmod 644 $image_name/etc/inc/*");
  753. _exec("chmod 644 $image_name/conf.default/config.xml");
  754. _exec("chmod 644 $image_name/usr/local/www/*");
  755. _exec("chmod 755 $image_name/usr/local/www/*.php");
  756. _exec("chmod 755 $image_name/usr/local/www/*.cgi");
  757. _exec("chmod 644 $image_name/usr/local/captiveportal/*");
  758. _exec("chmod 755 $image_name/usr/local/captiveportal/*.php");
  759. _log("permissions set.");
  760. }
  761. function _stamp_package_as_patched($package_version) {
  762. global $dirs;
  763. touch($dirs['packages'] ."/$package_version/$package_version.patched");
  764. _log("patched $package_version");
  765. }
  766. function _is_patched($package_version) {
  767. global $dirs;
  768. return(file_exists($dirs['packages'] ."/$package_version/$package_version.patched"));
  769. }
  770. function _platform_to_kernel($platform) {
  771. global $platforms;
  772. if($platform == "generic-pc-cdrom" || $platform == "generic-pc") {
  773. $kernel = "M0N0WALL_GENERIC";
  774. } else if($platform == "generic-pc-smp") {
  775. $kernel = "M0N0WALL_GENERIC_SMP";
  776. } else if($platform == "wrap") {
  777. $kernel = "M0N0WALL_WRAPALIX";
  778. } else {
  779. $kernel = "M0N0WALL_" . strtoupper($platform);
  780. }
  781. return $kernel;
  782. }
  783. function _exec($cmd) {
  784. $ret = 0;
  785. _log($cmd);
  786. passthru($cmd, $ret);
  787. if($ret != 0) {
  788. _log("COMMAND FAILED: $cmd");
  789. exit(1);
  790. }
  791. }
  792. function _log($msg) {
  793. print "$msg\n";
  794. }
  795. function _get_dir_size($dir) {
  796. exec("du -d 0 $dir", $out);
  797. $out = preg_split("/\s+/", $out[0]);
  798. return $out[0];
  799. }
  800. function _prompt($msg, $duration=0) {
  801. $msg = wordwrap(" - $msg", 74, "\n - ");
  802. if($duration) {
  803. print "--[ Attention! ]-------------------------------------------------------------\n\n";
  804. }
  805. print "$msg\n\n";
  806. if($duration) {
  807. print "--[ T-MINUS ";
  808. print "$duration";
  809. $i = $duration-1;
  810. for($i; $i>0; $i--) {
  811. sleep(1);
  812. print ", $i";
  813. }
  814. sleep(1);
  815. print "\n\n";
  816. }
  817. }
  818. function _usage() {
  819. print "\n";
  820. print "./m0n0dev.php new image_name start a new image\n";
  821. print "./m0n0dev.php patch something patch a target\n";
  822. print "./m0n0dev.php build something build a target\n";
  823. print "./m0n0dev.php parsecheck check for stupid mistakes\n";
  824. print "./m0n0dev.php populate something image populate an image with a target\n";
  825. print "./m0n0dev.php package platform image package image for specified platform\n";
  826. print "\nHelp is available by prefixing the command with \"help\" (i.e. help patch)\n\n";
  827. exit(1);
  828. }
  829. // DONE by rOger Eisenecher: I could generate these...
  830. $functions = get_defined_functions();
  831. sort($functions["user"]);
  832. foreach ($functions["user"] as $func) {
  833. $parts = explode('_', $func, 2);
  834. $group = $parts[0];
  835. $f = $parts[1];
  836. $funcs["$group"][] = $f;
  837. }
  838. $h["patch"] = "available patch options: " . implode(", ", $funcs["patch"]);
  839. $h["build"] = "available build options: " . implode(", ", $funcs["build"]);
  840. $h["populate"] = "available populate options: " . implode(", ", $funcs["populate"]);
  841. // --[ command line parsing ]--------------------------------------------------
  842. // nothing to do, here's what's possible
  843. if($argc == 1) {
  844. _usage();
  845. // here's some help if it's available
  846. } else if($argv[1] == "help") {
  847. // not enough arguments
  848. if($argc == 2) {
  849. _log("Not enough arguments provided for help");
  850. }
  851. // form a command name and see if it's in the help array
  852. $c = implode(" ", array_slice($argv, 2));
  853. array_key_exists($c, $h) ?
  854. _prompt($h[$c]) :
  855. _log("no help available on ($c)! :(");;
  856. } else if ($argv[1] == "new") {
  857. $image_name = "{$dirs['images']}/" . rtrim($argv[2], "/");
  858. create($image_name);
  859. populate_everything($image_name);
  860. // patch functions are all defined with no arguments
  861. } else if($argv[1] == "patch") {
  862. $f = implode("_", array_slice($argv, 1));
  863. function_exists($f) ?
  864. $f() :
  865. _log("Invalid patch command!");
  866. // build functions are all defined with no arguments except for "build_kernel"
  867. } else if($argv[1] == "build") {
  868. if($argv[2] == "kernel") {
  869. build_kernel($argv[3]);
  870. } else {
  871. $f = implode("_", array_slice($argv, 1));
  872. function_exists($f) ?
  873. $f() :
  874. _log("Invalid build command!");
  875. }
  876. // populate functions are all defined with a single argument:
  877. // (image_name directory)
  878. } else if($argv[1] == "populate") {
  879. // make a function name out of the arguments
  880. $f = implode("_", array_slice($argv, 1, 2));
  881. // not a valid function, show usage
  882. if(!function_exists($f)) {
  883. _log("Invalid populate command!");
  884. }
  885. // construct an absolute path to the image
  886. $image_name = $dirs['images']. "/" . rtrim($argv[3], "/");
  887. // not a valid image, show usage
  888. if(!file_exists($image_name)) {
  889. _log("Image does not exist!");
  890. }
  891. $f($image_name);
  892. // the package function is defined with two arguments:
  893. // (platform, image_name)
  894. } else if($argv[1] == "package") {
  895. // construct an absolute path to the image
  896. $image_name = $dirs['images']. "/" . rtrim($argv[3], "/");
  897. // not a valid image, show usage
  898. if(!file_exists($image_name)) {
  899. _log("Image does not exist!");
  900. }
  901. // we're packaging all platforms go right ahead
  902. if($argv[2] == "all") {
  903. foreach($platforms as $platform) {
  904. package($platform, $image_name);
  905. }
  906. // check the specific platform before attempting to package
  907. } else if(in_array($argv[2], $platforms)) {
  908. package($argv[2], $image_name);
  909. // not a valid package command...
  910. } else {
  911. _log("Invalid packaging command!");
  912. }
  913. } else if ($argv[1] == "parsecheck") {
  914. passthru("find {$dirs['webgui']}/ -type f -name \"*.php\" -exec php -l {} \; -print | grep Parse");
  915. passthru("find {$dirs['webgui']}/ -type f -name \"*.inc\" -exec php -l {} \; -print | grep Parse");
  916. passthru("find {$dirs['phpconf']}/ -type f -name \"*rc.*\" -exec php -l {} \; -print | grep Parse");
  917. passthru("find {$dirs['phpconf']}/ -type f -name \"*.inc\" -exec php -l {} \; -print | grep Parse");
  918. // hmmm, don't have any verbs like that!
  919. } else {
  920. _log("Huh?");
  921. exit(1);
  922. }
  923. exit();
  924. ?>