From ff5a1f3252689c2c473ef89ab025667ae3b23b16 Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Mon, 9 Mar 2015 11:28:50 +0100 Subject: [PATCH] INI file activation --- bin/pharext | Bin 38953 -> 41514 bytes src/pharext/Installer.php | 106 +++++++++++++++++++++++++++++++++----- 2 files changed, 92 insertions(+), 14 deletions(-) diff --git a/bin/pharext b/bin/pharext index bf6f0c59245183a8ae8b253304458996357a18c0..6137e91b8dfd00df99eeb788ad1753f2974c7a65 100755 GIT binary patch delta 2987 zcma)8U2GIp6mI#=ZbS$LG}{HP!?et{-Q6OI4b+yuKrKlLX$hgUb)C-K*&RD`XPCLu zADg=Jpb0+sa$nW(st?+vi3tIsB*r)6n~&-nF%TYnQDba8=iZs65SrMexqI(D=R4+7ZobvEfy+Kf05tqk}0}!1QEe+cteDK#`tjMS!+)oC&7j$dl=LE&OH{fpU{BQp*6c zr4aJovYDOD^bsB<^f~K5!T$wFy-HyQWE81$W}00HETb(wFI&Q^sSl``UbSqr?zliRVEU;=~Rh*NzF4 zDq3{p1CD5HnIVlE)blLgHuMx!lHfW-Qsh^MzjiX{m=_+YQUyX`Bn4Huw-Z( zAi*`bG^9_Zv=|h>`OWg=GAA&!@q{s#)k#-ODwWDK0~G1;X32Sx7W$<#(@!&snUE1l zGP=8o8^@Fzy6Bu7--eM1J~^y@+?gz?AHPqIi0bvb;@pY7Sh9U75ztBtl$c%weYr#$ z<~(f3Y{IMtc4?6CFyVROEf(5W*4D50w~Gfo9lNp;Fc1WLZ69=Z#w?B!*^Od7JkZ1o zXvmFC0Ckhes8)m>r;(x-i8nMJxjuwU7t_4-!3IV^4bW;%H7_Eh3POHJsZ z$-z(53L{#t-ADos6QqR(769D|fJ$J`kU=(MV#Y*wnN1hT&@hpQ8B-hvFMu(+K(ZNZ zXgKL$jH;koU>K}IEJ;AmWoh-RN{|luCbt@fR(*Rq?n%8G3m9yM;D2gbJ34b}ISXP% z?cu^0tn`#lP3u*xF^QY{C+BQd8N5LwDsChl&GRkxvb(GtY$$H!cP!2?~=1oH#+kY-mc`hHAjHH8F4KCgB0RE|hp? z4DUx2STv3a@&pLj9BEIWIk12ir8F=nj9kW@7rLUg(mB)>XU&?Hi;S%aQ%^=JB8LgmLmK(uf=#W! z0`HVzXauUwkZ#gHFff2YG(mFXD}p9b6X?dwJZl%UrCk)*)b8_WX*mHJI`7Xb1aKJ; z95?6D)OGPyO<#L!x?b8^sZ_=7;wx)Ee0X73I}zp^9m7DY1(gxEI!l$09h2#a(7OQD zFbdN-znsqjfPQ3w&<>Dnjzn>sX=<1VVA(P1RXvDS}eDiiGCCk~`+DXu{^ z*RU#Twi_9xidIc^D;i3pLg1V697rd)8bGEj2zbiC1LS@~;UI1$VNLgjYpb!9F|IrW z6ekENGo%(!w5Ymng)B56E@Hgq#xiSql0*A9y(+lop5cV9nv{P5`K>+Ad6fw70Z_jmjOU&C!9XUER|2WoPk5C8xG delta 650 zcmZ2=glXjlrVXA_tdE%(82BdpNm(+n1y1giG6Ye3q;x^lYbkAkqhbsUY=M76Ky;ph zt-)k9X+4l!7=&t*HU{x_OB)EJ@}EgNPTkFM-VN-NUj=DR-VvG!TB?T)5u&{z|F_4F;B{Q$MBrzuktg9ZZ3nqf3QvoKX zqfk;*nhG=pVRLd$YGPh#frd&+YHk6FOlDqMzJ`)Zex7=XLRx-NdTNP6Nxnj2a!F=c zW@1UILPejd;Y1)<9P(jtX|i~_yPyiCQIyqG+t&H16yEIetYIXMc+ z`MJ4?c`1{3MV1Mw6qlytE7&TeCFT^TYARH7P1cQ;WmYW)c|%e_1*#P21C_kQ+*F{T z#^l)OGINL17ee#4-mC1`@rcJ(BFSdDBtRCZJwz*Q9S0$%wPOhxv zpL}12W3zUz8}DS#2I0*LbKkMZ_?fb%Z|2>$p?9v1?p&L^U1fF$ErH37!QIK%2>|x! B(e?lU diff --git a/src/pharext/Installer.php b/src/pharext/Installer.php index 589abd6..c88b0d6 100644 --- a/src/pharext/Installer.php +++ b/src/pharext/Installer.php @@ -45,7 +45,9 @@ class Installer implements Command CliArgs::OPTIONAL|CliArgs::MULTI|CliArgs::REQARG], ["s", "sudo", "Installation might need increased privileges", CliArgs::OPTIONAL|CliArgs::SINGLE|CliArgs::OPTARG, - "sudo -S %s"] + "sudo -S %s"], + ["i", "ini", "Activate in this php.ini instead of loaded default php.ini", + CliArgs::OPTIONAL|CliArgs::SINGLE|CliArgs::REQARG], ]); } @@ -139,15 +141,35 @@ class Installer implements Command exit(4); } + // phpize $this->exec("phpize", $this->php("ize")); - $this->exec("configure", "./configure --with-php-config=". $this->php("-config") . " ". - implode(" ", (array) $this->args->configure)); - $this->exec("make", $this->args->verbose ? "make -j3" : "make -sj3"); - $this->exec("install", $this->args->verbose ? "make install" : "make -s install", true); - $this->cleanup($temp); + // configure + $args = ["--with-php-config=". $this->php("-config")]; + if ($this->args->configure) { + $args = array_merge($args, $this->args->configure); + } + $this->exec("configure", "./configure", $args); + + // make + if ($this->args->verbose) { + $this->exec("make", "make", ["-j3"]); + } else { + $this->exec("make", "make", ["-j3", "-s"]); + } + + // install + if ($this->args->verbose) { + $this->exec("install", "make", ["install"], true); + } else { + $this->exec("install", "make", ["install", "-s"], true); + } + + // activate + $this->activate(); - $this->info("Don't forget to activiate the extension in your php.ini!\n\n"); + // cleanup + $this->cleanup($temp); } /** @@ -195,19 +217,31 @@ class Installer implements Command /** * Execute a system command * @param string $name pretty name - * @param string $command full command + * @param string $command command + * @param array $args command arguments * @param bool $sudo whether the command may need escalated privileges */ - private function exec($name, $command, $sudo = false) { - $this->info("Running %s ...%s", $this->args->verbose ? $command : $name, $this->args->verbose ? "\n" : " "); + private function exec($name, $command, array $args = null, $sudo = false) { + $exec = escapeshellcmd($command); + if ($args) { + $exec .= " ". implode(" ", array_map("escapeshellarg", (array) $args)); + } + + if ($this->args->verbose) { + $this->info("Running %s ...\n", $exec); + } else { + $this->info("Running %s ... ", $name); + } + if ($sudo && isset($this->args->sudo)) { - $retval = $this->sudo(sprintf($this->args->sudo." 2>&1", $command), $output); + $retval = $this->sudo(sprintf($this->args->sudo." 2>&1", $exec), $output); } elseif ($this->args->verbose) { - passthru($command ." 2>&1", $retval); + passthru($exec ." 2>&1", $retval); } else { - exec($command ." 2>&1", $output, $retval); + exec($exec ." 2>&1", $output, $retval); $output = implode("\n", $output); } + if ($retval) { $this->error("Command %s failed with (%s)\n", $command, $retval); if (isset($output) && !$this->args->quiet) { @@ -215,7 +249,10 @@ class Installer implements Command } exit(2); } - $this->info("OK\n"); + if (!$this->args->verbose) { + // we already have a bunch of output + $this->info("OK\n"); + } } /** @@ -230,4 +267,45 @@ class Installer implements Command } return $cmd; } + + private function activate() { + if ($this->args->ini) { + $files = [realpath($this->args->ini)]; + } else { + $files = array_filter(array_map("trim", explode(",", php_ini_scanned_files()))); + $files[] = php_ini_loaded_file(); + } + + $extension = basename(current(glob("modules/*.so"))); + $pattern = preg_quote($extension); + + foreach ($files as $index => $file) { + $temp = new Tempfile("phpini"); + foreach (file($file) as $line) { + if (preg_match("/^\s*extension\s*=\s*[\"']?{$pattern}[\"']?\s*(;.*)?\$/", $line)) { + // already there + $this->info("Extension already activated\n"); + return; + } + fwrite($temp->getStream(), $line); + } + } + + // not found, add extension line to the last process file + if (isset($temp, $file)) { + fprintf($temp->getStream(), "extension=%s\n", $extension); + $temp->closeStream(); + + $path = $temp->getPathname(); + $stat = stat($file); + + $ugid = sprintf("%d:%d", $stat["uid"], $stat["gid"]); + $this->exec("INI owner transfer", "chown", [$ugid, $path], true); + + $perm = decoct($stat["mode"] & 0777); + $this->exec("INI permission transfer", "chmod", [$perm, $path], true); + + $this->exec("INI activation", "mv", [$path, $file], true); + } + } } -- 2.30.2