summaryrefslogtreecommitdiff
path: root/src/Propellor/Property/DebianMirror.hs
blob: cd98b6ffcbcb2d561848bb64761187112da2a2d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
module Propellor.Property.DebianMirror
	( DebianPriority(..)
	, showPriority
	, mirror
	, mirrorCdn
	) where

import Propellor
import qualified Propellor.Property.File as File
import qualified Propellor.Property.Apt as Apt
import qualified Propellor.Property.Cron as Cron
import qualified Propellor.Property.User as User

import Data.List


data DebianPriority = Essential | Required | Important | Standard | Optional | Extra
	deriving (Show, Eq)

showPriority :: DebianPriority -> String
showPriority Essential = "essential"
showPriority Required  = "required"
showPriority Important = "important"
showPriority Standard  = "standard"
showPriority Optional  = "optional"
showPriority Extra     = "extra"

mirror :: Apt.Url -> FilePath -> [DebianSuite] -> [Architecture] -> [Apt.Section] -> Bool -> [DebianPriority] -> Cron.Times -> Property NoInfo
mirror url dir suites archs sections source priorities crontimes = propertyList
	("Debian mirror " ++ dir)
	[ Apt.installed ["debmirror"]
	, User.accountFor (User "debmirror")
	, File.dirExists dir
	, File.ownerGroup dir (User "debmirror") (Group "debmirror")
	, check (not . and <$> mapM suitemirrored suites) $ cmdProperty "debmirror" args
		`describe` "debmirror setup"
	, Cron.niceJob ("debmirror_" ++ dir) crontimes (User "debmirror") "/" $
		unwords ("/usr/bin/debmirror" : args)
	]
  where
	suitemirrored suite = doesDirectoryExist $ dir </> "dists" </> Apt.showSuite suite
	architecturearg = intercalate ","
	suitearg = intercalate "," $ map Apt.showSuite suites
	priorityRegex pp = "(" ++ intercalate "|" (map showPriority pp) ++ ")"
	args =
		[ "--dist" , suitearg
		, "--arch", architecturearg archs
		, "--section", intercalate "," sections
		, "--limit-priority", "\"" ++ priorityRegex priorities ++ "\""
		]
		++
		(if source then [] else ["--nosource"])
		++
		[ "--host", url
		, "--method", "http"
		, "--keyring", "/usr/share/keyrings/debian-archive-keyring.gpg"
		, dir
		]

mirrorCdn :: FilePath -> [DebianSuite] -> [Architecture] -> [Apt.Section] -> Bool -> [DebianPriority] -> Cron.Times -> Property NoInfo
mirrorCdn = mirror "http://httpredir.debian.org/debian"