summaryrefslogtreecommitdiff
path: root/lib/builder-utils.sh
diff options
context:
space:
mode:
authorDaniel Schwager <[email protected]>2012-01-30 22:07:08 (GMT)
committer Daniel Schwager <[email protected]>2012-01-30 22:07:08 (GMT)
commite9754434bb0eca9750d84059b1aac41525468da1 (patch)
treeda0907394a52ce5a140f45d82737c41027278795 /lib/builder-utils.sh
parent976d2a3ec93e5b384b9b1a8d29c76ebf750ce7f9 (diff)
- New: added semantic check of variable "TYPE"
- Improved: Added prefix "DL_" to all attributes of the file-array (SOURCE[], FILE[], ..) - Improved: refactored variable creation and moved code to builder-utils.sh - New: Added DIST_FORCE_DOWNLOAD variable to select wget or plowdown - Improvement: refactored code - New: Added log_info() and log_debug() functions - New: Added new array WINST_* (builder-product.cfg) to defined custom winst variables
Diffstat (limited to 'lib/builder-utils.sh')
-rw-r--r--lib/builder-utils.sh122
1 files changed, 107 insertions, 15 deletions
diff --git a/lib/builder-utils.sh b/lib/builder-utils.sh
index b7d5477..996a6f7 100644
--- a/lib/builder-utils.sh
+++ b/lib/builder-utils.sh
@@ -4,13 +4,15 @@
# 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 src=$1
- local dst=$2
+ 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
@@ -20,30 +22,46 @@ function retrieve_file() {
cp $fileurl $dst 2>/dev/null
else
rm -f $dst
- wget --tries=1 -O $dst --timeout=5 -q --no-verbose $src
+ if [ "$downloader" = "wget" ]; then
+ wget --tries=1 -O $dst --timeout=5 -q --no-verbose "$src"
+ if [ "$?" == "1" ] ; then
+ rm $dst
+ fi
+ elif [ "$downloader" = "plowdown" ]; then
+ fatal_error "plowdown not implemented yet"
+ else
+ fatal_error "Downloader not implemented: $downloader"
+ fi
fi
}
#############################################
-# void extract_file (src, dst)
+# 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 src=$1
- local dst=$2
+function process_file() {
+
+ local format=$1
+ local src=$2
+ local dst=$3
+
+ log_debug "Compression format: $format"
- if [ "${EXTRACTWITH}" = "7zip" ]; then
+ if [ "$format" = "cp" ]; then
+ cp $src $dst
+ elif [ "$format" = "7zip" ]; then
7z x -o$dst $src
- elif [ "${EXTRACTWITH}" = "unzip" ]; then
+ elif [ "$format}" = "unzip" ]; then
unzip $src -d $dst
else
- 7z x -o$dst $src
+ fatal_error "Unknown compression format: $format"
fi
}
@@ -66,17 +84,26 @@ function call_entry_point() {
}
+###################
+# Fata Error
+###################
+fatal_error() {
+ echo "FATAL: $1"
+ exit 0
+}
###################
# Check error
###################
builder_check_error() {
- if [ $? == 1 ] ; then
- echo "FATAL: $1"
- exit 0
+ if [ "$?" == "1" ] ; then
+ fatal_error "$1"
fi
}
+###################
+# Logging Debug
+###################
log_debug() {
local str=$1
@@ -86,6 +113,17 @@ log_debug() {
}
###################
+# Logging Info
+###################
+log_info() {
+ local str=$1
+
+ if [ "$DEBUG_LEVEL" = "info" ] ; then
+ echo $str
+ fi
+}
+
+###################
# Convert image
###################
convert_image() {
@@ -119,7 +157,7 @@ convert_image() {
else
# Imagemagic is unable to detect the aspect ratio so just force 160x160
# this could result in streched images
- log_debug "Icon Wight: $wight Hight: $hight"
+ log_debug "Icon Wight: $wight unknown Hight: $hight"
convert $src -transparent white -background transparent -resize 160x160 \
xc:transparent +swap -gravity center -composite $dst
builder_check_error "converting image"
@@ -131,4 +169,58 @@ convert_image() {
wight=`identify -format "%w" $dst`
log_debug "Opsi Icon Wight: $wight Hight: $hight"
-} \ No newline at end of file
+}
+
+
+###################
+# Create variable file
+#
+# Create a file containing all important winst variables
+# (declaration and setings)
+#
+# Parameter
+# file: file to create
+#
+###################
+create_winst_varfile() {
+ local var_file=$1
+
+ echo -n >$var_file
+ for (( i = 0 ; i < ${#DL_SOURCE[@]} ; i++ )) ; do
+ if [ -z ${DL_WINST_NAME[$i]} ] ; then continue ; fi
+
+ if [ ! -z "${DL_ARCH[$i]}" ] ; then arch_str="${DL_ARCH[$i]}\\" ; fi
+ echo "DefVar \$${DL_WINST_NAME[$i]}\$" >>$var_file
+ echo "Set \$${DL_WINST_NAME[$i]}\$ = \"%ScriptPath%\\${arch_str}${DL_FILE[$i]}\"" >>$var_file
+ done
+
+ # publish some other variables
+ for var in VENDOR PN VERSION RELEASE PRIORITY ADVICE TYPE CREATOR_TAG CREATOR_NAME CREATOR_EMAIL ; do
+ echo "DefVar \$${var}\$" >>$var_file
+ echo "Set \$${var}\$ = \"${!var}\"" >>$var_file
+ done
+
+ # copy image and create variable
+ echo "DefVar \$IconFile\$" >>$var_file
+ echo "Set \$IconFile\$ = \"%ScriptPath%\\`basename $ICONFILE`\"" >>$var_file
+
+ # publish custom variables
+ for (( i = 0 ; i < ${#WINST_NAME[@]} ; i++ )) ; do
+
+ # replace DL_EXTRACT_WINST_PATH
+ local index=`echo ${WINST_VALUE[$i]} | sed -e "s#.*@DL_EXTRACT_WINST_PATH\[\([0-9]\)\]@.*#\1#"`
+ log_debug "calculated (DL_EXTRACT_WINST_PATH), Index: $index"
+ if [ "$index" != "${WINST_VALUE[$i]}" ] ; then
+ if [ ! -z "${DL_ARCH[$index]}" ] ; then arch_part="\\\\${DL_ARCH[$index]}" ; fi
+ if [ ! -z "${DL_EXTRACT_WINST_PATH[$index]}" ] ; then extr_part="\\\\${DL_EXTRACT_WINST_PATH[$index]}" ; fi
+ local new_val="%ScriptPath%$arch_part$extr_part"
+ WINST_VALUE[$i]=`echo ${WINST_VALUE[$i]} | sed -e "s#@DL_EXTRACT_WINST_PATH\[[0-9]\]@#$new_val#"`
+ log_debug "calculated (DL_EXTRACT_WINST_PATH) WINST_VALUE: ${WINST_VALUE[$i]}"
+ fi
+
+ echo "DefVar \$${WINST_NAME[$i]}\$" >>$var_file
+ echo "Set \$${WINST_NAME[$i]}\$ = \"${WINST_VALUE[$i]}\"" >>$var_file
+ done
+
+ echo >>$var_file
+}

Powered by Domaintechnik.at | Hosting - Domain - Webspace