From 45a8527882dee7ed62fc2d1c460d92f12fee205e Mon Sep 17 00:00:00 2001 From: Tracey Clark Date: Thu, 14 Mar 2019 19:58:36 -0500 Subject: [PATCH] Added stub for backup routine --- update-gitea.pl | 44 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/update-gitea.pl b/update-gitea.pl index b48deae..b3038bf 100644 --- a/update-gitea.pl +++ b/update-gitea.pl @@ -12,6 +12,8 @@ use strict; use warnings; #use LWP::Simple; use LWP::UserAgent; +use IO::Compress::Bzip2 qw(bzip2 $Bzip2Error) ; +# use Compress::Bzip2 qw(:all :constant :utilities :gzip); # cant get output use Data::Dumper; use JSON; @@ -19,11 +21,10 @@ use JSON; ### The user must set these variables ### # SET email address my $email='tclark77@tlcnet.info'; - +my $filetype='-linux-amd64.xz'; # gitea is hosted on github # GET /repos/go-gitea/gitea/releases/latest - # https://api.github.com/repos/go-gitea/gitea/releases/latest =json @@ -38,23 +39,45 @@ $VAR1 = { =cut -# my $backup_zip = '~/gitea.zip'; # HEREHERE may need to change my $gitea_bin = '/home/gitea/bin/gitea'; my $gitea_current_version_string = `$gitea_bin --version`; my $gitea_current_version; if ( $gitea_current_version_string =~ m/ion\ (\w+)\ b/ ) { $gitea_current_version = $1; } - printf("The version of gitea that is running is \"$gitea_current_version\"\n"); +# Backup the current binary +my $gitea_bin_backup = '/home/gitea/bin/gitea.' . $gitea_current_version . '.bz2'; +printf("Gitea bin backup will be $gitea_bin_backup\n"); +printf("!! Input is $gitea_bin\n and output is $gitea_bin_backup\n"); + +=example +# IO::File mode +print($z $string); +printf($z $format, $string); +close($z); +=cut + +my $input = $gitea_bin; +my $temp_out = '/home/gitea/tempout.bz'; +my $bz = new IO::Compress::Bzip2 $temp_out + or die "bzip2 failed: $Bzip2Error\n"; +# bzip2 $input => "$gitea_bin_backup" +# or die "bzip2 failed: $Bzip2Error\n"; # This works, but writes garbage to end of filename + # need to do in OO way + # https://metacpan.org/pod/IO::Compress::Bzip2 + +print $bz $gitea_bin; # This writes the filename as string to the bz +$bz->close(); + my $baseURL = q{https://github.com/go-gitea/gitea/}; my $latestURL = q{https://api.github.com/repos/go-gitea/gitea/releases/latest}; # https://hubpages.com/technology/Use-Perl-to-access-REST-API # Spin up the browser object (via LWP::UserAgent) my $ua = LWP::UserAgent->new( - ssl_opts => { verify_hostname => 0 }, # not worried about SSL certs + #ssl_opts => { verify_hostname => 0 }, # not worried about SSL certs cookie_jar => {}, # keep cookies in RAM but not persistent between sessions ); @@ -72,19 +95,22 @@ printf("The latest gitea version is $tag\n"); if ( $tag gt $gitea_current_version ) { printf("Proceeding with update\n"); + my $dl_filename='gitea-' . $tag . $filetype; + printf("Downloaded filename will be $dl_filename\n"); } +# Get the download_url from the array + # Download version specified # Stop service # Backup current gitea mv +# $gitea_bin + + -# Build URL ex -# https://dl.gitea.io/gitea/1.7.3/gitea-1.7.3-linux-amd64.xz -# https://dl.gitea.io/gitea/$version/gitea-$version-linux-amd64.xz -# GITEA_XZ=gitea-$version-linux-amd64.xz # wget