summaryrefslogtreecommitdiff
path: root/fsmgr.hs
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2020-06-10 13:27:48 -0400
committerAndrew Cady <d@jerkface.net>2020-06-10 13:27:48 -0400
commit53ae74b98a12cb137c5299d1e3a9a715db09c9a0 (patch)
tree9e93e900ef932b1a1ceea8b3381a6fecabe49454 /fsmgr.hs
parentea6de9aeee6173363384b3b3a1dc4d37a900f961 (diff)
avoid hard-coded codename
Diffstat (limited to 'fsmgr.hs')
-rw-r--r--fsmgr.hs30
1 files changed, 25 insertions, 5 deletions
diff --git a/fsmgr.hs b/fsmgr.hs
index 2a2309e..2ea67d3 100644
--- a/fsmgr.hs
+++ b/fsmgr.hs
@@ -48,13 +48,32 @@ debarch = unsafePerformIO $ do
48 Stdout out <- cmd "dpkg-architecture -q DEB_BUILD_ARCH" 48 Stdout out <- cmd "dpkg-architecture -q DEB_BUILD_ARCH"
49 return $ chomp out 49 return $ chomp out
50 50
51getDebianCodename :: String
52getDebianCodename = unsafePerformIO $ do
53 (Stdout codename) <- cmd "sh -c" [". /etc/os-release && printf '%s' \"$VERSION_CODENAME\""]
54 return codename
55
51uname :: String 56uname :: String
52uname = unsafePerformIO $ do 57uname = unsafePerformIO $ do
53 Stdout out <- cmd "uname -r" 58 Stdout out <- cmd "uname -r"
54 return $ last . wordsBy '-' . head . lines $ out 59 return $ last . wordsBy '-' . head . lines $ out
55 60
56aptListFiles :: String -> [FilePath] 61data AptListCfg =
57aptListFiles codename = ("/var/lib/apt/lists" </>) . (replace "stretch" codename) <$> observedCorrectListForStretch 62 AptListCfg
63 { releaseCodename :: String
64 , architecture :: String
65 , translationLang :: String
66 }
67
68aptListCfg :: AptListCfg
69aptListCfg = AptListCfg getDebianCodename debarch "en"
70
71aptListFiles :: AptListCfg -> [FilePath]
72aptListFiles AptListCfg{..} =
73 ("/var/lib/apt/lists" </>) .
74 (replace "Translation-en" $ "Translation-" ++ translationLang) .
75 (replace "amd64" architecture) .
76 (replace "stretch" releaseCodename) <$> observedCorrectListForStretch
58 where 77 where
59 observedCorrectListForStretch = 78 observedCorrectListForStretch =
60 [ "httpredir.debian.org_debian_dists_stretch_main_binary-amd64_Packages" 79 [ "httpredir.debian.org_debian_dists_stretch_main_binary-amd64_Packages"
@@ -95,8 +114,7 @@ buildRoot config@DiskImageConfig{..} finalOut = do
95 ["dpkg"] [if unpackOnly then "--unpack" else "--install"] (dynamicNames <$> debs) 114 ["dpkg"] [if unpackOnly then "--unpack" else "--install"] (dynamicNames <$> debs)
96 {- 2.5. install apt package cache -} 115 {- 2.5. install apt package cache -}
97 when installAptLists $ do 116 when installAptLists $ do
98 (Stdout codename) <- cmd "sh -c" [". /etc/os-release && [ \"$VERSION_CODENAME\" ] && echo -n $VERSION_CODENAME"] 117 cmd_ "rsync -Ra" (("/./" ++) <$> aptListFiles aptListCfg) (mountpoint ++ "/")
99 cmd_ "rsync -Ra" (("/./" ++) <$> aptListFiles codename) (mountpoint ++ "/")
100 {- 3. binaries -} 118 {- 3. binaries -}
101 let go b = do 119 let go b = do
102 p <- fromMaybe (fail $ "not found in ${PATH}: " ++ b) <$> liftIO (pathLocate b) 120 p <- fromMaybe (fail $ "not found in ${PATH}: " ++ b) <$> liftIO (pathLocate b)
@@ -366,9 +384,11 @@ cgroupChroot groupName mnt [] = cgroupChroot groupName mnt ["/bin/bash"]
366cgroupChroot groupName mnt args = do 384cgroupChroot groupName mnt args = do
367 let cgdir = "/sys/fs/cgroup/pids" </> groupName 385 let cgdir = "/sys/fs/cgroup/pids" </> groupName
368 createDirectoryIfMissing False cgdir 386 createDirectoryIfMissing False cgdir
387
388 -- TODO: unshare hostname & set from /etc/hostname inside root
369 cmd_ (Cwd mnt) (WithStderr False) 389 cmd_ (Cwd mnt) (WithStderr False)
370 "unshare --ipc --uts --cgroup --mount --pid --fork chroot ." 390 "unshare --ipc --uts --cgroup --mount --pid --fork chroot ."
371 "sh -exc" ["mount -t proc proc /proc; mount -t devpts devpts /dev/pts; exec \"$@\""] 391 "sh -exc" ["mount -t proc proc /proc; mount -t devpts devpts /dev/pts; hostname -F /etc/hostname; exec \"$@\""]
372 "sh" args 392 "sh" args
373 393
374earlyFail :: IO () 394earlyFail :: IO ()