362 lines
9.0 KiB
Bash
362 lines
9.0 KiB
Bash
|
|
#############################################
|
|
# void retrieve_file (src, dst)
|
|
#
|
|
# Description: retrieve file from an URL
|
|
#
|
|
# Parameter
|
|
# downloader: program to download the files
|
|
# src: source url to get file from
|
|
# dst: path to store file to
|
|
#
|
|
#############################################
|
|
function retrieve_file() {
|
|
local downloader=$1
|
|
local src=$2
|
|
local dst=$3
|
|
|
|
# Check, if the URL is a file URL starting with file://
|
|
if [ -f $dst ] && [ -z ${DIST_FORCE_DOWNLOAD} ]; then
|
|
echo " Info: File still cached/downloaded. To force a download, set DIST_FORCE_DOWNLOAD=1"
|
|
elif [[ $src == file://* ]]; then
|
|
fileurl=`echo $src | sed "s/^file:\/\///"`
|
|
cp $fileurl $dst 2>/dev/null
|
|
else
|
|
rm -f $dst
|
|
if [ "$downloader" = "wget" ]; then
|
|
wget --no-check-certificate --tries=1 -O $dst --timeout=5 -q --no-verbose "$src"
|
|
if [ "$?" == "1" ] ; then
|
|
rm $dst
|
|
fi
|
|
elif [ "$downloader" = "plowdown" ]; then
|
|
plowdown --max-retries=1 -o ${dst%/*} "$src"
|
|
elif [ "$downloader" = "aria2c" ]; then
|
|
#aria2c --seed-time=0 -d ${dst%/*} -o ${dst##*/} "$src"
|
|
aria2c --seed-time=0 --allow-overwrite=true -o ${dst##*/} "$src"
|
|
mv -f ${dst##*/} ${dst%/*}
|
|
else
|
|
fatal_error "Downloader not implemented: $downloader"
|
|
fi
|
|
fi
|
|
}
|
|
|
|
#############################################
|
|
# void extract_file (format, src, dst)
|
|
#
|
|
# Description: Extract a file
|
|
#
|
|
# Parameter
|
|
# format: compression format
|
|
# src: source file to be used
|
|
# dst: path to extract the file
|
|
#
|
|
#############################################
|
|
function process_file() {
|
|
|
|
local format=$1
|
|
local src=$2
|
|
local dst=$3
|
|
local option=$4
|
|
|
|
log_debug "Compression format: $format"
|
|
|
|
if [ "$format" = "cp" ]; then
|
|
cp $src $dst
|
|
elif [ "$format" = "7zip" ]; then
|
|
$CMD_7z x -y $option -o$dst $src
|
|
elif [ "$format" = "unzip" ]; then
|
|
$CMD_unzip $option -o $src -d $dst
|
|
elif [ "$format" = "unrar" ]; then
|
|
$CMD_unrar x -y $option $src $dst
|
|
elif [ "$format" = "targz" ]; then
|
|
$CMD_tar xzvf $option $src -C $dst
|
|
elif [ "$format" = "tarbz2" ]; then
|
|
$CMD_tar xjvf $option $src -C $dst
|
|
elif [ "$format" = "cab" ]; then
|
|
$CMD_cabextract $option -d $dst $src
|
|
else
|
|
fatal_error "Unknown compression format: $format"
|
|
fi
|
|
}
|
|
|
|
|
|
#############################################
|
|
# check if method is available and call it
|
|
#############################################
|
|
function call_entry_point() {
|
|
local _resultvar=$1
|
|
local func=$2
|
|
|
|
# Entry point
|
|
type $func &>/dev/null
|
|
if [ $? == 0 ] ; then
|
|
$func
|
|
eval $_resultvar="0"
|
|
else
|
|
eval $_resultvar="1"
|
|
fi
|
|
|
|
}
|
|
|
|
###################
|
|
# Fata Error
|
|
###################
|
|
fatal_error() {
|
|
echo "FATAL: $1"
|
|
exit 1
|
|
}
|
|
|
|
###################
|
|
# Check error
|
|
###################
|
|
builder_check_error() {
|
|
if [ "$?" == "1" ] ; then
|
|
fatal_error "$1"
|
|
fi
|
|
}
|
|
|
|
###################
|
|
# Logging Debug
|
|
###################
|
|
log_debug() {
|
|
local str=$1
|
|
|
|
if [ "$DEBUG_LEVEL" = "debug" ] || [ "$DEBUG_LEVEL" = "info" ] ; then
|
|
echo $str
|
|
fi
|
|
}
|
|
|
|
###################
|
|
# Logging Info
|
|
###################
|
|
log_info() {
|
|
local str=$1
|
|
|
|
if [ "$DEBUG_LEVEL" = "info" ] ; then
|
|
echo $str
|
|
fi
|
|
}
|
|
|
|
#####################
|
|
# void calc_release()
|
|
#
|
|
# Description:
|
|
# Calculate new release based on
|
|
# the latest one found in the repository.
|
|
#
|
|
# $RELEASE is set to the calculated release.
|
|
#
|
|
####################
|
|
function calc_release() {
|
|
|
|
# Find all revision files and sort them
|
|
local file_list=`mktemp /tmp/aio-builder.calc_release.XXXXXXXXXXX`
|
|
for cfg_file in `find ${AIO_REPOS_BASE_DIR} -name "${PN}-${VERSION}-${CREATOR_TAG}*.cfg" -print ` ; do
|
|
. ${cfg_file}
|
|
printf "%08d;$cfg_file\n" $REV_RELEASE >> ${file_list}
|
|
done
|
|
local oldest_cfg=`sort -n ${file_list} | cut -f 2 -d ";" | tail -1`
|
|
rm -f ${file_list}
|
|
|
|
if [ ! -f "${oldest_cfg}" ] ; then
|
|
echo "Warning: no cfg-file found for this product. RELEASE will be set to 1"
|
|
RELEASE=1
|
|
else
|
|
log_debug "calc_release() oldest_cfg: ${oldest_cfg}"
|
|
. ${oldest_cfg}
|
|
log_debug " latest release: $REV_RELEASE"
|
|
RELEASE=`expr ${REV_RELEASE} + 1 2> /dev/null`
|
|
builder_check_error "Cannot incrememnt REV_RELEASE from file ${oldest_cfg}"
|
|
fi
|
|
}
|
|
|
|
###################
|
|
# Write Package Ini file
|
|
#
|
|
# Create a ini file containing needed information for package uninstall
|
|
#
|
|
# Parameter
|
|
# file: file to create / modify
|
|
#
|
|
###################
|
|
write_ini_file() {
|
|
local ini_file=$1
|
|
local ini_section=$2
|
|
local ini_option=$3
|
|
local ini_value=$4
|
|
|
|
touch $ini_file
|
|
$CMD_inifile $(cygpath -pw "$ini_file") [$ini_section] $ini_option=$ini_value
|
|
}
|
|
|
|
|
|
###################
|
|
# Get Verison of File
|
|
#
|
|
# Copy file only if it is newer
|
|
#
|
|
# Parameter
|
|
# File: to process
|
|
# Var:
|
|
#
|
|
###################
|
|
# return 0 if program version is equal or greater than check version
|
|
check_version()
|
|
{
|
|
local version=$1 check=$2
|
|
local winner=$(echo -e "$version\n$check" | sed '/^$/d' | sort -Vr | head -1)
|
|
[[ "$winner" = "$version" ]] && return 0
|
|
return 1
|
|
}
|
|
|
|
|
|
###################
|
|
# Get Verison of File
|
|
#
|
|
# Copy file only if it is newer
|
|
#
|
|
# Parameter
|
|
# File: to process
|
|
# Var:
|
|
#
|
|
###################
|
|
|
|
|
|
get_file_ver() {
|
|
local getver_file=$2
|
|
local __resultvar=$1
|
|
# local myresult=`$CMD_showver $(cygpath -pw "$getver_file") | grep FileVersion: | rev | cut -d: -f1 | rev | tr -d ' '`
|
|
local myresult=`cscript //nologo $(cygpath -pw "$BASEDIR/libexec/VersionInfo.vbs") $(cygpath -pw "$getver_file") | tr -d '\r' | tr -d '\n'`
|
|
local mydate=`date -r $getver_file +%Y.%m.%d.%M`
|
|
if [ "x$myresult" = "x" ] ; then
|
|
echo "$getver_file -> $mydate"
|
|
eval $__resultvar="'$mydate'"
|
|
else
|
|
echo "$getver_file -> $myresult"
|
|
eval $__resultvar="'$myresult'"
|
|
fi
|
|
}
|
|
|
|
###################
|
|
# Copy Verison
|
|
#
|
|
# Copy file only if it is newer
|
|
#
|
|
# Parameter
|
|
# source: sourcefiel
|
|
# target: Targetfile
|
|
#
|
|
###################
|
|
copyver() {
|
|
local source_file=$1
|
|
local target_file=$2
|
|
local source_ver="0.0.0.0"
|
|
local target_ver="0.0.0.0"
|
|
|
|
echo "Source File: $source_file Target Version: $target_file"
|
|
if [ -f "$source_file" ] && [ -f "$target_file" ] ; then
|
|
get_file_ver source_ver $source_file
|
|
get_file_ver target_ver $target_file
|
|
if check_version $source_ver $target_ver ; then
|
|
echo "Source Verssion: $source_ver > Target Version: $target_ver"
|
|
echo "Copying File"
|
|
cp -a $source_file $target_file
|
|
else
|
|
echo "Source Verssion: $source_ver =< Target Version: $target_ver"
|
|
echo "Not Copying File"
|
|
fi
|
|
elif [ -f "$source_file" ] && [ ! -f "$target_file" ] ; then
|
|
get_file_ver source_ver $source_file
|
|
echo "Source Verssion: $source_ver"
|
|
echo "Copying File"
|
|
cp -a $source_file $target_file
|
|
else
|
|
echo "Nothing to copy"
|
|
fi
|
|
}
|
|
|
|
###################
|
|
# Tidy xml
|
|
#
|
|
# Tidy XML files (mainly Sereby package.xml)
|
|
#
|
|
# Parameter
|
|
# source: sourcefiel
|
|
# target: Targetfile
|
|
#
|
|
###################
|
|
tidy_xml() {
|
|
local source_file=$1
|
|
local target_file=$2
|
|
|
|
cat $source_file | $CMD_tidy -utf8 -xml -w 255 -i -c -q -asxml | sed -e 's!>!>!g' -e 's!<!<!g' > $target_file
|
|
}
|
|
|
|
#############################################
|
|
# void extract_file (format, src, dst)
|
|
#
|
|
# Description: Extract a file
|
|
#
|
|
# Parameter
|
|
# format: compression format
|
|
# src: source file to be used
|
|
# dst: path to extract the file
|
|
#
|
|
#############################################
|
|
function extract_file() {
|
|
|
|
local format=$1
|
|
local src=$2
|
|
local dst=$3
|
|
local option=$4
|
|
local src_dir=`dirname "$src"`
|
|
local src_file=`basename "$src"`
|
|
local dst_dir=`dirname "$dst"`
|
|
local dst_file=`basename "$dst"`
|
|
|
|
log_debug "Compression format: $format"
|
|
|
|
mkdir -p $dst
|
|
if [ "$format" = "msi-a" ]; then
|
|
mkdir /cygdrive/c/msi-adm
|
|
pushd $src_dir
|
|
echo $src_file
|
|
$CMD_msiexec /a "$src_file" $option TARGETDIR="c:\msi-adm"
|
|
popd
|
|
cp -r /cygdrive/c/msi-adm/* $dst
|
|
rm -rf /cygdrive/c/msi-adm
|
|
elif [ "$format" = "msp-a" ]; then
|
|
pushd $dst_dir
|
|
cp $src $dst_dir
|
|
$CMD_msiexec /p "$src_file" /a "$dst_file" SHORTFILENAMES=TRUE /qb
|
|
popd
|
|
elif [ "$format" = "msp-x" ]; then
|
|
$CMD_msix $(cygpath -pw "$src") /out $(cygpath -pw "$dst")
|
|
elif [ "$format" = "7zip" ]; then
|
|
$CMD_7z x -y $option -o$dst $src
|
|
elif [ "$format" = "unzip" ]; then
|
|
$CMD_unzip $option -o $src -d $dst
|
|
elif [ "$format" = "unrar" ]; then
|
|
$CMD_unrar x -y $option $(cygpath -pw "$src") $(cygpath -pw "$dst")
|
|
elif [ "$format" = "cab" ]; then
|
|
$CMD_cabextract $option -d $dst $src
|
|
elif [ "$format" = "cab-sfx" ]; then
|
|
$CMD_cabextract $option -d $dst $src
|
|
$CMD_xmlstarlet sel -N X="http://schemas.microsoft.com/wix/2008/Burn" -t -m "//X:Payload" -v "concat(@SourcePath,'-',@FilePath)" -n $dst/0 | tr '\\' '/' > $dst/rename.list
|
|
for i in `cat $dst/rename.list`
|
|
do
|
|
pushd $dst
|
|
local src_var=$(echo $i | cut -f1 -d-)
|
|
local dst_var=$(echo $i | cut -f2 -d-)
|
|
mkdir -p $(dirname $dst_var)
|
|
mv -v $src_var $dst_var
|
|
popd
|
|
done
|
|
elif [ "$format" = "inno" ]; then
|
|
$CMD_innounp -x -d"$(cygpath -pw "$dst")" "$(cygpath -pw "$src")"
|
|
else
|
|
fatal_error "Unknown compression format: $format"
|
|
fi
|
|
}
|
|
|