77 lines
2.0 KiB
Lua
77 lines
2.0 KiB
Lua
local createVersion = require('/apis/libversion');
|
|
|
|
local DEFAULT_SANDBOX_URL = 'wss://trapos.trapcloud.fr';
|
|
local SANDBOX_URL_SETTING = 'sandbox.url';
|
|
local SANDBOX_PASSWORD_SETTING = 'sandbox.password';
|
|
|
|
local function isBlank(value)
|
|
return type(value) ~= 'string' or value == '';
|
|
end
|
|
|
|
local function printUsage()
|
|
print('trapos-postinstall usage:');
|
|
print();
|
|
print('\t\ttrapos-postinstall');
|
|
print('\t\ttrapos-postinstall version');
|
|
print('\t\ttrapos-postinstall help');
|
|
end
|
|
|
|
local command = ...;
|
|
|
|
if command == 'version' or command == '-version' or command == '--version' then
|
|
print('v' .. createVersion().forSelf());
|
|
return;
|
|
end
|
|
|
|
if command == 'help' or command == '-help' or command == '--help' then
|
|
printUsage();
|
|
return;
|
|
end
|
|
|
|
if command ~= nil and command ~= '' then
|
|
printUsage();
|
|
return;
|
|
end
|
|
|
|
local function readManifestVersion()
|
|
if not fs.exists('/trapos/manifest.json') then return nil; end
|
|
local f = fs.open('/trapos/manifest.json', 'r');
|
|
if not f then return nil; end
|
|
local data = f.readAll();
|
|
f.close();
|
|
local manifest = data and textutils.unserializeJSON(data);
|
|
return manifest and manifest.version or nil;
|
|
end
|
|
|
|
local version = readManifestVersion();
|
|
local configuredSandboxUrl = false;
|
|
|
|
if isBlank(settings.get(SANDBOX_URL_SETTING)) then
|
|
shell.run('set', SANDBOX_URL_SETTING, DEFAULT_SANDBOX_URL);
|
|
configuredSandboxUrl = true;
|
|
end
|
|
|
|
local hasSandboxPassword = not isBlank(settings.get(SANDBOX_PASSWORD_SETTING));
|
|
|
|
print();
|
|
if version then
|
|
print('=> TrapOS v' .. version .. ' installed.');
|
|
else
|
|
print('=> TrapOS installed.');
|
|
end
|
|
if configuredSandboxUrl then
|
|
print('=> Configured sandbox.url to ' .. DEFAULT_SANDBOX_URL .. '.');
|
|
else
|
|
print('=> Keeping existing sandbox.url.');
|
|
end
|
|
if hasSandboxPassword then
|
|
print('=> Sandbox password already configured.');
|
|
else
|
|
print('=> Sandbox password not set.');
|
|
end
|
|
print();
|
|
print('Get started:');
|
|
print(' sandbox --help -- open the sandbox help');
|
|
print(' trapos-upgrade -- update and upgrade TrapOS');
|
|
print();
|