From 75e8629de2e505c90376afa4c38fcd7524b5f3eb Mon Sep 17 00:00:00 2001 From: kake26 Date: Fri, 18 Nov 2022 21:50:29 +0000 Subject: [PATCH] Working version of mod updater This is a fully working version of the mod updater. I've used it serveral times and it does work. --- update.pl | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/update.pl b/update.pl index e737602..7128678 100644 --- a/update.pl +++ b/update.pl @@ -11,7 +11,7 @@ use Storable; $updfile = "index.json"; # I could use JSON here, but it might be easier to abuse jq $updlsturl = "https://content.minetest.net/api/packages/"; # give use a json file of everything available -$modpath = "/home/kake26/.var/app/net.minetest.Minetest/.minetest/mods/"; # where your server stores its mods +$modpath = "/home/kake26/.minetest/mods/"; # where your server stores its mods sub chk_update () { @@ -34,6 +34,9 @@ foreach my $key (keys %{ $conf->{"mods"}}) { # the fing arrow -> sigh could have if ($conf->{"mods"}{$key}{"release"} != $release2) { print "Mod $key current release: " . $release2 . " installed: " . $conf->{"mods"}{$key}{"release"} ."!\n"; + # we should trigger the updater here + + &do_update($key,$release2,$author2); }else{ print "Mod $key up to date\n"; } @@ -42,7 +45,7 @@ foreach my $key (keys %{ $conf->{"mods"}}) { # the fing arrow -> sigh could have } sub get_ready (){ -$mods = `find $modpath -maxdepth 1 -type d -print`; # -print is there for a reason, find saved a huge amount of time +$mods = `find $modpath -type d -maxdepth 1 -print`; # -print is there for a reason, find saved a huge amount of time @mods = split("\n",$mods); foreach(@mods){ @tmods = split("\/",$_); @@ -70,10 +73,20 @@ system("wget -O index2.json $updlsturl"); return; } -sub do_update () { - +sub do_update ($mod,$ver,$author) { +# https://content.minetest.net/packages/TenPlus1/mob_horse/download/ +# https://content.minetest.net/packages/jp/i3/releases/14157/download/ + $mod = $_[0]; + $ver = $_[1]; + $author = $_[2]; + + system("wget -O $mod.zip https://content.minetest.net/packages/$author/$mod/releases/$ver/download/"); + system("unzip -o $mod.zip"); + # print "Update info $mod $ver $author\n"; } +# Maybe get ready and check update should be called every time + if (-e "mods"){ # load data print "Loading data\n"; @@ -83,4 +96,4 @@ if (-e "mods"){ get_ready(); # chk_update expects a hash retrived from storables so program needs to be run again after this #chk_update(); -} \ No newline at end of file +}