Advertisement
marietto2020

Untitled

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