update:#I6BT4I
https://gitee.com/spark-community-works-collections/oyo/issues/I6BT4I
This commit is contained in:
parent
cb8e70c6ac
commit
b220fc45a5
yoyo-getfastmirror
@ -6,7 +6,7 @@ import 'package:yoyo_get_fast_mirror/src/version.dart';
|
||||
|
||||
const executableName = 'yoyo-getfastmirror';
|
||||
const packageName = 'yoyo_get_fast_mirror';
|
||||
const description = 'A Very Good Project created by Yoyo.';
|
||||
const description = 'A Very Good aptss created by Yoyo.';
|
||||
|
||||
class YoyoGetFastMirrorCommandRunner extends CommandRunner<int> {
|
||||
/// {@macro yoyo_get_fast_mirror_command_runner}
|
||||
|
11
yoyo-getfastmirror/lib/src/commands/modules/getfastmirro/Ubuntu/ubuntu_sources_list_template.dart
11
yoyo-getfastmirror/lib/src/commands/modules/getfastmirro/Ubuntu/ubuntu_sources_list_template.dart
@ -1,11 +0,0 @@
|
||||
String ubuntuSourcesListTemplate(String ubuntuMirrorUrl) {
|
||||
return '''
|
||||
# Generate by yoyo-getfastmirror
|
||||
# Author: Github/Riceneeder
|
||||
|
||||
deb $ubuntuMirrorUrl jammy main restricted universe multiverse
|
||||
deb $ubuntuMirrorUrl jammy-updates main restricted universe multiverse
|
||||
deb $ubuntuMirrorUrl jammy-backports main restricted universe multiverse
|
||||
deb $ubuntuMirrorUrl jammy-security main restricted universe multiverse
|
||||
''';
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
String yoyoSourcesListTemplate(String yoyoMirrorUrl) {
|
||||
return '''
|
||||
# Generate by yoyo-getfastmirror
|
||||
# Author: Gtibhub/Riceneeder
|
||||
|
||||
deb [arch=amd64] $yoyoMirrorUrl kokomi main
|
||||
''';
|
||||
}
|
@ -1,9 +1,7 @@
|
||||
import 'package:mason_logger/mason_logger.dart';
|
||||
import 'package:yoyo_get_fast_mirror/src/commands/modules/getfastmirro/Ubuntu/ubuntu_get_mirro_list.dart';
|
||||
import 'package:yoyo_get_fast_mirror/src/commands/modules/getfastmirro/Ubuntu/ubuntu_sources_list_template.dart';
|
||||
import 'package:yoyo_get_fast_mirror/src/commands/modules/getfastmirro/Yoyo/yoyo_get_mirro_list.dart';
|
||||
import 'package:yoyo_get_fast_mirror/src/commands/modules/getfastmirro/Yoyo/yoyo_is_exist.dart';
|
||||
import 'package:yoyo_get_fast_mirror/src/commands/modules/getfastmirro/Yoyo/yoyo_sources_list_template.dart';
|
||||
import 'package:yoyo_get_fast_mirror/src/commands/modules/getfastmirro/utils/generate_apt_fast_config_file.dart';
|
||||
import 'package:yoyo_get_fast_mirror/src/commands/modules/getfastmirro/utils/network_test.dart';
|
||||
import 'package:yoyo_get_fast_mirror/src/commands/modules/getfastmirro/utils/test_mirro_speed.dart';
|
||||
@ -57,19 +55,16 @@ Future<Map<String, dynamic>> getFastMirror({bool onlyTest = false}) async {
|
||||
if (yoyoIsExist()) {
|
||||
final fastestYoyoMirror =
|
||||
sortedUrlListAndTimeYoyo.first.entries.first.value;
|
||||
final yoyoSourcesListFile = yoyoSourcesListTemplate(fastestYoyoMirror);
|
||||
writeMirrorIntoFile(
|
||||
yoyoSourcesListFile,
|
||||
fastestYoyoMirror,
|
||||
'/etc/apt/sources.list.d/yoyo-os.list',
|
||||
);
|
||||
}
|
||||
//Ubuntu
|
||||
final fastestUbuntuMirror =
|
||||
sortedUrlListAndTimeUbuntu.first.entries.first.value;
|
||||
final ubuntuSourcesLIstFile =
|
||||
ubuntuSourcesListTemplate(fastestUbuntuMirror);
|
||||
writeMirrorIntoFile(
|
||||
ubuntuSourcesLIstFile,
|
||||
fastestUbuntuMirror,
|
||||
'/etc/apt/sources.list',
|
||||
);
|
||||
}
|
||||
|
@ -3,12 +3,21 @@ import 'package:mason_logger/mason_logger.dart';
|
||||
|
||||
final done = lightGreen.wrap('Done');
|
||||
final Logger _logger = Logger();
|
||||
RegExp urlReg = RegExp(
|
||||
r'\b(([\w-]+://?|www[.])[^\s()<>]+(?:[\w\d]+|([^[:punct:]\s]|/)))',
|
||||
);
|
||||
|
||||
///mirror 镜像源网址
|
||||
void writeMirrorIntoFile(String mirror, String path) {
|
||||
final file = File(path);
|
||||
final writting = lightYellow.wrap('Writting $path');
|
||||
final file = File(path);
|
||||
var fileContent = file.readAsStringSync();
|
||||
final url = urlReg.allMatches(fileContent);
|
||||
for (final item in url) {
|
||||
fileContent = fileContent.replaceAll(item.group(0) ?? '', mirror);
|
||||
}
|
||||
_logger.info(writting);
|
||||
if (!file.existsSync()) file.createSync(recursive: true);
|
||||
file.writeAsStringSync(mirror);
|
||||
file.writeAsStringSync(fileContent);
|
||||
_logger.info(done);
|
||||
}
|
||||
|
@ -1,3 +1,3 @@
|
||||
#! /bin/bash
|
||||
|
||||
dart compile exe bin/yoyo_get_fast_mirror.dart -o release/yoyo-getfastmirror
|
||||
dart pub get && dart compile exe bin/yoyo_get_fast_mirror.dart -o release/yoyo-getfastmirror
|
Loading…
x
Reference in New Issue
Block a user