From 0ab0216d0b400fae78a6a6916ef9f82ed31dc0fa Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sat, 29 Mar 2014 23:45:48 -0400 Subject: configure hostname etc --- Property/Hostname.hs | 15 +++++++++++++++ Property/Ssh.hs | 17 ++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 Property/Hostname.hs (limited to 'Property') diff --git a/Property/Hostname.hs b/Property/Hostname.hs new file mode 100644 index 00000000..b4c28a2b --- /dev/null +++ b/Property/Hostname.hs @@ -0,0 +1,15 @@ +module Property.Hostname where + +import Data.List +import System.Posix +import Control.Applicative +import Data.Maybe + +import Property +import Utility.SafeCommand +import Utility.Exception + +type HostName = String + +set :: HostName -> Property +set hostname = fileHasContent "/etc/hostname" [hostname] diff --git a/Property/Ssh.hs b/Property/Ssh.hs index cca021a4..ce9c171b 100644 --- a/Property/Ssh.hs +++ b/Property/Ssh.hs @@ -38,4 +38,19 @@ hasAuthorizedKeys = go <=< homedir (readFile $ home ".ssh" "authorized_keys") restartSshd :: Property -restartSshd = CmdProperty "ssh restart" "service" [Param "sshd", Param "restart"] +restartSshd = cmdProperty "service" [Param "sshd", Param "restart"] + +{- Blow away existing host keys and make new ones. Use a flag + - file to prevent doing this more than once. -} +uniqueHostKeys :: Property +uniqueHostKeys = flagFile prop "/etc/ssh/.unique_host_keys" + `onChange` restartSshd + where + prop = IOProperty "ssh unique host keys" $ do + void $ boolSystem "sh" + [ Param "-c" + , Param "rm -f /etc/ssh/ssh_host_*" + ] + ensureProperty $ + cmdProperty "/var/lib/dpkg/info/openssh-server.postinst" + [Param "configure"] -- cgit v1.2.3