57 lines
1.3 KiB
Go
57 lines
1.3 KiB
Go
package fastmirror
|
|
|
|
import (
|
|
"log"
|
|
"runtime"
|
|
)
|
|
|
|
func CLIEntry() {
|
|
log.Println("Starting Fastmirror CLI")
|
|
|
|
if runtime.GOOS != "linux" {
|
|
log.Fatal("This program is only for Linux")
|
|
}
|
|
if err := isUbuntu(); err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
sourcesFilePath, err := findSourcesFilePath()
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
log.Printf("Found sources file: %s", sourcesFilePath)
|
|
|
|
// Extract suites from the existing sources file
|
|
suites, err := extractSuites(sourcesFilePath)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
log.Printf("Extracted suites: %v", suites)
|
|
|
|
// Create backup of the sources file
|
|
if err := createBackup(sourcesFilePath); err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
// Create sources.list.d directory if it doesn't exist
|
|
if err := createSourcesListD(); err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
// Fetch and find the fastest mirror
|
|
fastestMirrorURL, fastestTime, latencies, err := findFastestMirror(suites)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
log.Printf("Fastest mirror: %s", fastestMirrorURL)
|
|
|
|
// Display latency statistics
|
|
displayLatencyStatistics(latencies, fastestMirrorURL, fastestTime)
|
|
|
|
// Update sources file with the fastest mirror
|
|
if err := updateSourcesFile(sourcesFilePath, fastestMirrorURL, suites); err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
log.Println("Fastmirror CLI finished successfully")
|
|
}
|