]>
git.wh0rd.org - tt-rss.git/blob - include/update_self.php
2 function update_self_step($link, $step, $params, $force = false) {
3 // __FILE__ is in include/ so we need to go one level up
4 $work_dir = dirname(dirname(__FILE__
));
5 $parent_dir = dirname($work_dir);
7 if (!chdir($work_dir)) {
8 array_push($log, "Unable to change to work directory: $work_dir");
14 if (!is_array($params)) $params = array();
18 array_push($log, "Work directory: $work_dir");
20 if (!is_writable($work_dir) && !is_writable("$parent_dir")) {
21 $user = posix_getpwuid(posix_geteuid());
22 $user = $user["name"];
23 array_push($log, "Both tt-rss and parent directories should be writable as current user ($user).");
27 if (!file_exists("$work_dir/config.php") ||
!file_exists("$work_dir/include/sanity_check.php")) {
28 array_push($log, "Work directory $work_dir doesn't look like tt-rss installation.");
32 if (!is_writable(sys_get_temp_dir())) {
33 array_push($log, "System temporary directory should be writable as current user.");
37 array_push($log, "Checking for tar...");
40 system("tar --version >/dev/null", $system_rc);
42 if ($system_rc != 0) {
43 array_push($log, "Could not run tar executable (RC=$system_rc).");
47 array_push($log, "Checking for latest version...");
49 $version_info = json_decode(fetch_file_contents("http://tt-rss.org/version.php"),
52 if (!is_array($version_info)) {
53 array_push($log, "Unable to fetch version information.");
57 $target_version = $version_info["version"];
58 $target_dir = "$parent_dir/tt-rss-$target_version";
60 array_push($log, "Target version: $target_version");
61 $params["target_version"] = $target_version;
63 if (version_compare(VERSION
, $target_version) != -1 && !$force) {
64 array_push($log, "Your Tiny Tiny RSS installation is up to date.");
68 if (file_exists($target_dir)) {
69 array_push($log, "Target directory $target_dir already exists.");
75 $target_version = $params["target_version"];
77 array_push($log, "Downloading checksums...");
78 $md5sum_data = fetch_file_contents("http://tt-rss.org/download/md5sum.txt");
81 array_push($log, "Could not download checksums.");
85 $md5sum_data = explode("\n", $md5sum_data);
87 foreach ($md5sum_data as $line) {
88 $pair = explode(" ", $line);
90 if ($pair[1] == "tt-rss-$target_version.tar.gz") {
91 $target_md5sum = $pair[0];
96 if (!$target_md5sum) {
97 array_push($log, "Unable to locate checksum for target version.");
101 $params["target_md5sum"] = $target_md5sum;
105 $target_version = $params["target_version"];
106 $target_md5sum = $params["target_md5sum"];
108 array_push($log, "Downloading distribution tarball...");
110 $tarball_url = "http://tt-rss.org/download/tt-rss-$target_version.tar.gz";
111 $data = fetch_file_contents($tarball_url);
114 array_push($log, "Could not download distribution tarball ($tarball_url).");
118 array_push($log, "Verifying tarball checksum...");
120 $test_md5sum = md5($data);
122 if ($test_md5sum != $target_md5sum) {
123 array_push($log, "Downloaded checksum doesn't match (got $test_md5sum, expected $target_md5sum).");
127 $tmp_file = tempnam(sys_get_temp_dir(), 'tt-rss');
128 array_push($log, "Saving download to $tmp_file");
130 if (!file_put_contents($tmp_file, $data)) {
131 array_push($log, "Unable to save download.");
135 $params["tmp_file"] = $tmp_file;
139 $tmp_file = $params["tmp_file"];
140 $target_version = $params["target_version"];
142 if (!chdir($parent_dir)) {
143 array_push($log, "Unable to change into parent directory.");
147 $old_dir = tmpdirname($parent_dir, "tt-rss-old");
149 array_push($log, "Renaming tt-rss directory to ".basename($old_dir));
150 if (!rename($work_dir, $old_dir)) {
151 array_push($log, "Unable to rename tt-rss directory.");
155 array_push($log, "Extracting tarball...");
156 system("tar zxf $tmp_file", $system_rc);
158 if ($system_rc != 0) {
159 array_push($log, "Error while extracting tarball (RC=$system_rc).");
163 $target_dir = "$parent_dir/tt-rss-$target_version";
165 array_push($log, "Renaming target directory...");
166 if (!rename($target_dir, $work_dir)) {
167 array_push($log, "Unable to rename target directory.");
171 if (!chdir($work_dir)) {
172 array_push($log, "Unable to change to work directory: $work_dir");
176 array_push($log, "Copying config.php...");
177 if (!copy("$old_dir/config.php", "$work_dir/config.php")) {
178 array_push($log, "Unable to copy config.php to $work_dir.");
182 array_push($log, "Cleaning up...");
185 array_push($log, "Fixing permissions...");
187 $directories = array(
189 CACHE_DIR
. "/htmlpurifier",
190 CACHE_DIR
. "/export",
191 CACHE_DIR
. "/images",
192 CACHE_DIR
. "/magpie",
193 CACHE_DIR
. "/simplepie",
197 foreach ($directories as $dir) {
198 array_push($log, "-> $dir");
202 array_push($log, "Upgrade completed.");
203 array_push($log, "Your old tt-rss directory is saved at $old_dir. ".
204 "Please migrate locally modified files (if any) and remove it.");
205 array_push($log, "You might need to re-enter current directory in shell to see new files.");
213 return array("step" => $step, "stop" => $stop, "params" => $params, "log" => $log);
217 function update_self($link, $force = false) {
223 $rc = update_self_step($link, $step, $params, $force);
225 $params = $rc['params'];
228 foreach ($rc['log'] as $line) {