diff --git a/yoyo-getfastmirror/lib/src/command_runner.dart b/yoyo-getfastmirror/lib/src/command_runner.dart index 94a9401..dcf533c 100644 --- a/yoyo-getfastmirror/lib/src/command_runner.dart +++ b/yoyo-getfastmirror/lib/src/command_runner.dart @@ -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} diff --git a/yoyo-getfastmirror/lib/src/commands/modules/getfastmirro/Ubuntu/ubuntu_sources_list_template.dart b/yoyo-getfastmirror/lib/src/commands/modules/getfastmirro/Ubuntu/ubuntu_sources_list_template.dart deleted file mode 100644 index 9a3b791..0000000 --- a/yoyo-getfastmirror/lib/src/commands/modules/getfastmirro/Ubuntu/ubuntu_sources_list_template.dart +++ /dev/null @@ -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 -'''; -} diff --git a/yoyo-getfastmirror/lib/src/commands/modules/getfastmirro/Yoyo/yoyo_sources_list_template.dart b/yoyo-getfastmirror/lib/src/commands/modules/getfastmirro/Yoyo/yoyo_sources_list_template.dart deleted file mode 100644 index a7c6260..0000000 --- a/yoyo-getfastmirror/lib/src/commands/modules/getfastmirro/Yoyo/yoyo_sources_list_template.dart +++ /dev/null @@ -1,8 +0,0 @@ -String yoyoSourcesListTemplate(String yoyoMirrorUrl) { - return ''' -# Generate by yoyo-getfastmirror -# Author: Gtibhub/Riceneeder - -deb [arch=amd64] $yoyoMirrorUrl kokomi main -'''; -} diff --git a/yoyo-getfastmirror/lib/src/commands/modules/getfastmirro/getfastmirror.dart b/yoyo-getfastmirror/lib/src/commands/modules/getfastmirro/getfastmirror.dart index 583dc65..6e459e6 100644 --- a/yoyo-getfastmirror/lib/src/commands/modules/getfastmirro/getfastmirror.dart +++ b/yoyo-getfastmirror/lib/src/commands/modules/getfastmirro/getfastmirror.dart @@ -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', ); } diff --git a/yoyo-getfastmirror/lib/src/commands/modules/getfastmirro/utils/write_mirror_into_file.dart b/yoyo-getfastmirror/lib/src/commands/modules/getfastmirro/utils/write_mirror_into_file.dart index c9b6991..36847b3 100644 --- a/yoyo-getfastmirror/lib/src/commands/modules/getfastmirro/utils/write_mirror_into_file.dart +++ b/yoyo-getfastmirror/lib/src/commands/modules/getfastmirro/utils/write_mirror_into_file.dart @@ -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); } diff --git a/yoyo-getfastmirror/release.sh b/yoyo-getfastmirror/release.sh index f271dcf..5bdbc70 100755 --- a/yoyo-getfastmirror/release.sh +++ b/yoyo-getfastmirror/release.sh @@ -1,3 +1,3 @@ #! /bin/bash -dart compile exe bin/yoyo_get_fast_mirror.dart -o release/yoyo-getfastmirror \ No newline at end of file +dart pub get && dart compile exe bin/yoyo_get_fast_mirror.dart -o release/yoyo-getfastmirror \ No newline at end of file