# HG changeset patch # User anatofuz # Date 1597188824 -32400 # Node ID 77db1db8cf443110f21273efbf8c325672a6aef3 add growi-update.pl diff -r 000000000000 -r 77db1db8cf44 current_growi_version.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/current_growi_version.txt Wed Aug 12 08:33:44 2020 +0900 @@ -0,0 +1,1 @@ +4.1.2 diff -r 000000000000 -r 77db1db8cf44 growi-update.pl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/growi-update.pl Wed Aug 12 08:33:44 2020 +0900 @@ -0,0 +1,64 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use Cwd qw/getcwd/; + + +my $growi_version_text = 'current_growi_version.txt'; +my $latest_version_url = 'https://github.com/weseek/growi/releases/latest'; +my $growi_dir = 'growi'; +my $update_growi_sh = 'update.sh'; + +my $latest_version = fetch_latest_version($latest_version_url); +print "latest: $latest_version\n"; + +my $current_version = read_growi_version_txt($growi_version_text); + +if ($current_version eq $latest_version) { + exit 0; +} + +update_growi($growi_dir, $update_growi_sh); + +overwrrite_growi_version_txt($growi_version_text, $latest_version); + + +sub read_growi_version_txt { + my $file = shift; + open my $fh, '<', $file; + my $version = <$fh>; + chomp $version; + close $fh; + return $version; +} + +sub overwrrite_growi_version_txt { + my ($file, $version) = @_; + open my $fh, '>', $file; + print $fh "$version\n"; + close $fh; +} + + +sub fetch_latest_version { + my $url = shift; + my $response = `curl $url`; #using curl command because perl core http module can't use https + + # response == You are being redirected. + + unless ($response =~ m|tag/v([\d\.]+)"|) { + die 'did not fetch latest version'; + } + + my $latest_version = $1; + + return $latest_version; +} + +sub update_growi { + my ($dir, $shell_script) = @_; + my $current_dir = getcwd(); + chdir $dir; + system("./$shell_script"); + chdir $current_dir; +}