forked from ports/contrib
remove xdelta binary diff feature crux devs disagree
This commit is contained in:
parent
4931af51b6
commit
5c359d061d
@ -1,668 +0,0 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# pre-install
|
||||
#
|
||||
# Copyright (c) 2008 Danny Rawlins
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
# USA.
|
||||
#
|
||||
|
||||
# colours
|
||||
BOLD="\033[1m"
|
||||
RED="\033[1;31;40m"
|
||||
YELLOW="\033[1;33;40m"
|
||||
GREEN="\033[1;32;40m"
|
||||
BLUE="\033[1;34;40m"
|
||||
CLEAR="\033[0m"
|
||||
|
||||
print_info() {
|
||||
printf "${BOLD}${BLUE}[${CLEAR}%s${BLUE}]${CLEAR} %s\n" 'INFO' "${1}"
|
||||
}
|
||||
|
||||
print_count() {
|
||||
local ITEM MSG
|
||||
|
||||
if [ "$#" -lt '1' ]; then
|
||||
print_error 'print_count() to few arguments.'
|
||||
fi
|
||||
|
||||
if [ "$#" -gt '2' ]; then
|
||||
print_error 'print_count() to many arguments.'
|
||||
fi
|
||||
|
||||
if [ "$#" -gt '1' ]; then
|
||||
ITEM="${1}"
|
||||
MSG="${2}"
|
||||
else
|
||||
MSG="${1}"
|
||||
fi
|
||||
|
||||
#TODO add in dynamic count item var
|
||||
if [ "${PKG_PRINT_COUNT}" = 'yes' ]; then
|
||||
printf "${BOLD}${BLUE}[${GREEN}%3.0f%s${BLUE}]${CLEAR} %s\n" "$(printf "(${PKG_COUNT} / ${PKG_LOG_VERBOSE_TOTAL_COUNT}) * 100\n" | \
|
||||
bc -l)" '%' "${MSG}"
|
||||
|
||||
PKG_COUNT=$(($PKG_COUNT + 1))
|
||||
fi
|
||||
}
|
||||
|
||||
log_very_verbose() {
|
||||
if [ "${PKG_LOG_VERY_VERBOSE}" = 'yes' ]; then
|
||||
printf "${BOLD}${BLUE}[${CLEAR}LOG_VERY_VERBOSE${BLUE}]${CLEAR} %s\n" "${1}"
|
||||
fi
|
||||
}
|
||||
|
||||
print_error() {
|
||||
printf "${BOLD}${BLUE}[${RED}%s${BLUE}]${CLEAR} %s\n" 'ERROR' "$1" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
print_warn() {
|
||||
printf "${BOLD}${BLUE}[${YELLOW}%s${BLUE}]${CLEAR} %s\n" 'WARN' "$1" >&2
|
||||
}
|
||||
|
||||
log_debug() {
|
||||
if [ "${LOG_DEBUG}" = 'yes' ]; then
|
||||
printf "${BOLD}${BLUE}[${RED}%s${BLUE}]${CLEAR} %s\n" 'DEBUG' "$1"
|
||||
fi
|
||||
}
|
||||
|
||||
explode_filename_old() {
|
||||
local FILE
|
||||
|
||||
if [ "$#" -lt '3' ]; then
|
||||
print_error 'explode_filename_old() to few arguments.'
|
||||
fi
|
||||
|
||||
if [ "$#" -gt '3' ]; then
|
||||
print_error 'explode_filename_old() to many arguments.'
|
||||
fi
|
||||
|
||||
OLD_FILE_NAME="${1}"
|
||||
OLD_FILE_VERSION="${2}"
|
||||
#FILE="$(printf ${3} | sed -e "s|${NEW_FILE_VERSION}|${OLD_FILE_VERSION}|")"
|
||||
FILE="${3}"
|
||||
|
||||
OLD_FILE_PREFIX="$(printf "${FILE}" | sed -e "s|^${OLD_FILE_NAME}\(.*\)${OLD_FILE_VERSION}\(.*\)\(.t.*$\)|\1|")"
|
||||
OLD_FILE_SUFFIX="$(printf "${FILE}" | sed -e "s|^${OLD_FILE_NAME}\(.*\)${OLD_FILE_VERSION}\(.*\)\(.t.*$\)|\2|")"
|
||||
OLD_FILE_EXT="$(printf "${FILE}" | sed -e "s|^${OLD_FILE_NAME}\(.*\)${OLD_FILE_VERSION}\(.*\)\(.t.*$\)|\3|")"
|
||||
|
||||
OLD_FILE="${OLD_FILE_NAME}${OLD_FILE_PREFIX}${OLD_FILE_VERSION}${OLD_FILE_SUFFIX}${OLD_FILE_EXT}"
|
||||
|
||||
log_debug "explode_filename_old() OLD_FILE_NAME ${OLD_FILE_NAME}"
|
||||
log_debug "explode_filename_old() OLD_FILE_VERSION ${OLD_FILE_VERSION} <- misleading we dont know this yet"
|
||||
log_debug "explode_filename_old() FILE ${FILE}"
|
||||
log_debug "explode_filename_old() OLD_FILE_PREFIX ${OLD_FILE_PREFIX}"
|
||||
log_debug "explode_filename_old() OLD_FILE_SUFFIX ${OLD_FILE_SUFFIX}"
|
||||
log_debug "explode_filename_old() OLD_FILE_EXT ${OLD_FILE_EXT}"
|
||||
log_debug "explode_filename_old() OLD_FILE ${OLD_FILE}"
|
||||
}
|
||||
|
||||
explode_filename_new() {
|
||||
local FILE
|
||||
|
||||
if [ "$#" -lt '3' ]; then
|
||||
print_error 'explode_filename_new() to few arguments.'
|
||||
fi
|
||||
|
||||
if [ "$#" -gt '3' ]; then
|
||||
print_error 'explode_filename_new() to many arguments.'
|
||||
fi
|
||||
|
||||
NEW_FILE_NAME="${1}"
|
||||
NEW_FILE_VERSION="${2}"
|
||||
FILE="${3}"
|
||||
|
||||
NEW_FILE_PREFIX="$(printf "${FILE}" | sed -e "s|^${NEW_FILE_NAME}\(.*\)${NEW_FILE_VERSION}\(.*\)\(.t.*$\)|\1|")"
|
||||
NEW_FILE_SUFFIX="$(printf "${FILE}" | sed -e "s|^${NEW_FILE_NAME}\(.*\)${NEW_FILE_VERSION}\(.*\)\(.t.*$\)|\2|")"
|
||||
NEW_FILE_EXT="$(printf "${FILE}" | sed -e "s|^${NEW_FILE_NAME}\(.*\)${NEW_FILE_VERSION}\(.*\)\(.t.*$\)|\3|")"
|
||||
|
||||
NEW_FILE="${NEW_FILE_NAME}${NEW_FILE_PREFIX}${NEW_FILE_VERSION}${NEW_FILE_SUFFIX}${NEW_FILE_EXT}"
|
||||
|
||||
log_debug "explode_filename_new() NEW_FILE_NAME ${NEW_FILE_NAME}"
|
||||
log_debug "explode_filename_new() NEW_FILE_VERSION ${NEW_FILE_VERSION}"
|
||||
log_debug "explode_filename_new() FILE ${FILE}"
|
||||
log_debug "explode_filename_new() NEW_FILE_PREFIX ${NEW_FILE_PREFIX}"
|
||||
log_debug "explode_filename_new() NEW_FILE_SUFFIX ${NEW_FILE_SUFFIX}"
|
||||
log_debug "explode_filename_new() NEW_FILE_EXT ${NEW_FILE_EXT}"
|
||||
log_debug "explode_filename_new() NEW_FILE ${NEW_FILE}"
|
||||
}
|
||||
|
||||
get_basename() {
|
||||
local FILE="`echo $1 | sed 's|^.*://.*/||g'`"
|
||||
echo $FILE
|
||||
}
|
||||
|
||||
is_installed() {
|
||||
local PACKAGE
|
||||
|
||||
if [ "$#" -gt '1' ]; then
|
||||
print_error 'is_installed() to many arguments.'
|
||||
fi
|
||||
|
||||
if [ "$#" -lt '1' ]; then
|
||||
print_error 'is_installed() to few arguments.'
|
||||
fi
|
||||
|
||||
PACKAGE="${1}"
|
||||
|
||||
if [ -z "$(pkginfo -i | egrep "^$PACKAGE ")" ]; then
|
||||
print_error "'$PACKAGE' is not installed, can not do a incremental update."
|
||||
fi
|
||||
}
|
||||
|
||||
pkg_portcheck() {
|
||||
is_installed 'xdelta'
|
||||
is_installed 'coreutils'
|
||||
is_installed 'tar'
|
||||
is_installed 'sed'
|
||||
is_installed 'curl'
|
||||
is_installed 'bc' #FIXME could make it optional
|
||||
}
|
||||
|
||||
check_file_exists() {
|
||||
local FILE="${1}"
|
||||
|
||||
if [ "$#" -gt '1' ]; then
|
||||
print_error 'check_file_exists() to many arguments.'
|
||||
fi
|
||||
|
||||
if [ -e "${FILE}" ]; then
|
||||
RETURN=1
|
||||
else
|
||||
RETURN=0
|
||||
fi
|
||||
}
|
||||
|
||||
check_file_missing() {
|
||||
local FILE="${1}"
|
||||
|
||||
if [ "$#" -gt '1' ]; then
|
||||
print_error 'check_file_missing() to many arguments.'
|
||||
fi
|
||||
|
||||
if [ ! -e "${FILE}" ]; then
|
||||
RETURN=1
|
||||
else
|
||||
RETURN=0
|
||||
fi
|
||||
|
||||
#if [ ! -f "${FILE}" ]; then
|
||||
# print_error "'${FILE}' is not a regular file."
|
||||
#fi
|
||||
}
|
||||
|
||||
array() {
|
||||
printf "${2}" | tr --delete '\n' | sed \
|
||||
-e 's|[\t| ]\+| |g' \
|
||||
-e 's| ||' | cut --delimiter=' ' --fields="${1}"
|
||||
}
|
||||
|
||||
array_count() {
|
||||
printf "${1}" | tr --delete '\n' | sed \
|
||||
-e 's|[\t| ]\+| |g' \
|
||||
-e 's|^ ||' \
|
||||
-e 's| $||' | wc --words
|
||||
}
|
||||
|
||||
array_end() {
|
||||
local COUNT="$(array_count "${1}")"
|
||||
printf "${1}" | tr --delete '\n' | sed \
|
||||
-e 's|[\t| ]\+| |g' \
|
||||
-e 's|^ ||' \
|
||||
-e 's| $||' | cut --delimiter=' ' --fields="${COUNT}"
|
||||
}
|
||||
|
||||
pkg_checks() {
|
||||
local NEW_FILE="${NEW_FILE_NAME}${NEW_FILE_PREFIX}${NEW_FILE_VERSION}${NEW_FILE_SUFFIX}${NEW_FILE_EXT}"
|
||||
|
||||
if [ -e "${PKGMK_SOURCE_DIR}/${NEW_FILE}" ]; then
|
||||
print_info "File '${PKGMK_SOURCE_DIR}/${NEW_FILE}' exists, nothing to do."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ -z "$(ls ${PKGMK_SOURCE_DIR}/${OLD_FILE_NAME}-*${OLD_FILE_EXT})" ]; then
|
||||
print_info 'No source archive to use; proceed to download source archive.'
|
||||
exit 0
|
||||
fi
|
||||
|
||||
case ${OLD_FILE_EXT} in
|
||||
.tar.gz) is_installed 'gzip' ;;
|
||||
.tar.bz2) is_installed 'bzip2' ;;
|
||||
.tar.lzma) is_installed 'lzma' ;;
|
||||
.tar.lrzip) is_installed 'lrzip' ;;
|
||||
esac
|
||||
|
||||
case ${NEW_FILE_EXT} in
|
||||
.tar.gz) is_installed 'gzip' ;;
|
||||
.tar.bz2) is_installed 'bzip2' ;;
|
||||
.tar.lzma) is_installed 'lzma' ;;
|
||||
.tar.lrzip) is_installed 'lrzip' ;;
|
||||
esac
|
||||
}
|
||||
|
||||
pkg_work_dir() {
|
||||
if [ ! -e "${PKGMK_WORK_DIR}" ]; then
|
||||
mkdir -p "${PKGMK_WORK_DIR}" || exit 1
|
||||
fi
|
||||
cd "${PKGMK_WORK_DIR}" || exit 1
|
||||
}
|
||||
|
||||
pkg_pick_mirror() {
|
||||
# pick a server to download patches
|
||||
#local PKG_DIFF_MIRROR_TOTAL="$(array_count "${PKG_DIFF_MIRRORS}")"
|
||||
case $(date +%S) in
|
||||
*[15]) PKG_DIFF_MIRROR=4 ;;
|
||||
*[30]) PKG_DIFF_MIRROR=3 ;;
|
||||
*[45]) PKG_DIFF_MIRROR=2 ;;
|
||||
*) PKG_DIFF_MIRROR=1 ;;
|
||||
esac
|
||||
}
|
||||
|
||||
pkg_make_list() {
|
||||
local FILE ADD_DIFF PATCH
|
||||
|
||||
ADD_DIFF='yes'
|
||||
DELTA_FILE_LIST=''
|
||||
|
||||
for FILE in ${XDELTA_FILES}; do
|
||||
|
||||
PATCH="$(printf "${FILE}" | \
|
||||
sed -e "s|^${OLD_FILE_NAME}${OLD_FILE_PREFIX}\(.*\)${OLD_FILE_SUFFIX}.tar-${NEW_FILE_NAME}${NEW_FILE_PREFIX}.*|\1|")"
|
||||
|
||||
if [ "${ADD_DIFF}" = 'yes' ]; then
|
||||
DELTA_FILE_LIST="${FILE} ${DELTA_FILE_LIST}"
|
||||
if [ "${HAS_VERSION}" = "${PATCH}" ]; then
|
||||
ADD_DIFF='no'
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
if [ -z "${HAS_VERSION}" ]; then
|
||||
print_error 'HAS_VERSION still empty in pkg_make_list()'
|
||||
fi
|
||||
|
||||
log_debug "Has version: ${HAS_VERSION}"
|
||||
}
|
||||
|
||||
pkg_parse_local_list() {
|
||||
local FILE SOURCE_VERSION SOURCE_VERSIONS LOCAL_PATCH_FILES GET_VERSION \
|
||||
PATCH_NEW_VERSION PATCH_OLD_VERSION PATCH_OLD_VERSIONS
|
||||
|
||||
GET_VERSION='yes'
|
||||
|
||||
SOURCE_VERSIONS="$(ls --sort=version --reverse ${PKGMK_SOURCE_DIR}/${OLD_FILE_NAME}${OLD_FILE_PREFIX}*${OLD_FILE_SUFFIX}${OLD_FILE_EXT} | \
|
||||
sed -e "s|.*/${OLD_FILE_NAME}${OLD_FILE_PREFIX}\(.*\)${OLD_FILE_SUFFIX}${OLD_FILE_EXT}|\1|" | \
|
||||
xargs)"
|
||||
|
||||
# print source archive version list, newist to oldist sorted.
|
||||
log_debug "Local version list: ${SOURCE_VERSIONS}"
|
||||
|
||||
# do we have any local xdelta files?
|
||||
LOCAL_PATCH_FILES="$(ls --sort=version --reverse ${PKGMK_SOURCE_DIR}/*.xdelta 2> /dev/null | \
|
||||
sed -e "s|.*/${OLD_FILE_NAME}${OLD_FILE_PREFIX}\(.*\)${OLD_FILE_SUFFIX}.tar-.*|\1|" | xargs)"
|
||||
|
||||
if [ -n "${LOCAL_PATCH_FILES}" ]; then
|
||||
|
||||
for FILE in ${LOCAL_PATCH_FILES}; do
|
||||
PATCH_OLD_VERSION="$(printf "${FILE}" | \
|
||||
sed -e "s|.*/${OLD_FILE_NAME}${OLD_FILE_PREFIX}\(.*\)${OLD_FILE_SUFFIX}.tar-${NEW_FILE_NAME}${NEW_FILE_PREFIX}.*|\1|")"
|
||||
PATCH_OLD_VERSIONS="${PATCH_OLD_VERSION} ${PATCH_OLD_VERSIONS}"
|
||||
done
|
||||
|
||||
# print patch version list, oldist to newist sorted.
|
||||
log_debug "Local patch list: ${PATCH_OLD_VERSIONS}"
|
||||
|
||||
XDELTA_FILES="$(ls --sort=version --reverse ${PKGMK_SOURCE_DIR}/ | grep '.xdelta' | \
|
||||
grep "${NEW_FILE_NAME}" | sed -e 's|.*/||' | xargs)"
|
||||
|
||||
# find most recent source archive to use that matches a xdelta file
|
||||
#TODO fix this to also work with older Pkgfile versions when we
|
||||
# have more recent versions
|
||||
for SOURCE_VERSION in $SOURCE_VERSIONS; do
|
||||
for FILE in $XDELTA_FILES; do
|
||||
|
||||
PATCH_OLD_VERSION="$(printf "${FILE}" | \
|
||||
sed -e "s|^${OLD_FILE_NAME}${OLD_FILE_PREFIX}\(.*\)${OLD_FILE_SUFFIX}.tar-${NEW_FILE_NAME}${NEW_FILE_PREFIX}.*|\1|")"
|
||||
|
||||
if [ "${GET_VERSION}" = 'yes' ]; then
|
||||
if [ "${SOURCE_VERSION}" = "${PATCH_OLD_VERSION}" ]; then
|
||||
HAS_VERSION="${SOURCE_VERSION}"
|
||||
GET_VERSION='no'
|
||||
fi
|
||||
fi
|
||||
done
|
||||
done
|
||||
|
||||
if [ -z "${HAS_VERSION}" ]; then
|
||||
print_info 'No useable local patch files, proceed to download list.'
|
||||
pkg_parse_remote_list
|
||||
fi
|
||||
|
||||
log_debug "Has version: ${HAS_VERSION}"
|
||||
|
||||
log_debug "Using local archive version ${HAS_VERSION}"
|
||||
PATCH_VERSIONS="$(printf "${PATCH_OLD_VERSIONS}" | sed -e "s|.*\($HAS_VERSION.*\)$|\1|")"
|
||||
log_debug "Using local patches: ${PATCH_VERSIONS}"
|
||||
|
||||
# check if we are missing any needed patches
|
||||
if [ -z "$(ls ${PKGMK_SOURCE_DIR}/*$(array_end "${PATCH_VERSIONS}")*${NEW_FILE_NAME}${NEW_FILE_PREFIX}${NEW_FILE_VERSION}${NEW_FILE_SUFFIX}.tar.xdelta 2> /dev/null)" ]; then
|
||||
print_info 'Missing patch files, fetching list.'
|
||||
pkg_parse_remote_list
|
||||
fi
|
||||
|
||||
pkg_make_list
|
||||
pkg_extract
|
||||
|
||||
else
|
||||
print_info 'No local patch files, proceed to download list.'
|
||||
pkg_parse_remote_list
|
||||
fi
|
||||
}
|
||||
|
||||
pkg_download_delta_list() {
|
||||
local URL
|
||||
unset XDELTA_FILES
|
||||
|
||||
pkg_pick_mirror
|
||||
URL="$(array "${PKG_DIFF_MIRROR}" "${PKG_DIFF_MIRRORS}")"
|
||||
#printf "Patching source files.\n"
|
||||
print_info "Retrieving delta list from '$URL'."
|
||||
|
||||
log_debug "curl --fail --silent --retry 3 --connect-timeout 20 "${URL}" | \
|
||||
grep '.xdelta' | grep "${NEW_FILE_NAME}" | sed -e 's|.*[HREF|href]=\"||' -e 's|\".*||' | \
|
||||
sort --reverse | xargs"
|
||||
|
||||
XDELTA_FILES="$(curl --fail --silent --retry 3 --connect-timeout 20 "$URL" | \
|
||||
grep '.xdelta' | grep "${NEW_FILE_NAME}" | sed -e 's|.*[HREF|href]=\"||' \
|
||||
-e 's|\".*||' | sort --reverse | xargs)"
|
||||
|
||||
# this check is not enough data may stop sooner than it should
|
||||
if [ -z "${XDELTA_FILES}" ]; then
|
||||
print_error 'Could not download xdelta file list.'
|
||||
fi
|
||||
}
|
||||
|
||||
pkg_parse_remote_list() {
|
||||
local FILE SOURCE_VERSION SOURCE_VERSIONS LOCAL_PATCH_FILES \
|
||||
GET_VERSION ADD_DIFF PATCH_NEW_VERSION PATCH_OLD_VERSION \
|
||||
PATCH_OLD_VERSIONS
|
||||
|
||||
GET_VERSION='yes'
|
||||
ADD_DIFF='yes'
|
||||
|
||||
pkg_download_delta_list # returns $XDELTA_FILES
|
||||
|
||||
SOURCE_VERSIONS="$(ls --sort=version --reverse ${PKGMK_SOURCE_DIR}/${OLD_FILE_NAME}${OLD_FILE_PREFIX}*${OLD_FILE_SUFFIX}${OLD_FILE_EXT} | \
|
||||
sed -e "s|.*/${OLD_FILE_NAME}${OLD_FILE_PREFIX}\(.*\)${OLD_FILE_SUFFIX}${OLD_FILE_EXT}|\1|" | \
|
||||
xargs)"
|
||||
|
||||
# print source archive version list, newist to oldist sorted.
|
||||
log_debug "Local version list: ${SOURCE_VERSIONS}"
|
||||
|
||||
# print patch version list, oldist to newist sorted.
|
||||
if [ "${LOG_DEBUG}" = 'yes' ]; then
|
||||
for FILE in $XDELTA_FILES; do
|
||||
PATCH_OLD_VERSION="$(printf "${FILE}" | \
|
||||
sed -e "s|^${OLD_FILE_NAME}${OLD_FILE_PREFIX}\(.*\)${OLD_FILE_SUFFIX}.tar-${NEW_FILE_NAME}${NEW_FILE_PREFIX}.*|\1|")"
|
||||
PATCH_OLD_VERSIONS="${PATCH_OLD_VERSION} ${PATCH_OLD_VERSIONS}"
|
||||
done
|
||||
log_debug "Remote version list: ${PATCH_OLD_VERSIONS}"
|
||||
unset PATCH_OLD_VERSION PATCH_OLD_VERSIONS
|
||||
fi
|
||||
|
||||
# find most recent source archive to use
|
||||
for SOURCE_VERSION in $SOURCE_VERSIONS; do
|
||||
for FILE in $XDELTA_FILES; do
|
||||
|
||||
PATCH_OLD_VERSION="$(printf "${FILE}" | \
|
||||
sed -e "s|^${OLD_FILE_NAME}${OLD_FILE_PREFIX}\(.*\)${OLD_FILE_SUFFIX}.tar-${NEW_FILE_NAME}${NEW_FILE_PREFIX}.*|\1|")"
|
||||
|
||||
if [ "${GET_VERSION}" = 'yes' ]; then
|
||||
if [ "${SOURCE_VERSION}" = "${PATCH_OLD_VERSION}" ]; then
|
||||
HAS_VERSION="${SOURCE_VERSION}"
|
||||
GET_VERSION='no'
|
||||
fi
|
||||
fi
|
||||
done
|
||||
done
|
||||
|
||||
if [ -z "${HAS_VERSION}" ]; then
|
||||
print_info 'No source archive matches any delta version, proceed to download source archive(s).'
|
||||
fi
|
||||
|
||||
pkg_make_list
|
||||
pkg_download_diff
|
||||
pkg_parse_local_list # reparse list again
|
||||
|
||||
log_debug "Using local archive '${PKGMK_SOURCE_DIR}/${OLD_FILE_NAME}${OLD_FILE_PREFIX}${HAS_VERSION}${OLD_FILE_SUFFIX}${OLD_FILE_EXT}'."
|
||||
log_debug "Using local version '${HAS_VERSION}'."
|
||||
}
|
||||
|
||||
pkg_download_diff() {
|
||||
local URL COUNT TOTAL FILE DOWNLOAD_TOTAL
|
||||
|
||||
URL="$(array "${PKG_DIFF_MIRROR}" "${PKG_DIFF_MIRRORS}")"
|
||||
COUNT='1'
|
||||
|
||||
# count missing files to download.
|
||||
for FILE in ${DELTA_FILE_LIST}; do
|
||||
if [ ! -e "${PKGMK_SOURCE_DIR}/${FILE}" ]; then
|
||||
DOWNLOAD_TOTAL="${FILE} ${DOWNLOAD_TOTAL}"
|
||||
fi
|
||||
done
|
||||
|
||||
TOTAL="$(printf "${DOWNLOAD_TOTAL}" | wc --words)"
|
||||
unset DOWNLOAD_TOTAL
|
||||
|
||||
if [ "${TOTAL}" -gt '1' ]; then
|
||||
print_info 'Downloading deltas.'
|
||||
else
|
||||
print_info 'Downloading delta.'
|
||||
fi
|
||||
|
||||
for FILE in ${DELTA_FILE_LIST}; do
|
||||
|
||||
if [ ! -e "${PKGMK_SOURCE_DIR}/${FILE}" ]; then
|
||||
printf " ${BOLD}${BLUE}[${GREEN}%3.0f%s${BLUE}]${CLEAR} %s\n" "$(printf "($COUNT / $TOTAL) * 100\n" | \
|
||||
bc -l)" '%' "Downloading ${FILE}."
|
||||
|
||||
if [ "${PKG_LOG_VERY_VERBOSE}" = 'yes' ]; then
|
||||
log_very_verbose "curl --fail --silent --remote-name \
|
||||
--retry 3 \"${URL}${FILE}\""
|
||||
fi
|
||||
|
||||
curl --fail --silent --remote-name --retry 3 "${URL}${FILE}"
|
||||
|
||||
if [ "$?" -gt '0' ]; then
|
||||
error "Failed to download '${URL}${FILE}'."
|
||||
fi
|
||||
|
||||
mv "${FILE}" "${PKGMK_SOURCE_DIR}/${FILE}"
|
||||
COUNT="$(($COUNT + 1))"
|
||||
fi
|
||||
|
||||
log_very_verbose "Copying ${PKGMK_SOURCE_DIR}/${FILE} to ${PKGMK_WORK_DIR}/"
|
||||
cp "${PKGMK_SOURCE_DIR}/${FILE}" . || exit 1
|
||||
done
|
||||
|
||||
#if [ "${TOTAL}" -gt '0' ]; then
|
||||
# printf "Done.\n"
|
||||
#fi
|
||||
}
|
||||
|
||||
pkg_extract() {
|
||||
local OLD_FILE OLD_FILE_TAR
|
||||
|
||||
OLD_FILE="${OLD_FILE_NAME}${OLD_FILE_PREFIX}${HAS_VERSION}${OLD_FILE_SUFFIX}${OLD_FILE_EXT}"
|
||||
OLD_FILE_TAR="${OLD_FILE_NAME}${OLD_FILE_PREFIX}${HAS_VERSION}${OLD_FILE_SUFFIX}.tar"
|
||||
|
||||
log_very_verbose "Copying ${PKGMK_SOURCE_DIR}/${OLD_FILE} to ${PKGMK_WORK_DIR}/"
|
||||
cp "${PKGMK_SOURCE_DIR}/${OLD_FILE}" .
|
||||
print_count 'Decompressing source archive.'
|
||||
|
||||
case ${OLD_FILE_EXT} in
|
||||
.tar.gz) gzip -d "${OLD_FILE}" ;;
|
||||
.tar.bz2) bzip2 -d "${OLD_FILE}" ;;
|
||||
.tar.lzma) lzma -d "${OLD_FILE}" ;;
|
||||
.tar.lrzip) lrzip -d "${OLD_FILE}" ;;
|
||||
esac
|
||||
|
||||
log_very_verbose "Decompressed tarball ${OLD_FILE} to ${OLD_FILE_TAR}"
|
||||
pkg_patch
|
||||
}
|
||||
|
||||
pkg_patch() {
|
||||
local PATCH PATCH_OLD_VERSION PATCH_OLD_VERSION_TAR COUNT TOTAL
|
||||
|
||||
TOTAL="$(array_count "${DELTA_FILE_LIST}")"
|
||||
COUNT='1'
|
||||
|
||||
if [ "${TOTAL}" -gt '1' ]; then
|
||||
print_info 'Patching files.'
|
||||
else
|
||||
print_info 'Patching file.'
|
||||
fi
|
||||
|
||||
for PATCH in ${DELTA_FILE_LIST}; do
|
||||
log_very_verbose "Copying ${PATCH} to ${PKGMK_WORK_DIR}/"
|
||||
cp "${PKGMK_SOURCE_DIR}/${PATCH}" . || exit 1
|
||||
|
||||
PATCH_OLD_VERSION="$(printf "${PATCH}" | \
|
||||
sed -e "s|^${OLD_FILE_NAME}${OLD_FILE_PREFIX}\(.*\)${OLD_FILE_SUFFIX}.tar-${NEW_FILE_NAME}-.*|\1|")"
|
||||
|
||||
PATCH_OLD_VERSION_TAR="${OLD_FILE_NAME}${OLD_FILE_PREFIX}${PATCH_OLD_VERSION}${OLD_FILE_SUFFIX}.tar"
|
||||
log_very_verbose "Patching ${PATCH_OLD_VERSION_TAR} with ${PATCH}"
|
||||
|
||||
printf " ${BOLD}${BLUE}[${GREEN}%3.0f%s${BLUE}]${CLEAR} %s\n" "$(printf "($COUNT / $TOTAL) * 100\n" | \
|
||||
bc -l)" '%' "Applying patch ${PATCH}."
|
||||
|
||||
COUNT="$(($COUNT + 1))"
|
||||
xdelta patch "${PATCH}" || exit 1
|
||||
|
||||
if [ "${PKG_KEEP_WORKING}" = 'no' ]; then
|
||||
log_very_verbose "Removing old files ${PATCH} ${PATCH_OLD_VERSION_TAR}"
|
||||
rm "${PATCH}" "${PATCH_OLD_VERSION_TAR}"
|
||||
fi
|
||||
done
|
||||
|
||||
pkg_compress
|
||||
}
|
||||
|
||||
pkg_compress() {
|
||||
local NEW_FILE_TAR="${NEW_FILE_NAME}${NEW_FILE_PREFIX}${NEW_FILE_VERSION}${NEW_FILE_SUFFIX}.tar"
|
||||
|
||||
print_count 'Compressing patched source archive.'
|
||||
|
||||
case ${NEW_FILE_EXT} in
|
||||
.tar.gz) gzip -9 "${NEW_FILE_TAR}" ;;
|
||||
.tar.bz2) bzip2 -9 "${NEW_FILE_TAR}" ;;
|
||||
.tar.lzma) lzma -9 "${NEW_FILE_TAR}" ;;
|
||||
.tar.lrzip) lrzip -L 9 "${NEW_FILE_TAR}" ;;
|
||||
esac
|
||||
|
||||
pkg_save_new_source
|
||||
}
|
||||
|
||||
pkg_save_new_source() {
|
||||
print_count 'Saving archive.'
|
||||
log_very_verbose "Moving ${NEW_FILE} to $PKGMK_SOURCE_DIR/"
|
||||
mv "${NEW_FILE}" "$PKGMK_SOURCE_DIR/"
|
||||
cd - > /dev/null
|
||||
|
||||
if [ "${PKG_KEEP_WORKING}" = 'no' ]; then
|
||||
rmdir "$PKGMK_WORK_DIR"
|
||||
fi
|
||||
|
||||
pkgmk -um
|
||||
|
||||
# prevent a loop
|
||||
exit 0
|
||||
|
||||
#print_info 'Done'
|
||||
}
|
||||
|
||||
main() {
|
||||
pkg_portcheck
|
||||
|
||||
for FILE in ${source[@]}; do
|
||||
|
||||
# don't try to patch local files
|
||||
if [ -n "$(printf "${FILE}" | egrep '^.*://.*')" ]; then
|
||||
|
||||
explode_filename_new "${NEW_FILE_NAME}" "${NEW_FILE_VERSION}" \
|
||||
"$(get_basename "${FILE}")"
|
||||
|
||||
explode_filename_old "${OLD_FILE_NAME}" "${NEW_FILE_VERSION}" \
|
||||
"$(get_basename "${FILE}")" #FIXME is set to new
|
||||
|
||||
PKG_COUNT='1'
|
||||
pkg_checks
|
||||
pkg_work_dir
|
||||
pkg_parse_local_list
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
check_file_missing 'Pkgfile'
|
||||
if [ "${RETURN}" = 1 ]; then
|
||||
print_error "Missing file './Pkgfile'."
|
||||
else
|
||||
. ./Pkgfile
|
||||
fi
|
||||
|
||||
check_file_missing '/etc/pkgmk.conf'
|
||||
if [ "${RETURN}" = 1 ]; then
|
||||
print_error "Missing file '/etc/pkgmk.conf'."
|
||||
else
|
||||
. /etc/pkgmk.conf
|
||||
fi
|
||||
|
||||
[ -z "${PKGMK_WORK_DIR}" ] && PKGMK_WORK_DIR="$PWD/work"
|
||||
[ -z "${PKGMK_SOURCE_DIR}" ] && PKGMK_SOURCE_DIR="$PWD"
|
||||
|
||||
[ -z "${sname}" ] && sname="${name}"
|
||||
[ -z "${OLD_FILE_NAME}" ] && OLD_FILE_NAME="$sname"
|
||||
[ -z "${NEW_FILE_VERSION}" ] && NEW_FILE_VERSION="$version"
|
||||
[ -z "${NEW_FILE_NAME}" ] && NEW_FILE_NAME="$sname"
|
||||
[ -z "${OLD_FILE_PREFIX}" ] && OLD_FILE_PREFIX="${NEW_FILE_PREFIX}"
|
||||
[ -z "${OLD_FILE_SUFFIX}" ] && OLD_FILE_SUFFIX="${NEW_FILE_SUFFIX}"
|
||||
[ -z "${OLD_FILE_EXT}" ] && OLD_FILE_EXT="${NEW_FILE_EXT}"
|
||||
|
||||
# if diff is set overide the default
|
||||
[ -n "${diff}" ] && PKG_DIFF_MIRRORS="${diff}"
|
||||
|
||||
# list of servers to download from
|
||||
if [ -z "${PKG_DIFF_MIRRORS}" ]; then
|
||||
PKG_DIFF_MIRRORS="
|
||||
http://nanonyme.dy.fi/mirrors/hvl/distfiles/$name/
|
||||
http://www.dcaf-security.org/distfiles/$name/
|
||||
http://shortcircuit.net.au/~romster/distfiles/$name/
|
||||
http://nanonyme.dy.fi/mirrors/hvl/distfiles/$name/
|
||||
"
|
||||
fi
|
||||
|
||||
[ -z "${LOG_DEBUG}" ] && LOG_DEBUG='no'
|
||||
[ -z "${PKG_LOG_VERY_VERBOSE}" ] && PKG_LOG_VERY_VERBOSE='no'
|
||||
[ -z "${PKG_PRINT_COUNT}" ] && PKG_PRINT_COUNT='yes'
|
||||
|
||||
[ -z "${PKG_KEEP_WORKING}" ] && PKG_KEEP_WORKING='no'
|
||||
|
||||
readonly PKG_LOG_VERBOSE_TOTAL_COUNT=3
|
||||
|
||||
main "$@"
|
||||
|
||||
# End of file
|
@ -1,49 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
. Pkgfile
|
||||
. /etc/pkgmk.conf
|
||||
OLD_VERSION='1.4.6'
|
||||
|
||||
[ -z "$PKGMK_WORK_DIR" ] && PKGMK_WORK_DIR="$PWD/work"
|
||||
[ -z "$PKGMK_SOURCE_DIR" ] && PKGMK_SOURCE_DIR="$PWD"
|
||||
|
||||
if [ -e "$PKGMK_SOURCE_DIR/wesnoth-$version.tar.bz2" ]; then
|
||||
echo 'You have the latest source file.'
|
||||
exit
|
||||
fi
|
||||
|
||||
if [ -n "`pkginfo -i | egrep '^xdelta '`" ]; then
|
||||
if [ -e "$PKGMK_SOURCE_DIR/wesnoth-$OLD_VERSION.tar.bz2" ]; then
|
||||
|
||||
if [ ! -e "$PKGMK_WORK_DIR" ]; then
|
||||
mkdir -p "$PKGMK_WORK_DIR"
|
||||
fi
|
||||
cd "$PKGMK_WORK_DIR"
|
||||
|
||||
if [ ! -e "$PKGMK_SOURCE_DIR/wesnoth-$OLD_VERSION.tar-wesnoth-$version.tar.xdelta" ]; then
|
||||
wget http://optusnet.dl.sourceforge.net/sourceforge/wesnoth/wesnoth-$OLD_VERSION.tar-wesnoth-$version.tar.xdelta --directory-prefix=$PKGMK_SOURCE_DIR
|
||||
fi
|
||||
|
||||
cp $PKGMK_SOURCE_DIR/wesnoth-$OLD_VERSION.tar.bz2 .
|
||||
cp $PKGMK_SOURCE_DIR/wesnoth-$OLD_VERSION.tar-wesnoth-$version.tar.xdelta .
|
||||
echo -n '[ 33%] Decompressing source, '
|
||||
bzip2 -d wesnoth-$OLD_VERSION.tar.bz2
|
||||
echo 'done.'
|
||||
echo -n '[ 66%] Patching source, '
|
||||
xdelta patch wesnoth-$OLD_VERSION.tar-wesnoth-$version.tar.xdelta
|
||||
rm wesnoth-$OLD_VERSION.tar
|
||||
mv wesnoth-$OLD_VERSION.tar-wesnoth-$version.tar.xdelta $PKGMK_SOURCE_DIR/
|
||||
echo 'done.'
|
||||
echo -n '[100%] Compressing patched source, '
|
||||
bzip2 -9 wesnoth-$version.tar
|
||||
echo 'done.'
|
||||
mv wesnoth-$version.tar.bz2 $PKGMK_SOURCE_DIR/
|
||||
else
|
||||
echo "'wesnoth-$OLD_VERSION.tar.bz2' not found proceed to run Pkgfile."
|
||||
exit
|
||||
fi
|
||||
else
|
||||
echo "Warning: 'xdelta' is not installed can not do a incremental update."
|
||||
fi
|
||||
|
||||
# End of file
|
Loading…
x
Reference in New Issue
Block a user