From 79f4b1d7d65aa48a786f27e1178be5dec34ddfba Mon Sep 17 00:00:00 2001 From: b Date: Sat, 29 Mar 2025 21:45:41 +0100 Subject: [PATCH] add updater; improve uploader diff --- makefile | 3 +++ remote.txt | 3 +++ update.1.pl | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++ upload.1.pl | 13 +++++---- 4 files changed, 89 insertions(+), 7 deletions(-) create mode 100644 update.1.pl diff --git a/makefile b/makefile index 0e58e39..b310e67 100644 --- a/makefile +++ b/makefile @@ -39,14 +39,17 @@ CONFIGURE_CMD = $(PERL) ./configure.pl --do perl=$(PERL) _base_path=$(BASE_PATH) # keep these 2 lists in the same order!: GENERATE_FROM=\ makedata.1.pl\ +update.1.pl\ upload.1.pl TO_GENERATE=\ makedata.pl\ +update.pl\ upload.pl EXEC=\ makedata.pl\ +update.pl\ upload.pl BIN=\ diff --git a/remote.txt b/remote.txt index 51a9ec1..fe7592a 100644 --- a/remote.txt +++ b/remote.txt @@ -1,5 +1,8 @@ user: b server: bicyclesonthemoon.info data-test: /botm/data/test-bsta +bin-test: /botm/bin/test-bsta data-bsta: /botm/data/bsta +bin-bsta: /botm/bin/bsta data-again: /botm/data/bstagain +bin-again: /botm/bin/bstagain diff --git a/update.1.pl b/update.1.pl new file mode 100644 index 0000000..d787f21 --- /dev/null +++ b/update.1.pl @@ -0,0 +1,77 @@ +###RUN_PERL: #!/usr/bin/perl + +# update.pl is generated from update.1.pl. +# +# run update on BSTA server +# +# Copyright (C) 2025 Balthasar Szczepański +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +use strict; +use utf8; +use Encode::Locale ('decode_argv'); +use Encode ('encode', 'decode'); + +###PERL_LIB: use lib ~/ott/bsta/lib +use botm_common ( + 'join_path', + 'read_data_file', + 'system_encoded' +); + +binmode STDIN, ':encoding(UTF-8)'; +binmode STDOUT, ':encoding(UTF-8)'; +binmode STDERR, ':encoding(UTF-8)'; +decode_argv(); + +my $time = time(); +srand ($time-$$); + +###PERL_ETC_REMOTE_PATH: ETC_REMOTE_PATH = ~/ott/bsta/etc/remote.txt + +my %remote; +my $target; +my $server; + +print $time." UPDATE\n"; + +if (@ARGV < 1) { + print STDERR "no remote target\n"; + print "FAIL\n"; + exit 1; +} + +$target = 'bin-'.shift(@ARGV); + +%remote = read_data_file(ETC_REMOTE_PATH()); +unless ( + (exists $remote{'server'}) and + (exists $remote{'user' }) and + (exists $remote{$target }) +) { + print STDERR "didn't get remote target\n"; + print "FAIL\n"; + exit 1; +} + +$server = $remote{'user'}.'@'.$remote{'server'}; +$target = $remote{$target }; + +my $r = system_encoded('ssh', ( + 'ssh', '-q', '-T', $server, '-t', + join_path('/', $target, 'update.pl').' '.join(' ', @ARGV) +)); + +print(($r == 0) ? "OK\n" : "FAIL\n"); diff --git a/upload.1.pl b/upload.1.pl index 8e187f6..9fad710 100644 --- a/upload.1.pl +++ b/upload.1.pl @@ -2,7 +2,7 @@ # upload.pl is generated from upload.1.pl. # -# make data files from chapter files +# upload frames, attachment & stuff # # Copyright (C) 2025 Balthasar Szczepański # @@ -367,18 +367,17 @@ foreach my $upload (@upload_list) { } foreach my $key (keys %keys) { unless (exists $local_data{$key}) { - push(@differences, '--> '.$key); + push(@differences, '--> '.$key.': '.$remote_data{$key}); next; } unless (exists $remote_data{$key}) { - push(@differences, '<-- '.$key); + push(@differences, '<-- '.$key.': '.$local_data{$key}); next; } unless ($local_data{$key} eq $remote_data{$key}) { - push(@differences, '=/= '.$key); - push(@differences, '<== '.$local_data{$key}.' <=='); - push(@differences, '==> '.$remote_data{$key}.' ==>'); - push(@differences, '=\='); + push(@differences, '=/= '.$key.':'); + push(@differences, '<== '.$local_data{$key}); + push(@differences, '==> '.$remote_data{$key}); next; } } -- 2.30.2