]> us-delaporte.pagekite.me Git - dotfiles.git/blob - invoke/minecraft-remote/tasks.py
Use editor for invoke tasks
[dotfiles.git] / invoke / minecraft-remote / tasks.py
1 from invoke import task
2 from invoke import tasks
3 import os
4 from datetime import datetime as dt
5
6 IP=os.environ.get('LUANTI_IP')
7 USER=os.environ.get('LUANTI_USER')
8 HOME=os.environ.get('LUANTI_HOME')
9 LOCAL_HOME=os.environ.get('HOME')
10
11 TODAY = dt.now().strftime('%Y.%m.%d')
12
13 USER_AT_IP=f'{USER}@{IP}'
14 SSH=f'ssh {USER}@{IP}'
15 SCP=f'scp {USER}@{IP}'
16
17 DATE_TAR=f'{TODAY}.tar'
18
19 # Minecraft
20 LOCAL_BACKUPS=f'{LOCAL_HOME}/backup/minecraft'
21
22 MINECRAFT=f'{HOME}/Minecraft'
23
24 DIRS = ['world', 'world_nether', 'world_the_end', 'plugins']
25
26 # TODO: Set these
27 JAVA=f'{HOME}/java/jdk21/bin/java'
28 JAVA_OPTS=f'-Xms3g -Xmx7g'
29 OPTIONS=f'--nogui'
30
31 SERVE=f'screen -S Minecraft -d -m {JAVA} {JAVA_OPTS} -jar {MINECRAFT}/server.jar {OPTIONS}'
32
33 @task
34 def compress_world(c):
35 for world in DIRS:
36 c.run(f'{SSH} -C tar cf /tmp/{world}.{DATE_TAR} --directory={MINECRAFT} {world}')
37 c.run(f'{SSH} -C ls /tmp | grep .tar')
38
39
40 @task(compress_world)
41 def backup(c):
42 stopped = input("Is the server stopped?")
43 if(stopped != 'y'):
44 print("so go stop the server...")
45 exit()
46 c.run(f'mkdir -p {LOCAL_BACKUPS}')
47
48 for world in DIRS:
49 c.run(f'{SCP}:/tmp/{world}.{DATE_TAR} {LOCAL_BACKUPS}')
50
51 c.run(f'ls -lh {LOCAL_BACKUPS} | grep .tar')
52 verify_backup(c)
53
54 @task
55 def verify_backup(c):
56 for world in DIRS:
57 c.run(f'tar tvf {LOCAL_BACKUPS}/{world}.{DATE_TAR} | tail')
58 c.run(f'tar tvf {LOCAL_BACKUPS}/{world}.{DATE_TAR} | wc')
59
60 @task
61 def check_server(c):
62 result = c.run(f'ssh {USER}@{IP} -C screen -ls')
63
64 @task(verify_backup)
65 def serve(c):
66 print(f"Attempting to connect to {IP}")
67 result = c.run(f'ssh {USER}@{IP} -C {SERVE}')
68 print(f'Server should now be running in a remote screen session.')
69 print(result)
70
71
72 @task
73 def serve(c):
74 print(f"Attempting to connect to {IP}")
75 result = c.run(f'ssh {USER}@{IP} -C {SERVE}')
76 print(f'Server should now be running in a remote screen session.')
77 print(result)
78