Commit 21a30c14 authored by Kerenoc's avatar Kerenoc
Browse files

Updater : restore updater (based on Gitlab CI)

parent 14547b15
......@@ -5,9 +5,24 @@ image: alpine:3.10
stages:
- build
default:
before_script:
- echo "Preparing build"
compute_digests:
stage: build
when: manual
script:
- echo "Computing digests"
- cd gcstar/lib/gcstar
- sh ../../../tools/computeDigests.sh
- mv list_file_digests.txt ../../..
artifacts:
name: "digests"
paths:
- list_file_digests.txt
build_packages:
stage: build
when: manual
script:
- echo "Start building packages"
- echo "http://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories
- cat /etc/apk/repositories
- apk -U update
......@@ -25,36 +40,12 @@ default:
- mv makeself-2.4.0/*.sh .
- cd ..
- cd tools
- ant prepare
- echo "End preparing build"
build_installer:
stage: build
when: manual
script:
- echo "Building installer"
- ant makeself
- mv ../dist/gcstar*.run ..
- echo "End building installer"
artifacts:
name: "linux_installer"
paths:
- gcstar*.run
after_script:
- ls -l dist
build_packages:
stage: build
when: manual
script:
- echo "Building packages"
- ant packages
- mv ../dist/gcstar*.rpm ..
- ant
- ls -l ../RPM/BUILD/gcstar
- echo "End building packages"
artifacts:
name: "linux_packages"
paths:
- gcstar*.rpm
- dist
after_script:
- ls -l dist
......@@ -3,6 +3,7 @@ package GCUpdater;
###################################################
#
# Copyright 2005 Tian
# Copyright 2018-2022 Kerenoc
#
# This file is part of GCstar.
#
......@@ -27,44 +28,68 @@ use strict;
use LWP;
use Digest::MD5 qw(md5 md5_hex md5_base64);
use File::Find;
my $BASE_URL = 'http://gitlab.com/Kerenoc/GCstar/raw/v';
my $INDEX_FILE = 'list_modified_files.txt';
my $REPO_URL = 'http://gitlab.com/Kerenoc/GCstar/-/';
my $BASE_URL = $REPO_URL.'raw/main/gcstar/lib/gcstar/';
my $INDEX_URL = $REPO_URL.'jobs/artifacts/Gtk2/raw/list_file_digests.txt?job=compute_digests';
my $INDEX_FILE = 'list_file_digests.txt';
{
package GCRealUpdater;
use File::Basename;
use File::Path;
use GCUtils 'localName';
sub new
{
my ($proto, $lang, $baseDir, $toBeUpdated, $version) = @_;
my $class = ref($proto) || $proto;
my $self = {
lang => $lang,
baseUrl => $BASE_URL,
indexUrl => $INDEX_URL,
indexFile => $INDEX_FILE,
baseInstallation => $baseDir.'/',
toBeUpdated => $toBeUpdated
};
bless ($self, $class);
$self->abort($self->{lang}->{UpdateNoPermission}.$baseDir) if (! -w localName($baseDir));
$self->{next} = 0;
$self->{total} = undef;
return $self;
}
sub abort
{
my ($self, $msg) = @_;
print "$msg\n";
exit 1;
}
sub getNextFile
{
my $self = shift;
return $self->{filesList}->[$self->{next}];
}
sub createBrowser
{
my ($self, $proxy) = @_;
$self->{browser} = LWP::UserAgent->new;
$self->{browser} = LWP::UserAgent->new;
$self->{browser}->proxy(['http'], $proxy) if $proxy;
}
sub checkFile
{
my ($self, $file) = @_;
return 1 if $self->{toBeUpdated}->{all};
foreach ('plugins', 'import', 'export', 'lang', 'models', 'extract')
{
......@@ -72,31 +97,56 @@ my $INDEX_FILE = 'list_modified_files.txt';
}
return 0;
}
sub updateNext
sub updateFiles
{
my $self = shift;
my $file = $self->{filesList}->[$self->{next}];
print "Saving in ",$self->{baseInstallation}.$file,"\n";
mkpath(localName(dirname($self->{baseInstallation}.$file)));
my $response = $self->{browser}->get($self->{baseUrl}.$file, ':content_file' => $self->{baseInstallation}.$file);
# update file if sizes are different or digests are different
foreach my $item(@{$self->{filesList}})
{
my ($f, $d) = split /\|/, $item;
my $fileName = localName($self->{baseInstallation}.$f);
if (defined $f && -r $fileName)
{
open (my $fh, '<', $fileName);
my $fileDigest = Digest::MD5->new->addfile($fh)->hexdigest;
close $fh;
# different digests => update
$self->updateFile($fileName) if ($d ne $fileDigest);
}
}
}
sub updateFile
{
my ($self, $fileName) = @_;
print "Updating ",$fileName,"\n";
mkpath($fileName) if ! -r $fileName;
my $file = $fileName;
$file =~ s|.*/lib/gcstar/||;
my $response = $self->{browser}->get($self->{baseUrl}.$file, ':content_file' => $fileName);
if (!$response->is_success)
{
print $response->message, "\n";
#print $self->{lang}->{UpdateFileNotFound},"\n";
}
$self->{next}++;
}
sub getIndex
{
my $self = shift;
print "Getting index file ".$self->{baseUrl}.$INDEX_FILE."\n";
my $response = $self->{browser}->get($self->{baseUrl}.$INDEX_FILE, ':content_file' => $self->{baseInstallation}.$INDEX_FILE);
$self->abort("!!! ".$self->{lang}->{UpdateNone}) if !$response->is_success;
print "Saving in ".$self->{baseInstallation}.$INDEX_FILE."\n";
open INDEX, localName($self->{baseInstallation}.$INDEX_FILE);
# download a file containing all the digests for the source files from Gitlab CI
print "Getting index file from Gitlab repository\n";
my $response = $self->{browser}->get($self->{indexUrl},
':content_file' => $self->{baseInstallation}.$self->{indexFile});
$self->abort("!!! ".$self->{lang}->{UpdateNone}) if (!$response->is_success);
print "Using index file ".$self->{baseInstallation}.$self->{indexFile}."\n";
open INDEX, localName($self->{baseInstallation}.$self->{indexFile});
$self->{filesList} = [];
while (<INDEX>)
{
......@@ -107,36 +157,18 @@ my $INDEX_FILE = 'list_modified_files.txt';
close INDEX;
$self->{total} = scalar @{$self->{filesList}};
}
sub total
{
my $self = shift;
$self->getIndex if ( !defined $self->{total});
return $self->{total};
}
sub new
{
my ($proto, $lang, $baseDir, $toBeUpdated, $version) = @_;
my $class = ref($proto) || $proto;
my $self = {
lang => $lang,
baseUrl => $BASE_URL.$version.'_U/gcstar/lib/gcstar/',
baseInstallation => $baseDir.'/',
toBeUpdated => $toBeUpdated
};
bless ($self, $class);
$self->abort($self->{lang}->{UpdateNoPermission}.$baseDir) if (! -w localName($baseDir));
$self->{next} = 0;
$self->{total} = undef;
return $self;
}
}
{
package GCTextUpdater;
sub new
{
my ($proto, $lang, $baseDir, $toBeUpdated, $noProxy, $version) = @_;
......@@ -147,21 +179,21 @@ my $INDEX_FILE = 'list_modified_files.txt';
updater => GCRealUpdater->new($lang, $baseDir, $toBeUpdated, $version)
};
bless ($self, $class);
return $self;
}
sub update
{
my $self = shift;
my $proxy;
if (!$self->{noProxy})
{
# use proxy from options, don't ask
#$proxy = <STDIN>;
#chomp $proxy;
# get environment variables and configuration file
# copied from the main gcstar program to avoid modify it
......@@ -169,35 +201,31 @@ my $INDEX_FILE = 'list_modified_files.txt';
my $home = $ENV{'HOME'};
$home = $ENV{'APPDATA'} if ($^O =~ /win32/i);
$home =~ s/\\/\//g if ($^O =~ /win32/i);
$ENV{XDG_CONFIG_HOME} = $home.'/gcstar/config' if ($^O =~ /win32/i);
$ENV{XDG_CONFIG_HOME} = $home.'/.config' if ! exists $ENV{XDG_CONFIG_HOME};
$ENV{XDG_DATA_HOME} = $home.'/gcstar' if ($^O =~ /win32/i);
$ENV{XDG_DATA_HOME} = $home.'/.local/share' if ! exists $ENV{XDG_DATA_HOME};
$ENV{GCS_CONFIG_HOME} = $ENV{XDG_CONFIG_HOME}.'/gcstar';
$ENV{GCS_CONFIG_HOME} = $ENV{XDG_CONFIG_HOME} if ($^O =~ /win32/i);
$ENV{GCS_CONFIG_FILE} = $ENV{GCS_CONFIG_HOME}.'/GCstar.conf';
use GCOptions;
my $self->{options} = new GCOptionLoader($ENV{GCS_CONFIG_FILE}, 1);
$proxy = $self->{options}->proxy if ($self->{options}->proxy !~ m/^#/);
}
$self->{updater}->createBrowser($proxy);
my $count = $self->{updater}->total;
print $self->{lang}->{UpdateNone},"\n" if !$count;
for (my $i = 0; $i < $count; $i++)
{
print $i+1," / $count : ",$self->{updater}->getNextFile,"\n";
$self->{updater}->updateNext;
}
print "Checking ".$count." files\n";
$self->{updater}->updateFiles();
print "Updating ended\n";
}
}
1;
#! bash
#
# computeDigests.sh
#
# script to compute the MD5 digests of Perl file for uppdating GCstar
#
#
rm list_file_digests.txt
find . -name "*.pm" | \
while read f
do
tr -d "\r" < "$f" | \
md5sum | \
sed "s/ .*//" | \
sed "s,^,$f|," | \
sed "s,^./,," >> list_file_digests.txt
done
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment