diff options
author | Andrew Cady <d@jerkface.net> | 2019-10-04 11:16:15 -0400 |
---|---|---|
committer | Andrew Cady <d@jerkface.net> | 2019-10-04 11:38:33 -0400 |
commit | a9aab3eddf957e1ac4ef29a1dc6374567827c343 (patch) | |
tree | f6c9fd1888649b373d5632041eea42e18311bd2f | |
parent | 5fe5fe7b394e119501e05c7e6ab18f4df02320b2 (diff) |
enable $(karch) in package names
-rw-r--r-- | fsmgr.hs | 49 |
1 files changed, 47 insertions, 2 deletions
@@ -10,7 +10,7 @@ | |||
10 | {-# LANGUAGE ScopedTypeVariables #-} | 10 | {-# LANGUAGE ScopedTypeVariables #-} |
11 | 11 | ||
12 | module Main where | 12 | module Main where |
13 | import Rebase.Prelude hiding (bool, hash, o, (<.>)) | 13 | import Rebase.Prelude hiding (bool, hash, o, (<.>), join) |
14 | 14 | ||
15 | import qualified Rebase.Data.Text as Text | 15 | import 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 | |||
32 | noParent (EmptyImageOfBytes _) = True | 32 | noParent (EmptyImageOfBytes _) = True |
33 | noParent (ParentImageConfigFile _) = False | 33 | noParent (ParentImageConfigFile _) = False |
34 | 34 | ||
35 | split :: Eq a => [a] -> [a] -> [[a]] | ||
36 | split _ [] = [] | ||
37 | split 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 | |||
47 | spanList :: ([a] -> Bool) -> [a] -> ([a], [a]) | ||
48 | spanList _ [] = ([],[]) | ||
49 | spanList func list@(x:xs) = | ||
50 | if func list | ||
51 | then (x:ys,zs) | ||
52 | else ([],list) | ||
53 | where (ys,zs) = spanList func xs | ||
54 | |||
55 | breakList :: ([a] -> Bool) -> [a] -> ([a], [a]) | ||
56 | breakList func = spanList (not . func) | ||
57 | |||
58 | startswith :: Eq a => [a] -> [a] -> Bool | ||
59 | startswith = isPrefixOf | ||
60 | |||
61 | join :: [a] -> [[a]] -> [a] | ||
62 | join delim l = concat (intersperse delim l) | ||
63 | |||
64 | replace :: Eq a => [a] -> [a] -> [a] -> [a] | ||
65 | replace old new l = join new . split old $ l | ||
66 | |||
67 | wordsBy c s = words (rep <$> s) | ||
68 | where | ||
69 | rep x | x == c = ' ' | ||
70 | | otherwise = x | ||
71 | |||
72 | uname :: String | ||
73 | uname = unsafePerformIO $ do | ||
74 | Stdout out <- cmd "uname -r" | ||
75 | return $ last . wordsBy '-' . head . lines $ out | ||
76 | |||
77 | dynamicNames :: FilePath -> FilePath | ||
78 | dynamicNames = replace "$(karch)" uname | ||
79 | |||
35 | buildRoot :: DiskImageConfig -> FilePath -> Action () | 80 | buildRoot :: DiskImageConfig -> FilePath -> Action () |
36 | buildRoot config@DiskImageConfig{..} finalOut = do | 81 | buildRoot 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 |