Moved backup routine to separate file for modularity
This commit is contained in:
parent
501e85f277
commit
13d223e2d5
2 changed files with 73 additions and 12 deletions
44
backup-gitea-bin.pl
Executable file
44
backup-gitea-bin.pl
Executable file
|
|
@ -0,0 +1,44 @@
|
||||||
|
#!/usr/bin/perl
|
||||||
|
|
||||||
|
# backup_gitea_bin.pl
|
||||||
|
# Author: Tracey Clark
|
||||||
|
# Created: 2019-06-20
|
||||||
|
# You must have a mail transport agent installed to run this script
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
|
||||||
|
### TEST CODE ###
|
||||||
|
my $gitea_bin='/home/tracey/tmp/testbin';
|
||||||
|
my $gitea_current_version='1';
|
||||||
|
my %binary_file = (
|
||||||
|
input => $gitea_bin,
|
||||||
|
version => $gitea_current_version,
|
||||||
|
);
|
||||||
|
my ( %opts ) = %binary_file;
|
||||||
|
my $input = $opts{input};
|
||||||
|
my $version = $opts{version};
|
||||||
|
my $gitea_bin_backup = '/home/tracey/tmp/testbin.' . $gitea_current_version . '.bz2';
|
||||||
|
|
||||||
|
### TEST CODE ###
|
||||||
|
# my ( %opts ) = %{shift()};
|
||||||
|
# my $input = $opts{input};
|
||||||
|
# my $version = $opts{version};
|
||||||
|
printf("Backing up the current binary\n");
|
||||||
|
printf("Input in backup_bin script 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");
|
||||||
|
# Do this with a system call to make a compressed copy of the current binary
|
||||||
|
# bzip2 -k file.txt
|
||||||
|
# my $status = system("vi", "fred.txt");
|
||||||
|
# if (($status >>=8) != 0) {
|
||||||
|
# die "Failed to run vi";
|
||||||
|
# }
|
||||||
|
|
||||||
|
# HEREHERE how to specify output file??
|
||||||
|
my $bzip_status = system("/bin/bzip2 -k $input");
|
||||||
|
if (($bzip_status >>=8) != 0) {
|
||||||
|
die "Failed to run bzip2";
|
||||||
|
}
|
||||||
|
|
@ -42,7 +42,6 @@ elsif ( $gitea_current_version_string =~ m/ion\ (\d+\d+\w*)\s/ ) {
|
||||||
$gitea_current_version = $1;
|
$gitea_current_version = $1;
|
||||||
printf("Current version of gitea that is installed is $1\n");
|
printf("Current version of gitea that is installed is $1\n");
|
||||||
$alphanum_ver = 1;
|
$alphanum_ver = 1;
|
||||||
print("!! Alpha num is true\n");
|
|
||||||
}
|
}
|
||||||
my %binary_file = (
|
my %binary_file = (
|
||||||
input => $gitea_bin,
|
input => $gitea_bin,
|
||||||
|
|
@ -64,12 +63,15 @@ printf($z $format, $string);
|
||||||
close($z);
|
close($z);
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
|
# This method may not work. Check the module. Ken said doing this through system call was more reliable & performant
|
||||||
my $input = $gitea_bin;
|
my $input = $gitea_bin;
|
||||||
my $temp_out = '/home/gitea/tempout.bz';
|
my $temp_out = '/home/gitea/tempout.bz';
|
||||||
my $bz = new IO::Compress::Bzip2 $temp_out
|
my $bz = new IO::Compress::Bzip2 $temp_out
|
||||||
or die "bzip2 failed: $Bzip2Error\n";
|
or die "bzip2 failed: $Bzip2Error\n";
|
||||||
|
|
||||||
backup_bin( \%binary_file );
|
#backup_bin( \%binary_file );
|
||||||
|
backup_gitea_bin.pl( \%binary_file );
|
||||||
|
|
||||||
|
|
||||||
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};
|
||||||
|
|
@ -138,18 +140,33 @@ if ( $tag gt $gitea_current_version || $alphanum_ver == 1 ) {
|
||||||
|
|
||||||
##### Subroutines #####
|
##### Subroutines #####
|
||||||
|
|
||||||
sub backup_bin {
|
sub check_deps {
|
||||||
my ( %opts ) = %{shift()};
|
# Check to make sure dependencies installed on system - unit test??
|
||||||
my $input = $opts{input};
|
# bzip2
|
||||||
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");
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# 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");
|
||||||
|
# # Do this with a system call to make a compressed copy of the current binary
|
||||||
|
# # bzip2 -k file.txt
|
||||||
|
# # my $status = system("vi", "fred.txt");
|
||||||
|
# # if (($status >>=8) != 0) {
|
||||||
|
# # die "Failed to run vi";
|
||||||
|
# # }
|
||||||
|
# my $bzip_status = system("bzip2 -k", "$input");
|
||||||
|
# if (($status >>=8) != 0) {
|
||||||
|
# die "Failed to run bzip2";
|
||||||
|
# }
|
||||||
|
#
|
||||||
|
# return;
|
||||||
|
# }
|
||||||
|
|
||||||
sub get_download_url {
|
sub get_download_url {
|
||||||
my ($dl_filename, $rel_id) = @_;
|
my ($dl_filename, $rel_id) = @_;
|
||||||
my $dl_url;
|
my $dl_url;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue