From 5c4db395a147b64a1c7836baa72c102e68ecf8b4 Mon Sep 17 00:00:00 2001 From: Tracey Clark Date: Mon, 4 Mar 2019 13:52:34 -0600 Subject: [PATCH] Initial commit of perl script to perform gitea updates. Logic to compare current version with latest published version is complete --- update-gitea.pl | 100 ++++++++++++++++++++++++++++++++++++++++++++++++ update-gitea.sh | 29 -------------- 2 files changed, 100 insertions(+), 29 deletions(-) create mode 100644 update-gitea.pl delete mode 100644 update-gitea.sh diff --git a/update-gitea.pl b/update-gitea.pl new file mode 100644 index 0000000..b48deae --- /dev/null +++ b/update-gitea.pl @@ -0,0 +1,100 @@ +#!/usr/bin/perl + +# Update gitea based on version provided +# Author: Tracey Clark +# Created: 2019-03-04 +# You must have a mail transport agent installed to run this script + +# Note: Daily backups are also being run from cron +# /home/gitea/gitea_backup.sh + +use strict; +use warnings; +#use LWP::Simple; +use LWP::UserAgent; +use Data::Dumper; +use JSON; + +########################################## +### The user must set these variables ### +# SET email address +my $email='tclark77@tlcnet.info'; + + +# gitea is hosted on github +# GET /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 $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"); + +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 + cookie_jar => {}, # keep cookies in RAM but not persistent between sessions + ); + +my $resp = $ua->get($latestURL); +my $latest_release_hash = decode_json($resp->content); + +# printf("!! Print the json response if we have one:\n"); +# printf Dumper $latest_release_hash; + +# In case we need to deref later +#my %latest_release_data = %$latest_release_hash; + +my $tag = $latest_release_hash->{tag_name}; +printf("The latest gitea version is $tag\n"); + +if ( $tag gt $gitea_current_version ) { + printf("Proceeding with update\n"); +} + +# Download version specified + +# Stop service + +# Backup current gitea mv + +# 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 + +# Unzip downloaded gitea +# unxz $GITEA_XZ + +# Change perms unless we run this as user gitea + +# Restart gitea + +# Test + +# Email diff --git a/update-gitea.sh b/update-gitea.sh deleted file mode 100644 index 1715f58..0000000 --- a/update-gitea.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/bash -# Update gitea based on version provided - -# Ask for version if not passed in # - -# Download version specified - -# Stop service - -# Backup current gitea mv - -# 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 - -# Unzip downloaded gitea -# unxz $GITEA_XZ - -# Change perms unless we run this as user gitea - -# Restart gitea - -# Test - -# Email