@@ -21,7 +21,6 @@ class Install extends Command
21
21
protected $ installInfo = [];
22
22
23
23
24
-
25
24
use CommonTrait;
26
25
27
26
/**
@@ -44,6 +43,74 @@ protected function configure()
44
43
}
45
44
46
45
46
+ /**
47
+ * 检测系统
48
+ * @author hihozhou
49
+ */
50
+ protected function checkOs ()
51
+ {
52
+ if (file_exists ('/usr/bin/yum ' )) {
53
+ $ pm = 'yum ' ;
54
+ $ process = new Process ('command -v lsb_release >/dev/null 2>&1 || { yum -y install redhat-lsb-core; } ' );//todo 给予当前用户
55
+ try {
56
+ $ process ->mustRun ();
57
+ } catch (\Exception $ e ) {
58
+ throw new RuntimeException ($ process ->getErrorOutput ());
59
+ }
60
+ } else if (file_exists ('/usr/bin/apt-get ' )) {
61
+ $ pm = 'apt-get ' ;
62
+ $ process = new Process ('command -v lsb_release >/dev/null 2>&1 || { yum -y install redhat-lsb-core; } ' );//todo 给予当前用户
63
+ try {
64
+ $ process ->mustRun ();
65
+ } catch (\Exception $ e ) {
66
+ throw new RuntimeException ($ process ->getErrorOutput ());
67
+ }
68
+ }
69
+ //
70
+ $ process = new Process ('command -v lsb_release >/dev/null 2>&1 || { echo >&2 "Fail to use lsb_release!"; exit 1; } ' );
71
+ try {
72
+ $ process ->mustRun ();
73
+ } catch (\Exception $ e ) {
74
+ throw new RuntimeException ($ process ->getErrorOutput ());
75
+ }
76
+
77
+
78
+ // if (file_exists('/etc/redhat-release')) {
79
+ // //RedHat,Centos
80
+ // $OS = 'CentOS';
81
+ // }elseif (){}
82
+ // else {
83
+ // throw new RuntimeException('Does not support this OS, Please contact the author!');
84
+ // }
85
+ }
86
+
87
+
88
+ //todo 检测并安装cmake
89
+ protected function checkCmakeOrInstall (OutputInterface $ output )
90
+ {
91
+
92
+ $ checkCommad = 'command -v cmake1 >/dev/null 2>&1 || { echo >&2 "Compiling OpenCV requires cmake, but no cmake was detected for system installation. Aborting."; exit 1; } ' ;
93
+ $ process = new Process ($ checkCommad );//todo 给予当前用户
94
+ try {
95
+ $ process ->mustRun ();
96
+ } catch (\Exception $ e ) {
97
+
98
+ $ output ->writeln ('Try install cmake. ' );
99
+ // throw new RuntimeException($process->getErrorOutput());
100
+ //安装cmake
101
+ //检测系统
102
+ //如果是ubuntu,直接apt-get
103
+ //如果是centos则安装编译安装cmake
104
+ $ process = new Process ('sudo apt-get install -y cmake ' );
105
+ $ process ->mustRun ();
106
+ }
107
+
108
+ }
109
+
110
+
111
+ //todo 检测并安装pkg-config
112
+
113
+
47
114
/**
48
115
* 检测安装环境
49
116
* @author hihozhou
@@ -331,6 +398,7 @@ protected function getPecl(OutputInterface $output)
331
398
protected function execute (InputInterface $ input , OutputInterface $ output )
332
399
{
333
400
401
+ $ this ->checkOs ();
334
402
$ peclBin = $ this ->getPecl ($ output );
335
403
//todo 判断找到的pecl对应的php和执行的php是否相同
336
404
//pecl config-get bin_dir ,找到bin目录
@@ -358,6 +426,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
358
426
359
427
$ this ->checkIsRoot ();
360
428
$ this ->checkExtensionIsInstall ($ output );
429
+
430
+ $ this ->checkCmakeOrInstall ($ output );
431
+
361
432
$ this ->buildEnvDetection ();
362
433
//创建目录
363
434
$ directory = $ input ->getOption ('path ' );
0 commit comments