From 13d223e2d537c43d5fa8a167ab20d8dd1f42443e Mon Sep 17 00:00:00 2001 From: Tracey Clark Date: Thu, 20 Jun 2019 09:46:26 -0500 Subject: [PATCH] Moved backup routine to separate file for modularity --- backup-gitea-bin.pl | 44 ++++++++++++++++++++++++++++++++++++++++++++ update-gitea.pl | 41 +++++++++++++++++++++++++++++------------ 2 files changed, 73 insertions(+), 12 deletions(-) create mode 100755 backup-gitea-bin.pl diff --git a/backup-gitea-bin.pl b/backup-gitea-bin.pl new file mode 100755 index 0000000..eb106d6 --- /dev/null +++ b/backup-gitea-bin.pl @@ -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"; +} diff --git a/update-gitea.pl b/update-gitea.pl index 7306597..76d6dfc 100755 --- a/update-gitea.pl +++ b/update-gitea.pl @@ -42,7 +42,6 @@ elsif ( $gitea_current_version_string =~ m/ion\ (\d+\d+\w*)\s/ ) { $gitea_current_version = $1; printf("Current version of gitea that is installed is $1\n"); $alphanum_ver = 1; - print("!! Alpha num is true\n"); } my %binary_file = ( input => $gitea_bin, @@ -64,12 +63,15 @@ printf($z $format, $string); close($z); =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 $temp_out = '/home/gitea/tempout.bz'; my $bz = new IO::Compress::Bzip2 $temp_out 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 $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 ##### -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"); - - return; +sub check_deps { + # Check to make sure dependencies installed on system - unit test?? + # bzip2 } +# 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 { my ($dl_filename, $rel_id) = @_; my $dl_url;