refactor(updater_shim): finish porting to nu

Signed-off-by: zontreck <tarapiccari@gmail.com>
This commit is contained in:
zontreck 2024-10-05 01:53:58 -07:00
parent 2c25a43ba2
commit 737045ecf7
4 changed files with 51 additions and 14 deletions

View file

@ -17,4 +17,14 @@ CancelCallback(string sTimerID) {
string BuildPacket(string sOperation, list lParams) {
return llList2Json(JSON_OBJECT, lParams + ["op", sOperation]);
}
string MakeSession(string SessionType)
{
// We will encode the 1st digit of the session type into the actual UUID itself
// Begin replacement
string sTmp = llGenerateKey();
sTmp = llGetSubString(SessionType, 0,0) + llGetSubString(sTmp, 1, -1);
return llToUpper(sTmp);
}

View file

@ -1,6 +1,7 @@
integer LINK_SIGNAL_SETTINGS = 0904241;
integer LINK_SIGNAL_REBOOT = 0904242;
integer LINK_SIGNAL_CALLBACKS = 0904243;
integer LINK_SIGNAL_UPDATE = 0905241;
string OP_SETTINGS_WRITE = "1";
@ -17,6 +18,9 @@ string OP_CALLBACK_CHK_STATUS = "3";
string OP_CALLBACK_READY = "4";
string OP_CALLBACK = "5";
string OP_UPDATE_START = "1";
string OP_UPDATE_DONE = "2";
string EMPTY_JSON = "{}";
@ -36,4 +40,5 @@ integer g_iClientPin;
integer g_iUpdateRunning;
integer g_iCurrentBundle;
integer g_iServerListener;
integer g_iUpdateHasStarted;
integer g_iUpdateHasStarted;
key g_kSession;

View file

@ -0,0 +1,12 @@
/*
This file is a part of NuSystem (https://git.zontreck.com/AriasCreations/NuSystem)
NuSystem is licensed under the GPL.
Please see the Git Source Tree for structured information on changes to indivudual files
Initial Author: Aria (aria@zontreck.com)
*/
#include "../raw/updater/shim.lsl"

View file

@ -1,4 +1,10 @@
#include "includes/common.lsl"
#include "Variables.lsl"
#include "Functions.lsl"
#include "Version.lsl"
#include "../external/AriasCreations/Common.lsl"
#include "../external/AriasCreations/Helpers.lsl"
string g_sOldVersion = "";
default
{
@ -8,15 +14,17 @@ default
// We can now perform update specific preparations
// First off send the update started signal
if(llGetStartParameter()==0)llSetScriptState(llGetScriptName(), FALSE);
if(llGetInventoryType("SynthOS Installer") == INVENTORY_SCRIPT){
if(llGetInventoryType("NuInstaller [AC]") == INVENTORY_SCRIPT){
llSetScriptState(llGetScriptName(), FALSE);
return;
}
g_kSession = MakeSession(SESSION_UPDATE);
signal(SIGNAL_UPDATE_START, g_kSession);
LM(LINK_SIGNAL_UPDATE, OP_UPDATE_START, llList2Json(JSON_OBJECT, ["session", g_kSession]));
g_iStartup = llGetStartParameter();
g_iUpdaterListener = llListen(UPDATER_CHANNEL, "", "", "");
g_sOldVersion = llLinksetDataRead("version");
}
dataserver( key kID, string sData )
@ -30,7 +38,7 @@ default
{
DeleteDSReq(kID);
llRemoveInventory(llList2String(lMeta,1)); // Delete the BOM file
llRegionSayTo(g_kUpdatePair, UPDATER_CHANNEL, Build("upgrade_security", ["pin", g_iClientPin, "secure_channel", g_iUpdaterSecureChannel]));
llRegionSayTo(g_kUpdatePair, UPDATER_CHANNEL, BuildPacket("upgrade_security", ["pin", g_iClientPin, "secure_channel", g_iUpdaterSecureChannel]));
}else {
if(sData=="")jump next;
list lTmp = llParseString2List(sData,["|"], []);
@ -54,7 +62,8 @@ default
// Check the startup number against the pairing code
if(iChannel == UPDATER_CHANNEL)
{
if(llJsonGetValue(sMsg,["operation"]) == "connect")
string sOp = llJsonGetValue(sMsg, ["op"]);
if(sOp == "connect")
{
integer iPair = (integer)llJsonGetValue(sMsg,["pair"]);
if(iPair == g_iStartup){
@ -72,7 +81,7 @@ default
if(llGetInventoryType(sBOM)==INVENTORY_NOTECARD)
UpdateDSRequest(NULL, llGetNotecardLine(sBOM,1), SetDSMeta(["read", sBOM, 1])); // Start at line 1 to skip the Version Number
else
llRegionSayTo(g_kUpdatePair, UPDATER_CHANNEL, Build("upgrade_security", ["pin", g_iClientPin, "secure_channel", g_iUpdaterSecureChannel]));
llRegionSayTo(g_kUpdatePair, UPDATER_CHANNEL, BuildPacket("upgrade_security", ["pin", g_iClientPin, "secure_channel", g_iUpdaterSecureChannel]));
}
}
@ -84,11 +93,12 @@ default
// Due to SL not telling us UUIDs of things that we do not have full permission to, we must rely on a force update all approach.
// This is not ideal but it is how non-full perm stuff must be updated.
if (llJsonGetValue(sMsg, ["operation"]) == "began")
string sOp = llJsonGetValue(sMsg, ["op"]);
if (sOp == "began")
{
// The updater has begun to send items or install scripts. It'll be quiet for a little bit while the install happens.
// Currently there is nothing here to process
} else if(llJsonGetValue(sMsg, ["operation"]) == "ended")
} else if(sOp == "ended")
{
// The updater has sent us everything and it has started to reset itself.
// We can safely assume the update is done. Sleep for about 10 seconds and then dispatch the update done signal
@ -104,13 +114,13 @@ default
llSetScriptState(sName, TRUE); // We do not care about resetting them right here. Let them start up, then sleep and send the update done signal
}
llSleep(10);
signal(SIGNAL_UPDATE_DONE, g_kSession);
LM(LINK_SIGNAL_UPDATE, OP_UPDATE_DONE, llList2Json(JSON_OBJECT, ["session", g_kSession]));
llSetRemoteScriptAccessPin(0);
signal(SIGNAL_RESET, g_kSession);
LM(LINK_SIGNAL_REBOOT, "0", EMPTY_JSON);
llSleep(1);
llSay(0, "Update completed to "+llLinksetDataRead("os.softwareversion"));
llSay(0, "Update completed to "+llLinksetDataRead("version") + " from version " + g_sOldVersion);
llRemoveInventory(llGetScriptName()); // Clean up ourself
} else if(llJsonGetValue(sMsg, ["operation"]) == "prepare")
} else if(sOp == "prepare")
{
string sItem=llJsonGetValue(sMsg,["details", "name"]);
// This signal is specific to items that need to be removed to make room for the newer item
@ -121,7 +131,7 @@ default
// Send back the details packet which will include details like the item name, and type
// We are sending it on the main json payload this time instead of inside a json object ["details"]
llRegionSayTo(kID, iChannel, Build("continue", llJson2List(llJsonGetValue(sMsg,["details"]))));
llRegionSayTo(kID, iChannel, BuildPacket("continue", llJson2List(llJsonGetValue(sMsg,["details"]))));
}
}