diff --git a/yoyo-getfastmirror/lib/src/commands/modules/getfastmirro/Ubuntu/ubuntu_get_mirro_list.dart b/yoyo-getfastmirror/lib/src/commands/modules/getfastmirro/Ubuntu/ubuntu_get_mirro_list.dart new file mode 100644 index 0000000..61878f7 --- /dev/null +++ b/yoyo-getfastmirror/lib/src/commands/modules/getfastmirro/Ubuntu/ubuntu_get_mirro_list.dart @@ -0,0 +1,9 @@ +const List ubuntuMirrorList = [ + 'https://mirrors.tuna.tsinghua.edu.cn/ubuntu/', + 'https://mirrors.aliyun.com/ubuntu/', + 'https://repo.huaweicloud.com/ubuntu/' +]; + +List ubuntuGetMirrorList(){ + return ubuntuMirrorList; +} diff --git a/yoyo-getfastmirror/lib/src/commands/modules/getfastmirro/ubuntu_sources_list_template.dart b/yoyo-getfastmirror/lib/src/commands/modules/getfastmirro/Ubuntu/ubuntu_sources_list_template.dart similarity index 100% rename from yoyo-getfastmirror/lib/src/commands/modules/getfastmirro/ubuntu_sources_list_template.dart rename to yoyo-getfastmirror/lib/src/commands/modules/getfastmirro/Ubuntu/ubuntu_sources_list_template.dart diff --git a/yoyo-getfastmirror/lib/src/commands/modules/getfastmirro/get_mirro_list.dart b/yoyo-getfastmirror/lib/src/commands/modules/getfastmirro/Yoyo/yoyo_get_mirro_list.dart similarity index 87% rename from yoyo-getfastmirror/lib/src/commands/modules/getfastmirro/get_mirro_list.dart rename to yoyo-getfastmirror/lib/src/commands/modules/getfastmirro/Yoyo/yoyo_get_mirro_list.dart index c00610f..c69c802 100644 --- a/yoyo-getfastmirror/lib/src/commands/modules/getfastmirro/get_mirro_list.dart +++ b/yoyo-getfastmirror/lib/src/commands/modules/getfastmirro/Yoyo/yoyo_get_mirro_list.dart @@ -7,7 +7,7 @@ Uri mirrorsUri = Uri( ); /// 获取镜像列表,返回一个 List -Future> getMirrorList() async { +Future> yoyoGetMirrorList() async { final response = await http.get(mirrorsUri); final list = response.body.replaceAll('\n', ' ').trimRight().split(' '); return list; diff --git a/yoyo-getfastmirror/lib/src/commands/modules/getfastmirro/Yoyo/yoyo_is_exist.dart b/yoyo-getfastmirror/lib/src/commands/modules/getfastmirro/Yoyo/yoyo_is_exist.dart new file mode 100644 index 0000000..5c2cd53 --- /dev/null +++ b/yoyo-getfastmirror/lib/src/commands/modules/getfastmirro/Yoyo/yoyo_is_exist.dart @@ -0,0 +1,7 @@ +import 'dart:io'; + +File file = File('/etc/apt/sources.list.d/yoyo-os.list'); + +bool yoyoIsExist() { + return file.existsSync(); +} diff --git a/yoyo-getfastmirror/lib/src/commands/modules/getfastmirro/yoyo_sources_list_template.dart b/yoyo-getfastmirror/lib/src/commands/modules/getfastmirro/Yoyo/yoyo_sources_list_template.dart similarity index 100% rename from yoyo-getfastmirror/lib/src/commands/modules/getfastmirro/yoyo_sources_list_template.dart rename to yoyo-getfastmirror/lib/src/commands/modules/getfastmirro/Yoyo/yoyo_sources_list_template.dart diff --git a/yoyo-getfastmirror/lib/src/commands/modules/getfastmirro/getfastmirror.dart b/yoyo-getfastmirror/lib/src/commands/modules/getfastmirro/getfastmirror.dart index b4b427e..583dc65 100644 --- a/yoyo-getfastmirror/lib/src/commands/modules/getfastmirro/getfastmirror.dart +++ b/yoyo-getfastmirror/lib/src/commands/modules/getfastmirro/getfastmirror.dart @@ -1,19 +1,16 @@ import 'package:mason_logger/mason_logger.dart'; -import 'package:yoyo_get_fast_mirror/src/commands/modules/getfastmirro/generate_apt_fast_config_file.dart'; -import 'package:yoyo_get_fast_mirror/src/commands/modules/getfastmirro/get_mirro_list.dart'; -import 'package:yoyo_get_fast_mirror/src/commands/modules/getfastmirro/network_test.dart'; -import 'package:yoyo_get_fast_mirror/src/commands/modules/getfastmirro/test_mirro_speed.dart'; -import 'package:yoyo_get_fast_mirror/src/commands/modules/getfastmirro/ubuntu_sources_list_template.dart'; -import 'package:yoyo_get_fast_mirror/src/commands/modules/getfastmirro/write_mirror_into_file.dart'; -import 'package:yoyo_get_fast_mirror/src/commands/modules/getfastmirro/yoyo_sources_list_template.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'; +import 'package:yoyo_get_fast_mirror/src/commands/modules/getfastmirro/utils/write_mirror_into_file.dart'; final Map status = {}; final Logger _logger = Logger(); -const List ubuntuMirrorList = [ - 'https://mirrors.tuna.tsinghua.edu.cn/ubuntu/', - 'https://mirrors.aliyun.com/ubuntu/', - 'https://repo.huaweicloud.com/ubuntu/' -]; final outputYoyo = lightGreen.wrap('Yoyo Mirrors:'); final outputUbuntu = lightGreen.wrap('Ubuntu Mirrors:'); @@ -25,11 +22,19 @@ Future> getFastMirror({bool onlyTest = false}) async { status['msg'] = 'NetWork Error'; return status; } - //获取Yoyo镜像地址 - final yoYoMirrorList = await getMirrorList(); - _logger.info("\n$outputYoyo\n${yoYoMirrorList.join('\n')}\n"); - //测试Yoyo镜像并获取时间和排序后的Map - final sortedUrlListAndTimeYoyo = await testMirroSpeed(yoYoMirrorList); + // 如果 yoyo-os.list 存在,获取Yoyo镜像地址 + final yoYoMirrorList = yoyoIsExist() ? await yoyoGetMirrorList() : ['none']; + if (yoyoIsExist()) { + _logger.info("\n$outputYoyo\n${yoYoMirrorList.join('\n')}\n"); + } + // 如果 yoyo-os.list 存在,测试Yoyo镜像并获取时间和排序后的Map + final sortedUrlListAndTimeYoyo = yoyoIsExist() + ? await testMirroSpeed(yoYoMirrorList) + : [ + {'url': '', 'time': 'none'} + ]; + // 获取Ubuntua镜像地址 + final ubuntuMirrorList = ubuntuGetMirrorList(); //测试Ubuntu镜像并获取时间和排序后的Map _logger.info("\n$outputUbuntu\n${ubuntuMirrorList.join('\n')}\n"); final sortedUrlListAndTimeUbuntu = await testMirroSpeed(ubuntuMirrorList); @@ -37,7 +42,9 @@ Future> getFastMirror({bool onlyTest = false}) async { if (!onlyTest) { try { generateAptFastConfigFile( - sortedUrlListAndTimeYoyo, sortedUrlListAndTimeUbuntu,); + sortedUrlListAndTimeYoyo, + sortedUrlListAndTimeUbuntu, + ); } catch (e) { status['success'] = false; status['msg'] = 'Generate Config File Error'; @@ -46,14 +53,16 @@ Future> getFastMirror({bool onlyTest = false}) async { status['success'] = true; } //写入镜像源文件 - //Yoyo - final fastestYoyoMirror = - sortedUrlListAndTimeYoyo.first.entries.first.value; - final yoyoSourcesListFile = yoyoSourcesListTemplate(fastestYoyoMirror); - writeMirrorIntoFile( - yoyoSourcesListFile, - '/etc/apt/sources.list.d/yoyo-os.list', - ); + //如果 yoyo-os.list 存在,Yoyo + if (yoyoIsExist()) { + final fastestYoyoMirror = + sortedUrlListAndTimeYoyo.first.entries.first.value; + final yoyoSourcesListFile = yoyoSourcesListTemplate(fastestYoyoMirror); + writeMirrorIntoFile( + yoyoSourcesListFile, + '/etc/apt/sources.list.d/yoyo-os.list', + ); + } //Ubuntu final fastestUbuntuMirror = sortedUrlListAndTimeUbuntu.first.entries.first.value; diff --git a/yoyo-getfastmirror/lib/src/commands/modules/getfastmirro/apt_fast_config_template.dart b/yoyo-getfastmirror/lib/src/commands/modules/getfastmirro/utils/apt_fast_config_template.dart similarity index 97% rename from yoyo-getfastmirror/lib/src/commands/modules/getfastmirro/apt_fast_config_template.dart rename to yoyo-getfastmirror/lib/src/commands/modules/getfastmirro/utils/apt_fast_config_template.dart index f5670f1..e97e2f2 100644 --- a/yoyo-getfastmirror/lib/src/commands/modules/getfastmirro/apt_fast_config_template.dart +++ b/yoyo-getfastmirror/lib/src/commands/modules/getfastmirro/utils/apt_fast_config_template.dart @@ -13,15 +13,7 @@ String aptFastConfigTemplate(String yoYoMirroList,String ubuntuMirroList) { # # Default: apt-get # -_APTMGR=apt - -if grep -Eqi "linuxmint" /etc/os-release;then -_APTMGR=apt-get -fi - -if [ -x "\$(command -v oyo)" ]; then -_APTMGR=apt-get -fi +_APTMGR=/usr/bin/apt #### # @@ -41,7 +33,7 @@ fi # # Default: dialog enabled # -DOWNLOADBEFORE=true +# DOWNLOADBEFORE=true # Choose mirror list to speed up downloads from same archive. To select some diff --git a/yoyo-getfastmirror/lib/src/commands/modules/getfastmirro/generate_apt_fast_config_file.dart b/yoyo-getfastmirror/lib/src/commands/modules/getfastmirro/utils/generate_apt_fast_config_file.dart similarity index 96% rename from yoyo-getfastmirror/lib/src/commands/modules/getfastmirro/generate_apt_fast_config_file.dart rename to yoyo-getfastmirror/lib/src/commands/modules/getfastmirro/utils/generate_apt_fast_config_file.dart index 4f3244c..fed4bf6 100644 --- a/yoyo-getfastmirror/lib/src/commands/modules/getfastmirro/generate_apt_fast_config_file.dart +++ b/yoyo-getfastmirror/lib/src/commands/modules/getfastmirro/utils/generate_apt_fast_config_file.dart @@ -1,5 +1,5 @@ import 'dart:io'; -import 'package:yoyo_get_fast_mirror/src/commands/modules/getfastmirro/apt_fast_config_template.dart'; +import 'package:yoyo_get_fast_mirror/src/commands/modules/getfastmirro/utils/apt_fast_config_template.dart'; final tmpDir = Directory.systemTemp.path; final String filePath = '$tmpDir/oyo/apt-fast.conf'; diff --git a/yoyo-getfastmirror/lib/src/commands/modules/getfastmirro/network_test.dart b/yoyo-getfastmirror/lib/src/commands/modules/getfastmirro/utils/network_test.dart similarity index 100% rename from yoyo-getfastmirror/lib/src/commands/modules/getfastmirro/network_test.dart rename to yoyo-getfastmirror/lib/src/commands/modules/getfastmirro/utils/network_test.dart diff --git a/yoyo-getfastmirror/lib/src/commands/modules/getfastmirro/test_mirro_speed.dart b/yoyo-getfastmirror/lib/src/commands/modules/getfastmirro/utils/test_mirro_speed.dart similarity index 97% rename from yoyo-getfastmirror/lib/src/commands/modules/getfastmirro/test_mirro_speed.dart rename to yoyo-getfastmirror/lib/src/commands/modules/getfastmirro/utils/test_mirro_speed.dart index c7b311e..a82ce0f 100644 --- a/yoyo-getfastmirror/lib/src/commands/modules/getfastmirro/test_mirro_speed.dart +++ b/yoyo-getfastmirror/lib/src/commands/modules/getfastmirro/utils/test_mirro_speed.dart @@ -28,6 +28,7 @@ Future>> testMirroSpeed( } } spinner.updateMessage(''); + // ignore: cascade_invocations spinner.stop(); _logger.info(logMsg.toString()); final resultMap = testResult.asMap(); diff --git a/yoyo-getfastmirror/lib/src/commands/modules/getfastmirro/write_mirror_into_file.dart b/yoyo-getfastmirror/lib/src/commands/modules/getfastmirro/utils/write_mirror_into_file.dart similarity index 100% rename from yoyo-getfastmirror/lib/src/commands/modules/getfastmirro/write_mirror_into_file.dart rename to yoyo-getfastmirror/lib/src/commands/modules/getfastmirro/utils/write_mirror_into_file.dart