diff options
author | Andrew Cady <d@jerkface.net> | 2020-06-10 13:27:48 -0400 |
---|---|---|
committer | Andrew Cady <d@jerkface.net> | 2020-06-10 13:27:48 -0400 |
commit | 53ae74b98a12cb137c5299d1e3a9a715db09c9a0 (patch) | |
tree | 9e93e900ef932b1a1ceea8b3381a6fecabe49454 /fsmgr.hs | |
parent | ea6de9aeee6173363384b3b3a1dc4d37a900f961 (diff) |
avoid hard-coded codename
Diffstat (limited to 'fsmgr.hs')
-rw-r--r-- | fsmgr.hs | 30 |
1 files changed, 25 insertions, 5 deletions
@@ -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 | ||
51 | getDebianCodename :: String | ||
52 | getDebianCodename = unsafePerformIO $ do | ||
53 | (Stdout codename) <- cmd "sh -c" [". /etc/os-release && printf '%s' \"$VERSION_CODENAME\""] | ||
54 | return codename | ||
55 | |||
51 | uname :: String | 56 | uname :: String |
52 | uname = unsafePerformIO $ do | 57 | uname = 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 | ||
56 | aptListFiles :: String -> [FilePath] | 61 | data AptListCfg = |
57 | aptListFiles codename = ("/var/lib/apt/lists" </>) . (replace "stretch" codename) <$> observedCorrectListForStretch | 62 | AptListCfg |
63 | { releaseCodename :: String | ||
64 | , architecture :: String | ||
65 | , translationLang :: String | ||
66 | } | ||
67 | |||
68 | aptListCfg :: AptListCfg | ||
69 | aptListCfg = AptListCfg getDebianCodename debarch "en" | ||
70 | |||
71 | aptListFiles :: AptListCfg -> [FilePath] | ||
72 | aptListFiles 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"] | |||
366 | cgroupChroot groupName mnt args = do | 384 | cgroupChroot 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 | ||
374 | earlyFail :: IO () | 394 | earlyFail :: IO () |