home *** CD-ROM | disk | FTP | other *** search
/ Australian Personal Computer 2003 July / CD 2 Debian 3.0r1 / Debian.iso / isolinux / idepci.bin / idepci / usr / sbin / debootstrap < prev    next >
Encoding:
Text File  |  2002-03-14  |  4.4 KB  |  192 lines

  1. #!/bin/sh -e
  2.  
  3. unset TMP TEMP TMPDIR || true
  4.  
  5. if [ "$DEBOOTSTRAP_DIR" = "" ]; then
  6.     DEBOOTSTRAP_DIR=/usr/lib/debootstrap
  7. fi
  8.  
  9. DEVICES_TARGZ=$DEBOOTSTRAP_DIR/devices.tar.gz
  10.  
  11. . $DEBOOTSTRAP_DIR/functions
  12.  
  13. export LANG=C
  14. umask 022
  15.  
  16. usage()
  17. {
  18.     echo "Usage: ${0##*/} [OPTION]... <suite> <target> [<mirror> [<script>]]"
  19.     echo "Bootstrap Debian base system."
  20.     echo
  21.     cat <<EOF
  22.       --arch                 set the target architecture (use if no dpkg)
  23.                                [ --arch powerpc ]
  24.       --download-only        download packages, but don't perform installation
  25.       --print-debs           print the packages to be installed, and exit
  26.       --unpack-tarball       acquire .debs from a tarball instead of http
  27.       --boot-floppies        used for internal purposes by boot-floppies
  28.       --help                 display this help and exit
  29.       --include=A,B,C        adds specified names to the list of base packages
  30.       --exclude=A,B,C        removes specified packages from the list
  31.       --verbose              don't turn off the output of wget
  32. EOF
  33. }
  34.  
  35. if [ $# != 0 ] ; then
  36.   while true ; do
  37.     case "$1" in
  38.     --help)
  39.       usage
  40.       exit 0
  41.       ;;
  42.     --boot-floppies)
  43.       if ! (echo -n "" >&3) 2>/dev/null; then
  44.         error 1 "If running debootstrap by hand, don't use --boot-floppies"
  45.       fi
  46.       USE_BOOTFLOPPIES_INTERACTION=yes
  47.       shift
  48.       ;;
  49.     --print-debs)
  50.       JUST_PRINT_DEBS=yes
  51.       shift
  52.       ;;
  53.     --download-only)
  54.       DOWNLOAD_ONLY=yes
  55.       shift
  56.       ;;
  57.     --arch)
  58.       if [ -n "$2" ] ; then
  59.         ARCH="$2"
  60.         shift 2
  61.       else
  62.         error 1 "option requires an argument $1"
  63.       fi
  64.       ;;
  65.     --unpack-tarball)
  66.       if [ -n "$2" ] ; then
  67.         if [ ! -f "$2" ] ; then
  68.           error 1 "$2: No such file or directory"
  69.         fi
  70.         UNPACK_TARBALL="$2"
  71.         shift 2
  72.       else
  73.         error 1 "option requires an argument $1"
  74.       fi
  75.       ;;
  76.   --include*)
  77.     additional="$(echo $1 | cut -f2 -d"="|tr , " ")"
  78.     shift 1
  79.     ;;
  80.   --exclude*)
  81.     exclude="$(echo $1 | cut -f2 -d"="|tr , " ")"
  82.     shift 1
  83.     ;;
  84.   --verbose)
  85.     export verbose=true
  86.     shift 1
  87.     ;;
  88.     *)
  89.       break
  90.       ;;
  91.     esac
  92.   done
  93. else
  94.   info "usage: [OPTION]... <suite> <target> [<mirror> [<script>]]"
  95.   info "Try \`${0##*/} --help for more information."
  96.   error 1 "You must specify a suite and a target."
  97. fi
  98.  
  99. if [ "$1" = "" -o \( "$2" = "" -a "$JUST_PRINT_DEBS" = "" \) ]; then
  100.   info "usage: [OPTION]... <suite> <target> [<mirror> [<script>]]"
  101.   info "Try \`${0##*/} --help for more information."
  102.   error 1 "You must specify a suite and a target."
  103. fi
  104.  
  105. SUITE="$1"
  106. TARGET="$2"
  107. if [ "${TARGET#/}" = "${TARGET}" ]; then
  108.   if [ "${TARGET%/*}" = "$TARGET" ] ; then
  109.     TARGET="$(echo `pwd`/$TARGET)"
  110.   else
  111.     TARGET="$(cd ${TARGET%/*}; echo `pwd`/${TARGET##*/})"
  112.   fi
  113. fi
  114.  
  115. MIRRORS="http://ftp.debian.org/debian"
  116. SCRIPT="$DEBOOTSTRAP_DIR/scripts/$1"
  117. if [ "$3" != "" ]; then
  118.   MIRRORS="$3"
  119.   if [ "$4" != "" ]; then
  120.     SCRIPT="$4"
  121.   fi
  122. fi
  123.  
  124. # Remove trailing /'s
  125. TARGET="${TARGET%/}"
  126. MIRRORS="${MIRRORS%/}"
  127.  
  128. if [ "$ARCH" != "" ]; then
  129.     true
  130. elif [ -x /usr/bin/dpkg ] && /usr/bin/dpkg --print-architecture >/dev/null 2>&1
  131. then
  132.     ARCH=`/usr/bin/dpkg --print-architecture`
  133. elif [ -e $DEBOOTSTRAP_DIR/arch ]; then
  134.     ARCH=`cat $DEBOOTSTRAP_DIR/arch`
  135. else
  136.     error 1 "Couldn't work out current architecture"
  137. fi
  138.  
  139. export MIRRORS ARCH SUITE TARGET
  140.  
  141. if [ "$JUST_PRINT_DEBS" = "" -a "$DOWNLOAD_ONLY" = "" -a -x /usr/bin/id ] && [ `id -u` -ne 0 ]; then
  142.   error 1 "debootstrap can only run as root"
  143. fi
  144.  
  145. if [ ! -e "$SCRIPT" ]; then
  146.   error 1 "No such script: $SCRIPT"
  147. fi
  148.  
  149. mkdir -p "$TARGET"
  150.  
  151. PKGDETAILS=$DEBOOTSTRAP_DIR/pkgdetails
  152.  
  153. if [ "$UNPACK_TARBALL" ]; then
  154.   if [ "${UNPACK_TARBALL#/}" = "$UNPACK_TARBALL" ]; then
  155.     error 1 "Tarball must be given a complete path"
  156.   fi
  157.   if [ "${UNPACK_TARBALL%.tar}" != "$UNPACK_TARBALL" ]; then
  158.     (cd "$TARGET" && tar -xf "$UNPACK_TARBALL")
  159.   elif [ "${UNPACK_TARBALL%.tgz}" != "$UNPACK_TARBALL" ]; then
  160.     (cd "$TARGET" && zcat "$UNPACK_TARBALL" | tar -xf -)
  161.   else
  162.     error 1 "Unknown tarball: must be either .tar or .tgz"
  163.   fi
  164. fi
  165.  
  166. . "$SCRIPT"
  167.  
  168. work_out_debs
  169.  
  170. if [ "$JUST_PRINT_DEBS" ]; then
  171.   echo "$all_debs"
  172.   exit 0
  173. fi
  174.  
  175. download $all_debs
  176.  
  177. if [ "$DOWNLOAD_ONLY" ]; then
  178.   exit 0
  179. fi
  180.  
  181. install_debs
  182.  
  183. if [ -e "$TARGET/etc/apt/sources.list" ]; then
  184.   rm -f "$TARGET/etc/apt/sources.list"
  185. fi
  186.  
  187. if [ -n "$USE_BOOTFLOPPIES_INTERACTION" ] ; then
  188.   echo "I: debootstrap: Successfully completed" # goes to /dev/tty4
  189.   sleep 1 # give the user a second to see the success notice.
  190. fi
  191.  
  192.