[RELEASE] Simple Github Sync with Changelog

Greetings everyone!

This is a simple bash script that I’ve been using for months for keeping my server updated with the Github Repository. This script is great for keeping all your resources updated. When you, or a collaborator, push(es) an update to the Github’s Master or Dev branch, this script mixed in with the crontab will keep the server files updated. All you have to do is restart the resource or the server (depending on the update).

Usage

  • Place this script in the user’s root directory
  • Either ensure your server files are in ~/server-data/, OR change the $FILEPATH variable in this script to the path of the server files. If you are not experienced with filepaths or bash scripting, just make sure your server files are in server-data.
  • Set up your repository clone in ~/
  • Change the repository path in this script on line 2 (REPO="")
  • Run the script using bash gitscript.sh

CRONTAB
Editing the crontab is a good way to get a script to run on an interval. My server runs this script every 30 minutes. To figure out how to set up the crontab interval, check out this website: https://crontab.guru/

  • From the SSH prompt, type crontab -e
  • Press i (for insert-mode/typing)
  • Enter: */30 * * * * ~/gitscript.sh
  • hit ESC (command mode)
  • type :wq (colon-w-q)

The script will now run every 30 minutes. It’s a good idea to run the script manually and ensure it works before you set up the crontab.

Using the Changelog
To use the Changelog for your server, website, etc, ensure the permissions are set properly for read/write access and then use it from your script. You can simply use io.iopen("changelog.txt") to read the file if you’re using Lua, since this file is created in the base filepath.

FILE/DOWNLOAD
gitscript.sh (1.5 KB)

SPECIAL NOTE
I use my Repository (private) to update all the server files including the config, so my gitscript I shared here doesn’t only sync resources. If your repository is a specific resource, you will need to edit the filepath to reflect that. If you need any help getting it to work, feel free to reply to this post!

8 Likes

Amazing way to keep the server in sync for developers

2 Likes

How do you set up a Github Repository for a server in the first place?

All of my resources and configs are on the repo. I don’t use anyone else’s scripts.

So how does this authenticate with GitHub? Even to pull repos on your own PC you have to log in to GitHub first so how does this do that and prevent people from just cloning other repos

You can use an SSH key to authenticate with Github, which would bypass the requirement of logging in since you’re authorizing via a key. The repo I use for my server is private - I put the SSH key up on my GitHub account and the server just handles the rest.

https://docs.github.com/en/enterprise/2.15/user/articles/adding-a-new-ssh-key-to-your-github-account