diff options
| author | Sean Whitton <spwhitton@spwhitton.name> | 2016-06-12 10:14:03 +0900 |
|---|---|---|
| committer | Sean Whitton <spwhitton@spwhitton.name> | 2016-06-12 10:14:03 +0900 |
| commit | 655cb124a8db04361a60dee5e4e908f125c42e8b (patch) | |
| tree | 55c037af0bd86197c96d5a079702a9e633b68207 /src/Propellor/Property/Reboot.hs | |
| parent | ff1fc058c230ad0cf34d1faf3acfd5c64682e278 (diff) | |
factor out some code I will use
Diffstat (limited to 'src/Propellor/Property/Reboot.hs')
| -rw-r--r-- | src/Propellor/Property/Reboot.hs | 14 |
1 files 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] |
