#!/usr/bin/env oil2script /* RC #AutomaticClassLoader # Use local resolvers, fallback to 8.8.8.8 NameServerDirectory "file:/etc/resolv.conf" "8.8.8.8" # Load any local host data HostTable "file:/etc/hosts" DNSresolver VISTAcheckVersion $* ENDRC */ %include class VISTAcheckVersion { int allDone; oid sleepingThread; oid queryObj; } inherits from Object; VISTAcheckVersion:create(optional string url) { logOutput(LOG_DEBUG, "argv=",argv,"\n"); assoc acl; acl = makeDefaultACL(); allow("httpResult"); queryObj = send "createObject"("VISTAgetCurrentRelease", acl, 5, url, thisObject) to ObjectCreator; sleepingThread = thisThread; while (allDone == 0) { send "suspendThread" to thisThread; } sleepingThread = nil; logOutput(LOG_DEBUG, "create thread terminated ", thisThread, "\n"); // force shutdown as DNS resolver will keep system active OMEshutdown(); // force shutdown } VISTAcheckVersion:delete() { } VISTAcheckVersion:httpResult(any resultText) { if (resultText == "") { logOutput(LOG_ERROR, "No version result obtained\n"); } else { int l = length(resultText); if (midchar(resultText, l - 1) == '\n') { // drop trailing newline resultText = midstr(resultText, 0, l - 1); } logOutput(LOG_DEBUG, "VERSION result: ", resultText); array resultTokens = tokenizeString(resultText, " ", 0); array versionTokens = tokenizeString(resultTokens[0], ".", 1); any majorVersion = getSystemInfoAttribute("vista_major_version"); any minorVersion = getSystemInfoAttribute("vista_minor_version"); any release = getSystemInfoAttribute("vista_release_version"); int newVersion = false; if (majorVersion < versionTokens[0]) { newVersion = true; } else if (majorVersion == versionTokens[0]) { if (minorVersion < versionTokens[1]) { newVersion = true; } else if (minorVersion == versionTokens[1]) { if (release < versionTokens[2]) { newVersion = true; } } } if (newVersion == true) { logOutput(LOG_INFO, "NEW VERSION AVAILABLE: ", resultText); } else { logOutput(LOG_INFO, "CURRENT VERSION AVAILABLE: ", resultText); } } allDone = 1; if (sleepingThread != nil) { logOutput(LOG_DEBUG, "wake sleeping thread ", sleepingThread, "\n"); send "releaseThread" to sleepingThread; } } /* vim: set expandtab shiftwidth=4 tabstop=4: */