Updated update-gitea.pl\n Made things into subs.
This commit is contained in:
parent
52a764c8df
commit
ad31caba8a
1 changed files with 64 additions and 46 deletions
106
update-gitea.pl
106
update-gitea.pl
|
|
@ -13,7 +13,6 @@ use warnings;
|
||||||
#use LWP::Simple;
|
#use LWP::Simple;
|
||||||
use LWP::UserAgent;
|
use LWP::UserAgent;
|
||||||
use IO::Compress::Bzip2 qw(bzip2 $Bzip2Error) ;
|
use IO::Compress::Bzip2 qw(bzip2 $Bzip2Error) ;
|
||||||
# use Compress::Bzip2 qw(:all :constant :utilities :gzip); # cant get output
|
|
||||||
use Data::Dumper;
|
use Data::Dumper;
|
||||||
use JSON;
|
use JSON;
|
||||||
|
|
||||||
|
|
@ -23,53 +22,22 @@ use JSON;
|
||||||
my $email='tclark77@tlcnet.info';
|
my $email='tclark77@tlcnet.info';
|
||||||
my $filetype='-linux-amd64.xz';
|
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
|
# https://api.github.com/repos/go-gitea/gitea/releases/latest
|
||||||
|
|
||||||
=json
|
|
||||||
$VAR1 = {
|
|
||||||
'upload_url' => 'https://uploads.github.com/repos/go-gitea/gitea/releases/15817548/assets{?name,label}',
|
|
||||||
'assets_url' => 'https://api.github.com/repos/go-gitea/gitea/releases/15817548/assets',
|
|
||||||
'tag_name' => 'v1.7.3',
|
|
||||||
'author' => {
|
|
||||||
'gravatar_id' => '',
|
|
||||||
etc
|
|
||||||
},
|
|
||||||
|
|
||||||
=cut
|
|
||||||
|
|
||||||
my $gitea_bin = '/home/gitea/bin/gitea';
|
my $gitea_bin = '/home/gitea/bin/gitea';
|
||||||
my $gitea_current_version_string = `$gitea_bin --version`;
|
my $gitea_current_version_string = `$gitea_bin --version`;
|
||||||
my $gitea_current_version;
|
my $gitea_current_version;
|
||||||
if ( $gitea_current_version_string =~ m/ion\ (\d+\.\d+\.\d*)\s+b/ ) {
|
if ( $gitea_current_version_string =~ m/ion\ (\d+\.\d+\.\d*)\s+b/ ) {
|
||||||
$gitea_current_version = $1;
|
$gitea_current_version = $1;
|
||||||
}
|
}
|
||||||
|
my %binary_file = (
|
||||||
|
input => $gitea_bin,
|
||||||
|
version => $gitea_current_version,
|
||||||
|
);
|
||||||
|
|
||||||
printf("The version of gitea that is running is \"$gitea_current_version\"\n");
|
printf("The version of gitea that is running is \"$gitea_current_version\"\n");
|
||||||
|
|
||||||
# Backup the current binary
|
# Backup the current binary
|
||||||
my $gitea_bin_backup = '/home/gitea/bin/gitea.' . $gitea_current_version . '.bz2';
|
backup_bin( \%binary_file );
|
||||||
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 $baseURL = q{https://github.com/go-gitea/gitea/};
|
||||||
my $latestURL = q{https://api.github.com/repos/go-gitea/gitea/releases/latest};
|
my $latestURL = q{https://api.github.com/repos/go-gitea/gitea/releases/latest};
|
||||||
|
|
@ -91,21 +59,61 @@ my $latest_release_hash = decode_json($resp->content);
|
||||||
|
|
||||||
my $tag = $latest_release_hash->{tag_name};
|
my $tag = $latest_release_hash->{tag_name};
|
||||||
printf("The latest gitea version is $tag\n");
|
printf("The latest gitea version is $tag\n");
|
||||||
|
my $assetsURL = $latest_release_hash->{tag_name};
|
||||||
|
|
||||||
if ( $tag gt $gitea_current_version ) {
|
if ( $tag gt $gitea_current_version ) {
|
||||||
printf("Proceeding with update\n");
|
printf("Proceeding with update\n");
|
||||||
my $dl_filename='gitea-' . $tag . $filetype;
|
download_bin($tag);
|
||||||
printf("Downloaded filename will be $dl_filename\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# If install_bin good then cleanup()
|
||||||
|
|
||||||
|
#notification( $email );
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
##### Subroutines #####
|
||||||
|
|
||||||
|
sub backup_bin {
|
||||||
|
my ( %opts ) = %{shift()};
|
||||||
|
my $input = $opts{input};
|
||||||
|
my $version = $opts{version};
|
||||||
|
printf("Backing up the current binary\n");
|
||||||
|
printf("Input in backup_bin sub is $input\n and version is $version\n");
|
||||||
|
my $gitea_bin_backup = '/home/gitea/bin/gitea.' . $gitea_current_version . '.bz2';
|
||||||
|
printf("Gitea bin backup will be $gitea_bin_backup\n");
|
||||||
|
|
||||||
|
|
||||||
|
my $status = bzip2 $input => $gitea_bin_backup
|
||||||
|
or die "bzip2 failed: $Bzip2Error\n";
|
||||||
|
#$bz->close();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub download_bin {
|
||||||
|
my $dl_tag = shift;
|
||||||
|
my $dl_filename='gitea-' . $dl_tag . $filetype;
|
||||||
|
printf("Downloaded filename will be $dl_filename\n");
|
||||||
|
# Unzip downloaded gitea
|
||||||
|
|
||||||
# Get the download_url from the array
|
# Get the download_url from the array
|
||||||
|
|
||||||
# Download version specified\
|
# Download version specified\
|
||||||
# $gitea_bin
|
# $gitea_bin
|
||||||
# wget
|
# wget
|
||||||
|
|
||||||
# Unzip downloaded gitea
|
|
||||||
# unxz $GITEA_XZ
|
# unxz $GITEA_XZ
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub install_bin{
|
||||||
|
|
||||||
# Stop service
|
# Stop service
|
||||||
|
|
||||||
|
|
@ -117,7 +125,17 @@ if ( $tag gt $gitea_current_version ) {
|
||||||
|
|
||||||
# verify systemctld status is good
|
# verify systemctld status is good
|
||||||
|
|
||||||
# If good then remove downloaded binary and old backup set install_status=success ELSE remove "gitea" and restore from backup and set install_status=fail
|
# return the status
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
# Notification
|
sub cleanup {
|
||||||
# $install_status message
|
# remove downloaded binary and old backup set install_status=success ELSE remove "gitea" and restore from backup and set install_status=fail
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub notification {
|
||||||
|
my $to = shift;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue