mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 23:34:24 +01:00
opt. for docker & apt
This commit is contained in:
35
lib/core/extension/ssh_client.dart
Normal file
35
lib/core/extension/ssh_client.dart
Normal file
@@ -0,0 +1,35 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:dartssh2/dartssh2.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:toolbox/core/extension/uint8list.dart';
|
||||
|
||||
typedef OnStd = void Function(String data, StreamSink<Uint8List> sink);
|
||||
typedef OnStdin = void Function(StreamSink<Uint8List> sink);
|
||||
|
||||
typedef PwdRequestFunc = Future<String> Function();
|
||||
final pwdRequestWithUserReg = RegExp(r'\[sudo\] password for (.+):');
|
||||
|
||||
extension SSHClientX on SSHClient {
|
||||
Future<int?> exec(String cmd,
|
||||
{OnStd? onStderr, OnStd? onStdout, OnStdin? stdin}) async {
|
||||
final session = await execute(cmd);
|
||||
|
||||
if (onStderr != null) {
|
||||
await for (final data in session.stderr) {
|
||||
onStderr(data.string, session.stdin);
|
||||
}
|
||||
}
|
||||
if (onStdout != null) {
|
||||
await for (final data in session.stdout) {
|
||||
onStdout(data.string, session.stdin);
|
||||
}
|
||||
}
|
||||
if (stdin != null) {
|
||||
stdin(session.stdin);
|
||||
}
|
||||
|
||||
session.close();
|
||||
return session.exitCode;
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,6 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:toolbox/data/model/distribution.dart';
|
||||
|
||||
@@ -60,4 +63,6 @@ extension StringX on String {
|
||||
}
|
||||
|
||||
String get withLangExport => 'export LANG=en_US.UTF-8 && $this';
|
||||
|
||||
Uint8List get uint8List => Uint8List.fromList(utf8.encode(this));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user