diff options
-rw-r--r-- | fsmgr.hs | 8 | ||||
-rwxr-xr-x | selfstrap | 40 |
2 files changed, 32 insertions, 16 deletions
@@ -141,10 +141,10 @@ buildRoot config@DiskImageConfig{..} finalOut = do | |||
141 | mountpoint = finalOut <.> "mnt" | 141 | mountpoint = finalOut <.> "mnt" |
142 | cmd_ "sh -c" ["if mountpoint -q \"$0\"; then umount \"$0\"; fi", mountpoint] | 142 | cmd_ "sh -c" ["if mountpoint -q \"$0\"; then umount \"$0\"; fi", mountpoint] |
143 | 143 | ||
144 | let (abortion :: IO ()) = ignoreErrors' $ do | 144 | let (abortion :: IO ()) = do |
145 | cmd_ "umount" [mountpoint] | 145 | ignoreErrors' $ cmd_ (EchoStderr False) "umount" [mountpoint] |
146 | cmd_ "rmdir" [mountpoint] | 146 | ignoreErrors' $ cmd_ (EchoStderr False) "rmdir" [mountpoint] |
147 | cmd_ "rm -f" [out] | 147 | ignoreErrors' $ cmd_ (EchoStderr False) "rm -f" [out] |
148 | 148 | ||
149 | handle' abortion $ buildInitialImage config mountpoint out | 149 | handle' abortion $ buildInitialImage config mountpoint out |
150 | 150 | ||
@@ -125,7 +125,21 @@ apt_() | |||
125 | # Avoid deleting lists on the calling system. | 125 | # Avoid deleting lists on the calling system. |
126 | set -- "$@" -o APT::Get::List-Cleanup=false | 126 | set -- "$@" -o APT::Get::List-Cleanup=false |
127 | 127 | ||
128 | eatmydata -- apt-"${apt_cmd}" "$@" | 128 | set -- apt-"${apt_cmd}" "$@" |
129 | if command -v eatmydata >/dev/null | ||
130 | then | ||
131 | set -- eatmydata -- "$@" | ||
132 | fi | ||
133 | ( | ||
134 | set -x | ||
135 | "$@" | ||
136 | ) | ||
137 | r=$? | ||
138 | if [ "$r" != 0 ] | ||
139 | then | ||
140 | echo "Error: apt-${apt_cmd} returned $r" >&2 | ||
141 | return $r | ||
142 | fi | ||
129 | } | 143 | } |
130 | apt_get() { apt_ get "$@"; } | 144 | apt_get() { apt_ get "$@"; } |
131 | apt_cache() { apt_ cache "$@"; } | 145 | apt_cache() { apt_ cache "$@"; } |
@@ -164,9 +178,9 @@ prepare_chroot() | |||
164 | [ "$TARGET" ] || die 'no $TARGET' | 178 | [ "$TARGET" ] || die 'no $TARGET' |
165 | [ -d "$TARGET"/proc ] || mkdir "$TARGET"/proc | 179 | [ -d "$TARGET"/proc ] || mkdir "$TARGET"/proc |
166 | [ -d "$TARGET"/sys ] || mkdir "$TARGET"/sys | 180 | [ -d "$TARGET"/sys ] || mkdir "$TARGET"/sys |
167 | mount -t proc proc "$TARGET"/proc | 181 | mountpoint -q "$TARGET"/proc || mount -t proc proc "$TARGET"/proc |
168 | mount -t sysfs sysfs "$TARGET"/sys | 182 | mountpoint -q "$TARGET"/sys || mount -t sysfs sysfs "$TARGET"/sys |
169 | mount --bind /dev "$TARGET"/dev | 183 | mountpoint -q "$TARGET"/dev || mount -t tmpfs tmpfs "$TARGET"/dev |
170 | } | 184 | } |
171 | 185 | ||
172 | cleanup_chroot() | 186 | cleanup_chroot() |
@@ -224,7 +238,7 @@ write_sources_list() | |||
224 | "deb ${debian_mirror} ${target_release}-backports main contrib non-free" \ | 238 | "deb ${debian_mirror} ${target_release}-backports main contrib non-free" \ |
225 | "deb ${debian_security_mirror} ${target_release}$_updates main contrib non-free" | 239 | "deb ${debian_security_mirror} ${target_release}$_updates main contrib non-free" |
226 | fi | 240 | fi |
227 | if apt policy | grep -q ' sid/' | 241 | if apt-cache policy 2>/dev/null | grep -q ' sid/' |
228 | then | 242 | then |
229 | printf '%s\n' \ | 243 | printf '%s\n' \ |
230 | "deb ${debian_mirror} sid main contrib non-free" | 244 | "deb ${debian_mirror} sid main contrib non-free" |
@@ -271,7 +285,7 @@ parse_apt_simul_line() | |||
271 | 285 | ||
272 | dpkg_unpack() | 286 | dpkg_unpack() |
273 | { | 287 | { |
274 | [ "$TARGET" -a -d "$TARGET" ] || die 'no $TARGET' | 288 | [ "$TARGET" -a "$TARGET" != '/' -a -d "$TARGET" ] || die 'no $TARGET' |
275 | local deb="$1" multiarch="$2" SET_STATUS="$3" command PKG | 289 | local deb="$1" multiarch="$2" SET_STATUS="$3" command PKG |
276 | PKG=${deb##*/} | 290 | PKG=${deb##*/} |
277 | PKG=${PKG%%_*} | 291 | PKG=${PKG%%_*} |
@@ -337,9 +351,9 @@ dpkg_configure_from_apt_actions() | |||
337 | preinst=/var/lib/dpkg/info/${package}${multiarch}.preinst | 351 | preinst=/var/lib/dpkg/info/${package}${multiarch}.preinst |
338 | if [ -x "$TARGET"/"$preinst" ]; then | 352 | if [ -x "$TARGET"/"$preinst" ]; then |
339 | extract_tmp_ci "$deb" | 353 | extract_tmp_ci "$deb" |
340 | prepare_chroot "$TARGET" | 354 | # prepare_chroot "$TARGET" |
341 | verbosely ${CHROOT_PROG:-chroot} "$TARGET" "$preinst" install | 355 | verbosely ${CHROOT_PROG:-chroot} "$TARGET" "$preinst" install |
342 | cleanup_chroot "$TARGET" | 356 | # cleanup_chroot "$TARGET" |
343 | remove_tmp_ci | 357 | remove_tmp_ci |
344 | fi | 358 | fi |
345 | ;; | 359 | ;; |
@@ -348,9 +362,9 @@ dpkg_configure_from_apt_actions() | |||
348 | postinst=/var/lib/dpkg/info/${package}${multiarch}.postinst | 362 | postinst=/var/lib/dpkg/info/${package}${multiarch}.postinst |
349 | if [ -x "$TARGET"/"$postinst" ]; then | 363 | if [ -x "$TARGET"/"$postinst" ]; then |
350 | extract_tmp_ci "$deb" | 364 | extract_tmp_ci "$deb" |
351 | prepare_chroot "$TARGET" | 365 | # prepare_chroot "$TARGET" |
352 | verbosely ${CHROOT_PROG:-chroot} "$TARGET" "$postinst" configure | 366 | verbosely ${CHROOT_PROG:-chroot} "$TARGET" "$postinst" configure |
353 | cleanup_chroot "$TARGET" | 367 | # cleanup_chroot "$TARGET" |
354 | remove_tmp_ci | 368 | remove_tmp_ci |
355 | fi | 369 | fi |
356 | ;; | 370 | ;; |
@@ -483,16 +497,18 @@ if [ "$REAL_APT_INSTALL" ]; then | |||
483 | # 1. binaries used by dpkg 'inst' scripts. | 497 | # 1. binaries used by dpkg 'inst' scripts. |
484 | # 2. /etc/passwd and /etc/group so that 'chown' works | 498 | # 2. /etc/passwd and /etc/group so that 'chown' works |
485 | 499 | ||
500 | prepare_chroot "$TARGET" | ||
501 | trap 'cleanup_chroot "$TARGET"' EXIT | ||
502 | |||
486 | # Unpack required packages. Handles (1) | 503 | # Unpack required packages. Handles (1) |
487 | # Note: populate_rootfs() already created a necessary symlink /usr/bin/awk -> /usr/bin/mawk | 504 | # Note: populate_rootfs() already created a necessary symlink /usr/bin/awk -> /usr/bin/mawk |
488 | apt_extract $required_packages eatmydata | 505 | apt_extract $required_packages eatmydata |
506 | # apt_get install -y $required_packages eatmydata | ||
489 | 507 | ||
490 | # This handles (2). | 508 | # This handles (2). |
491 | # An alternative (used by debootstrap) is to configure base-passwd | 509 | # An alternative (used by debootstrap) is to configure base-passwd |
492 | install_etc_passwd | 510 | install_etc_passwd |
493 | 511 | ||
494 | prepare_chroot "$TARGET" | ||
495 | trap 'cleanup_chroot "$TARGET"' EXIT | ||
496 | apt_get install -y $required_packages $EXTRA_PACKAGES | 512 | apt_get install -y $required_packages $EXTRA_PACKAGES |
497 | else | 513 | else |
498 | apt_extract $required_packages | 514 | apt_extract $required_packages |