From bb10fdfb30948fe096f746fa1b8c1020ab306fe9 Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Sat, 15 Jul 2017 08:12:42 -0700 Subject: add Apt.proxy, Apt.useLocalCacher --- src/Propellor/Property/Apt.hs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/Propellor/Property/Apt.hs') diff --git a/src/Propellor/Property/Apt.hs b/src/Propellor/Property/Apt.hs index 686ddb6c..07164df6 100644 --- a/src/Propellor/Property/Apt.hs +++ b/src/Propellor/Property/Apt.hs @@ -20,6 +20,9 @@ import Propellor.Types.Info data HostMirror = HostMirror Url deriving (Eq, Show, Typeable) +data HostAptProxy = HostAptProxy Url + deriving (Eq, Show, Typeable) + -- | Indicate host's preferred apt mirror (e.g. an apt cacher on the host's LAN) mirror :: Url -> Property (HasInfo + UnixLike) mirror u = pureInfoProperty (u ++ " apt mirror selected") @@ -493,3 +496,19 @@ suitePinBlock p suite pin = dpkgStatus :: FilePath dpkgStatus = "/var/lib/dpkg/status" + +-- | Set apt's proxy +proxy :: Url -> Property (HasInfo + DebianLike) +proxy u = tightenTargets $ + proxyInfo `before` proxyConfig `describe` desc + where + proxyInfo = pureInfoProperty desc (InfoVal (HostAptProxy u)) + proxyConfig = "/etc/apt/apt.conf.d/20proxy" `File.hasContent` + [ "Acquire::HTTP::Proxy \"" ++ u ++ "\";" ] + desc = (u ++ " apt proxy selected") + +-- | Cause apt to proxy downloads via an apt cacher on localhost +useLocalCacher :: Property (HasInfo + DebianLike) +useLocalCacher = proxy "http://localhost:3142" + `requires` serviceInstalledRunning "apt-cacher-ng" + -- cgit v1.2.3