]>
git.wh0rd.org - tt-rss.git/blob - plugins/updater/init.php
2 class Updater
extends Plugin
{
9 "Updates tt-rss installation to latest version.",
14 function init($host) {
15 $this->link
= $host->get_link();
18 $host->add_hook($host::HOOK_PREFS_TAB
, $this);
20 $host->add_command("update-self",
21 "update tt-rss installation to latest version",
25 function update_self_step($link, $step, $params, $force = false) {
26 // __FILE__ is in plugins/updater so we need to go one level up
27 $work_dir = dirname(dirname(dirname(__FILE__
)));
28 $parent_dir = dirname($work_dir);
31 if (!is_array($params)) $params = array();
35 if (!chdir($work_dir)) {
36 array_push($log, "Unable to change to work directory: $work_dir");
43 array_push($log, "Work directory: $work_dir");
45 if (!is_writable($work_dir) ||
!is_writable("$parent_dir")) {
46 $user = posix_getpwuid(posix_geteuid());
47 $user = $user["name"];
48 array_push($log, "Both tt-rss and parent directories should be writable as current user ($user).");
52 if (!file_exists("$work_dir/config.php") ||
!file_exists("$work_dir/include/sanity_check.php")) {
53 array_push($log, "Work directory $work_dir doesn't look like tt-rss installation.");
57 if (!is_writable(sys_get_temp_dir())) {
58 array_push($log, "System temporary directory should be writable as current user.");
63 putenv("PATH=" . getenv("PATH") . PATH_SEPARATOR
. "/bin" .
64 PATH_SEPARATOR
. "/usr/bin");
66 array_push($log, "Checking for tar...");
69 system("which tar >/dev/null", $system_rc);
71 if ($system_rc != 0) {
72 array_push($log, "Could not run tar executable (RC=$system_rc).");
76 array_push($log, "Checking for gunzip...");
79 system("which gunzip >/dev/null", $system_rc);
81 if ($system_rc != 0) {
82 array_push($log, "Could not run gunzip executable (RC=$system_rc).");
86 array_push($log, "Checking for latest version...");
88 $version_info = json_decode(fetch_file_contents("http://tt-rss.org/version.php"),
91 if (!is_array($version_info)) {
92 array_push($log, "Unable to fetch version information.");
96 $target_version = $version_info["version"];
97 $target_dir = "$parent_dir/Tiny-Tiny-RSS-$target_version";
99 array_push($log, "Target version: $target_version");
100 $params["target_version"] = $target_version;
102 if (version_compare(VERSION
, $target_version) != -1 && !$force) {
103 array_push($log, "Your Tiny Tiny RSS installation is up to date.");
107 if (file_exists($target_dir)) {
108 array_push($log, "Target directory $target_dir already exists.");
114 $target_version = $params["target_version"];
116 /* array_push($log, "Downloading checksums...");
117 $md5sum_data = fetch_file_contents("http://tt-rss.org/download/md5sum.txt");
120 array_push($log, "Could not download checksums.");
124 $md5sum_data = explode("\n", $md5sum_data);
126 foreach ($md5sum_data as $line) {
127 $pair = explode(" ", $line);
129 if ($pair[1] == "tt-rss-$target_version.tar.gz") {
130 $target_md5sum = $pair[0];
135 if (!$target_md5sum) {
136 array_push($log, "Unable to locate checksum for target version.");
140 $params["target_md5sum"] = $target_md5sum; */
142 array_push($log, "Proceeding to download...");
146 $target_version = $params["target_version"];
147 // $target_md5sum = $params["target_md5sum"];
149 array_push($log, "Downloading distribution tarball...");
151 $tarball_url = "https://github.com/gothfox/Tiny-Tiny-RSS/archive/$target_version.tar.gz";
152 $data = fetch_file_contents($tarball_url);
155 array_push($log, "Could not download distribution tarball ($tarball_url).");
159 /* array_push($log, "Verifying tarball checksum...");
161 $test_md5sum = md5($data);
163 if ($test_md5sum != $target_md5sum) {
164 array_push($log, "Downloaded checksum doesn't match (got $test_md5sum, expected $target_md5sum).");
168 $tmp_file = tempnam(sys_get_temp_dir(), 'tt-rss');
169 array_push($log, "Saving download to $tmp_file");
171 if (!file_put_contents($tmp_file, $data)) {
172 array_push($log, "Unable to save download.");
176 $params["tmp_file"] = $tmp_file;
180 $tmp_file = $params["tmp_file"];
181 $target_version = $params["target_version"];
183 if (!chdir($parent_dir)) {
184 array_push($log, "Unable to change into parent directory.");
188 array_push($log, "Extracting tarball...");
189 system("tar zxf $tmp_file", $system_rc);
191 if ($system_rc != 0) {
192 array_push($log, "Error while extracting tarball (RC=$system_rc).");
196 $target_dir = "$parent_dir/Tiny-Tiny-RSS-$target_version";
198 if (!is_dir($target_dir)) {
199 array_push($log, "Target directory ($target_dir) not found.");
203 $old_dir = tmpdirname($parent_dir, "tt-rss-old");
205 array_push($log, "Renaming tt-rss directory to ".basename($old_dir));
206 if (!rename($work_dir, $old_dir)) {
207 array_push($log, "Unable to rename tt-rss directory.");
211 array_push($log, "Renaming target directory...");
212 if (!rename($target_dir, $work_dir)) {
213 array_push($log, "Unable to rename target directory.");
217 if (!chdir($work_dir)) {
218 array_push($log, "Unable to change to work directory: $work_dir");
222 array_push($log, "Copying config.php...");
223 if (!copy("$old_dir/config.php", "$work_dir/config.php")) {
224 array_push($log, "Unable to copy config.php to $work_dir.");
228 array_push($log, "Cleaning up...");
231 array_push($log, "Fixing permissions...");
233 $directories = array(
235 CACHE_DIR
. "/export",
236 CACHE_DIR
. "/images",
238 CACHE_DIR
. "/simplepie",
242 foreach ($directories as $dir) {
243 array_push($log, "-> $dir");
247 if (ICONS_DIR
== "feed-icons") {
248 array_push($log, "Migrating feed icons...");
250 $icons = glob("$old_dir/feed-icons/*.ico");
253 foreach ($icons as $icon) {
254 $icon = basename($icon);
256 if (copy("$old_dir/feed-icons/$icon", "$work_dir/feed-icons/$icon")) {
261 array_push($log, "Done; $icons_copied files copied");
264 array_push($log, "Not migrating feed icons, ICONS_DIR modified.");
267 array_push($log, "Upgrade completed.");
268 array_push($log, "Your old tt-rss directory is saved at $old_dir. ".
269 "Please migrate locally modified files (if any) and remove it.");
270 array_push($log, "You might need to re-enter current directory in shell to see new files.");
279 return array("step" => $step, "stop" => $stop, "params" => $params, "log" => $log);
282 function update_self_cli($link, $force = false) {
288 $rc = $this->update_self_step($link, $step, $params, $force);
290 $params = $rc['params'];
293 foreach ($rc['log'] as $line) {
300 function update_self($args) {
301 _debug("Warning: self-updating is experimental. Use at your own risk.");
302 _debug("Please backup your tt-rss directory before continuing. Your database will not be modified.");
303 _debug("Type 'yes' to continue.");
305 $input = read_stdin();
307 if ($input != 'yes' && $input != 'force')
310 $this->update_self_cli($link, $input == 'force');
313 function get_prefs_js() {
314 return file_get_contents(dirname(__FILE__
) . "/updater.js");
317 function hook_prefs_tab($args) {
318 if ($args != "prefPrefs") return;
320 if (($_SESSION["access_level"] >= 10 || SINGLE_USER_MODE
) && CHECK_FOR_NEW_VERSION
) {
321 print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Update Tiny Tiny RSS')."\">";
323 if ($_SESSION["pref_last_version_check"] +
86400 +
rand(-1000, 1000) < time()) {
324 $_SESSION["version_data"] = @check_for_update
($this->link
);
325 $_SESSION["pref_last_version_check"] = time();
328 if (is_array($_SESSION["version_data"])) {
329 $version = $_SESSION["version_data"]["version"];
330 $version_id = $_SESSION["version_data"]["version_id"];
331 print_notice(T_sprintf("New version of Tiny Tiny RSS is available (%s).", "<b>$version</b>"));
333 $details = "http://tt-rss.org/redmine/versions/$version_id";
335 print "<p><button onclick=\"window.open('$details')\" dojoType=\"dijit.form.Button\">".__("See the release notes")."</button>";
337 print " <button dojoType=\"dijit.form.Button\" onclick=\"return updateSelf()\">".
338 __('Update Tiny Tiny RSS')."</button></p>";
341 print_notice(__("Your Tiny Tiny RSS installation is up to date."));
344 print "</div>"; #pane
348 function updateSelf() {
349 print "<form style='display : block' name='self_update_form' id='self_update_form'>";
351 print "<div class='error'>".__("Do not close this dialog until updating is finished. Backup your tt-rss directory before continuing.")."</div>";
353 print "<ul class='selfUpdateList' id='self_update_log'>";
354 print "<li>" . __("Ready to update.") . "</li>";
357 print "<div class='dlgButtons'>";
358 print "<button id=\"self_update_start_btn\" dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('updateSelfDlg').start()\" >".
359 __("Start update")."</button>";
360 print "<button id=\"self_update_stop_btn\" onclick=\"return dijit.byId('updateSelfDlg').close()\" dojoType=\"dijit.form.Button\">".
361 __("Close this window")."</button>";
366 function performUpdate() {
367 $step = (int) $_REQUEST["step"];
368 $params = json_decode($_REQUEST["params"], true);
369 $force = (bool) $_REQUEST["force"];
371 if (($_SESSION["access_level"] >= 10 || SINGLE_USER_MODE
) && CHECK_FOR_NEW_VERSION
) {
372 print json_encode($this->update_self_step($this->link
, $step, $params, $force));