Skip to content

Commit 21f8920

Browse files
committed
卸载命令
1 parent e6d51ed commit 21f8920

9 files changed

+151
-78
lines changed

README.md

+21-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
1-
## PHPOpenCV Installer
1+
# PHPOpenCV Installer
22

3+
PHPOpenCV Installer是一个简易安装phpopencv扩展,自动检测编译安装opencv并编译php扩展
4+
5+
## 目录
6+
7+
8+
9+
10+
## 环境要求
11+
12+
- cmake3.5+(编译安装opencv时候需要)
13+
- pkg-config
14+
- Qt5+(编译安装opencv时候需要)
15+
- php7+
16+
- pecl
17+
18+
19+
## 使用
320

421
First, download the PHPOpenCV installer using Composer:
522

@@ -47,4 +64,6 @@ phpopencv install
4764

4865
| <img src="/images/ubuntu.png" width="48px" height="48px" alt="Chrome logo"> | <img src="/images/centos.jpg" width="48px" height="48px" alt="Edge logo"> |
4966
|:---:|:---:|
50-
| 16+ ✔ | 7+ ✔ |
67+
| 16+ ✔ | 7+ ✔ |
68+
69+

change.log

Whitespace-only changes.

composer.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212
"autoload": {
1313
"psr-4": {
1414
"CV\\Installer\\Console\\": "src/"
15-
}
15+
},
16+
"files": [
17+
"src/helpers.php"
18+
]
1619
},
1720
"require": {
1821
"php": ">=7.0.0",

phpopencv

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#!/usr/bin/env php
22

33
<?php
4-
if (file_exists(__DIR__.'/../../autoload.php')) {
5-
require __DIR__.'/../../autoload.php';
4+
if (file_exists(__DIR__ . '/../../autoload.php')) {
5+
require __DIR__ . '/../../autoload.php';
66
} else {
7-
require __DIR__.'/vendor/autoload.php';
7+
require __DIR__ . '/vendor/autoload.php';
88
}
99
$app = new Symfony\Component\Console\Application('PHPOpenCV Installer', '1.0.0');
10-
$app->add(new CV\Installer\Console\InstallCommand);
11-
$app->add(new CV\Installer\Console\UninstallCommand);
10+
$app->add(new CV\Installer\Console\Command\Install);
11+
$app->add(new CV\Installer\Console\Command\Uninstall);
1212
$app->run();

src/InstallCommand.php src/Command/Install.php

+6-21
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<?php
22

3-
namespace CV\Installer\Console;
3+
namespace CV\Installer\Console\Command;
44

5+
use CV\Installer\Console\CommonTrait;
56
use Symfony\Component\Console\Command\Command;
67
use Symfony\Component\Console\Exception\RuntimeException;
78
use Symfony\Component\Console\Input\InputArgument;
@@ -11,18 +12,18 @@
1112
use Symfony\Component\Process\Exception\ProcessFailedException;
1213
use Symfony\Component\Process\Process;
1314

14-
class InstallCommand extends Command
15+
class Install extends Command
1516
{
1617

1718
const EXTENSION_NAME = 'opencv';
1819
const OPENCV_VERSION = '4.0.0';
1920

2021
protected $installInfo = [];
2122

22-
protected $isRoot = false;
23-
protected $systemUsername;
2423

2524

25+
use CommonTrait;
26+
2627
/**
2728
* Configure the command options.
2829
*
@@ -43,30 +44,14 @@ protected function configure()
4344
}
4445

4546

46-
protected function checkIsRoot()
47-
{
48-
$process = new Process(['whoami']);
49-
try {
50-
$process->mustRun();
51-
$username = str_replace(PHP_EOL, '', $process->getOutput());
52-
if ($username == 'root') {
53-
$this->isRoot = true;
54-
}
55-
$this->systemUsername = $username;
56-
} catch (\Exception $e) {
57-
throw new RuntimeException($process->getErrorOutput());
58-
}
59-
}
60-
61-
6247
/**
6348
* 检测安装环境
6449
* @author hihozhou
6550
* @throws RuntimeException
6651
*/
6752
protected function buildEnvDetection()
6853
{
69-
$shellPath = __DIR__ . '/../opencv-install-environment-detection.sh';
54+
$shellPath = dirname(__DIR__) . '/../opencv-install-environment-detection.sh';
7055
$process = new Process([$shellPath]);//todo 给予当前用户
7156
try {
7257
$process->mustRun();

src/Command/Uninstall.php

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: hiho
5+
* Date: 19-4-11
6+
* Time: 下午7:11
7+
*/
8+
9+
namespace CV\Installer\Console\Command;
10+
11+
12+
use CV\Installer\Console\CommonTrait;
13+
use Symfony\Component\Console\Command\Command;
14+
use Symfony\Component\Console\Exception\RuntimeException;
15+
use Symfony\Component\Console\Input\InputInterface;
16+
use Symfony\Component\Console\Output\OutputInterface;
17+
use Symfony\Component\Process\Process;
18+
19+
class Uninstall extends Command
20+
{
21+
22+
use CommonTrait;
23+
24+
/**
25+
* Configure the command options.
26+
*
27+
* @return void
28+
*/
29+
protected function configure()
30+
{
31+
$this->setName('uninstall')
32+
->setDescription('Uninstall PHPOpenCV extension and OpenCV');
33+
}
34+
35+
36+
/**
37+
* Execute the command.
38+
*
39+
* @param \Symfony\Component\Console\Input\InputInterface $input
40+
* @param \Symfony\Component\Console\Output\OutputInterface $output
41+
*
42+
* @return void
43+
*/
44+
protected function execute(InputInterface $input, OutputInterface $output)
45+
{
46+
47+
$this->checkIsRoot();
48+
// todo 通过日志文件获取
49+
//卸载扩展
50+
$commands = [
51+
'cd /opt/phpopencv/opencv/build',
52+
($this->isRoot ? '' : 'sudo ') . 'make uninstall',
53+
($this->isRoot ? '' : 'sudo ') . 'find . -name "*opencv*" | xargs ' . ($this->isRoot ? '' : 'sudo ') . 'rm -rf'
54+
];
55+
$output->writeln('通过php-config --extension-dir查找扩展存放的目录');
56+
$process = new Process('php-config --extension-dir');
57+
$process->mustRun();
58+
$extDir = str_replace(PHP_EOL, '', $process->getOutput());
59+
$openCVSoPath = $extDir . '/opencv.so';
60+
if (file_exists($openCVSoPath)) {
61+
$commands[] = ($this->isRoot ? '' : 'sudo ') . 'rm ' . $openCVSoPath;
62+
}
63+
try {
64+
$process = new Process(implode(' && ', $commands));
65+
$process->setTty(Process::isTtySupported());//检查TTY支持
66+
$process->mustRun();
67+
} catch (\Exception $e) {
68+
throw new RuntimeException('Aborting.');
69+
}
70+
//cd /opt/opencv/opencv/build
71+
//sudo make uninstall
72+
//sudo find . -name "*opencv*" | xargs sudo rm -rf\
73+
//通过pkg-config php-config --extension-dir 删除
74+
75+
}
76+
}

src/CommonTrait.php

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: hiho
5+
* Date: 19-6-4
6+
* Time: 下午9:16
7+
*/
8+
9+
namespace CV\Installer\Console;
10+
11+
12+
use Symfony\Component\Process\Process;
13+
14+
trait CommonTrait
15+
{
16+
protected $isRoot = false;
17+
protected $systemUsername;
18+
19+
20+
/**
21+
* 判断是否是超级管理员
22+
* @author hihozhou
23+
*/
24+
protected function checkIsRoot()
25+
{
26+
$process = new Process(['whoami']);
27+
try {
28+
$process->mustRun();
29+
$username = str_replace(PHP_EOL, '', $process->getOutput());
30+
if ($username == 'root') {
31+
$this->isRoot = true;
32+
}
33+
$this->systemUsername = $username;
34+
} catch (\Exception $e) {
35+
throw new \RuntimeException($process->getErrorOutput());
36+
}
37+
}
38+
}

src/UninstallCommand.php

-49
This file was deleted.

src/helpers.php

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<?php declare(strict_types=1);

0 commit comments

Comments
 (0)