Take a look at AdmiOS's updater:
local config = libCFG.readConfig("/etc/update.cfg")
local latest = tonumber(libNET.getFile(config["repo"] .. "version"))
local current = tonumber(config["version"])
if latest > current then
print("\nThere is an update!")
print("Your version: " .. current .. "\nLatest version: " .. latest)
print("Update? (Y/N)")
local e = {os.pullEvent("key")}
if e[2] == 21 then
print("Getting installer...")
libNET.downloadSaveFile("http://pastebin.com/raw/dAH7J9X8", "/.installer_temp")
print("Running installer...")
shell.run("/.installer_temp update")
else
print("Update dismissed. Continuing Boot...")
end
end
if fs.exists("/.installer_temp") then
print("\nRemoving Update remains...")
fs.delete("/.installer_temp")
end
This code runs in the every* bootup of the OS
*this does not include the shell login since it doesnt execute init files.
So, I made some APIs to do stuff and i used 2 of them (libCFG and libNET) You probably don't have then. So i'm just going to explain what they do.
libCFG just takes a config files and turns it into a table (Available in the Apis section of programs)
libNET gots files from the internet and does some stuff with them.
So, first, i get the contents of the update config file. This has the URL of the site that has the version file. (the file only contains a number and nothing else)
Second, i download the version file and return it's contents to a variable named
latest.
Third, i get the current version from the config file said above (saved in variable
current). And compare them with
if latest > current thenIf latest version is bigger than the current version. I prompt the user for updates.
When the user presses y (Detected with
if e[2] == 21 then) i go and download the installer to
/.installer_temp (My installer gets the latest version from GitHub.) and execute it with the argument
update that makes the installer skip creating a new user. It will get everything from GitHub as said above and it will reboot (rebooting happens in the installer)
After the reboot, the files should be updated. And the program will run agan to check for updates. It will probably not find any since the user just updated. Then it will check if
/.installer_temp exists and if so, will delete it. Removing the unneccecary file.
I'm sorry for the wall of text but this should explain what i do to keep AdmiOS updated.
If you have any questions, i will try to answer them here.