initial working copy

This commit is contained in:
Paul M 2022-08-11 22:08:58 -05:00
parent f4c837fd72
commit 00ffcbc05a
5 changed files with 126 additions and 0 deletions

1
index.json Normal file

File diff suppressed because one or more lines are too long

1
index2.json Normal file

File diff suppressed because one or more lines are too long

BIN
mods Normal file

Binary file not shown.

22
update.bash Executable file
View file

@ -0,0 +1,22 @@
#!/bin/bash
updfile=index.json # name of file to save list of packages as
updlsturl=https://content.minetest.net/api/packages/ # give use a json file of everything available
function get_updfile () {
wget -O $updfile $updlsturl
}
function check_mods () {
# we check the mods folder to see whats there then
return
}
if [[ -f "$updfile" ]]
then
# if the file is there move on unless the script is asked to update it
echo "Located packages file, using"
else
echo "File not found, fetching ..."
get_updfile
fi

102
update.pl Normal file
View file

@ -0,0 +1,102 @@
#!/usr/bin/perl
# This was a bash script until I determined the level of invoking the ancient gods of the console required to make
# that work would be just too much
use Storable;
use Data::Dumper;
# I know declaring a empty hash is 100% unnessecary but I am anyway
%conf = {}; # this will be stored used to keep track of stuff
%conf2 = {};
$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/";
sub chk_update () {
print "Checking for updates...\n";
#print Dumper($conf);
foreach my $key (keys %{ $conf->{"mods"}}) { # the fing arrow -> sigh could have saved so much time
print "Checking mod $key \n";
# So we can now check against index2.json
$author2 = `jq -c '.[] | select(.name =="$key") | .author' index2.json`;
$author2 =~ s/\"//g;
$release2 = `jq -c '.[] | select(.name =="$key") | .release' index2.json`;
$release2 =~ s/\"//g;
chomp($author2);
chomp($release2);
#print "Current release $release2 author $author2 installed ". $conf->{"mods"}{$key}{"release"} ." \n";
if ($conf->{"mods"}{$key}{"release"} != $release2) {
print "Mod $key current release: " . $release2 . " installed: " . $conf{"mods"}{$key}{"release"} ."!\n";
}else{
print "Mod $key up to date\n";
}
}
}
sub get_ready (){
$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("\/",$_);
$tmname = pop(@tmods);
if ($tmname eq "mods"){
next;
}
# At this point we should have a mod's name
#print "Mod name $tmname\n";
$author = `jq -c '.[] | select(.name =="$tmname") | .author' index.json`; #jq is a time saver
$author =~ s/\"//g;
chomp($author);
$release = `jq -c '.[] | select(.name =="$tmname") | .release' index.json`;
$release =~ s/\"//g;
chomp($release);
#print "$author\n";
$conf{"mods"}{$tmname}{"author"} = $author;
$conf{"mods"}{$tmname}{"release"} = $release;
}
store \%conf, 'mods';
return;
}
sub get_file () {
# get the
system("wget -O index2.json $updlsturl");
return;
}
sub do_update () {
}
if (-e "mods"){
# load data
print "Loading data\n";
$conf = retrieve('mods');
#print "Saved...\n";
#print Dumper($conf2);
#print "Freash...\n";
#get_ready();
#print Dumper($conf);
chk_update();
}else{
get_ready();
chk_update();
}
#get_ready();