Sinisterly
[Haskell] mirrorank - script for Arch Linux - Printable Version

+- Sinisterly (https://sinister.li)
+-- Forum: Computers (https://sinister.li/Forum-Computers)
+--- Forum: Operating Systems (https://sinister.li/Forum-Operating-Systems)
+--- Thread: [Haskell] mirrorank - script for Arch Linux (/Thread-Haskell-mirrorank-script-for-Arch-Linux)



[Haskell] mirrorank - script for Arch Linux - Deque - 12-01-2012

I made a little script for Arch that takes a newly updated mirrorlist, removes all comments from the german servers and calls rankmirrors with this new list afterwards to sort the mirrors by speed. It just automates the process of doing this (under "Sorting mirrors").

I know that this is not much, but maybe it is helpful to some people here. Just exchange the word "German" to your desired language.

Code:
import Data.List import System.Cmd main = do x <- readFile "/etc/pacman.d/mirrorlist.pacnew" writeFile "/etc/pacman.d/mirrorlist.backup" $ unlines (prepareList (lines x)) system "rankmirrors -n 6 /etc/pacman.d/mirrorlist.backup > /etc/pacman.d/mirrorlist" prepareList :: [String] -> [String] prepareList xss = _prepareList xss "German" "#" "Server" _prepareList :: Eq a => [[a]] -> [a] -> [a] -> [a] -> [[a]] _prepareList xss start comment server = case xss of [] -> [] xs : xss' -> if contains xs start then [xs] ++ (removeComments xss' comment server) else [xs] ++ (_prepareList xss' start comment server) removeComments :: Eq a => [[a]] -> [a] -> [a] -> [[a]] removeComments xss comment server = case xss of [] -> [] xs : xss' -> if contains xs server then [drop 1 xs] ++ (removeComments xss' comment server) else xs : xss' contains :: Eq a => [a] -> [a] -> Bool contains xs [] = True contains xs (y : ys') = case xs of [] -> False x : xs' -> if x == y then contains xs' ys' else contains xs' (y : ys')