From 1e045b67b9cb8bf60019f0c72279e2be438db72d Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 30 Mar 2014 01:44:36 -0400 Subject: unattended updates --- Property/Apt.hs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'Property') diff --git a/Property/Apt.hs b/Property/Apt.hs index c326170c..9db8a6a3 100644 --- a/Property/Apt.hs +++ b/Property/Apt.hs @@ -3,6 +3,8 @@ module Property.Apt where import Data.Maybe import Control.Applicative import Data.List +import System.IO +import Control.Monad import Property import Utility.SafeCommand @@ -93,3 +95,23 @@ isInstalled ps = catMaybes . map parse . lines autoRemove :: Property autoRemove = runApt [Param "-y", Param "autoremove"] + +unattendedUpgrades :: Bool -> Property +unattendedUpgrades enabled = installed ["unattended-upgrades"] + `onChange` reConfigure "unattended-upgrades" + [("unattended-upgrades/enable_auto_updates" + , "boolean" + , if enabled then "true" else "false")] + +{- Preseeds debconf values and reconfigures the package so it takes + - effect. -} +reConfigure :: Package -> [(String, String, String)] -> Property +reConfigure package vals = reconfigure `requires` setselections + where + setselections = IOProperty "preseed" $ makeChange $ + withHandle StdinHandle createProcessSuccess + (proc "debconf-set-selections" []) $ \h -> do + forM_ vals $ \(template, tmpltype, value) -> + hPutStrLn h $ unwords [package, template, tmpltype, value] + hClose h + reconfigure = cmdProperty "dpkg-reconfigure" [Param "-fnone", Param package] -- cgit v1.2.3