summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoey Hess2014-03-30 01:44:36 -0400
committerJoey Hess2014-03-30 01:44:36 -0400
commit1e045b67b9cb8bf60019f0c72279e2be438db72d (patch)
tree2c44e6efdcef8ae5fe3181edf3ce63811ec51856
parent13431d874cbaa333150e3f3cbf14b4f72062d94a (diff)
unattended updates
-rw-r--r--HostProp.hs3
-rw-r--r--Property/Apt.hs22
2 files changed, 25 insertions, 0 deletions
diff --git a/HostProp.hs b/HostProp.hs
index 2b393cdd..25120e27 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 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]