From 655cb124a8db04361a60dee5e4e908f125c42e8b Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Sun, 12 Jun 2016 10:14:03 +0900 Subject: factor out some code I will use --- src/Propellor/Property/Reboot.hs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/Propellor/Property/Reboot.hs b/src/Propellor/Property/Reboot.hs index 78c253d2..343ee25b 100644 --- a/src/Propellor/Property/Reboot.hs +++ b/src/Propellor/Property/Reboot.hs @@ -9,7 +9,7 @@ import Propellor.Base import Data.List -data Version = String +type KernelVersion = String now :: Property Linux now = tightenTargets $ cmdProperty "reboot" [] @@ -59,19 +59,25 @@ toKernelNewerThan v = undefined runningInstalledKernel :: IO Bool runningInstalledKernel = do - kernelver <- takeWhile (/= '\n') <$> readProcess "uname" ["-r"] + kernelver <- runningKernelVersion when (null kernelver) $ error "failed to read uname -r" - kernelimages <- concat <$> mapM kernelsIn ["/", "/boot/"] + kernelimages <- installedKernelImages when (null kernelimages) $ error "failed to find any installed kernel images" findVersion kernelver <$> readProcess "file" ("-L" : kernelimages) +runningKernelVersion :: IO KernelVersion +runningKernelVersion = takeWhile (/= '\n') <$> readProcess "uname" ["-r"] + +installedKernelImages :: IO [String] +installedKernelImages = concat <$> mapM kernelsIn ["/", "/boot/"] + -- | File output looks something like this, we want to unambiguously -- match the running kernel version: -- Linux kernel x86 boot executable bzImage, version 3.16-3-amd64 (debian-kernel@lists.debian.org) #1 SMP Debian 3.1, RO-rootFS, swap_dev 0x2, Normal VGA -findVersion :: String -> String -> Bool +findVersion :: KernelVersion -> KernelVersion -> Bool findVersion ver s = (" version " ++ ver ++ " ") `isInfixOf` s kernelsIn :: FilePath -> IO [FilePath] -- cgit v1.2.3