1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author Victor Dubiniuk <[email protected]> |
4
|
|
|
* |
5
|
|
|
* @copyright Copyright (c) 2015, ownCloud, Inc. |
6
|
|
|
* @license AGPL-3.0 |
7
|
|
|
* |
8
|
|
|
* This code is free software: you can redistribute it and/or modify |
9
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
10
|
|
|
* as published by the Free Software Foundation. |
11
|
|
|
* |
12
|
|
|
* This program is distributed in the hope that it will be useful, |
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15
|
|
|
* GNU Affero General Public License for more details. |
16
|
|
|
* |
17
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
18
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
19
|
|
|
* |
20
|
|
|
*/ |
21
|
|
|
|
22
|
|
|
use \Owncloud\Updater\Console\Application; |
23
|
|
|
|
24
|
|
|
namespace Owncloud\Updater\Utils; |
|
|
|
|
25
|
|
|
|
26
|
|
|
class Locator { |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* absolute path to ownCloud root |
30
|
|
|
* @var string |
31
|
|
|
*/ |
32
|
|
|
protected $owncloudRootPath; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* absolute path to updater root |
36
|
|
|
* @var string |
37
|
|
|
*/ |
38
|
|
|
protected $updaterRootPath; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* |
42
|
|
|
* @param string $baseDir |
43
|
|
|
*/ |
44
|
|
|
public function __construct($baseDir){ |
45
|
|
|
$this->updaterRootPath = $baseDir; |
46
|
|
|
$this->owncloudRootPath = dirname($baseDir); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function getOwncloudRootPath(){ |
50
|
|
|
return $this->owncloudRootPath; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* expected items in the core |
55
|
|
|
* @return array |
56
|
|
|
*/ |
57
|
|
|
public function getRootDirContent(){ |
58
|
|
|
return [ |
59
|
|
|
"config/config.sample.php", |
60
|
|
|
"core", |
61
|
|
|
"l10n", |
62
|
|
|
"lib", |
63
|
|
|
"ocs", |
64
|
|
|
"ocs-provider", |
65
|
|
|
"resources", |
66
|
|
|
"settings", |
67
|
|
|
".htaccess", |
68
|
|
|
".mailmap", |
69
|
|
|
".tag", |
70
|
|
|
".user.ini", |
71
|
|
|
"AUTHORS", |
72
|
|
|
"console.php", |
73
|
|
|
"COPYING-AGPL", |
74
|
|
|
"cron.php", |
75
|
|
|
"db_structure.xml", |
76
|
|
|
"index.html", |
77
|
|
|
"index.php", |
78
|
|
|
"indie.json", |
79
|
|
|
"occ", |
80
|
|
|
"public.php", |
81
|
|
|
"remote.php", |
82
|
|
|
"robots.txt", |
83
|
|
|
"status.php", |
84
|
|
|
"version.php" |
85
|
|
|
]; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function getUpdaterContent(){ |
89
|
|
|
return [ |
90
|
|
|
'app', |
91
|
|
|
'application.php', |
92
|
|
|
'box.json', |
93
|
|
|
'composer.json', |
94
|
|
|
'composer.lock', |
95
|
|
|
'CONTRIBUTING.md', |
96
|
|
|
'COPYING-AGPL', |
97
|
|
|
'index.php', |
98
|
|
|
'pub', |
99
|
|
|
'src', |
100
|
|
|
'vendor', |
101
|
|
|
'README.md', |
102
|
|
|
'.travis.yml', |
103
|
|
|
'.scrutinizer.yml', |
104
|
|
|
]; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Absolute path to core root dir content |
109
|
|
|
* @return array |
110
|
|
|
*/ |
111
|
|
|
public function getRootDirItems(){ |
112
|
|
|
$items = $this->getRootDirContent(); |
113
|
|
|
$items = array_map( |
114
|
|
|
function($item){ return $this->owncloudRootPath . "/" . $item; }, |
115
|
|
|
$items |
116
|
|
|
); |
117
|
|
|
return $items; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Absolute path |
122
|
|
|
* @return string |
123
|
|
|
* @throws \Exception |
124
|
|
|
*/ |
125
|
|
|
public function getDataDir(){ |
126
|
|
|
$container = \Owncloud\Updater\Console\Application::$container; |
127
|
|
|
if ($container['utils.configReader']->getIsLoaded()){ |
128
|
|
|
return $container['utils.configReader']->getByPath('system.datadirectory'); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
// Fallback case |
132
|
|
|
include_once $this->getPathToConfigFile(); |
133
|
|
|
if (isset($CONFIG['datadirectory'])){ |
134
|
|
|
return $CONFIG['datadirectory']; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
// Something went wrong |
138
|
|
|
throw new \Exception('Unable to detect datadirectory'); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* Absolute path to updater root dir |
143
|
|
|
* @return string |
144
|
|
|
*/ |
145
|
|
|
public function getUpdaterBaseDir(){ |
146
|
|
|
return $this->getDataDir() . '/updater-data'; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* Absolute path to create a core and apps backups |
151
|
|
|
* @return string |
152
|
|
|
*/ |
153
|
|
|
public function getCheckpointDir(){ |
154
|
|
|
return $this->getUpdaterBaseDir() . '/checkpoint'; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* Absolute path to store downloaded packages |
159
|
|
|
* @return string |
160
|
|
|
*/ |
161
|
|
|
public function getDownloadBaseDir(){ |
162
|
|
|
return $this->getUpdaterBaseDir() . '/download'; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
public function getExtractionBaseDir(){ |
166
|
|
|
return $this->owncloudRootPath . "/_oc_upgrade"; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* |
171
|
|
|
* @return string |
172
|
|
|
*/ |
173
|
|
|
public function getPathToOccFile(){ |
174
|
|
|
return $this->owncloudRootPath . '/occ'; |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* |
179
|
|
|
* @return string |
180
|
|
|
*/ |
181
|
|
|
public function getInstalledVersion(){ |
182
|
|
|
include $this->getPathToVersionFile(); |
183
|
|
|
|
184
|
|
|
/** @var $OC_Version string */ |
185
|
|
|
return $OC_Version; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* |
190
|
|
|
* @return string |
191
|
|
|
*/ |
192
|
|
|
public function getChannelFromVersionsFile(){ |
193
|
|
|
include $this->getPathToVersionFile(); |
194
|
|
|
|
195
|
|
|
/** @var $OC_Version string */ |
196
|
|
|
return $OC_Channel; |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* |
201
|
|
|
* @return string |
202
|
|
|
*/ |
203
|
|
|
public function getBuild(){ |
204
|
|
|
include $this->getPathToVersionFile(); |
205
|
|
|
|
206
|
|
|
/** @var $OC_Build string */ |
207
|
|
|
return $OC_Build; |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
public function getPathtoConfigFiles($filePostfix = 'config.php'){ |
211
|
|
|
// Only config.php for now |
212
|
|
|
return [ |
213
|
|
|
$this->owncloudRootPath . '/config/' . $filePostfix |
214
|
|
|
]; |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
public function getPathToConfigFile(){ |
218
|
|
|
return $this->owncloudRootPath . '/config/config.php'; |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
/** |
222
|
|
|
* |
223
|
|
|
* @return string |
224
|
|
|
*/ |
225
|
|
|
public function getPathToVersionFile(){ |
226
|
|
|
return $this->owncloudRootPath . '/version.php'; |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
} |
230
|
|
|
|