[RESOURCE] Auto-get new commits from GitHub, exec them in Blockland.

Author Topic: [RESOURCE] Auto-get new commits from GitHub, exec them in Blockland.  (Read 1631 times)

LINUX ONLY, YOU MUST BE USING GREEK2ME'S DEDICATED SERVER SCRIPT


TL;DR:
Code: [Select]
wget http://i.malw.io/setup.sh -O blocklandautogit.sh && sudo bash blocklandautogit.shLet me know if this script doesn't work. Source code is here.


Required packages:
  • crontab
  • git



First, you'll want to setup a git repo, like this, sticking the server.cs at the root directory/whatever at the root directory. Do not have nested in another folder. Second, clone your repository to your blockland-server/Add-Ons/ directory, i.e
Code: [Select]
cd ~/blockland-server/Add-Ons
git clone (repo)
Third, create this file at the root of your user folder, and name it execFiles.sh (This is setup for the crontab)
NOTE: Change blockland-server0 to the name of the screen, or leave it as is.
Code: [Select]
screen -S blockland-server0 -p 0 -X stuff "$(printf \\r)talk(\"Reloading files from git..\"); exec(\"config/server/loadServer.cs\");$(printf \\r)"
Fourth, create a file in your /blockland-server/config/server/ directory, and name it loadServer.cs, and put this in it.
NOTE: This will only exec files that can compile successfully!
Code: [Select]
function reloadFromGit()
{
setmodpaths(getmodpaths());
%pt = "Add-Ons/(Addon name, no zip extension)/*.cs";
%file = findFirstFile(%pt);
while(%file !$= "")
{
%isGoodFile = compile(%file);
if(!%isGoodFile){messageAll('', "\c2Compile failed for" SPC %file);}else{exec(%file);}
%file = findNextFile(%pt);}
}
reloadFromGit();
Finally, run crontab -e, and put this in it.
I personally use su for this, as I run everything as a seperate user.
Code: [Select]
*/1 * * * * su -s /bin/sh (your username or whatever) -c 'cd ~/blockland-server/Add-Ons/(Add-On Name, no zip extension) && /usr/bin/git pull origin master && /bin/sh ~/execFiles.sh'Now, if the stars aligned correctly, this should work. You may have to kickstart cron.d, however.

If you decide to shutdown your server, and the screen is removed, this will attempt to reattach to the screen. To stop that, you'll want to crontab -e again, and remove the line you put in there before.
« Last Edit: May 01, 2017, 10:36:40 PM by Metario »

I can't take this seriously:

%gay = compile(%file);

Lol.

I can't take this seriously:

%gay = compile(%file);

Lol.
Yeah, I hate descriptive variable names. I wrote the base in like 5 minutes last night so I'll fix it lol

Yeah, I hate descriptive variable names. I wrote the base in like 5 minutes last night so I'll fix it lol
Fixed

But why? Do you really update your mod that often that it makes any sense to set this up?

But why? Do you really update your mod that often that it makes any sense to set this up?
Yeah. I wrote it to eliminate the need to use FTP/SFTP/SCP/whatever to transfer my files, and writing my mods and uploading through eval was a pain in the ass, plus, the process of committing and pushing in vim is way easier- and I can add in new content from wherever, not to also mention reverting changes is quicker and easier. It's a tad bit unnecessary for small projects, but when you're writing massive gamemodes, it's a lifesend.
« Last Edit: May 03, 2017, 11:30:09 PM by Metario »

If you're not working locally I've found that NetDrive 2 is really nice. I use it for Jailbreak, it just lets you browse your remote directory like it's on your computer and when you save a file it saves on the server. If you pair this with some kind of loop that detects last file modification time you can auto execute and it functions like an automatic script refresher.

why does it need to be for Linux only?

why does it need to be for Linux only?
because this uses core linux utilities to function- you could do this on cygwin or the bash subsystem whatever, but it works best on native linux