]>
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.");
62 array_push($log, "Checking for tar...");
65 system("which tar >/dev/null", $system_rc);
67 if ($system_rc != 0) {
68 array_push($log, "Could not run tar executable (RC=$system_rc).");
72 array_push($log, "Checking for gunzip...");
75 system("which gunzip >/dev/null", $system_rc);
77 if ($system_rc != 0) {
78 array_push($log, "Could not run gunzip executable (RC=$system_rc).");
82 array_push($log, "Checking for latest version...");
84 $version_info = json_decode(fetch_file_contents("http://tt-rss.org/version.php"),
87 if (!is_array($version_info)) {
88 array_push($log, "Unable to fetch version information.");
92 $target_version = $version_info["version"];
93 $target_dir = "$parent_dir/Tiny-Tiny-RSS-$target_version";
95 array_push($log, "Target version: $target_version");
96 $params["target_version"] = $target_version;
98 if (version_compare(VERSION
, $target_version) != -1 && !$force) {
99 array_push($log, "Your Tiny Tiny RSS installation is up to date.");
103 if (file_exists($target_dir)) {
104 array_push($log, "Target directory $target_dir already exists.");
110 $target_version = $params["target_version"];
112 /* array_push($log, "Downloading checksums...");
113 $md5sum_data = fetch_file_contents("http://tt-rss.org/download/md5sum.txt");
116 array_push($log, "Could not download checksums.");
120 $md5sum_data = explode("\n", $md5sum_data);
122 foreach ($md5sum_data as $line) {
123 $pair = explode(" ", $line);
125 if ($pair[1] == "tt-rss-$target_version.tar.gz") {
126 $target_md5sum = $pair[0];
131 if (!$target_md5sum) {
132 array_push($log, "Unable to locate checksum for target version.");
136 $params["target_md5sum"] = $target_md5sum; */
138 array_push($log, "Proceeding to download...");
142 $target_version = $params["target_version"];
143 // $target_md5sum = $params["target_md5sum"];
145 array_push($log, "Downloading distribution tarball...");
147 $tarball_url = "https://github.com/gothfox/Tiny-Tiny-RSS/archive/$target_version.tar.gz";
148 $data = fetch_file_contents($tarball_url);
151 array_push($log, "Could not download distribution tarball ($tarball_url).");
155 /* array_push($log, "Verifying tarball checksum...");
157 $test_md5sum = md5($data);
159 if ($test_md5sum != $target_md5sum) {
160 array_push($log, "Downloaded checksum doesn't match (got $test_md5sum, expected $target_md5sum).");
164 $tmp_file = tempnam(sys_get_temp_dir(), 'tt-rss');
165 array_push($log, "Saving download to $tmp_file");
167 if (!file_put_contents($tmp_file, $data)) {
168 array_push($log, "Unable to save download.");
172 $params["tmp_file"] = $tmp_file;
176 $tmp_file = $params["tmp_file"];
177 $target_version = $params["target_version"];
179 if (!chdir($parent_dir)) {
180 array_push($log, "Unable to change into parent directory.");
184 array_push($log, "Extracting tarball...");
185 system("tar zxf $tmp_file", $system_rc);
187 if ($system_rc != 0) {
188 array_push($log, "Error while extracting tarball (RC=$system_rc).");
192 $target_dir = "$parent_dir/Tiny-Tiny-RSS-$target_version";
194 if (!is_dir($target_dir)) {
195 array_push($log, "Target directory ($target_dir) not found.");
199 $old_dir = tmpdirname($parent_dir, "tt-rss-old");
201 array_push($log, "Renaming tt-rss directory to ".basename($old_dir));
202 if (!rename($work_dir, $old_dir)) {
203 array_push($log, "Unable to rename tt-rss directory.");
207 array_push($log, "Renaming target directory...");
208 if (!rename($target_dir, $work_dir)) {
209 array_push($log, "Unable to rename target directory.");
213 if (!chdir($work_dir)) {
214 array_push($log, "Unable to change to work directory: $work_dir");
218 array_push($log, "Copying config.php...");
219 if (!copy("$old_dir/config.php", "$work_dir/config.php")) {
220 array_push($log, "Unable to copy config.php to $work_dir.");
224 array_push($log, "Cleaning up...");
227 array_push($log, "Fixing permissions...");
229 $directories = array(
231 CACHE_DIR
. "/export",
232 CACHE_DIR
. "/images",
234 CACHE_DIR
. "/simplepie",
238 foreach ($directories as $dir) {
239 array_push($log, "-> $dir");
243 if (ICONS_DIR
== "feed-icons") {
244 array_push($log, "Migrating feed icons...");
246 $icons = glob("$old_dir/feed-icons/*.ico");
249 foreach ($icons as $icon) {
250 $icon = basename($icon);
252 if (copy("$old_dir/feed-icons/$icon", "$work_dir/feed-icons/$icon")) {
257 array_push($log, "Done; $icons_copied files copied");
260 array_push($log, "Not migrating feed icons, ICONS_DIR modified.");
263 array_push($log, "Upgrade completed.");
264 array_push($log, "Your old tt-rss directory is saved at $old_dir. ".
265 "Please migrate locally modified files (if any) and remove it.");
266 array_push($log, "You might need to re-enter current directory in shell to see new files.");
275 return array("step" => $step, "stop" => $stop, "params" => $params, "log" => $log);
278 function update_self_cli($link, $force = false) {
284 $rc = $this->update_self_step($link, $step, $params, $force);
286 $params = $rc['params'];
289 foreach ($rc['log'] as $line) {
296 function update_self($args) {
297 _debug("Warning: self-updating is experimental. Use at your own risk.");
298 _debug("Please backup your tt-rss directory before continuing. Your database will not be modified.");
299 _debug("Type 'yes' to continue.");
301 $input = read_stdin();
303 if ($input != 'yes' && $input != 'force')
306 $this->update_self_cli($link, $input == 'force');
309 function get_prefs_js() {
310 return file_get_contents(dirname(__FILE__
) . "/updater.js");
313 function hook_prefs_tab($args) {
314 if ($args != "prefPrefs") return;
316 if (($_SESSION["access_level"] >= 10 || SINGLE_USER_MODE
) && CHECK_FOR_NEW_VERSION
) {
317 print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Update Tiny Tiny RSS')."\">";
319 if ($_SESSION["pref_last_version_check"] +
86400 +
rand(-1000, 1000) < time()) {
320 $_SESSION["version_data"] = @check_for_update
($this->link
);
321 $_SESSION["pref_last_version_check"] = time();
324 if (is_array($_SESSION["version_data"])) {
325 $version = $_SESSION["version_data"]["version"];
326 print_notice(T_sprintf("New version of Tiny Tiny RSS is available (%s).", "<b>$version</b>"));
328 print "<p><button dojoType=\"dijit.form.Button\" onclick=\"return updateSelf()\">".
329 __('Update Tiny Tiny RSS')."</button></p>";
332 print_notice(__("Your Tiny Tiny RSS installation is up to date."));
335 print "</div>"; #pane
339 function updateSelf() {
340 print "<form style='display : block' name='self_update_form' id='self_update_form'>";
342 print "<div class='error'>".__("Do not close this dialog until updating is finished. Backup your tt-rss directory before continuing.")."</div>";
344 print "<ul class='selfUpdateList' id='self_update_log'>";
345 print "<li>" . __("Ready to update.") . "</li>";
348 print "<div class='dlgButtons'>";
349 print "<button id=\"self_update_start_btn\" dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('updateSelfDlg').start()\" >".
350 __("Start update")."</button>";
351 print "<button id=\"self_update_stop_btn\" onclick=\"return dijit.byId('updateSelfDlg').close()\" dojoType=\"dijit.form.Button\">".
352 __("Close this window")."</button>";
357 function performUpdate() {
358 $step = (int) $_REQUEST["step"];
359 $params = json_decode($_REQUEST["params"], true);
360 $force = (bool) $_REQUEST["force"];
362 if (($_SESSION["access_level"] >= 10 || SINGLE_USER_MODE
) && CHECK_FOR_NEW_VERSION
) {
363 print json_encode($this->update_self_step($this->link
, $step, $params, $force));