Support yum.

This commit is contained in:
Junyuan Feng
2022-04-07 18:56:33 +08:00
parent 00cfd0f88d
commit fa73c4feee
8 changed files with 64 additions and 27 deletions

View File

@@ -52,10 +52,10 @@ Support, but not tested|Windows/Linux
- [x] Theme switch
- [x] Migrate from `ssh2` to `dartssh2`
- [x] Desktop support
- [ ] Apt manager
- [ ] SFTP
- [x] Apt manager
- [x] SFTP
- [ ] Snippet market
- [ ] Docker manager
- [x] Docker manager
## Build
Please use `make.dart` to build.

View File

@@ -29,7 +29,7 @@ class ServerTabMenuItems {
static const sftp = MenuItem(text: 'SFTP', icon: Icons.insert_drive_file);
static const snippet = MenuItem(text: 'Snippet', icon: Icons.label);
static const apt = MenuItem(text: 'Apt', icon: Icons.system_security_update);
static const apt = MenuItem(text: 'Apt/Yum', icon: Icons.system_security_update);
static const docker = MenuItem(text: 'Docker', icon: Icons.view_agenda);
static const edit = MenuItem(text: 'Edit', icon: Icons.edit);
}

View File

@@ -1,6 +1,6 @@
import 'package:toolbox/data/model/distribution.dart';
class AptUpgradePkgInfo {
class UpgradePkgInfo {
final String _raw;
final Distribution _dist;
@@ -9,7 +9,7 @@ class AptUpgradePkgInfo {
late String newVersion;
late String arch;
AptUpgradePkgInfo(this._raw, this._dist) {
UpgradePkgInfo(this._raw, this._dist) {
switch (_dist) {
case Distribution.debian:
case Distribution.unknown:
@@ -29,5 +29,13 @@ class AptUpgradePkgInfo {
nowVersion = split2[5].replaceFirst(']', '');
}
void _parseYum() {}
void _parseYum() {
final result = RegExp(r'\S+').allMatches(_raw);
final pkgAndArch = result.elementAt(0).group(0) ?? '.';
final split1 = pkgAndArch.split('.');
package = split1[0];
arch = split1[1];
newVersion = result.elementAt(1).group(0) ?? 'Unknown';
nowVersion = '';
}
}

View File

@@ -8,7 +8,7 @@ class AptProvider extends BusyProvider {
SSHClient? client;
Distribution? dist;
String? whoami;
List<AptUpgradePkgInfo>? upgradeable;
List<UpgradePkgInfo>? upgradeable;
String? error;
String? updateLog;
@@ -36,12 +36,10 @@ class AptProvider extends BusyProvider {
error = 'No client';
return;
}
await update();
final result = await client!.run('apt list --upgradeable').string;
final result = await _update();
try {
final list = result.split('\n').sublist(4);
list.removeWhere((element) => element.isEmpty);
upgradeable = list.map((e) => AptUpgradePkgInfo(e, dist!)).toList();
getUpgradeableList(result);
} catch (e) {
error = e.toString();
} finally {
@@ -49,12 +47,34 @@ class AptProvider extends BusyProvider {
}
}
Future<void> update() async {
if (client == null) {
error = 'No client';
return;
void getUpgradeableList(String raw) {
switch (dist) {
case Distribution.rehl:
var list = raw.split('\n').sublist(2);
list.removeWhere((element) => element.isEmpty);
final endLine = list.lastIndexWhere(
(element) => element.contains('Obsoleting Packages'));
list = list.sublist(0, endLine);
upgradeable = list.map((e) => UpgradePkgInfo(e, dist!)).toList();
break;
case Distribution.debian:
case Distribution.unknown:
default:
final list = raw.split('\n').sublist(4);
list.removeWhere((element) => element.isEmpty);
upgradeable = list.map((e) => UpgradePkgInfo(e, dist!)).toList();
}
}
Future<String> _update() async {
switch (dist) {
case Distribution.rehl:
return await client!.run('yum check-update').string;
case Distribution.debian:
default:
await client!.run('apt update');
return await client!.run('apt list --upgradeable').string;
}
}
Future<void> upgrade() async {
@@ -64,11 +84,21 @@ class AptProvider extends BusyProvider {
}
updateLog = null;
final session = await client!.execute('apt upgrade -y');
final session = await client!.execute(upgradeCmd);
session.stdout.listen((data) {
updateLog = (updateLog ?? '') + data.string;
notifyListeners();
});
refreshInstalled();
}
String get upgradeCmd {
switch (dist) {
case Distribution.rehl:
return 'yum upgrade -y';
case Distribution.debian:
default:
return 'apt upgrade -y';
}
}
}

View File

@@ -2,9 +2,9 @@
class BuildData {
static const String name = "ServerBox";
static const int build = 109;
static const int build = 110;
static const String engine =
"Flutter 2.10.4 • channel stable • https://github.com/flutter/flutter.git\nFramework • revision c860cba910 (12 days ago) • 2022-03-25 00:23:12 -0500\nEngine • revision 57d3bac3dd\nTools • Dart 2.16.2 • DevTools 2.9.2\n";
static const String buildAt = "2022-04-06 13:00:26.954649";
static const int modifications = 7;
static const String buildAt = "2022-04-06 13:48:27.717376";
static const int modifications = 0;
}

View File

@@ -129,7 +129,7 @@ class _AptManagePageState extends State<AptManagePage>
);
}
Widget _buildUpdateItem(AptUpgradePkgInfo info, AptProvider apt) {
Widget _buildUpdateItem(UpgradePkgInfo info, AptProvider apt) {
return ListTile(
title: Text(info.package),
subtitle: Text(

View File

@@ -194,10 +194,9 @@ class _ServerDetailPageState extends State<ServerDetailPage>
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
_buildMemExplain((ss.memory.used * mb).convertBytes, pColor),
_buildMemExplain(
(ss.memory.used * mb).convertBytes, pColor),
_buildMemExplain((ss.memory.cache * mb).convertBytes,
pColor.withAlpha(77)),
(ss.memory.cache * mb).convertBytes, pColor.withAlpha(77)),
_buildMemExplain(
((ss.memory.total - ss.memory.used) * mb).convertBytes,
progressColor.resolve(context))

View File

@@ -21,7 +21,7 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
FlutterMacOS: 57701585bf7de1b3fc2bb61f6378d73bbdea8424
path_provider_macos: 160cab0d5461f0c0e02995469a98f24bdb9a3f1f
url_launcher_macos: 45af3d61de06997666568a7149c1be98b41c95d4
url_launcher_macos: 597e05b8e514239626bcf4a850fcf9ef5c856ec3
PODFILE CHECKSUM: 6eac6b3292e5142cfc23bdeb71848a40ec51c14c