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.
This commit is contained in:
kake26 2022-11-18 21:50:29 +00:00
parent 234fd090ca
commit 75e8629de2

View file

@ -11,7 +11,7 @@ use Storable;
$updfile = "index.json"; # I could use JSON here, but it might be easier to abuse jq $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 $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 () { 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) { if ($conf->{"mods"}{$key}{"release"} != $release2) {
print "Mod $key current release: " . $release2 . " installed: " . $conf->{"mods"}{$key}{"release"} ."!\n"; print "Mod $key current release: " . $release2 . " installed: " . $conf->{"mods"}{$key}{"release"} ."!\n";
# we should trigger the updater here
&do_update($key,$release2,$author2);
}else{ }else{
print "Mod $key up to date\n"; 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 (){ 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); @mods = split("\n",$mods);
foreach(@mods){ foreach(@mods){
@tmods = split("\/",$_); @tmods = split("\/",$_);
@ -70,10 +73,20 @@ system("wget -O index2.json $updlsturl");
return; 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"){ if (-e "mods"){
# load data # load data
print "Loading data\n"; print "Loading data\n";