- 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
This commit is contained in:
@@ -16,7 +16,7 @@ builder_config() {
|
||||
|
||||
# project dependent configuration
|
||||
local config=${PRODUCT_DIR}/builder-product.cfg
|
||||
test -f ${config} || builder_check_error "can't read product config: ${config}"
|
||||
test -f ${config} || builder_check_error "cannot read product config: ${config}"
|
||||
. ${config}
|
||||
|
||||
# set default build configuration and source the user dependent file
|
||||
@@ -49,6 +49,11 @@ builder_config() {
|
||||
echo "configuration error: OPSI_REPOS_BASE_DIR directory does not exist: $OPSI_REPOS_BASE_DIR"
|
||||
exit 2
|
||||
fi
|
||||
|
||||
if [ "$TYPE" != "public" ] && [ "$TYPE" != "restrict" ] ; then
|
||||
fatal_error "unknown TYPE: $TYPE"
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
#####################
|
||||
@@ -81,10 +86,10 @@ builder_prepare() {
|
||||
####################
|
||||
builder_retrieve() {
|
||||
|
||||
for (( i = 0 ; i < ${#SOURCE[@]} ; i++ )) ; do
|
||||
local basename=${FILE[$i]}
|
||||
local urls=${SOURCE[$i]}
|
||||
local arch=${ARCH[$i]}
|
||||
for (( i = 0 ; i < ${#DL_SOURCE[@]} ; i++ )) ; do
|
||||
local basename=${DL_FILE[$i]}
|
||||
local urls=${DL_SOURCE[$i]}
|
||||
local arch=${DL_ARCH[$i]}
|
||||
local downloaded=0
|
||||
|
||||
# Add private repos to the urls
|
||||
@@ -102,19 +107,22 @@ builder_retrieve() {
|
||||
|
||||
echo "Downloading $basename"
|
||||
# check downloading from the defined URLs
|
||||
for src in `echo $urls | sed -e 's/;/\n/g'` ; do
|
||||
for src in `echo $urls | sed -e 's/[;,]/\n/g'` ; do
|
||||
if [ $downloaded == 1 ]; then continue; fi
|
||||
|
||||
echo " Info: Downloding from $src"
|
||||
local downloader=${DL_DOWNLOADER[$i]}
|
||||
if [ -z $downloader ]; then downloader="wget" ; fi
|
||||
|
||||
mkdir -p ${DIST_CACHE_DIR}/$arch
|
||||
DIST_FILE[$i]=${DIST_CACHE_DIR}/$arch/$basename
|
||||
retrieve_file $src ${DIST_FILE[$i]}
|
||||
DL_DIST_FILE[$i]=${DIST_CACHE_DIR}/$arch/$basename
|
||||
retrieve_file $downloader $src ${DL_DIST_FILE[$i]}
|
||||
|
||||
if [ $? == 0 ] ; then
|
||||
# testing the checksum of the downloaded files
|
||||
SHA1SUM=`cat ${PRODUCT_DIR}/${basename}.sha1sum | cut -d " " -f1`
|
||||
CHECKSUM=`sha1sum ${DIST_FILE[$i]} | cut -d " " -f1`
|
||||
if [ "$CHECKSUM" == "$SHA1SUM" ] ; then
|
||||
local sha1sum_val=`cat ${PRODUCT_DIR}/${basename}.sha1sum | cut -d " " -f1`
|
||||
local checksum_val=`sha1sum ${DL_DIST_FILE[$i]} | cut -d " " -f1`
|
||||
if [ "$checksum_val" == "$sha1sum_val" ] ; then
|
||||
downloaded=1
|
||||
echo " Info: Downloaded successfully"
|
||||
else
|
||||
@@ -146,51 +154,24 @@ builder_create() {
|
||||
find $INST_DIR/CLIENT_DATA -type f | xargs -n1 -iREP sh -c 'file -i $0 | grep "text/plain" && unix2dos $0' REP
|
||||
|
||||
# converting icon file
|
||||
local iconfile_src=${DIST_FILE[$ICON_FILE_INDEX]}
|
||||
local iconfile_src=${DL_DIST_FILE[$ICON_DL_INDEX]}
|
||||
ICONFILE=$OUTPUT_DIR/$PN.png
|
||||
convert_image $iconfile_src $ICONFILE
|
||||
cp -a $ICONFILE $INST_DIR/CLIENT_DATA
|
||||
|
||||
# copy binaries
|
||||
for (( i = 0 ; i < ${#SOURCE[@]} ; i++ )) ; do
|
||||
distfile=${DIST_FILE[$i]}
|
||||
if [ ! -z "${INSTALL[$i]}" ] ; then
|
||||
mkdir -p $INST_DIR/CLIENT_DATA/${ARCH[$i]}/${EXTRACTTO[$i]}
|
||||
extract_file ${DIST_FILE[$i]} $INST_DIR/CLIENT_DATA/${ARCH[$i]}/${EXTRACTTO[$i]}
|
||||
else
|
||||
mkdir -p $INST_DIR/CLIENT_DATA/${ARCH[$i]}
|
||||
cp ${DIST_FILE[$i]} $INST_DIR/CLIENT_DATA/${ARCH[$i]}
|
||||
fi
|
||||
for (( i = 0 ; i < ${#DL_SOURCE[@]} ; i++ )) ; do
|
||||
DL_EXTRACT_PATH[$i]=${INST_DIR}/CLIENT_DATA/${DL_ARCH[$i]}/${DL_EXTRACT_TO[$i]}
|
||||
local format=${DL_EXTRACT_FORMAT[$i]}
|
||||
if [ -z "$format" ] ; then format="cp"; fi
|
||||
|
||||
mkdir -p ${DL_EXTRACT_PATH[$i]}
|
||||
process_file $format ${DL_DIST_FILE[$i]} ${DL_EXTRACT_PATH[$i]}
|
||||
done
|
||||
|
||||
# create variables
|
||||
local var_file=$OUTPUT_DIR/variable.ins
|
||||
echo -n >$var_file
|
||||
for (( i = 0 ; i < ${#SOURCE[@]} ; i++ )) ; do
|
||||
if [ -z ${WINST[$i]} ] ; then continue ; fi
|
||||
if [ ! -z "${ARCH[$i]}" ] ; then arch_str="${ARCH[$i]}\\" ; fi
|
||||
if [ ! -z "${EXTRACTTO[$i]}" ] ; then extractto_str="${EXTRACTTO[$i]}\\" ; fi
|
||||
if [ ! $i -eq $ICON_FILE_INDEX ] ; then
|
||||
echo "DefVar \$${WINST[$i]}\$" >>$var_file
|
||||
if [ ! -z "${INSTALL[$i]}" ] ; then
|
||||
echo "Set \$${WINST[$i]}\$ = \"%ScriptPath%\\$arch_str$extractto_str${INSTALL[$i]}\"" >>$var_file
|
||||
else
|
||||
echo "Set \$${WINST[$i]}\$ = \"%ScriptPath%\\$arch_str${FILE[$i]}\"" >>$var_file
|
||||
fi
|
||||
fi
|
||||
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
|
||||
|
||||
echo >>$var_file
|
||||
# create winst variables
|
||||
local var_file=${OUTPUT_DIR}/variable.ins
|
||||
create_winst_varfile $var_file
|
||||
|
||||
# add the new vaiables to all *.ins winst files
|
||||
for inst_file in `find ${INST_DIR}/CLIENT_DATA -type f -name "*.ins"` ; do
|
||||
@@ -200,7 +181,7 @@ builder_create() {
|
||||
}" $inst_file
|
||||
done
|
||||
|
||||
# replace variables from OPSI control
|
||||
# replace variables from file OPSI/control
|
||||
local release_new=${CREATOR_TAG}${RELEASE}
|
||||
sed -e "s!VERSION!$VERSION!g" -e "s!RELEASE!${release_new}!g" -e "s!PRIORITY!$PRIORITY!g" -e "s!ADVICE!$ADVICE!g" ${PRODUCT_DIR}/OPSI/control >$INST_DIR/OPSI/control
|
||||
|
||||
@@ -226,6 +207,7 @@ builder_package() {
|
||||
# creating package
|
||||
local release_new=${CREATOR_TAG}${RELEASE}
|
||||
local opsi_file=${PN}_${VERSION}-${release_new}.opsi
|
||||
|
||||
pushd ${OUTPUT_DIR}
|
||||
rm -f ${opsi_file} ${OPSI_REPOS_FILE_PATTERN}.opsi
|
||||
LANG="C" opsi-makeproductfile -v $INST_DIR
|
||||
@@ -240,10 +222,9 @@ builder_package() {
|
||||
|
||||
# create source package
|
||||
zip -r ${OUTPUT_DIR}/${OPSI_REPOS_FILE_PATTERN}.zip $INST_DIR
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
#####################
|
||||
# publish
|
||||
#####################
|
||||
@@ -268,7 +249,7 @@ builder_publish() {
|
||||
builder_commit() {
|
||||
if [ -d "${PRODUCT_DIR}/.git" ]; then
|
||||
echo -n
|
||||
# echo "builder_commit() not implemented yet."
|
||||
log_debug "builder_commit() not implemented yet."
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
@@ -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() {
|
||||
|
||||
if [ "${EXTRACTWITH}" = "7zip" ]; then
|
||||
local format=$1
|
||||
local src=$2
|
||||
local dst=$3
|
||||
|
||||
log_debug "Compression format: $format"
|
||||
|
||||
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
|
||||
|
||||
@@ -85,6 +112,17 @@ log_debug() {
|
||||
fi
|
||||
}
|
||||
|
||||
###################
|
||||
# Logging Info
|
||||
###################
|
||||
log_info() {
|
||||
local str=$1
|
||||
|
||||
if [ "$DEBUG_LEVEL" = "info" ] ; then
|
||||
echo $str
|
||||
fi
|
||||
}
|
||||
|
||||
###################
|
||||
# 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"
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
###################
|
||||
# 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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user