diff --git a/README.md b/README.md index 7ff3a15a..a951a4a2 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/lib/data/model/app/menu_item.dart b/lib/data/model/app/menu_item.dart index ff555fec..a9e3d615 100644 --- a/lib/data/model/app/menu_item.dart +++ b/lib/data/model/app/menu_item.dart @@ -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); } diff --git a/lib/data/model/apt/upgrade_pkg_info.dart b/lib/data/model/apt/upgrade_pkg_info.dart index 12c21fae..1a68087b 100644 --- a/lib/data/model/apt/upgrade_pkg_info.dart +++ b/lib/data/model/apt/upgrade_pkg_info.dart @@ -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 = ''; + } } diff --git a/lib/data/provider/apt.dart b/lib/data/provider/apt.dart index 5d7ad58e..69582802 100644 --- a/lib/data/provider/apt.dart +++ b/lib/data/provider/apt.dart @@ -8,7 +8,7 @@ class AptProvider extends BusyProvider { SSHClient? client; Distribution? dist; String? whoami; - List? upgradeable; + List? 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 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 _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; } - await client!.run('apt update'); } Future 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'; + } + } } diff --git a/lib/data/res/build_data.dart b/lib/data/res/build_data.dart index 2409da3e..6cc79da4 100644 --- a/lib/data/res/build_data.dart +++ b/lib/data/res/build_data.dart @@ -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; } diff --git a/lib/view/page/apt.dart b/lib/view/page/apt.dart index a3a8ca23..521dc015 100644 --- a/lib/view/page/apt.dart +++ b/lib/view/page/apt.dart @@ -129,7 +129,7 @@ class _AptManagePageState extends State ); } - Widget _buildUpdateItem(AptUpgradePkgInfo info, AptProvider apt) { + Widget _buildUpdateItem(UpgradePkgInfo info, AptProvider apt) { return ListTile( title: Text(info.package), subtitle: Text( diff --git a/lib/view/page/server/detail.dart b/lib/view/page/server/detail.dart index 4b246d8e..99362c32 100644 --- a/lib/view/page/server/detail.dart +++ b/lib/view/page/server/detail.dart @@ -194,10 +194,9 @@ class _ServerDetailPageState extends State 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)) diff --git a/macos/Podfile.lock b/macos/Podfile.lock index 97f8dd1b..90cb92a8 100644 --- a/macos/Podfile.lock +++ b/macos/Podfile.lock @@ -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