refactor(updater): port updater to nusystem

Port the updater over to NuSystem. This is not the package server.

Signed-off-by: zontreck <tarapiccari@gmail.com>
This commit is contained in:
zontreck 2024-10-05 02:21:00 -07:00
parent 993b6feee4
commit 87fb6b610f
3 changed files with 81 additions and 16 deletions

View file

@ -32,3 +32,48 @@ string MakeSession(string SessionType)
sTmp = llGetSubString(SessionType, 0,0) + llGetSubString(sTmp, 1, -1);
return llToUpper(sTmp);
}
string compileVersion()
{
return llDumpList2String([VERSION,PREALPHA,DEV,BUILD, BUILD_NUM], "-");
}
// Version Number Comparison Function
/*
Stops at the first difference and returns the result. This function is not capable of comparing development states stored in the extra params at this time. Perhaps in the future these can just be converted to a number
This is TODO
RETURNS
0 - if both are the same
1 - if sCompare is greater
-1 - if sCompare is less than sInput
*/
integer VersionNumberCompare(string sInput, string sCompare)
{
list l1 = llParseString2List(sInput,["-"],[]);
list l2 = llParseString2List(sCompare,["-"],[]);
// TODO: Add here the conversion of the extra params like Prealpha, dev, and build num to extra decimals and as numbers. PREALPHA would be 0, ALPHA would be 1. etc. DEV can be perhaps -1 or maybe 0 and shift prealpha to 1.
list lInput = llParseString2List(llList2String(l1,0), ["."],[]);
list lCompare = llParseString2List(llList2String(l2,0), ["."],[]);
integer i=0;
integer end = llGetListLength(lInput);
integer iBias = 0; // Same!
for(i=0;i<end;i++)
{
integer iComp = (integer)llList2String(lCompare,i);
integer iCur = (integer)llList2String(lInput,i);
if(iComp < iCur)return -1;
if(iComp > iCur)return 1;
}
return 0;
}
/*
END VERSION CODE
*/

View file

@ -43,3 +43,21 @@ integer g_iCurrentBundle;
integer g_iServerListener;
integer g_iUpdateHasStarted;
key g_kSession;
string g_sBOM;
string UPDATER_SHIM = "NuUpdate Shim [AC]";
// VERSION NUMBER
// CHANGE ME WHEN UPDATING BUILDS
string VERSION = "0.0.0.1";
integer BUILD_NUM = 26;
string PREALPHA = "pa";
string ALPHA = "a";
string DEV = "dev";
string BUILD = "build";
string RC = "rc";
string BETA = "b";
string SESSION_UPDATE = "A";

View file

@ -1,9 +1,10 @@
/*
#include "Variables.lsl"
#include "Functions.lsl"
#include "Version.lsl"
#include "../external/AriasCreations/Common.lsl"
#include "../external/AriasCreations/Helpers.lsl"
This file is the updater
*/
#include "includes/common.lsl"
integer g_iDelOnFinish=0;
default
{
@ -50,29 +51,30 @@ default
//llSay(0, "DEBUG ["+llDumpList2String([iChannel, sName, kID, sMsg], " ~ ")+"]");
if(iChannel == UPDATER_CHANNEL)
{
if(llJsonGetValue(sMsg,["operation"]) == "checkupdate")
string sOp = llJsonGetValue(sMsg,["op"]);
if(sOp == "checkupdate")
{
string sVer = llJsonGetValue(sMsg,["myversion"]);
integer iCompare = VersionNumberCompare(compileVersion(), sVer);
if(iCompare == 0)
{
llRegionSayTo(kID, UPDATER_CHANNEL, Build("same", []));
llRegionSayTo(kID, UPDATER_CHANNEL, BuildPacket("same", []));
}else if(iCompare == -1){
// Bingo, we are good to begin
llRegionSayTo(kID, UPDATER_CHANNEL, Build("available", []));
llRegionSayTo(kID, UPDATER_CHANNEL, BuildPacket("available", []));
} else if(iCompare == 1)
{
llRegionSayTo(kID, UPDATER_CHANNEL, Build("older", []));
llRegionSayTo(kID, UPDATER_CHANNEL, BuildPacket("older", []));
}
} else if(llJsonGetValue(sMsg, ["operation"]) == "stage2")
} else if(llJsonGetValue(sMsg, ["op"]) == "stage2")
{
// Send the shim
g_iClientPin = (integer)llJsonGetValue(sMsg, ["pin"]);
g_iStartup = llAbs(llRound(llFrand(0xFFFF))); // Pairing code
llRemoteLoadScriptPin(kID, UPDATER_SHIM, g_iClientPin, TRUE, g_iStartup);
llSleep(5); // Wait for it to start up...and any lag that might be happening
llRegionSayTo(kID, UPDATER_CHANNEL, Build("connect", ["pair", g_iStartup, "bom", g_sBOM]));
} else if(llJsonGetValue(sMsg,["operation"]) == "upgrade_security")
llRegionSayTo(kID, UPDATER_CHANNEL, BuildPacket("connect", ["pair", g_iStartup, "bom", g_sBOM]));
} else if(llJsonGetValue(sMsg,["op"]) == "upgrade_security")
{
llListenControl(g_iUpdaterListener, FALSE);
g_iUpdaterSecureChannel = (integer)llJsonGetValue(sMsg,["secure_channel"]);
@ -87,7 +89,7 @@ default
UpdateDSRequest(NULL, llGetNotecardLine(g_sBOM, 1), SetDSMeta(["read_bom", 1]));
}
} else if(iChannel == g_iUpdaterSecureChannel){
if(llJsonGetValue(sMsg,["operation"]) == "continue")
if(llJsonGetValue(sMsg,["op"]) == "continue")
{
integer iScript = (integer)llJsonGetValue(sMsg,["type"]);
string sScript = llJsonGetValue(sMsg,["name"]);
@ -117,7 +119,7 @@ default
{
if(sData == EOF)
{
llRegionSayTo(g_kUpdatePair, g_iUpdaterSecureChannel, Build("ended", []));
llRegionSayTo(g_kUpdatePair, g_iUpdaterSecureChannel, BuildPacket("ended", []));
llGiveInventory(g_kUpdatePair, g_sBOM); // Give the manifest. We're done now
llSay(0, "Update completed!");
llSleep(2);
@ -138,7 +140,7 @@ default
string sDetailsPacket = llList2Json(JSON_OBJECT,["name", llList2String(lParams,1), "type", iType]);
UpdateDSRequest(kID, g_kBundleReader, SetDSMeta(lMeta));
llRegionSayTo(g_kUpdatePair, g_iUpdaterSecureChannel, Build("prepare", ["details", sDetailsPacket]));
llRegionSayTo(g_kUpdatePair, g_iUpdaterSecureChannel, BuildPacket("prepare", ["details", sDetailsPacket]));
jump done;
@next;