summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2019-10-04 11:16:15 -0400
committerAndrew Cady <d@jerkface.net>2019-10-04 11:38:33 -0400
commita9aab3eddf957e1ac4ef29a1dc6374567827c343 (patch)
treef6c9fd1888649b373d5632041eea42e18311bd2f
parent5fe5fe7b394e119501e05c7e6ab18f4df02320b2 (diff)
enable $(karch) in package names
-rw-r--r--fsmgr.hs49
1 files changed, 47 insertions, 2 deletions
diff --git a/fsmgr.hs b/fsmgr.hs
index 884ca22..66bcaa8 100644
--- a/fsmgr.hs
+++ b/fsmgr.hs
@@ -10,7 +10,7 @@
10{-# LANGUAGE ScopedTypeVariables #-} 10{-# LANGUAGE ScopedTypeVariables #-}
11 11
12module Main where 12module Main where
13import Rebase.Prelude hiding (bool, hash, o, (<.>)) 13import Rebase.Prelude hiding (bool, hash, o, (<.>), join)
14 14
15import qualified Rebase.Data.Text as Text 15import qualified Rebase.Data.Text as Text
16 ;import Rebase.Data.Text (pack, unpack) 16 ;import Rebase.Data.Text (pack, unpack)
@@ -32,6 +32,51 @@ noParent :: BaseImageSpecification -> Bool
32noParent (EmptyImageOfBytes _) = True 32noParent (EmptyImageOfBytes _) = True
33noParent (ParentImageConfigFile _) = False 33noParent (ParentImageConfigFile _) = False
34 34
35split :: Eq a => [a] -> [a] -> [[a]]
36split _ [] = []
37split delim str =
38 let (firstline, remainder) = breakList (startswith delim) str
39 in
40 firstline : case remainder of
41 [] -> []
42 x -> if x == delim
43 then [] : []
44 else split delim
45 (drop (length delim) x)
46
47spanList :: ([a] -> Bool) -> [a] -> ([a], [a])
48spanList _ [] = ([],[])
49spanList func list@(x:xs) =
50 if func list
51 then (x:ys,zs)
52 else ([],list)
53 where (ys,zs) = spanList func xs
54
55breakList :: ([a] -> Bool) -> [a] -> ([a], [a])
56breakList func = spanList (not . func)
57
58startswith :: Eq a => [a] -> [a] -> Bool
59startswith = isPrefixOf
60
61join :: [a] -> [[a]] -> [a]
62join delim l = concat (intersperse delim l)
63
64replace :: Eq a => [a] -> [a] -> [a] -> [a]
65replace old new l = join new . split old $ l
66
67wordsBy c s = words (rep <$> s)
68 where
69 rep x | x == c = ' '
70 | otherwise = x
71
72uname :: String
73uname = unsafePerformIO $ do
74 Stdout out <- cmd "uname -r"
75 return $ last . wordsBy '-' . head . lines $ out
76
77dynamicNames :: FilePath -> FilePath
78dynamicNames = replace "$(karch)" uname
79
35buildRoot :: DiskImageConfig -> FilePath -> Action () 80buildRoot :: DiskImageConfig -> FilePath -> Action ()
36buildRoot config@DiskImageConfig{..} finalOut = do 81buildRoot config@DiskImageConfig{..} finalOut = do
37 let out = finalOut <.> "tmp" 82 let out = finalOut <.> "tmp"
@@ -55,7 +100,7 @@ buildRoot config@DiskImageConfig{..} finalOut = do
55 -- When there is no parent, selfstrap should install packages marked 100 -- When there is no parent, selfstrap should install packages marked
56 -- "Required" even if no packages are specified. When there is a parent, 101 -- "Required" even if no packages are specified. When there is a parent,
57 -- assume that this has already happened. 102 -- assume that this has already happened.
58 cmd_ "selfstrap" (("--unpack" `consWhen` unpackOnly) ["-t", mountpoint]) packageNames 103 cmd_ "selfstrap" (("--unpack" `consWhen` unpackOnly) ["-t", mountpoint]) (dynamicNames <$> packageNames)
59 when (not $ null debs) $ do 104 when (not $ null debs) $ do
60 cmd_ (AddEnv "DEBIAN_FRONTEND" "noninteractive") 105 cmd_ (AddEnv "DEBIAN_FRONTEND" "noninteractive")
61 ["dpkg"] [if unpackOnly then "--unpack" else "--install"] debs 106 ["dpkg"] [if unpackOnly then "--unpack" else "--install"] debs