diff --git a/HostProp.hs b/HostProp.hs index 2b393cd..25120e2 100644 --- a/HostProp.hs +++ b/HostProp.hs @@ -38,6 +38,9 @@ getProperties "clam.kitenet.net" = , GitHome.installedFor "joey" -- Clam is a tor bridge. , Tor.isBridge + -- This is not an important system so I don't want to need to + -- manually upgrade it. + , Apt.unattendedUpgrades True -- Should come last as it reboots. , Apt.installed ["systemd-sysv"] `onChange` Reboot.scheduled "+10" ] diff --git a/Property/Apt.hs b/Property/Apt.hs index c326170..9db8a6a 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]