]> apps.delaporte.us Git - dotfiles.git/commitdiff
Add invoke to upload a local mod to the Luanti server
authorEdward Delaporte <edward@delaporte.us>
Thu, 25 Dec 2025 17:42:34 +0000 (11:42 -0600)
committerEdward Delaporte <edward@delaporte.us>
Thu, 25 Dec 2025 17:42:34 +0000 (11:42 -0600)
invoke/luanti-remote/tasks.py

index 61dc1a032fd9502b17fa0284b007f2bb881b80ba..196b26cbc4691b91d61cb51abd4e6d26609132e6 100644 (file)
@@ -18,8 +18,10 @@ BACKUP_FILE=f'world.{TODAY}.tar'
 LOCAL_BACKUPS=f'{LOCAL_HOME}/backup/luanti'
 
 LUANTI=f'{HOME}/luanti'
 LOCAL_BACKUPS=f'{LOCAL_HOME}/backup/luanti'
 
 LUANTI=f'{HOME}/luanti'
+LOCAL_LUANTI=f'{LOCAL_HOME}/.var/app/net.minetest.Minetest/.minetest'
 MODS=f'{LUANTI}/mods'
 WORLDS=f'{LUANTI}/worlds'
 MODS=f'{LUANTI}/mods'
 WORLDS=f'{LUANTI}/worlds'
+WORLD_CONF=f'{LUANTI}/worlds/{WORLD}/{WORLD}.mt'
 
 
 SERVE=f'screen -d -m {LUANTI}/bin/luantiserver --gameid minetest --worldname world'
 
 
 SERVE=f'screen -d -m {LUANTI}/bin/luantiserver --gameid minetest --worldname world'
@@ -89,6 +91,42 @@ def push_updated_mod(c, mod):
     c.run(f'{SSH} -C tar xf {tmpdir}/{mod}.tar --directory {MODS}')
     c.run(f'{SSH} -C ls -l {MODS}/{mod}')
 
     c.run(f'{SSH} -C tar xf {tmpdir}/{mod}.tar --directory {MODS}')
     c.run(f'{SSH} -C ls -l {MODS}/{mod}')
 
+@task
+def list_local_mods(c):
+    c.run(f'ls -al {LOCAL_LUANTI}/mods')
+
+@task
+def push_local_mod(c, mod):
+    tarfile = f'{LOCAL_BACKUPS}/mods/{mod}.tar'
+    print(f'Compressing local mod {mod} to {tarfile}')
+    c.run(f'tar cf {tarfile} --directory={LOCAL_LUANTI}/mods {mod}')
+    c.run(f'tar --list -f {tarfile} | tail')
+    c.run(f'tar --list -f {tarfile} | wc')
+
+    print(f'Pushing {tarfile} to {USER_AT_IP}:/tmp')
+    c.run(f'scp {tarfile} {USER_AT_IP}:/tmp')
+    c.run(f'{SSH} -C ls /tmp | grep {mod}')
+
+    print(f'Unpacking {mod}.tar...')
+    c.run(f'{SSH} -C tar xf /tmp/{mod}.tar --directory {MODS}')
+    c.run(f'{SSH} -C ls -l {MODS} | grep {mod}')
+    c.run(f'{SSH} -C ls -l {MODS}/{mod}')
+
+    print(f'Enable {mod} in config')
+    print(f'Remember to enable {mod} in config (invoke enable-mod {mod})')
+
+@task
+def enable_mod(c, mod):
+    enable_line = f'load_mod_{mod} = mods/{mod}'
+    result = c.run(f'{SSH} -C cat {WORLD_CONF} | grep {mod} &2>/dev/null')
+    print(result.stdout)
+    if(not mod in result.stdout):
+        print(f'Mod {mod} not found in {WORLD_CONF}. Adding.')
+        c.run(f'{SSH} -C "echo {enable_line} >> {WORLD_CONF}"')
+    else:
+        print(f'{MOD} already enabled in {WORLD_CONF}')
+        print(f'Grep result: {result.stdout}')
+    print("Remember to restart the server (invoke serve)!")
 
 @task
 def compress_world(c):
 
 @task
 def compress_world(c):