| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 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 |
tar xzf data.tar.gz |
|---|
| 98 |
DEBOOTSTRAP_DIR=`pwd`/usr/lib/debootstrap |
|---|
| 99 |
DEBOOTSTRAP=`pwd`/usr/sbin/debootstrap |
|---|
| 100 |
test -d "$DEBOOTSTRAP_DIR" || DEBOOTSTRAP_DIR=`pwd`/usr/share/debootstrap |
|---|
| 101 |
export DEBOOTSTRAP_DIR |
|---|
| 102 |
|
|---|
| 103 |
local arch |
|---|
| 104 |
arch=$(uname -i 2>/dev/null) || \ |
|---|
| 105 |
arch=$(arch 2>/dev/null) || |
|---|
| 106 |
arch= |
|---|
| 107 |
|
|---|
| 108 |
|
|---|
| 109 |
case $arch in |
|---|
| 110 |
(i?86|athlon) arch=i386;; |
|---|
| 111 |
esac |
|---|
| 112 |
|
|---|
| 113 |
test -z "$arch" || echo "$arch" >$DEBOOTSTRAP_DIR/arch |
|---|
| 114 |
} |
|---|
| 115 |
popd &>/dev/null |
|---|
| 116 |
|
|---|
| 117 |
test -x "$DEBOOTSTRAP" || { echo $"Can not find debootstrap at '$DEBOOTSTRAP'" >&2; exit 1; } |
|---|
| 118 |
} |
|---|
| 119 |
|
|---|
| 120 |
function fixupDebian |
|---|
| 121 |
{ |
|---|
| 122 |
$_RM -rf "$1"/dev |
|---|
| 123 |
$_MV "$1"/dev.X "$1"/dev |
|---|
| 124 |
} |
|---|
| 125 |
|
|---|
| 126 |
|
|---|
| 127 |
|
|---|
| 128 |
|
|---|
| 129 |
|
|---|
| 130 |
tmp=$(getopt -o '+d:m:s:' --long debug -n "$0" -- "$@") || exit 1 |
|---|
| 131 |
eval set -- "$tmp" |
|---|
| 132 |
|
|---|
| 133 |
init |
|---|
| 134 |
|
|---|
| 135 |
while true; do |
|---|
| 136 |
case "$1" in |
|---|
| 137 |
(-d) DISTRIBUTION=$2; shift;; |
|---|
| 138 |
(-m) MIRROR=$2; shift;; |
|---|
| 139 |
(-s) script=$2; shift;; |
|---|
| 140 |
(--debug) set -x;; |
|---|
| 141 |
(--) shift; break ;; |
|---|
| 142 |
(*) echo "vserver-build.debootstrap: internal error: unrecognized option '$1'" >&2 |
|---|
| 143 |
exit 1 |
|---|
| 144 |
;; |
|---|
| 145 |
esac |
|---|
| 146 |
shift |
|---|
| 147 |
done |
|---|
| 148 |
|
|---|
| 149 |
getDistribution '' 1 |
|---|
| 150 |
|
|---|
| 151 |
initVariables |
|---|
| 152 |
initFilesystem "$OPTION_FORCE" |
|---|
| 153 |
|
|---|
| 154 |
setup_writeOption "$VSERVER_NAME" |
|---|
| 155 |
setup_writeInitialFstab |
|---|
| 156 |
|
|---|
| 157 |
findDebootstrap |
|---|
| 158 |
|
|---|
| 159 |
if test -z "$script"; then |
|---|
| 160 |
findFile script "$__CONFDIR/.distributions/$DISTRIBUTION/debootstrap.script" \ |
|---|
| 161 |
"$__DISTRIBDIR/$DISTRIBUTION/debootstrap.script" '' |
|---|
| 162 |
fi |
|---|
| 163 |
|
|---|
| 164 |
export MIRROR |
|---|
| 165 |
test -z "$BUILD_INITPRE" || "$BUILD_INITPRE" "$SETUP_CONFDIR" "$UTIL_VSERVER_VARS" |
|---|
| 166 |
mv "$VDIR"/dev "$VDIR"/dev.X |
|---|
| 167 |
$_VNAMESPACE --new -- \ |
|---|
| 168 |
"$DEBOOTSTRAP" $options "$@" "$DISTRIBUTION" "$VDIR" "$MIRROR" "$script" || : |
|---|
| 169 |
fixupDebian "$VDIR" |
|---|
| 170 |
test -z "$BUILD_INITPOST" || "$BUILD_INITPOST" "$SETUP_CONFDIR" "$UTIL_VSERVER_VARS" |
|---|
| 171 |
|
|---|
| 172 |
$_RM -fr "$workdir" |
|---|
| 173 |
base.setSuccess |
|---|