opt.: install script

This commit is contained in:
lollipopkit
2024-02-23 11:01:47 +08:00
parent 37dc1056c9
commit fad3f41e58
3 changed files with 14 additions and 39 deletions

View File

@@ -33,17 +33,11 @@ enum ShellFunc {
/// Issue #168 /// Issue #168
/// Use `sh` for compatibility /// Use `sh` for compatibility
// static final installShellCmd = """ static const installShellCmd = """
// mkdir -p $_homeVar/$_srvBoxDir mkdir -p $_homeVar/$_srvBoxDir
// cat << 'EOF' > $_installShellPath cat > $_installShellPath
// ${ShellFunc.allScript} chmod +x $_installShellPath
// EOF """;
// chmod +x $_installShellPath
// """;
static const installerMkdirs = "mkdir -p $_homeVar/$_srvBoxDir";
static const installerShellWriter = "cat > $_installShellPath";
static const installerPermissionModifier = "chmod +x $_installShellPath";
String get flag { String get flag {
switch (this) { switch (this) {

View File

@@ -68,6 +68,11 @@ Future<ServerStatus> _getLinuxStatus(ServerStatusUpdateReq req) async {
try { try {
final cpus = OneTimeCpuStatus.parse(StatusCmdType.cpu.find(segments)); final cpus = OneTimeCpuStatus.parse(StatusCmdType.cpu.find(segments));
req.ss.cpu.update(cpus); req.ss.cpu.update(cpus);
} catch (e, s) {
Loggers.parse.warning(e, s);
}
try {
req.ss.temps.parse( req.ss.temps.parse(
StatusCmdType.tempType.find(segments), StatusCmdType.tempType.find(segments),
StatusCmdType.tempVal.find(segments), StatusCmdType.tempVal.find(segments),

View File

@@ -258,33 +258,6 @@ class ServerProvider extends ChangeNotifier {
notifyListeners(); notifyListeners();
} }
Future<void> _writeInstallerScript(Server s) async {
/// TODO: Find a better way to judge if the write is successful
// Issues #275
// Can't use writeResult to judge if the write is successful
// void ensure(String? writeResult) {
// if (writeResult == null || writeResult.isNotEmpty) {
// throw Exception("Failed to write installer script: $writeResult");
// }
// }
final client = s.client;
if (client == null) {
throw Exception("Invalid state: s.client cannot be null");
}
await client.run(ShellFunc.installerMkdirs).string;
await client.runForOutput(ShellFunc.installerShellWriter,
action: (session) async {
session.stdin.add(ShellFunc.allScript.uint8List);
}).string;
await client.run(ShellFunc.installerPermissionModifier).string;
}
Future<void> _getData(ServerPrivateInfo spi) async { Future<void> _getData(ServerPrivateInfo spi) async {
final sid = spi.id; final sid = spi.id;
final s = _servers[sid]; final s = _servers[sid];
@@ -333,7 +306,10 @@ class ServerProvider extends ChangeNotifier {
// Write script to server // Write script to server
// by ssh // by ssh
try { try {
await _writeInstallerScript(s); await s.client?.runForOutput(ShellFunc.installShellCmd,
action: (session) async {
session.stdin.add(ShellFunc.allScript.uint8List);
}).string;
} on SSHAuthAbortError catch (e) { } on SSHAuthAbortError catch (e) {
TryLimiter.inc(sid); TryLimiter.inc(sid);
s.status.err = e.toString(); s.status.err = e.toString();