You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

849 lines
24 KiB

  1. #!/bin/sh
  2. set -e
  3. VERSION='@VERSION@'
  4. unset TMP TEMP TMPDIR || true
  5. # might not be exported if we're running from init=/bin/sh or similar
  6. export PATH
  7. ###########################################################################
  8. if [ -z "$DEBOOTSTRAP_DIR" ]; then
  9. if [ -x /debootstrap/debootstrap ]; then
  10. DEBOOTSTRAP_DIR=/debootstrap
  11. else
  12. DEBOOTSTRAP_DIR=/usr/share/debootstrap
  13. fi
  14. fi
  15. . "$DEBOOTSTRAP_DIR/functions"
  16. exec 4>&1
  17. LANG=C
  18. EXTRA_SUITES=""
  19. USE_COMPONENTS=main
  20. KEYRING=""
  21. DISABLE_KEYRING=""
  22. FORCE_KEYRING=""
  23. VARIANT=""
  24. MERGED_USR="no"
  25. ARCH=""
  26. HOST_ARCH=""
  27. HOST_OS=""
  28. KEEP_DEBOOTSTRAP_DIR=""
  29. USE_DEBIANINSTALLER_INTERACTION=""
  30. SECOND_STAGE_ONLY=""
  31. CHROOTDIR=""
  32. MAKE_TARBALL=""
  33. EXTRACTOR_OVERRIDE=""
  34. UNPACK_TARBALL=""
  35. ADDITIONAL=""
  36. EXCLUDE=""
  37. VERBOSE=""
  38. CERTIFICATE=""
  39. CHECKCERTIF=""
  40. PRIVATEKEY=""
  41. CACHE_DIR=""
  42. DEF_MIRROR="http://pkgmaster.devuan.org/merged"
  43. DEF_HTTPS_MIRROR="https://pkgmaster.devuan.org/merged"
  44. # set $CONTAINER
  45. detect_container
  46. export LANG USE_COMPONENTS
  47. umask 022
  48. ###########################################################################
  49. ## phases:
  50. ## finddebs dldebs printdebs save_variables first_stage second_stage
  51. RESOLVE_DEPS=true
  52. WHAT_TO_DO="finddebs dldebs save_variables first_stage second_stage"
  53. am_doing_phase () {
  54. # usage: if am_doing_phase finddebs; then ...; fi
  55. local x;
  56. for x in "$@"; do
  57. if echo " $WHAT_TO_DO " | grep -q " $x "; then return 0; fi
  58. done
  59. return 1
  60. }
  61. ###########################################################################
  62. usage_err()
  63. {
  64. info USAGE1 "usage: [OPTION]... <suite> <target> [<mirror> [<script>]]"
  65. info USAGE2 "Try \`${0##*/} --help' for more information."
  66. error "$@"
  67. }
  68. usage()
  69. {
  70. echo "Usage: ${0##*/} [OPTION]... <suite> <target> [<mirror> [<script>]]"
  71. echo "Bootstrap a Debian base system into a target directory."
  72. echo
  73. cat <<EOF
  74. --help display this help and exit
  75. --version display version information and exit
  76. --verbose don't turn off the output of wget
  77. --download-only download packages, but don't perform installation
  78. --print-debs print the packages to be installed, and exit
  79. --arch=A set the architecture to install (use if no dpkg)
  80. [ --arch=powerpc ]
  81. --include=A,B,C adds specified names to the list of base packages
  82. --exclude=A,B,C removes specified packages from the list
  83. --extra-suites=A,B,C also use packages from the listed suites of the
  84. archive
  85. --components=A,B,C use packages from the listed components of the
  86. archive
  87. --variant=X use variant X of the bootstrap scripts
  88. (currently supported variants: buildd, fakechroot,
  89. minbase)
  90. --no-merged-usr do not make /{bin,sbin,lib}/ symlinks to /usr/
  91. --keyring=K check Release files against keyring K
  92. --no-check-gpg avoid checking Release file signatures
  93. --force-check-gpg force checking Release file signatures
  94. (also disables automatic fallback to HTTPS in case
  95. of a missing keyring), aborting otherwise
  96. --no-resolve-deps don't try to resolve dependencies automatically
  97. --log-extra-deps record extra dependency info in debootstrap.log
  98. --cache-dir=DIR Use specified directory as package cache directory
  99. --unpack-tarball=T acquire .debs from a tarball instead of http
  100. --make-tarball=T download .debs and create a gzipped tarball
  101. --second-stage-target=DIR
  102. Run second stage in a subdirectory instead of root
  103. (can be used to create a foreign chroot)
  104. (requires --second-stage)
  105. --extractor=TYPE override automatic .deb extractor selection
  106. (supported: $EXTRACTORS_SUPPORTED)
  107. --debian-installer used for internal purposes by debian-installer
  108. --private-key=file read the private key from file
  109. --certificate=file use the client certificate stored in file (PEM)
  110. --no-check-certificate do not check certificate against certificate authorities
  111. EOF
  112. }
  113. ###########################################################################
  114. if [ -z "$PKGDETAILS" ]; then
  115. error 1 NO_PKGDETAILS "No pkgdetails available; either install perl, or build pkgdetails.c from the base-installer source package"
  116. fi
  117. ###########################################################################
  118. if [ $# != 0 ] ; then
  119. while true ; do
  120. case "$1" in
  121. --help)
  122. usage
  123. exit 0
  124. ;;
  125. --version)
  126. echo "debootstrap $VERSION"
  127. exit 0
  128. ;;
  129. --debian-installer)
  130. if ! (echo -n "" >&3) 2>/dev/null; then
  131. error 1 ARG_DIBYHAND "If running debootstrap by hand, don't use --debian-installer"
  132. fi
  133. USE_DEBIANINSTALLER_INTERACTION=yes
  134. shift
  135. ;;
  136. --foreign)
  137. check_conflicting_option "$1"
  138. if [ -n "$LOOSEN_CONFLICTING_RESTRICTION" ]; then
  139. WHAT_TO_DO="first_stage"
  140. else
  141. WHAT_TO_DO="finddebs dldebs save_variables first_stage"
  142. fi
  143. shift
  144. ;;
  145. --second-stage)
  146. check_conflicting_option "$1"
  147. WHAT_TO_DO="second_stage"
  148. SECOND_STAGE_ONLY=true
  149. shift
  150. ;;
  151. --second-stage-target|--second-stage-target=?*)
  152. if [ "$SECOND_STAGE_ONLY" != "true" ] ; then
  153. error 1 STAGE2ONLY "option %s only applies in the second stage" "$1"
  154. fi
  155. if [ "$1" = "--second-stage-target" ] && [ -n "$2" ] ; then
  156. CHROOTDIR="$2"
  157. shift 2
  158. elif [ "$1" != "${1#--second-stage-target=}" ]; then
  159. CHROOTDIR="${1#--second-stage-target=}"
  160. shift
  161. else
  162. error 1 NEEDARG "option requires an argument: %s" "$1"
  163. fi
  164. ;;
  165. --print-debs)
  166. check_conflicting_option "$1"
  167. WHAT_TO_DO="finddebs printdebs kill_target"
  168. shift
  169. ;;
  170. --download-only)
  171. check_conflicting_option "$1"
  172. WHAT_TO_DO="finddebs dldebs"
  173. shift
  174. ;;
  175. --make-tarball|--make-tarball=?*)
  176. check_conflicting_option "$1"
  177. WHAT_TO_DO="finddebs dldebs save_variables maketarball kill_target"
  178. if [ "$1" = "--make-tarball" ] && [ -n "$2" ] ; then
  179. MAKE_TARBALL="$2"
  180. shift 2
  181. elif [ "$1" != "${1#--make-tarball=}" ]; then
  182. MAKE_TARBALL="${1#--make-tarball=}"
  183. shift
  184. else
  185. error 1 NEEDARG "option requires an argument %s" "$1"
  186. fi
  187. ;;
  188. --resolve-deps)
  189. # redundant, but avoids breaking compatibility
  190. RESOLVE_DEPS=true
  191. shift
  192. ;;
  193. --no-resolve-deps)
  194. RESOLVE_DEPS=false
  195. shift
  196. ;;
  197. --log-extra-deps)
  198. LOG_EXTRA_DEPS=true
  199. shift
  200. ;;
  201. --keep-debootstrap-dir)
  202. KEEP_DEBOOTSTRAP_DIR=true
  203. shift
  204. ;;
  205. --arch|--arch=?*)
  206. if [ "$1" = "--arch" ] && [ -n "$2" ] ; then
  207. ARCH="$2"
  208. shift 2
  209. elif [ "$1" != "${1#--arch=}" ]; then
  210. ARCH="${1#--arch=}"
  211. shift
  212. else
  213. error 1 NEEDARG "option requires an argument %s" "$1"
  214. fi
  215. ;;
  216. --extractor|--extractor=?*)
  217. if [ "$1" = "--extractor" ] && [ -n "$2" ] ; then
  218. EXTRACTOR_OVERRIDE="$2"
  219. shift 2
  220. elif [ "$1" != "${1#--extractor=}" ]; then
  221. EXTRACTOR_OVERRIDE="${1#--extractor=}"
  222. shift
  223. else
  224. error 1 NEEDARG "option requires an argument %s" "$1"
  225. fi
  226. if valid_extractor "$EXTRACTOR_OVERRIDE"; then
  227. if ! in_path "$EXTRACTOR_OVERRIDE"; then
  228. error 1 MISSINGEXTRACTOR "The selected extractor cannot be found: %s" "$EXTRACTOR_OVERRIDE"
  229. fi
  230. else
  231. error 1 BADEXTRACTOR "%s: unknown extractor" "$EXTRACTOR_OVERRIDE"
  232. fi
  233. ;;
  234. --unpack-tarball|--unpack-tarball=?*)
  235. if [ "$1" = "--unpack-tarball" ] && [ -n "$2" ] ; then
  236. check_conflicting_option "$1"
  237. if [ -n "$LOOSEN_CONFLICTING_RESTRICTION" ]; then
  238. WHAT_TO_DO="first_stage"
  239. else
  240. WHAT_TO_DO="first_stage second_stage"
  241. fi
  242. UNPACK_TARBALL="$2"
  243. shift 2
  244. elif [ "$1" != "${1#--unpack-tarball=}" ]; then
  245. check_conflicting_option "$1"
  246. if [ -n "$LOOSEN_CONFLICTING_RESTRICTION" ]; then
  247. WHAT_TO_DO="first_stage"
  248. else
  249. WHAT_TO_DO="first_stage second_stage"
  250. fi
  251. UNPACK_TARBALL="${1#--unpack-tarball=}"
  252. shift
  253. else
  254. error 1 NEEDARG "option requires an argument %s" "$1"
  255. fi
  256. if [ ! -f "$UNPACK_TARBALL" ] ; then
  257. error 1 NOTARBALL "%s: No such file or directory" "$UNPACK_TARBALL"
  258. fi
  259. ;;
  260. --include|--include=?*)
  261. if [ "$1" = "--include" ] && [ -n "$2" ]; then
  262. ADDITIONAL="$2"
  263. shift 2
  264. elif [ "$1" != "${1#--include=}" ]; then
  265. ADDITIONAL="${1#--include=}"
  266. shift 1
  267. else
  268. error 1 NEEDARG "option requires an argument %s" "$1"
  269. fi
  270. ADDITIONAL="$(echo "$ADDITIONAL" | tr , " ")"
  271. ;;
  272. --exclude|--exclude=?*)
  273. if [ "$1" = "--exclude" ] && [ -n "$2" ]; then
  274. EXCLUDE="$2"
  275. shift 2
  276. elif [ "$1" != "${1#--exclude=}" ]; then
  277. EXCLUDE="${1#--exclude=}"
  278. shift 1
  279. else
  280. error 1 NEEDARG "option requires an argument %s" "$1"
  281. fi
  282. EXCLUDE="$(echo "$EXCLUDE" | tr , " ")"
  283. ;;
  284. --verbose)
  285. VERBOSE=true
  286. export VERBOSE
  287. shift 1
  288. ;;
  289. --extra-suites|--extra-suites=?*)
  290. if [ "$1" = "--extra-suites" ] && [ -n "$2" ]; then
  291. EXTRA_SUITES="$2"
  292. shift 2
  293. elif [ "$1" != "${1#--extra-suites=}" ]; then
  294. EXTRA_SUITES="${1#--extra-suites=}"
  295. shift 1
  296. else
  297. error 1 NEEDARG "option requires an argument %s" "$1"
  298. fi
  299. EXTRA_SUITES="$(echo "$EXTRA_SUITES" | tr , " ")"
  300. ;;
  301. --components|--components=?*)
  302. if [ "$1" = "--components" ] && [ -n "$2" ]; then
  303. USE_COMPONENTS="$2"
  304. shift 2
  305. elif [ "$1" != "${1#--components=}" ]; then
  306. USE_COMPONENTS="${1#--components=}"
  307. shift 1
  308. else
  309. error 1 NEEDARG "option requires an argument %s" "$1"
  310. fi
  311. USE_COMPONENTS="$(echo "$USE_COMPONENTS" | tr , "|")"
  312. ;;
  313. --variant|--variant=?*)
  314. if [ "$1" = "--variant" ] && [ -n "$2" ]; then
  315. VARIANT="$2"
  316. shift 2
  317. elif [ "$1" != "${1#--variant=}" ]; then
  318. VARIANT="${1#--variant=}"
  319. shift 1
  320. else
  321. error 1 NEEDARG "option requires an argument %s" "$1"
  322. fi
  323. ;;
  324. --cache-dir|--cache-dir=?*)
  325. # Okay, let's check user's option
  326. if [ "$1" = "--cache-dir" ] && [ -n "$2" ] ; then
  327. CACHE_DIR="$2"
  328. shift 2
  329. elif [ "$1" != "${1#--cache-dir=}" ]; then
  330. CACHE_DIR="${1#--cache-dir=}"
  331. shift
  332. else
  333. error 1 NEEDARG "option requires an argument %s" "$1"
  334. fi
  335. if [ ! -z "${CACHE_DIR##/*}" ]; then
  336. error 1 NOTABSOLUTEPATH "cache directory should be specified with an absolute path"
  337. fi
  338. if [ ! -d "$CACHE_DIR" ] ; then
  339. error 1 NOCACHEDIR "%s: No such directory" "$CACHE_DIR"
  340. fi
  341. ;;
  342. --merged-usr)
  343. MERGED_USR=yes
  344. shift
  345. ;;
  346. --no-merged-usr)
  347. MERGED_USR=no
  348. shift
  349. ;;
  350. --keyring|--keyring=?*)
  351. if ! gpgv --version >/dev/null 2>&1; then
  352. error 1 NEEDGPGV "gpgv not installed, but required for Release verification"
  353. fi
  354. if [ "$1" = "--keyring" ] && [ -n "$2" ]; then
  355. KEYRING="$2"
  356. shift 2
  357. elif [ "$1" != "${1#--keyring=}" ]; then
  358. KEYRING="${1#--keyring=}"
  359. shift 1
  360. else
  361. error 1 NEEDARG "option requires an argument %s" "$1"
  362. fi
  363. if [ ! -e "$KEYRING" ]; then
  364. error 1 KEYRING "specified keyring file ($KEYRING) not found"
  365. fi
  366. ;;
  367. --no-check-gpg)
  368. shift 1
  369. DISABLE_KEYRING=1
  370. ;;
  371. --force-check-gpg)
  372. shift 1
  373. FORCE_KEYRING=1
  374. ;;
  375. --certificate|--certificate=?*)
  376. if [ "$1" = "--certificate" ] && [ -n "$2" ]; then
  377. CERTIFICATE="--certificate=$2"
  378. shift 2
  379. elif [ "$1" != "${1#--certificate=}" ]; then
  380. CERTIFICATE="--certificate=${1#--certificate=}"
  381. shift 1
  382. else
  383. error 1 NEEDARG "option requires an argument %s" "$1"
  384. fi
  385. ;;
  386. --private-key|--private-key=?*)
  387. if [ "$1" = "--private-key" ] && [ -n "$2" ]; then
  388. PRIVATEKEY="--private-key=$2"
  389. shift 2
  390. elif [ "$1" != "${1#--private-key=}" ]; then
  391. PRIVATEKEY="--private-key=${1#--private-key=}"
  392. shift 1
  393. else
  394. error 1 NEEDARG "option requires an argument %s" "$1"
  395. fi
  396. ;;
  397. --no-check-certificate)
  398. CHECKCERTIF="--no-check-certificate"
  399. shift
  400. ;;
  401. -*)
  402. error 1 BADARG "unrecognized or invalid option %s" "$1"
  403. ;;
  404. *)
  405. break
  406. ;;
  407. esac
  408. done
  409. fi
  410. ###########################################################################
  411. # do auto proxy discovery
  412. AUTOPROXY=""
  413. if ! doing_variant fakechroot && command -v apt-config >/dev/null; then
  414. eval "$(apt-config shell AUTOPROXY Acquire::http::ProxyAutoDetect)"
  415. if [ -z "$http_proxy" ] && [ -x "$AUTOPROXY" ]; then
  416. http_proxy="$($AUTOPROXY)"
  417. if [ -n "$http_proxy" ]; then
  418. info AUTOPROXY "Using auto-detected proxy: $http_proxy"
  419. export http_proxy
  420. fi
  421. fi
  422. fi
  423. ###########################################################################
  424. if [ -n "$DISABLE_KEYRING" ] && [ -n "$FORCE_KEYRING" ]; then
  425. error 1 BADARG "Both --no-check-gpg and --force-check-gpg specified, please pick one (at most)"
  426. fi
  427. ###########################################################################
  428. if [ "$SECOND_STAGE_ONLY" = "true" ]; then
  429. SUITE=$(cat "$DEBOOTSTRAP_DIR/suite")
  430. if [ -e "$DEBOOTSTRAP_DIR/extra-suites" ]; then
  431. EXTRA_SUITES=$(cat "$DEBOOTSTRAP_DIR/extra-suites")
  432. fi
  433. ARCH=$(cat "$DEBOOTSTRAP_DIR/arch")
  434. USER_MIRROR=$(cat "$DEBOOTSTRAP_DIR/mirror")
  435. if [ -e "$DEBOOTSTRAP_DIR/variant" ]; then
  436. VARIANT=$(cat "$DEBOOTSTRAP_DIR/variant")
  437. SUPPORTED_VARIANTS="$VARIANT"
  438. fi
  439. if [ -z "$CHROOTDIR" ]; then
  440. TARGET=/
  441. else
  442. TARGET=$CHROOTDIR
  443. fi
  444. SCRIPT="$DEBOOTSTRAP_DIR/suite-script"
  445. else
  446. if ! in_path wget; then
  447. error 1 NEEDWGET "You must install wget to download packages."
  448. fi
  449. if [ -z "$1" ] || [ -z "$2" ]; then
  450. usage_err 1 NEEDSUITETARGET "You must specify a suite and a target."
  451. fi
  452. SUITE="$1"
  453. TARGET="$2"
  454. USER_MIRROR="$3"
  455. TARGET="${TARGET%/}"
  456. if [ "${TARGET#/}" = "${TARGET}" ]; then
  457. if [ "${TARGET%/*}" = "$TARGET" ] ; then
  458. TARGET="$(pwd)/$TARGET"
  459. else
  460. TARGET="$(cd "${TARGET%/*}"; echo "$(pwd)/${TARGET##*/}")"
  461. fi
  462. fi
  463. SCRIPT="$DEBOOTSTRAP_DIR/scripts/$1"
  464. if [ -n "$VARIANT" ] && [ -e "${SCRIPT}.${VARIANT}" ]; then
  465. SCRIPT="${SCRIPT}.${VARIANT}"
  466. SUPPORTED_VARIANTS="$VARIANT"
  467. fi
  468. if [ "$4" != "" ]; then
  469. if [ -e "$DEBOOTSTRAP_DIR/scripts/$4" ]; then
  470. SCRIPT="$DEBOOTSTRAP_DIR/scripts/$4"
  471. else
  472. SCRIPT="$4"
  473. fi
  474. fi
  475. fi
  476. ###########################################################################
  477. if am_doing_phase kill_target; then
  478. # Require empty target when we are going to remove it afterwards
  479. if [ -d "$TARGET" ] && [ -n "$(ls -A "$TARGET")" ] && \
  480. [ "$KEEP_DEBOOTSTRAP_DIR" != "true" ]; then
  481. error 1 BADTARGET "Target directory '$TARGET' is not empty and it would be wiped"
  482. fi
  483. fi
  484. ###########################################################################
  485. if in_path dpkg && \
  486. dpkg --print-architecture >/dev/null 2>&1; then
  487. HOST_ARCH=$(/usr/bin/dpkg --print-architecture)
  488. elif in_path udpkg && \
  489. udpkg --print-architecture >/dev/null 2>&1; then
  490. HOST_ARCH=$(/usr/bin/udpkg --print-architecture)
  491. elif [ -e "$DEBOOTSTRAP_DIR/arch" ]; then
  492. HOST_ARCH=$(cat "$DEBOOTSTRAP_DIR/arch")
  493. fi
  494. HOST_OS="$HOST_ARCH"
  495. # basic host OS guessing for non-Debian systems
  496. if [ -z "$HOST_OS" ]; then
  497. case $(uname) in
  498. Linux)
  499. HOST_OS=linux
  500. ;;
  501. GNU/kFreeBSD)
  502. HOST_OS=kfreebsd
  503. ;;
  504. GNU)
  505. HOST_OS=hurd
  506. ;;
  507. FreeBSD*)
  508. HOST_OS=freebsd
  509. ;;
  510. esac
  511. fi
  512. if [ -z "$ARCH" ]; then
  513. ARCH="$HOST_ARCH"
  514. fi
  515. if [ -z "$ARCH" ] || [ -z "$HOST_OS" ]; then
  516. error 1 WHATARCH "Couldn't work out current architecture"
  517. fi
  518. if [ "$HOST_OS" = "kfreebsd" ] || [ "$HOST_OS" = "freebsd" ]; then
  519. for module in linprocfs fdescfs tmpfs linsysfs; do
  520. kldstat -m "$module" > /dev/null 2>&1 || warning SANITYCHECK "Probably required module %s is not loaded" "$module"
  521. done
  522. fi
  523. if [ "$TARGET" = "/" ]; then
  524. CHROOT_CMD=""
  525. else
  526. CHROOT_CMD="chroot \"$TARGET\""
  527. fi
  528. # fakeroot cannot check /proc/1/environ
  529. if [ "$HOST_OS" = Linux ] && ! doing_variant fakechroot && [ "$CONTAINER" = "lxc-libvirt" ]; then
  530. CHROOT_CMD="unshare --net $CHROOT_CMD"
  531. fi
  532. if [ -z "$SHA_SIZE" ]; then
  533. SHA_SIZE=256
  534. fi
  535. if ! in_path "sha${SHA_SIZE}sum" && ! in_path "sha${SHA_SIZE}"; then
  536. warning SHA_SIZE "Cannot find binary for checking sha%s checksums, falling back to sha1" "${SHA_SIZE}"
  537. SHA_SIZE=1
  538. fi
  539. DEBOOTSTRAP_CHECKSUM_FIELD="SHA$SHA_SIZE"
  540. export ARCH SUITE EXTRA_SUITES TARGET CHROOT_CMD SHA_SIZE DEBOOTSTRAP_CHECKSUM_FIELD
  541. if am_doing_phase first_stage second_stage; then
  542. if in_path id && [ "$(id -u)" -ne 0 ]; then
  543. error 1 NEEDROOT "debootstrap can only run as root"
  544. fi
  545. # Ensure that we can create working devices and executables on the target.
  546. if ! check_sane_mount "$TARGET"; then
  547. error 1 NOEXEC "Cannot install into target '$TARGET' mounted with noexec or nodev"
  548. fi
  549. fi
  550. if [ ! -e "$SCRIPT" ]; then
  551. error 1 NOSCRIPT "No such script: %s" "$SCRIPT"
  552. fi
  553. ###########################################################################
  554. if [ "$TARGET" != "" ]; then
  555. mkdir -p "$TARGET/debootstrap"
  556. fi
  557. ###########################################################################
  558. # Use of fd's by functions/scripts:
  559. #
  560. # stdin/stdout/stderr: used normally
  561. # fd 4: I:/W:/etc information
  562. # fd 5,6: spare for functions
  563. # fd 7,8: spare for scripts
  564. if [ "$USE_DEBIANINSTALLER_INTERACTION" = yes ]; then
  565. # stdout=stderr: full log of debootstrap run
  566. # fd 3: I:/W:/etc information
  567. exec 4>&3
  568. elif am_doing_phase printdebs; then
  569. # stderr: I:/W:/etc information
  570. # stdout: debs needed
  571. exec 4>&2
  572. else
  573. # stderr: used in exceptional circumstances only
  574. # stdout: I:/W:/etc information
  575. # $TARGET/debootstrap/debootstrap.log: full log of debootstrap run
  576. exec 4>&1
  577. exec >>"$TARGET/debootstrap/debootstrap.log"
  578. exec 2>&1
  579. fi
  580. ###########################################################################
  581. if [ -x /usr/bin/arch-test ] && am_doing_phase second_stage; then
  582. if doing_variant fakechroot; then
  583. ret=0; arch-test "$ARCH" || ret=$?
  584. # Avoid failure with old arch-test package
  585. elif arch-test --version > /dev/null 2>&1; then
  586. ret=0; arch-test -c "$TARGET" "$ARCH" || ret=$?
  587. else
  588. ret=3
  589. fi
  590. case $ret in
  591. 0) info ARCHEXEC "Target architecture can be executed" ;;
  592. 1) error 1 ARCHNOTEXEC "Unable to execute target architecture" ;;
  593. *) info ARCHEXECUNKNOWN "Can't verify that target arch works" ;;
  594. esac
  595. fi
  596. ###########################################################################
  597. if [ "$UNPACK_TARBALL" ]; then
  598. if [ "${UNPACK_TARBALL#/}" = "$UNPACK_TARBALL" ]; then
  599. error 1 TARPATH "Tarball must be given an absolute path"
  600. fi
  601. if [ "${UNPACK_TARBALL%.tar}" != "$UNPACK_TARBALL" ]; then
  602. (cd "$TARGET" && tar -xf "$UNPACK_TARBALL")
  603. elif [ "${UNPACK_TARBALL%.tar.[g|x]z}" != "$UNPACK_TARBALL" ]; then
  604. (cd "$TARGET" && tar -xf "$UNPACK_TARBALL")
  605. elif [ "${UNPACK_TARBALL%.tgz}" != "$UNPACK_TARBALL" ]; then
  606. (cd "$TARGET" && zcat "$UNPACK_TARBALL" | tar -xf -)
  607. else
  608. error 1 NOTTAR "Unknown tarball: must be .tar.[gz,xz], .tar or .tgz"
  609. fi
  610. fi
  611. ###########################################################################
  612. . "$SCRIPT"
  613. MIRRORS="$DEF_MIRROR"
  614. if [ "$USER_MIRROR" != "" ]; then
  615. MIRRORS="${USER_MIRROR%/}"
  616. fi
  617. export MIRRORS
  618. ok=false
  619. for v in $SUPPORTED_VARIANTS; do
  620. if doing_variant "$v"; then ok=true; fi
  621. done
  622. if ! "$ok"; then
  623. error 1 UNSUPPVARIANT "unsupported variant"
  624. fi
  625. ###########################################################################
  626. if am_doing_phase finddebs; then
  627. if [ "$FINDDEBS_NEEDS_INDICES" = "true" ] || \
  628. [ "$RESOLVE_DEPS" = "true" ]; then
  629. download_indices
  630. GOT_INDICES=true
  631. fi
  632. work_out_debs
  633. base=$(without "$base $ADDITIONAL" "$EXCLUDE")
  634. required=$(without "$required" "$EXCLUDE")
  635. if [ "$RESOLVE_DEPS" = true ]; then
  636. requiredX=$(echo "$required" | tr ' ' '\n' | sort | uniq)
  637. baseX=$(echo "$base" | tr ' ' '\n' | sort | uniq)
  638. info RESOLVEREQ "Resolving dependencies of required packages..."
  639. required=$(resolve_deps "$requiredX")
  640. info RESOLVEBASE "Resolving dependencies of base packages..."
  641. base=$(resolve_deps "$baseX")
  642. base=$(without "$base" "$required")
  643. if [ "$LOG_EXTRA_DEPS" = true ]; then
  644. baseN=$(without "$baseX" "$requiredX")
  645. baseU=$(without "$baseX" "$baseN")
  646. if [ "$baseU" != "" ]; then
  647. info REDUNDANTBASE "Found packages in base already in required: %s" "$baseU"
  648. fi
  649. requiredX=$(without "$required" "$requiredX")
  650. baseX=$(without "$base" "$baseX")
  651. if [ "$requiredX" != "" ]; then
  652. info NEWREQUIRED "Found additional required dependencies: %s" "$requiredX"
  653. fi
  654. if [ "$baseX" != "" ]; then
  655. info NEWBASE "Found additional base dependencies: %s" "$baseX"
  656. fi
  657. fi
  658. fi
  659. all_debs="$required $base"
  660. fi
  661. if am_doing_phase printdebs; then
  662. echo "$all_debs"
  663. fi
  664. if am_doing_phase dldebs; then
  665. if [ "$GOT_INDICES" != "true" ]; then
  666. download_indices
  667. fi
  668. download "$all_debs"
  669. fi
  670. if am_doing_phase save_variables; then
  671. cp "$0" "$TARGET/debootstrap/debootstrap"
  672. cp "$DEBOOTSTRAP_DIR/functions" "$TARGET/debootstrap/functions"
  673. cp "$SCRIPT" "$TARGET/debootstrap/suite-script"
  674. # pick up common setting scripts
  675. cp "$DEBOOTSTRAP_DIR"/scripts/*-common "$TARGET/debootstrap/"
  676. echo "$ARCH" >"$TARGET/debootstrap/arch"
  677. echo "$SUITE" >"$TARGET/debootstrap/suite"
  678. [ "" = "$EXTRA_SUITES" ] ||
  679. echo "$EXTRA_SUITES" >"$TARGET/debootstrap/extra-suites"
  680. [ "" = "$VARIANT" ] ||
  681. echo "$VARIANT" >"$TARGET/debootstrap/variant"
  682. echo "$required" >"$TARGET/debootstrap/required"
  683. echo "$base" >"$TARGET/debootstrap/base"
  684. chmod 755 "$TARGET/debootstrap/debootstrap"
  685. fi
  686. if am_doing_phase maketarball; then
  687. (cd "$TARGET";
  688. tar czf - var/lib/apt var/cache/apt debootstrap) >"$MAKE_TARBALL"
  689. fi
  690. if am_doing_phase first_stage; then
  691. choose_extractor
  692. if [ -n "$UNPACK_TARBALL" ]; then
  693. required=$(cat "$TARGET/debootstrap/required")
  694. base=$(cat "$TARGET/debootstrap/base")
  695. all_debs="$required $base"
  696. fi
  697. # first stage sets up the chroot -- no calls should be made to
  698. # "chroot $TARGET" here; but they should be possible by the time it's
  699. # finished
  700. first_stage_install
  701. if ! am_doing_phase second_stage; then
  702. cp "$0" "$TARGET/debootstrap/debootstrap"
  703. cp "$DEBOOTSTRAP_DIR/functions" "$TARGET/debootstrap/functions"
  704. cp "$SCRIPT" "$TARGET/debootstrap/suite-script"
  705. # pick up common setting scripts
  706. cp "$DEBOOTSTRAP_DIR"/scripts/*-common "$TARGET/debootstrap/"
  707. echo "$ARCH" >"$TARGET/debootstrap/arch"
  708. echo "$SUITE" >"$TARGET/debootstrap/suite"
  709. [ "" = "$EXTRA_SUITES" ] ||
  710. echo "$EXTRA_SUITES" >"$TARGET/debootstrap/extra-suites"
  711. echo "$USER_MIRROR" >"$TARGET/debootstrap/mirror"
  712. [ "" = "$VARIANT" ] ||
  713. echo "$VARIANT" >"$TARGET/debootstrap/variant"
  714. echo "$required" >"$TARGET/debootstrap/required"
  715. echo "$base" >"$TARGET/debootstrap/base"
  716. chmod 755 "$TARGET/debootstrap/debootstrap"
  717. fi
  718. # create sources.list
  719. if [ "${MIRRORS#http*://}" != "$MIRRORS" ]; then
  720. setup_apt_sources "${MIRRORS%% *}"
  721. else
  722. setup_apt_sources "$DEF_MIRROR"
  723. fi
  724. fi
  725. if am_doing_phase second_stage; then
  726. if [ "$SECOND_STAGE_ONLY" = true ]; then
  727. required=$(cat "$DEBOOTSTRAP_DIR/required")
  728. base=$(cat "$DEBOOTSTRAP_DIR/base")
  729. all_debs="$required $base"
  730. fi
  731. # second stage uses the chroot to clean itself up -- has to be able to
  732. # work from entirely within the chroot (in case we've booted into it,
  733. # possibly over NFS eg)
  734. second_stage_install
  735. if [ -e "$TARGET/debootstrap/debootstrap.log" ]; then
  736. if [ "$KEEP_DEBOOTSTRAP_DIR" = true ]; then
  737. cp "$TARGET/debootstrap/debootstrap.log" "$TARGET/var/log/bootstrap.log"
  738. else
  739. # debootstrap.log is still open as stdout/stderr and needs
  740. # to remain so, but after unlinking it some NFS servers
  741. # implement this by a temporary file in the same directory,
  742. # which makes it impossible to rmdir that directory.
  743. # Moving it instead works around the problem.
  744. mv "$TARGET/debootstrap/debootstrap.log" "$TARGET/var/log/bootstrap.log"
  745. fi
  746. fi
  747. sync
  748. if [ "$KEEP_DEBOOTSTRAP_DIR" = true ]; then
  749. if [ -x "$TARGET/debootstrap/debootstrap" ]; then
  750. chmod 644 "$TARGET/debootstrap/debootstrap"
  751. fi
  752. else
  753. rm -rf "$TARGET/debootstrap"
  754. fi
  755. fi
  756. if am_doing_phase kill_target; then
  757. if [ "$KEEP_DEBOOTSTRAP_DIR" != true ]; then
  758. info KILLTARGET "Deleting target directory"
  759. rm -rf --one-file-system "$TARGET"
  760. fi
  761. fi