From 757e35df1bc571cbe414b62cce1d6d3b0eca93b5 Mon Sep 17 00:00:00 2001 From: Andrew Cady Date: Mon, 12 Oct 2020 13:08:14 -0400 Subject: hacks and fixes, features and fixtures, axes and fackses --- fsmgr.hs | 17 +++++++++++------ selfstrap | 35 ++++++++++++++++++++++++++--------- 2 files changed, 37 insertions(+), 15 deletions(-) diff --git a/fsmgr.hs b/fsmgr.hs index bd4e303..dca488e 100644 --- a/fsmgr.hs +++ b/fsmgr.hs @@ -38,7 +38,7 @@ noParent (ParentImageConfigFile _) = False noParent (SeededImage _ _) = False dynamicNames :: FilePath -> FilePath -dynamicNames = replace "$(karch)" uname . replace "$(debarch)" debarch +dynamicNames = replace "$(kver)" (snd uname) . replace "$(karch)" (fst uname) . replace "$(debarch)" debarch chomp :: String -> String chomp = takeWhile (/= '\n') @@ -53,10 +53,10 @@ getDebianCodename = unsafePerformIO $ do (Stdout codename) <- cmd "sh -c" [". /etc/os-release && printf '%s' \"$VERSION_CODENAME\""] return codename -uname :: String +uname :: (String, String) uname = unsafePerformIO $ do Stdout out <- cmd "uname -r" - return $ last . wordsBy '-' . head . lines $ out + pure $ (reverse *** reverse . tail) . break (== '-') . reverse . head . lines $ out data AptListCfg = AptListCfg @@ -225,8 +225,13 @@ buildInitialImage :: DiskImageConfig -> FilePath -> FilePath -> Action () buildInitialImage DiskImageConfig{..} mountpoint out = do case initialImage of ParentImageConfigFile f -> do - let parent = "_build" f -<.> "btrfs" - need [parent] + let cwdParent = f -<.> "btrfs" + buildDirParent = "_build" cwdParent + parent <- liftIO (IO.doesFileExist cwdParent) >>= \case + True -> return cwdParent + False -> do + need [buildDirParent] + return buildDirParent cmd_ "cp --reflink" [parent, out] cmd_ "btrfstune -f -S0" [out] cmd_ "btrfstune -fu" [out] @@ -437,7 +442,7 @@ cgroupChroot groupName mnt args = do -- 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; hostname -F /etc/hostname; exec \"$@\""] + "sh -exc" ["mount -t proc proc /proc; mount -t devpts devpts /dev/pts; if [ -e /etc/hostname ]; then hostname -F /etc/hostname; fi; exec \"$@\""] "sh" args earlyFail :: IO () diff --git a/selfstrap b/selfstrap index 6766c0c..f5574f4 100755 --- a/selfstrap +++ b/selfstrap @@ -2,6 +2,7 @@ debian_mirror=http://httpredir.debian.org/debian debian_security_mirror=http://security.debian.org EXTRA_PACKAGES='apt debian-archive-keyring locales' +REAL_DPKG=y die() { printf 'Error: %s\n' "$*"; exit 1; } @@ -35,7 +36,8 @@ while [ $# -gt 0 ]; do EXTRA_PACKAGES="$EXTRA_PACKAGES $x" shift ;; --chroot) CHROOT_PROG=$2; shift ;; - --real-apt) REAL_APT_INSTALL=y ;; + --real-apt) REAL_APT_INSTALL=y + REAL_DPKG=y;; --) shift; break ;; *) usage 1 ;; esac @@ -195,12 +197,22 @@ populate_rootfs() write_sources_list() { local dest="$TARGET"/etc/apt/sources.list - [ -e "$dest" ] && return - printf '%s\n' \ - "deb ${debian_mirror} ${target_release} main contrib non-free" \ - "deb ${debian_mirror} ${target_release}-backports main contrib non-free" \ - "deb ${debian_security_mirror} ${target_release}/updates main contrib non-free" | - column -t > "$dest" + [ ! "$REWRITE_SOURCES_LIST" -a -e "$dest" ] && return + printf 'APT::Default-Release "%s";\n' "$target_release" > "$TARGET"/etc/apt/apt.conf.d/default-release + ( + printf '%s\n' \ + "deb ${debian_mirror} ${target_release} main contrib non-free" \ + "deb ${debian_mirror} ${target_release}-backports main contrib non-free" \ + "deb ${debian_security_mirror} ${target_release}/updates main contrib non-free" + if [ "$target_release" = stretch ] + then + printf '%s\n' \ + "deb ${debian_mirror} buster main contrib non-free" \ + "deb ${debian_mirror} buster-backports main contrib non-free" \ + "deb ${debian_security_mirror} buster/updates main contrib non-free" + + fi + ) | column -t > "$dest" } parse_apt_simul_line() @@ -337,6 +349,7 @@ apt_extract() dpkg_unpack_from_apt_actions() { + set -- while read line; do parse_apt_simul_line "$line" || die "parse_apt_simul_line: unexpected output from apt-get: $line" @@ -350,8 +363,8 @@ dpkg_unpack_from_apt_actions() case "$action" in Inst) printf 'Unpacking %s\n' "${deb##*/}" >&2 - if [ "$REAL_APT_INSTALL" ]; then - dpkg --extract "$deb" "$TARGET" || die 'dpkg' + if [ "$REAL_DPKG" ]; then + set -- "$@" "$deb" else is_multiarch_same "$package" && multiarch=":$arch" || multiarch= [ "$UNPACK_ONLY" ] && set_status=unpacked || set_status=installed @@ -363,6 +376,10 @@ dpkg_unpack_from_apt_actions() *) die "dpkg_unpack_from_apt_actions: unknown apt simul action: $action" ;; esac done + if [ $# -gt 0 ]; then + dpkg --no-triggers --unpack --force-unsafe-io --root="$TARGET" "$deb" || die 'dpkg' + # dpkg --configure --pending --root="$TARGET" + fi } install_etc_passwd() -- cgit v1.2.3