Various build.sh fixes
This commit is contained in:
parent
5eb28bfcaa
commit
19078eaede
@ -27,31 +27,46 @@ fetch_file() {
|
||||
FILE_NAME=$(basename ${URL})
|
||||
SHA512=$(curl -s -S ${DIGEST} | grep -A1 -e "^# SHA512 HASH" | grep -o -E -e "^[0-9a-f]{128} *${FILE_NAME}$" | awk '{print $1}')
|
||||
|
||||
if [ -z ${SHA512} ]; then
|
||||
die "Unable to get checksum for ${FILE_NAME}, abort"
|
||||
# Check if local cache is usable
|
||||
if [ ! -d ${LOCAL_CACHE} ] || [ ! -w ${LOCAL_CACHE} ]; then
|
||||
die "Local cache ${LOCAL_CACHE} unusable!"
|
||||
fi
|
||||
|
||||
# Do we have local copy
|
||||
if [ -f ${LOCAL_CACHE}/${FILE_NAME} ]; then
|
||||
# if we have local, correct copy use it
|
||||
if [ -z ${SHA512} ]; then
|
||||
# Let's try md5sum before giving up
|
||||
MD5=$(curl -s -S ${DIGEST} | grep -o -E -e "^[0-9a-f]{32} *${FILE_NAME}$" | awk '{print $1}')
|
||||
if [ -z ${MD5} ]; then
|
||||
die "Unable to get checksum for ${FILE_NAME}, abort"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Do we have local copy, if not download
|
||||
if [ ! -f ${LOCAL_CACHE}/${FILE_NAME} ]; then
|
||||
wget -O ${LOCAL_CACHE}/${FILE_NAME} ${URL} || die "Cannot download ${URL}!"
|
||||
fi
|
||||
|
||||
if [ ! -z ${SHA512} ]; then
|
||||
if [ $(sha512sum ${LOCAL_CACHE}/${FILE_NAME} | awk '{print $1}') = ${SHA512} ]; then
|
||||
cp ${LOCAL_CACHE}/${FILE_NAME} .
|
||||
return
|
||||
else
|
||||
echo "Invalid checksum for ${LOCAL_CACHE}/${FILE_NAME}, downloading new copy..."
|
||||
rm -f ${LOCAL_CACHE}/${FILE_NAME}
|
||||
die "Invalid checksum for ${LOCAL_CACHE}/${FILE_NAME}, removing cached copy."
|
||||
fi
|
||||
fi
|
||||
|
||||
wget -nc ${URL} || die "Cannot download ${URL}!"
|
||||
if [ $(sha512sum ${FILE_NAME} | awk '{print $1}') != ${SHA512} ]; then
|
||||
die "Invalid checksum for ${FILE_NAME}!"
|
||||
if [ ! -z ${MD5} ]; then
|
||||
if [ $(md5sum ${LOCAL_CACHE}/${FILE_NAME} | awk '{print $1}') = ${MD5} ]; then
|
||||
cp ${LOCAL_CACHE}/${FILE_NAME} .
|
||||
return
|
||||
else
|
||||
rm -f ${LOCAL_CACHE}/${FILE_NAME}
|
||||
die "Invalid checksum for ${LOCAL_CACHE}/${FILE_NAME}, removing cached copy."
|
||||
fi
|
||||
fi
|
||||
|
||||
# Check if local cache is usable
|
||||
if [ -d ${LOCAL_CACHE} ] && [ -w ${LOCAL_CACHE} ]; then
|
||||
cp ${FILE_NAME} ${LOCAL_CACHE}
|
||||
echo "Stored ${FILE_NAME} in local cache."
|
||||
fi
|
||||
die "No checksum available for ${FILE_NAME}!"
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -113,17 +128,17 @@ setup_chroot() {
|
||||
local ROOT_FS=$1
|
||||
|
||||
# Import certain values from host config
|
||||
_PORTDIR=$(. /etc/portage/make.conf && echo $PORTDIR)
|
||||
_DISTDIR=$(. /etc/portage/make.conf && echo $DISTDIR)
|
||||
_PKGDIR=$(. /etc/portage/make.conf && echo $PKGDIR)
|
||||
_PORTDIR=$(. ${MAKE_CONF} && echo $PORTDIR)
|
||||
_DISTDIR=$(. ${MAKE_CONF} && echo $DISTDIR)
|
||||
_PKGDIR=$(. ${MAKE_CONF} && echo $PKGDIR)
|
||||
HOST_PORTDIR=${_PORTDIR:-/usr/portage}
|
||||
HOST_DISTDIR=${_DISTDIR:-/usr/portage/distfiles}
|
||||
HOST_PKGDIR=${_PKGDIR:-/usr/portage/packages}
|
||||
|
||||
PORTAGE_SNAPSHOT="${GENTOO_MIRROR}/snapshots/portage-latest.tar.bz2"
|
||||
if [ ${BIND_PORTAGE} = 1 ] ; then
|
||||
if [ -d ${ROOT_FS}/${PORTDIR} ] ; then
|
||||
mount --bind ${HOST_PORTDIR} ${ROOT_FS}/${PORTDIR} || die "Error mounting ${PORTDIR}"
|
||||
if [ -d ${ROOT_FS}/${HOST_PORTDIR} ] ; then
|
||||
mount --bind ${HOST_PORTDIR} ${ROOT_FS}/${HOST_PORTDIR} || die "Error mounting ${HOST_PORTDIR}"
|
||||
fi
|
||||
else
|
||||
# install latest portage snapshot
|
||||
@ -164,7 +179,7 @@ cleanup() {
|
||||
umount ${ROOT_FS}/dev ${ROOT_FS}/sys ${ROOT_FS}/proc
|
||||
|
||||
if [ ${BIND_PORTAGE} != 0 ]; then
|
||||
umount ${ROOT_FS}/${HOST_PORTAGE}
|
||||
umount ${ROOT_FS}/${HOST_PORTDIR}
|
||||
fi
|
||||
}
|
||||
|
||||
@ -185,6 +200,7 @@ OPTIONS:
|
||||
-c local cache (default $LOCAL_CACHE)
|
||||
-b bind mount host portage tree
|
||||
-i interactive, setting up chroot and enter it, skip extracting stage3, portage, etc.
|
||||
-m make.conf to source portage location,etc. defaults to /etc/portage/make.conf
|
||||
-v Verbose
|
||||
EOF
|
||||
}
|
||||
@ -198,6 +214,7 @@ fi
|
||||
VERBOSE=0
|
||||
BIND_PORTAGE=0
|
||||
INTERACTIVE=0
|
||||
MAKE_CONF="/etc/portage/make.conf"
|
||||
while getopts ":a:p:t:r:c:m:bvhi" OPTIONS; do
|
||||
case $OPTIONS in
|
||||
a ) ARCH=$OPTARG;;
|
||||
|
Loading…
Reference in New Issue
Block a user