Added tidy and bak files to gitignore. Removed debug code from script and tidied
This commit is contained in:
parent
68619377d4
commit
a11b429d2b
2 changed files with 121 additions and 85 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -1,3 +1,5 @@
|
||||||
*~
|
*~
|
||||||
*.swp
|
*.swp
|
||||||
.vstags
|
.vstags
|
||||||
|
*.tdy
|
||||||
|
*.bak
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,8 @@ chomp $gitea_current_version_string;
|
||||||
print("System is running \"$gitea_current_version_string\"\n");
|
print("System is running \"$gitea_current_version_string\"\n");
|
||||||
|
|
||||||
unless ( defined $gitea_current_version_string ) {
|
unless ( defined $gitea_current_version_string ) {
|
||||||
die "[DIE]: Unable to get the version of the gitea binary on the system: $!";
|
die
|
||||||
|
"[DIE]: Unable to get the version of the gitea binary on the system: $!";
|
||||||
}
|
}
|
||||||
|
|
||||||
my %binary_file = get_current_version($gitea_current_version_string);
|
my %binary_file = get_current_version($gitea_current_version_string);
|
||||||
|
|
@ -72,14 +73,18 @@ printf("Release id: $release_id\n");
|
||||||
|
|
||||||
my $unz_filename = 'gitea-' . $tag . $filetype;
|
my $unz_filename = 'gitea-' . $tag . $filetype;
|
||||||
printf("Uncompressed filename: $unz_filename\n");
|
printf("Uncompressed filename: $unz_filename\n");
|
||||||
|
|
||||||
#ex: gitea-1.7.6-linux-amd64
|
#ex: gitea-1.7.6-linux-amd64
|
||||||
|
|
||||||
my $download_filename = $unz_filename . '.xz';
|
my $download_filename = $unz_filename . '.xz';
|
||||||
printf("Download file target: $download_filename\n");
|
printf("Download file target: $download_filename\n");
|
||||||
|
|
||||||
#ex: gitea-1.7.6-linux-amd64.xz
|
#ex: gitea-1.7.6-linux-amd64.xz
|
||||||
|
|
||||||
if ( versioncmp( $gitea_current_version, $tag ) == -1 ) {
|
if ( versioncmp( $gitea_current_version, $tag ) == -1 ) {
|
||||||
printf("Version tag is greater than the system version, proceeding with update\n");
|
printf(
|
||||||
|
"Version tag is greater than the system version, proceeding with update\n"
|
||||||
|
);
|
||||||
backup_bin( \%binary_file );
|
backup_bin( \%binary_file );
|
||||||
|
|
||||||
my $download_url = get_download_url( $download_filename, $release_id );
|
my $download_url = get_download_url( $download_filename, $release_id );
|
||||||
|
|
@ -102,6 +107,7 @@ if ( versioncmp($gitea_current_version, $tag) == -1 ) {
|
||||||
# Notify success notify(1)
|
# Notify success notify(1)
|
||||||
# If no start notify and end & notify fail notify(0)
|
# If no start notify and end & notify fail notify(0)
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
my $status = check_gitea_status();
|
my $status = check_gitea_status();
|
||||||
|
|
@ -117,19 +123,22 @@ chomp $gitea_current_version_string;
|
||||||
$gitea_current_version = $binary_file{'version'};
|
$gitea_current_version = $binary_file{'version'};
|
||||||
|
|
||||||
if ( versioncmp( $gitea_current_version, $tag ) == -1 ) {
|
if ( versioncmp( $gitea_current_version, $tag ) == -1 ) {
|
||||||
printf("Upstream version tag is STILL greater than the current system version, something went wrong\n");
|
printf(
|
||||||
|
"Upstream version tag is STILL greater than the current system version, something went wrong\n"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
print("Write something here to call cleanup and remove the old xz file and uncompressed file\n");
|
print(
|
||||||
|
"Write something here to call cleanup and remove the old xz file and uncompressed file\n"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#TODO Add check if running binary is the same version as what we downloaded
|
#TODO Add check if running binary is the same version as what we downloaded
|
||||||
|
|
||||||
# # If install_bin good then cleanup()
|
# # If install_bin good then cleanup()
|
||||||
|
|
||||||
# #notification( $email );
|
# #notification( $email );
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# ##### Subroutines #####
|
# ##### Subroutines #####
|
||||||
|
|
||||||
# sub check_deps {
|
# sub check_deps {
|
||||||
|
|
@ -154,12 +163,15 @@ sub get_current_version {
|
||||||
version => $current_version,
|
version => $current_version,
|
||||||
);
|
);
|
||||||
unless ( defined $current_version ) {
|
unless ( defined $current_version ) {
|
||||||
die RED "[DIE]: Unable to get the current gitea version! Value is $current_version", RESET
|
die RED
|
||||||
|
"[DIE]: Unable to get the current gitea version! Value is $current_version",
|
||||||
|
RESET;
|
||||||
}
|
}
|
||||||
return %binary_file;
|
return %binary_file;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub backup_bin {
|
sub backup_bin {
|
||||||
|
|
||||||
# Ghetto to get it working for now
|
# Ghetto to get it working for now
|
||||||
|
|
||||||
my (%opts) = %{ shift() };
|
my (%opts) = %{ shift() };
|
||||||
|
|
@ -167,9 +179,12 @@ sub backup_bin {
|
||||||
my $version = $opts{version};
|
my $version = $opts{version};
|
||||||
print GREEN "Backing up the current binary\n", RESET;
|
print GREEN "Backing up the current binary\n", RESET;
|
||||||
if ( defined $info ) {
|
if ( defined $info ) {
|
||||||
print YELLOW "[INFO] Input in backup_bin sub is:\n Directory $input\n Version $version\n", RESET;
|
print YELLOW
|
||||||
|
"[INFO] Input in backup_bin sub is:\n Directory $input\n Version $version\n",
|
||||||
|
RESET;
|
||||||
}
|
}
|
||||||
my $gitea_bin_backup = '/home/gitea/bin/gitea.' . $gitea_current_version . '.bz2';
|
my $gitea_bin_backup =
|
||||||
|
'/home/gitea/bin/gitea.' . $gitea_current_version . '.bz2';
|
||||||
print GREEN "Gitea bin backup will be $gitea_bin_backup\n", RESET;
|
print GREEN "Gitea bin backup will be $gitea_bin_backup\n", RESET;
|
||||||
system("cp $input $input.bak");
|
system("cp $input $input.bak");
|
||||||
|
|
||||||
|
|
@ -191,8 +206,12 @@ sub backup_bin {
|
||||||
sub get_download_url {
|
sub get_download_url {
|
||||||
my ( $dl_filename, $rel_id ) = @_;
|
my ( $dl_filename, $rel_id ) = @_;
|
||||||
my $dl_url;
|
my $dl_url;
|
||||||
|
|
||||||
# Get the download_url from the array
|
# Get the download_url from the array
|
||||||
my $assetsURL = 'https://api.github.com/repos/go-gitea/gitea/releases/' . $release_id . '/assets';
|
my $assetsURL =
|
||||||
|
'https://api.github.com/repos/go-gitea/gitea/releases/'
|
||||||
|
. $release_id
|
||||||
|
. '/assets';
|
||||||
if ( defined $info ) {
|
if ( defined $info ) {
|
||||||
print YELLOW "[INFO] Assets URL\n";
|
print YELLOW "[INFO] Assets URL\n";
|
||||||
print "$assetsURL\n", RESET;
|
print "$assetsURL\n", RESET;
|
||||||
|
|
@ -202,29 +221,38 @@ sub get_download_url {
|
||||||
my $asset_resp_array_ref = decode_json( $asset_resp->content );
|
my $asset_resp_array_ref = decode_json( $asset_resp->content );
|
||||||
|
|
||||||
if ( defined $verbose ) {
|
if ( defined $verbose ) {
|
||||||
printf(RED "[DEBUG] Array of hashes of the json response for the assets:\n");
|
printf( RED
|
||||||
|
"[DEBUG] Array of hashes of the json response for the assets:\n"
|
||||||
|
);
|
||||||
printf Dumper $asset_resp_array_ref, RESET;
|
printf Dumper $asset_resp_array_ref, RESET;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach my $asset_ref ( @{$asset_resp_array_ref} ) {
|
foreach my $asset_ref ( @{$asset_resp_array_ref} ) {
|
||||||
if ( defined $verbose ) {
|
if ( defined $verbose ) {
|
||||||
print(RED "[DEBUG] The asset ref in get_download_url is $asset_ref\n");
|
print( RED
|
||||||
print("The asset ref name in get_download_url is $asset_ref->{name}\n", RESET);
|
"[DEBUG] The asset ref in get_download_url is $asset_ref\n" );
|
||||||
|
print(
|
||||||
|
"The asset ref name in get_download_url is $asset_ref->{name}\n",
|
||||||
|
RESET
|
||||||
|
);
|
||||||
}
|
}
|
||||||
if ( $asset_ref->{name} eq $dl_filename ) {
|
if ( $asset_ref->{name} eq $dl_filename ) {
|
||||||
print("Yay we have a match for our desired file :D and it is \n");
|
print("Yay we have a match for our desired file :D and it is \n");
|
||||||
print $asset_ref->{name} . "\n";
|
print $asset_ref->{name} . "\n";
|
||||||
$dl_url = $asset_ref->{browser_download_url};
|
$dl_url = $asset_ref->{browser_download_url};
|
||||||
if ( defined $info ) {
|
if ( defined $info ) {
|
||||||
print YELLOW "[INFO] The download url from the response array is $dl_url\n", RESET;
|
print YELLOW
|
||||||
|
"[INFO] The download url from the response array is $dl_url\n",
|
||||||
|
RESET;
|
||||||
}
|
}
|
||||||
return $dl_url;
|
return $dl_url;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
unless ( defined $dl_url ) {
|
unless ( defined $dl_url ) {
|
||||||
print( RED "ONOES we have no download URL from the github API! Trying to build one manually\n", RESET);
|
print( RED
|
||||||
# die RED "[DIE] Can't continue without a download URL", RESET;
|
"ONOES we have no download URL from the github API! Trying to build one manually\n",
|
||||||
print BLUE "Tag we are passing *into* the build_download_url from get_download_url is $orig_tag\n", RESET;
|
RESET
|
||||||
|
);
|
||||||
my $dl_url = build_download_url( $orig_tag, $download_filename );
|
my $dl_url = build_download_url( $orig_tag, $download_filename );
|
||||||
return $dl_url;
|
return $dl_url;
|
||||||
}
|
}
|
||||||
|
|
@ -233,23 +261,28 @@ sub get_download_url {
|
||||||
|
|
||||||
sub build_download_url {
|
sub build_download_url {
|
||||||
my ( $url_tag, $url_file ) = @_;
|
my ( $url_tag, $url_file ) = @_;
|
||||||
print BLUE "Tag passed into build_download_url is $url_tag\n", RESET;
|
print "Building the URL based on the version\n";
|
||||||
|
|
||||||
# If getting the download URL fails through the API, use this to build it manually
|
# If getting the download URL fails through the API, use this to build it manually
|
||||||
# URL is in the form of
|
# URL is in the form of
|
||||||
# https://github.com/go-gitea/gitea/releases/download/v1.15.2/gitea-1.15.2-linux-amd64.xz
|
# https://github.com/go-gitea/gitea/releases/download/v1.15.2/gitea-1.15.2-linux-amd64.xz
|
||||||
my $built_url = 'https://github.com/go-gitea/gitea/releases/download/' . $url_tag . '/' . $url_file;
|
my $built_url =
|
||||||
|
'https://github.com/go-gitea/gitea/releases/download/'
|
||||||
|
. $url_tag . '/'
|
||||||
|
. $url_file;
|
||||||
if ( defined $info ) {
|
if ( defined $info ) {
|
||||||
print YELLOW "The URL built for the download is $built_url\n", RESET;
|
print YELLOW "The URL built for the download is $built_url\n", RESET;
|
||||||
}
|
}
|
||||||
return $built_url;
|
return $built_url;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub install_bin {
|
sub install_bin {
|
||||||
my $filename = shift;
|
my $filename = shift;
|
||||||
|
|
||||||
#my $unz_binary =
|
#my $unz_binary =
|
||||||
|
|
||||||
print("Unpacking the downloaded file, setting owner and permissions\n");
|
print("Unpacking the downloaded file, setting owner and permissions\n");
|
||||||
|
|
||||||
# Copy the downloaded binary to gitea and chmod it 750
|
# Copy the downloaded binary to gitea and chmod it 750
|
||||||
# Doing this with a filthy system call because the perl library
|
# Doing this with a filthy system call because the perl library
|
||||||
# for xz manipulation is a memory hog and buggy besides
|
# for xz manipulation is a memory hog and buggy besides
|
||||||
|
|
@ -271,6 +304,7 @@ sub check_gitea_status {
|
||||||
}
|
}
|
||||||
|
|
||||||
sub cleanup {
|
sub cleanup {
|
||||||
|
|
||||||
# remove downloaded binary and old backup set install_status=success ELSE remove "gitea" and restore from backup and set install_status=fail
|
# remove downloaded binary and old backup set install_status=success ELSE remove "gitea" and restore from backup and set install_status=fail
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue