From 53ae74b98a12cb137c5299d1e3a9a715db09c9a0 Mon Sep 17 00:00:00 2001 From: Andrew Cady Date: Wed, 10 Jun 2020 13:27:48 -0400 Subject: avoid hard-coded codename --- fsmgr.hs | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) (limited to 'fsmgr.hs') 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 Stdout out <- cmd "dpkg-architecture -q DEB_BUILD_ARCH" return $ chomp out +getDebianCodename :: String +getDebianCodename = unsafePerformIO $ do + (Stdout codename) <- cmd "sh -c" [". /etc/os-release && printf '%s' \"$VERSION_CODENAME\""] + return codename + uname :: String uname = unsafePerformIO $ do Stdout out <- cmd "uname -r" return $ last . wordsBy '-' . head . lines $ out -aptListFiles :: String -> [FilePath] -aptListFiles codename = ("/var/lib/apt/lists" ) . (replace "stretch" codename) <$> observedCorrectListForStretch +data AptListCfg = + AptListCfg + { releaseCodename :: String + , architecture :: String + , translationLang :: String + } + +aptListCfg :: AptListCfg +aptListCfg = AptListCfg getDebianCodename debarch "en" + +aptListFiles :: AptListCfg -> [FilePath] +aptListFiles AptListCfg{..} = + ("/var/lib/apt/lists" ) . + (replace "Translation-en" $ "Translation-" ++ translationLang) . + (replace "amd64" architecture) . + (replace "stretch" releaseCodename) <$> observedCorrectListForStretch where observedCorrectListForStretch = [ "httpredir.debian.org_debian_dists_stretch_main_binary-amd64_Packages" @@ -95,8 +114,7 @@ buildRoot config@DiskImageConfig{..} finalOut = do ["dpkg"] [if unpackOnly then "--unpack" else "--install"] (dynamicNames <$> debs) {- 2.5. install apt package cache -} when installAptLists $ do - (Stdout codename) <- cmd "sh -c" [". /etc/os-release && [ \"$VERSION_CODENAME\" ] && echo -n $VERSION_CODENAME"] - cmd_ "rsync -Ra" (("/./" ++) <$> aptListFiles codename) (mountpoint ++ "/") + cmd_ "rsync -Ra" (("/./" ++) <$> aptListFiles aptListCfg) (mountpoint ++ "/") {- 3. binaries -} let go b = do p <- fromMaybe (fail $ "not found in ${PATH}: " ++ b) <$> liftIO (pathLocate b) @@ -366,9 +384,11 @@ cgroupChroot groupName mnt [] = cgroupChroot groupName mnt ["/bin/bash"] cgroupChroot groupName mnt args = do let cgdir = "/sys/fs/cgroup/pids" groupName createDirectoryIfMissing False cgdir + + -- TODO: unshare hostname & set from /etc/hostname inside root cmd_ (Cwd mnt) (WithStderr False) "unshare --ipc --uts --cgroup --mount --pid --fork chroot ." - "sh -exc" ["mount -t proc proc /proc; mount -t devpts devpts /dev/pts; exec \"$@\""] + "sh -exc" ["mount -t proc proc /proc; mount -t devpts devpts /dev/pts; hostname -F /etc/hostname; exec \"$@\""] "sh" args earlyFail :: IO () -- cgit v1.2.3