vserver-build.debootstrap (5047B)
1 # $Id$ --*- sh -*-- 2 3 # Copyright (C) 2003 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de> 4 # 5 # This program is free software; you can redistribute it and/or modify 6 # it under the terms of the GNU General Public License as published by 7 # the Free Software Foundation; version 2 of the License. 8 # 9 # This program is distributed in the hope that it will be useful, 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 # GNU General Public License for more details. 13 # 14 # You should have received a copy of the GNU General Public License 15 # along with this program; if not, write to the Free Software 16 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 18 function init 19 { 20 workdir= 21 MIRROR= 22 options= 23 } 24 25 function initVariables 26 { 27 base.init 28 29 test -n "${MIRROR}" || { 30 local aux 31 findFile aux "$__CONFDIR"/.distributions/"$DISTRIBUTION"/debootstrap.mirror \ 32 "$__CONFDIR"/.defaults/apps/debootstrap/mirror \ 33 "$__DISTRIBDIR"/"$DISTRIBUTION"/debootstrap.mirror \ 34 "$__PKGLIBDEFAULTDIR"/debootstrap.mirror '' 35 test -z "$aux" || read MIRROR <"$aux" 36 } 37 local file 38 findFile file "$__CONFDIR"/.distributions/"$DISTRIBUTION"/debootstrap.options \ 39 "$__CONFDIR"/.defaults/apps/debootstrap/options '' 40 test -z "$file" || read options <"$file" 41 } 42 43 function initFilesystem 44 { 45 base.initFilesystem "$1" 46 47 mkdir -p "$SETUP_CONFDIR"/apps/pkgmgmt 48 touch "$SETUP_CONFDIR"/apps/pkgmgmt/internal 49 } 50 51 function findDebootstrap 52 { 53 test ! -x "$DEBOOTSTRAP" || return 0 54 55 pushd . &>/dev/null 56 DEBOOTSTRAP=$(which debootstrap 2>/dev/null) || { 57 dir=$($_MKTEMPDIR -p /var/tmp debootstrap.XXXXXX) 58 workdir=$dir 59 dst=$dir/debootstrap.deb 60 61 base._addGeneratedFile "$workdir" 62 63 findFile DEBOOTSTRAP_URI "$__CONFDIR"/.defaults/apps/debootstrap/uri "$__PKGLIBDEFAULTDIR"/debootstrap.uri 64 read tmp <$DEBOOTSTRAP_URI 65 case "$tmp" in 66 (/*) ln -s "$tmp" "$dst";; 67 (http://*|ftp://*) 68 echo $"\ 69 Could not find local version of 'debootstrap'; downloading it from 70 ${tmp}..." 71 $_WGET -nv -O "$dst" "$tmp" || { 72 $_CAT <<EOF >&2 73 ERROR: Could not download the debootstrap package from 74 75 $tmp 76 77 Usually, this means that Debian released a new version which is unknown 78 to util-vserver and removed the known ones. To fix this, go to 79 80 http://ftp.debian.org/debian/pool/main/d/debootstrap/ 81 82 (or a nearby mirror) and search the URL for the most recent *.deb 83 package matching your platform. Then, put this URL into 84 85 $__CONFDIR/.defaults/apps/debootstrap/uri 86 87 and retry the vserver-build command again. 88 EOF 89 exit 1 90 } 91 ;; 92 (*) echo $"Unsupported URI scheme '$tmp'" >&2 93 exit 1;; 94 esac 95 cd $dir 96 ar x "$dst" 97 local data=`ls -1 data.tar.*` 98 test "${data%.gz}" = "$data" || tar xzf data.tar.gz 99 test "${data%.bz2}" = "$data" || tar xjf data.tar.bz2 100 test "${data%.xz}" = "$data" || tar xJf data.tar.xz 101 DEBOOTSTRAP_DIR=`pwd`/usr/lib/debootstrap 102 DEBOOTSTRAP=`pwd`/usr/sbin/debootstrap 103 test -x "$DEBOOTSTRAP" || { 104 echo $"Unable to extract debootstrap: data file is $data" >&2 105 exit 1 106 } 107 test -d "$DEBOOTSTRAP_DIR" || DEBOOTSTRAP_DIR=`pwd`/usr/share/debootstrap 108 export DEBOOTSTRAP_DIR 109 110 local arch 111 arch=$(uname -i 2>/dev/null) || \ 112 arch=$(arch 2>/dev/null) || 113 arch= 114 115 ## Wash the calculated architecture 116 case $arch in 117 (i?86|athlon) arch=i386;; 118 (x86_64) arch=amd64;; 119 esac 120 121 test -z "$arch" || echo "$arch" >$DEBOOTSTRAP_DIR/arch 122 } 123 popd &>/dev/null 124 125 test -x "$DEBOOTSTRAP" || { echo $"Can not find debootstrap at '$DEBOOTSTRAP'" >&2; exit 1; } 126 } 127 128 function fixupDebian 129 { 130 $_RM -rf "$1"/dev 131 $_MV "$1"/dev.X "$1"/dev 132 } 133 134 135 ### main starts here <--- 136 137 138 tmp=$(getopt -o '+d:m:s:' --long debug -n "$0" -- "$@") || exit 1 139 eval set -- "$tmp" 140 141 init 142 143 while true; do 144 case "$1" in 145 (-d) DISTRIBUTION=$2; shift;; 146 (-m) MIRROR=$2; shift;; 147 (-s) script=$2; shift;; 148 (--debug) set -x;; 149 (--) shift; break ;; 150 (*) echo "vserver-build.debootstrap: internal error: unrecognized option '$1'" >&2 151 exit 1 152 ;; 153 esac 154 shift 155 done 156 157 getDistribution '' 1 158 159 initVariables 160 initFilesystem "$OPTION_FORCE" 161 162 setup_writeOption "$VSERVER_NAME" 163 setup_writeInitialFstab 164 165 findDebootstrap 166 167 if test -z "$script"; then 168 findFile script "$__CONFDIR/.distributions/$DISTRIBUTION/debootstrap.script" \ 169 "$__DISTRIBDIR/$DISTRIBUTION/debootstrap.script" '' 170 fi 171 172 export MIRROR 173 test -z "$BUILD_INITPRE" || "$BUILD_INITPRE" "$SETUP_CONFDIR" "$UTIL_VSERVER_VARS" 174 mv "$VDIR"/dev "$VDIR"/dev.X 175 $_VNAMESPACE --new -- \ 176 "$DEBOOTSTRAP" $options "$@" "$DISTRIBUTION" "$VDIR" "$MIRROR" "$script" || : ## HACK: ignore all errors... 177 fixupDebian "$VDIR" 178 test -z "$BUILD_INITPOST" || "$BUILD_INITPOST" "$SETUP_CONFDIR" "$UTIL_VSERVER_VARS" 179 180 $_RM -fr "$workdir" 181 base.setSuccess