add ini writer support

This commit is contained in:
Mario Fetka 2013-03-07 21:38:36 +01:00
parent a0e29cb0ac
commit 75adc590d0
3 changed files with 579 additions and 550 deletions

View File

@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
# #
# #
# enabled debug # enabled debug
# set -x # set -x
@ -9,31 +9,31 @@
# Controller # Controller
#################### ####################
builder_controller() { builder_controller() {
local result local result
# read config # read config
call_entry_point result config; (( $result == "0" )) || builder_config call_entry_point result config; (( $result == "0" )) || builder_config
# prepare # prepare
call_entry_point result prepare ; (( $result == "0" )) || builder_prepare call_entry_point result prepare ; (( $result == "0" )) || builder_prepare
# download and process dist files # download and process dist files
call_entry_point result retrieve; (( $result == "0" )) || builder_retrieve call_entry_point result retrieve; (( $result == "0" )) || builder_retrieve
# Create some special files # Create some special files
call_entry_point result create; (( $result == "0" )) || builder_create call_entry_point result create; (( $result == "0" )) || builder_create
# Start packaging # Start packaging
call_entry_point result package; (( $result == "0" )) || builder_package call_entry_point result package; (( $result == "0" )) || builder_package
# Upload to repos # Upload to repos
call_entry_point result publish; (( $result == "0" )) || builder_publish call_entry_point result publish; (( $result == "0" )) || builder_publish
# git commit # git commit
call_entry_point result commit; (( $result == "0" )) || builder_commit call_entry_point result commit; (( $result == "0" )) || builder_commit
# cleanup # cleanup
call_entry_point result cleanup; (( $result == "0" )) || builder_cleanup call_entry_point result cleanup; (( $result == "0" )) || builder_cleanup
} }
#################### ####################
@ -58,7 +58,7 @@ builder_check_error "no opsi product directory specified: $PRODUCT_DIR"
# source additional, product dependent callback (cb) targets # source additional, product dependent callback (cb) targets
if [ -f "$PRODUCT_DIR/builder-targets-cb.sh" ] ; then if [ -f "$PRODUCT_DIR/builder-targets-cb.sh" ] ; then
. "$PRODUCT_DIR/builder-targets-cb.sh" . "$PRODUCT_DIR/builder-targets-cb.sh"
fi fi
# call main # call main

View File

@ -9,259 +9,264 @@
# Read config # Read config
#################### ####################
builder_config() { builder_config() {
# Define commands # Define commands
CMD_7z="`which 7z`" ; builder_check_error "Command '7z' not installed" CMD_7z="`which 7z`" ; builder_check_error "Command '7z' not installed"
CMD_unzip="`which unzip`" ; builder_check_error "Command 'unzip' not installed" CMD_unzip="`which unzip`" ; builder_check_error "Command 'unzip' not installed"
CMD_unrar="`which unrar`" ; builder_check_error "Command 'unrar' not installed" CMD_unrar="`which unrar`" ; builder_check_error "Command 'unrar' not installed"
CMD_zip="`which zip`" ; builder_check_error "Command 'zip' not installed" CMD_zip="`which zip`" ; builder_check_error "Command 'zip' not installed"
CMD_lha="`which lha`" ; builder_check_error "Command 'lha' not installed" CMD_lha="`which lha`" ; builder_check_error "Command 'lha' not installed"
CMD_tar="`which tar`" ; builder_check_error "Command 'tar' not installed" CMD_tar="`which tar`" ; builder_check_error "Command 'tar' not installed"
CMD_cabextract="`which cabextract`" ; builder_check_error "Command 'cabextract' not installed" CMD_cabextract="`which cabextract`" ; builder_check_error "Command 'cabextract' not installed"
CMD_unix2dos="`which unix2dos`" ; builder_check_error "Command 'unix2dos' not installed" CMD_unix2dos="`which unix2dos`" ; builder_check_error "Command 'unix2dos' not installed"
CMD_identify="`which identify`" ; builder_check_error "Command 'identify' (ImageMagick) not installed" CMD_identify="`which identify`" ; builder_check_error "Command 'identify' (ImageMagick) not installed"
CMD_zsyncmake="`which zsyncmake`" ; builder_check_error "Command 'zsyncmake' not installed" CMD_zsyncmake="`which zsyncmake`" ; builder_check_error "Command 'zsyncmake' not installed"
CMD_comm="`which comm`" ; builder_check_error "Command 'comm' not installed" CMD_comm="`which comm`" ; builder_check_error "Command 'comm' not installed"
CMD_sha1sum="`which sha1sum`" ; builder_check_error "Command 'sha1sum' not installed" CMD_sha1sum="`which sha1sum`" ; builder_check_error "Command 'sha1sum' not installed"
CMD_iniset="`which ini-set`" ; builder_check_error "Command 'ini-set' (martINI a pypi project) not installed"
# Check temp dir
test -d ${TMP_DIR} # Check temp dir
builder_check_error "temp directory not available: $TMP_DIR" test -d ${TMP_DIR}
builder_check_error "temp directory not available: $TMP_DIR"
# project dependent configuration
local config=${PRODUCT_DIR}/builder-product.cfg # project dependent configuration
test -f ${config} || builder_check_error "cannot read product config: ${config}" local config=${PRODUCT_DIR}/builder-product.cfg
. ${config} test -f ${config} || builder_check_error "cannot read product config: ${config}"
. ${config}
# set default build configuration and source the user dependent file
local config=$BASEDIR/conf/opsi-builder.cfg # set default build configuration and source the user dependent file
. ${config} local config=$BASEDIR/conf/opsi-builder.cfg
. ${config}
# Source local build configuration (must be done AFTER sourcing the builder-product.cfg.cfg)
if [ -f "$OPSI_BUILDER" ] ; then # Source local build configuration (must be done AFTER sourcing the builder-product.cfg.cfg)
config=$OPSI_BUILDER if [ -f "$OPSI_BUILDER" ] ; then
else config=$OPSI_BUILDER
test -f $HOME/.opsi-builder.cfg && config=$HOME/.opsi-builder.cfg else
test -f $HOME/.opsi-builder.cfg && config=$HOME/.opsi-builder.cfg
fi
# Read ONLY the STATUS variable from the build configuration file
eval "`grep -E "^(STATUS|STATUS_INTEGRATION_RELEASE)=" $config`"
# change some variable from the builder-product.cfg dynamically:
# autogenerate release number, if we are in status "integration"
if [ "$STATUS" = "integration" ] ; then
if [ "${STATUS_INTEGRATION_RELEASE}" = "func:inc1" ] ; then
. ${config}
calc_release
else
# OPSI/control:RELEASE is limited to max 16 chars - take care in regards to the CREATOR_TAG
RELEASE="${STATUS_INTEGRATION_RELEASE}"
fi fi
fi
# Read ONLY the STATUS variable from the build configuration file
eval "`grep -E "^(STATUS|STATUS_INTEGRATION_RELEASE)=" $config`" # Read configurationfile
. ${config}
# change some variable from the builder-product.cfg dynamically: echo "Loaded builder configuration: $config"
# autogenerate release number, if we are in status "integration"
if [ "$STATUS" = "integration" ] ; then # Check variables
if [ "${STATUS_INTEGRATION_RELEASE}" = "func:inc1" ] ; then if [ -z ${OPSI_REPOS_BASE_DIR} ] || [ ! -d ${OPSI_REPOS_BASE_DIR} ] ; then
. ${config} echo "configuration error: OPSI_REPOS_BASE_DIR directory does not exist: $OPSI_REPOS_BASE_DIR"
calc_release exit 2
else fi
# OPSI/control:RELEASE is limited to max 16 chars - take care in regards to the CREATOR_TAG
RELEASE="${STATUS_INTEGRATION_RELEASE}" if [ "$TYPE" != "public" ] && [ "$TYPE" != "restricted" ] ; then
fi fatal_error "unknown TYPE: $TYPE"
fi fi
# Read configurationfile # Check, if variable is numeric
. ${config} if [ ! `expr ${OPSI_REPOS_PURGE_LIMIT} + 1 2> /dev/null` ] ; then
echo "Loaded builder configuration: $config" fatal_error "OPSI_REPOS_PURGE_LIMIT must be numeric"
fi
# Check variables
if [ -z ${OPSI_REPOS_BASE_DIR} ] || [ ! -d ${OPSI_REPOS_BASE_DIR} ] ; then
echo "configuration error: OPSI_REPOS_BASE_DIR directory does not exist: $OPSI_REPOS_BASE_DIR"
exit 2
fi
if [ "$TYPE" != "public" ] && [ "$TYPE" != "restricted" ] ; then
fatal_error "unknown TYPE: $TYPE"
fi
# Check, if variable is numeric
if [ ! `expr ${OPSI_REPOS_PURGE_LIMIT} + 1 2> /dev/null` ] ; then
fatal_error "OPSI_REPOS_PURGE_LIMIT must be numeric"
fi
} }
##################### #####################
# Prepare build # Prepare build
#################### ####################
builder_prepare() { builder_prepare() {
echo "builder_prepare: " echo "builder_prepare: "
# Check if the package is still build # Check if the package is still build
if [ "$OPSI_REPOS_FORCE_UPLOAD" != "true" ] && [ -f "${OPSI_REPOS_PRODUCT_DIR}/${OPSI_REPOS_FILE_PATTERN}.opsi" ] ; then if [ "$OPSI_REPOS_FORCE_UPLOAD" != "true" ] && [ -f "${OPSI_REPOS_PRODUCT_DIR}/${OPSI_REPOS_FILE_PATTERN}.opsi" ] ; then
echo "File ${OPSI_REPOS_PRODUCT_DIR}/${OPSI_REPOS_FILE_PATTERN}.opsi already exists." echo "File ${OPSI_REPOS_PRODUCT_DIR}/${OPSI_REPOS_FILE_PATTERN}.opsi already exists."
exit 1 exit 1
fi fi
mkdir -p $DIST_CACHE_DIR mkdir -p $DIST_CACHE_DIR
log_debug "Distribution directory: $DIST_CACHE_DIR" log_debug "Distribution directory: $DIST_CACHE_DIR"
# setup work directory # setup work directory
OUTPUT_DIR="$TMP_DIR/opsi-builder.`date +%Y%m%d-%H%M%S`.$$" OUTPUT_DIR="$TMP_DIR/opsi-builder.`date +%Y%m%d-%H%M%S`.$$"
mkdir -p ${OUTPUT_DIR} mkdir -p ${OUTPUT_DIR}
builder_check_error "Cannot create temp directory ${OUTPUT_DIR}" builder_check_error "Cannot create temp directory ${OUTPUT_DIR}"
# prepare # prepare
INST_DIR=$OUTPUT_DIR/$PN INST_DIR=$OUTPUT_DIR/$PN
mkdir $INST_DIR mkdir $INST_DIR
log_info " OUTPUT_DIR: $OUTPUT_DIR" log_info " OUTPUT_DIR: $OUTPUT_DIR"
} }
##################### #####################
# Download all dist files from one of the defined URLs. # Download all dist files from one of the defined URLs.
# and validate the checksum # and validate the checksum
#################### ####################
builder_retrieve() { builder_retrieve() {
for (( i = 0 ; i < ${#DL_SOURCE[@]} ; i++ )) ; do for (( i = 0 ; i < ${#DL_SOURCE[@]} ; i++ )) ; do
local basename=${DL_FILE[$i]} local basename=${DL_FILE[$i]}
local urls=${DL_SOURCE[$i]} local urls=${DL_SOURCE[$i]}
local arch=${DL_ARCH[$i]} local arch=${DL_ARCH[$i]}
local downloaded=0 local downloaded=0
# Add private repos to the urls # Add private repos to the urls
if [ ! -z ${DIST_PRIVATE_REPOS} ]; then if [ ! -z ${DIST_PRIVATE_REPOS} ]; then
urls="${DIST_PRIVATE_REPOS}/$basename;$urls" urls="${DIST_PRIVATE_REPOS}/$basename;$urls"
fi fi
# check existence of CRC file only in non devel mode # check existence of CRC file only in non devel mode
if [ ! -e "${PRODUCT_DIR}/${basename}.sha1sum" ] && [ "$CHECKSUM_AUTOCREATE" != "true" ] ; then if [ ! -e "${PRODUCT_DIR}/${basename}.sha1sum" ] && [ "$CHECKSUM_AUTOCREATE" != "true" ] ; then
fatal_error "You need to create the checksums with: sha1sum ${DIST_CACHE_DIR}/${basename} > ${PRODUCT_DIR}/${basename}.sha1sum" fatal_error "You need to create the checksums with: sha1sum ${DIST_CACHE_DIR}/${basename} > ${PRODUCT_DIR}/${basename}.sha1sum"
fi fi
echo "Downloading $basename" echo "Downloading $basename"
# check downloading from the defined URLs # 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 if [ $downloaded == 1 ]; then continue; fi
# Download file # Download file
echo " Info: Downloding from $src" echo " Info: Downloding from $src"
local downloader=${DL_DOWNLOADER[$i]} local downloader=${DL_DOWNLOADER[$i]}
if [ -z $downloader ]; then downloader="wget" ; fi if [ -z $downloader ]; then downloader="wget" ; fi
mkdir -p ${DIST_CACHE_DIR}/$arch mkdir -p ${DIST_CACHE_DIR}/$arch
DL_DIST_FILE[$i]=${DIST_CACHE_DIR}/$arch/$basename DL_DIST_FILE[$i]=${DIST_CACHE_DIR}/$arch/$basename
retrieve_file $downloader $src ${DL_DIST_FILE[$i]} retrieve_file $downloader $src ${DL_DIST_FILE[$i]}
if [ $? != 0 ] ; then if [ $? != 0 ] ; then
echo " Warning: Failed to download file - try next URL" echo " Warning: Failed to download file - try next URL"
continue; continue;
fi fi
# Check sha1 # Check sha1
if [ ! -e "${PRODUCT_DIR}/${basename}.sha1sum" ] && [ "$CHECKSUM_AUTOCREATE" == "true" ] ; then if [ ! -e "${PRODUCT_DIR}/${basename}.sha1sum" ] && [ "$CHECKSUM_AUTOCREATE" == "true" ] ; then
$CMD_sha1sum ${DL_DIST_FILE[$i]} > ${PRODUCT_DIR}/${basename}.sha1sum $CMD_sha1sum ${DL_DIST_FILE[$i]} > ${PRODUCT_DIR}/${basename}.sha1sum
downloaded=1 downloaded=1
echo " WARNING: SHA1 checksum (${DL_DIST_FILE[$i]}.sha1sum) was created dynamically because auf CHECKSUM_AUTOCREATE=$CHECKSUM_AUTOCREATE" echo " WARNING: SHA1 checksum (${DL_DIST_FILE[$i]}.sha1sum) was created dynamically because auf CHECKSUM_AUTOCREATE=$CHECKSUM_AUTOCREATE"
else else
# testing the checksum of the downloaded files # testing the checksum of the downloaded files
local sha1sum_val=`cat ${PRODUCT_DIR}/${basename}.sha1sum | cut -d " " -f1` local sha1sum_val=`cat ${PRODUCT_DIR}/${basename}.sha1sum | cut -d " " -f1`
local checksum_val=`sha1sum ${DL_DIST_FILE[$i]} | cut -d " " -f1` local checksum_val=`sha1sum ${DL_DIST_FILE[$i]} | cut -d " " -f1`
if [ "$checksum_val" = "$sha1sum_val" ] ; then if [ "$checksum_val" = "$sha1sum_val" ] ; then
downloaded=1 downloaded=1
fi fi
fi fi
# Print result # Print result
if [ "$downloaded" == "1" ] ; then if [ "$downloaded" == "1" ] ; then
echo " Info: Downloaded successfully" echo " Info: Downloaded successfully"
else else
echo " Error: The checksums do not match - try next URL" echo " Error: The checksums do not match - try next URL"
fi fi
done
echo
# Ups - no URL works
if [ $downloaded != 1 ] ; then
echo " Error: can download the file or checksum wrong (sha1sum ${DIST_CACHE_DIR}/${basename} > ${basename}.sha1sum)"
exit 1;
fi
done done
echo
# Ups - no URL works
if [ $downloaded != 1 ] ; then
echo " Error: can download the file or checksum wrong (sha1sum ${DIST_CACHE_DIR}/${basename} > ${basename}.sha1sum)"
exit 1;
fi
done
} }
##################### #####################
# Create files # Create files
#################### ####################
builder_create() { builder_create() {
# Copy files and convert text files to dos format # Copy files and convert text files to dos format
cp -Rv ${PRODUCT_DIR}/OPSI $INST_DIR cp -Rv ${PRODUCT_DIR}/OPSI $INST_DIR
cp -Rv ${PRODUCT_DIR}/CLIENT_DATA $INST_DIR cp -Rv ${PRODUCT_DIR}/CLIENT_DATA $INST_DIR
find $INST_DIR/CLIENT_DATA -type f | xargs -n1 -iREP sh -c 'file -i $0 | grep -v "utf-16" | grep "text/plain" && '$CMD_unix2dos' $0 ' REP >/dev/null find $INST_DIR/CLIENT_DATA -type f | xargs -n1 -iREP sh -c 'file -i $0 | grep -v "utf-16" | grep "text/plain" && '$CMD_unix2dos' $0 ' REP >/dev/null
# converting icon file # converting icon file
local iconfile_src=${DL_DIST_FILE[$ICON_DL_INDEX]} local iconfile_src=${DL_DIST_FILE[$ICON_DL_INDEX]}
ICONFILE=$OUTPUT_DIR/$PN.png ICONFILE=$OUTPUT_DIR/$PN.png
convert_image $iconfile_src $ICONFILE convert_image $iconfile_src $ICONFILE
cp -a $ICONFILE $INST_DIR/CLIENT_DATA cp -a $ICONFILE $INST_DIR/CLIENT_DATA
# copy binaries
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
# copy binaries mkdir -p ${DL_EXTRACT_PATH[$i]}
for (( i = 0 ; i < ${#DL_SOURCE[@]} ; i++ )) ; do process_file $format ${DL_DIST_FILE[$i]} ${DL_EXTRACT_PATH[$i]}
DL_EXTRACT_PATH[$i]=${INST_DIR}/CLIENT_DATA/${DL_ARCH[$i]}/${DL_EXTRACT_TO[$i]} done
local format=${DL_EXTRACT_FORMAT[$i]}
if [ -z "$format" ] ; then format="cp"; fi # create winst variables
local var_file=${OUTPUT_DIR}/variable.ins
mkdir -p ${DL_EXTRACT_PATH[$i]} create_winst_varfile $var_file
process_file $format ${DL_DIST_FILE[$i]} ${DL_EXTRACT_PATH[$i]}
done # write ini file
local ini_file=${INST_DIR}/CLIENT_DATA/opsi-$PN.ini
# create winst variables write_ini_file $ini_file
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
# add the new vaiables to all *.ins winst files sed -i -e "/@@BUILDER_VARIABLES@@/ {
for inst_file in `find ${INST_DIR}/CLIENT_DATA -type f -name "*.ins"` ; do
sed -i -e "/@@BUILDER_VARIABLES@@/ {
r "$var_file" r "$var_file"
d d
}" $inst_file }" $inst_file
done done
# replace variables from file OPSI/control # replace variables from file OPSI/control
local release_new=${CREATOR_TAG}${RELEASE} 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 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
# Create changelog based on git - if available # Create changelog based on git - if available
if [ -d "${PRODUCT_DIR}/.git" ] ; then if [ -d "${PRODUCT_DIR}/.git" ] ; then
git log --date-order --date=short | \ git log --date-order --date=short | \
sed -e '/^commit.*$/d' | \ sed -e '/^commit.*$/d' | \
awk '/^Author/ {sub(/\\$/,""); getline t; print $0 t; next}; 1' | \ awk '/^Author/ {sub(/\\$/,""); getline t; print $0 t; next}; 1' | \
sed -e 's/^Author: //g' | \ sed -e 's/^Author: //g' | \
sed -e 's/>Date: \([0-9]*-[0-9]*-[0-9]*\)/>\t\1/g' | \ sed -e 's/>Date: \([0-9]*-[0-9]*-[0-9]*\)/>\t\1/g' | \
sed -e 's/^\(.*\) \(\)\t\(.*\)/\3 \1 \2/g' > $INST_DIR/OPSI/changelog.txt sed -e 's/^\(.*\) \(\)\t\(.*\)/\3 \1 \2/g' > $INST_DIR/OPSI/changelog.txt
else else
echo "No git repository present." echo "No git repository present."
fi fi
} }
##################### #####################
# build opsi package # build opsi package
##################### #####################
builder_package() { builder_package() {
# creating package # creating package
local release_new=${CREATOR_TAG}${RELEASE} local release_new=${CREATOR_TAG}${RELEASE}
local opsi_file=${PN}_${VERSION}-${release_new}.opsi local opsi_file=${PN}_${VERSION}-${release_new}.opsi
pushd ${OUTPUT_DIR} pushd ${OUTPUT_DIR}
rm -f ${opsi_file} ${OPSI_REPOS_FILE_PATTERN}.opsi rm -f ${opsi_file} ${OPSI_REPOS_FILE_PATTERN}.opsi
LANG="C" opsi-makeproductfile -v $INST_DIR LANG="C" opsi-makeproductfile -v $INST_DIR
builder_check_error "Building OPSI-package" builder_check_error "Building OPSI-package"
popd popd
# rename opsi package file # rename opsi package file
if [ "${opsi_file}" != "${OPSI_REPOS_FILE_PATTERN}.opsi" ]; then if [ "${opsi_file}" != "${OPSI_REPOS_FILE_PATTERN}.opsi" ]; then
mv ${OUTPUT_DIR}/${opsi_file} ${OUTPUT_DIR}/${OPSI_REPOS_FILE_PATTERN}.opsi mv ${OUTPUT_DIR}/${opsi_file} ${OUTPUT_DIR}/${OPSI_REPOS_FILE_PATTERN}.opsi
builder_check_error "can't move file ${OUTPUT_DIR}/${opsi_file} ${OUTPUT_DIR}/${OPSI_REPOS_FILE_PATTERN}.opsi" builder_check_error "can't move file ${OUTPUT_DIR}/${opsi_file} ${OUTPUT_DIR}/${OPSI_REPOS_FILE_PATTERN}.opsi"
fi fi
# --exclude \*/.git\* # --exclude \*/.git\*
# create source- and binary package package # create source- and binary package package
test "${OPSI_REPOS_UPLOAD_BIN}" = "true" && $CMD_zip --exclude \*/.git\* @ -r ${OUTPUT_DIR}/${OPSI_REPOS_FILE_PATTERN}.zip $INST_DIR test "${OPSI_REPOS_UPLOAD_BIN}" = "true" && $CMD_zip --exclude \*/.git\* @ -r ${OUTPUT_DIR}/${OPSI_REPOS_FILE_PATTERN}.zip $INST_DIR
test "${OPSI_REPOS_UPLOAD_SOURCE}" = "true" && $CMD_zip --exclude \*/.git\* @ -r ${OUTPUT_DIR}/${OPSI_REPOS_FILE_PATTERN}-src.zip ${PRODUCT_DIR} test "${OPSI_REPOS_UPLOAD_SOURCE}" = "true" && $CMD_zip --exclude \*/.git\* @ -r ${OUTPUT_DIR}/${OPSI_REPOS_FILE_PATTERN}-src.zip ${PRODUCT_DIR}
} }
@ -269,45 +274,45 @@ builder_package() {
# publish # publish
##################### #####################
builder_publish() { builder_publish() {
# Upload file to repository # Upload file to repository
mkdir -p ${OPSI_REPOS_PRODUCT_DIR} mkdir -p ${OPSI_REPOS_PRODUCT_DIR}
echo "Publishing opsi-package to ${OPSI_REPOS_PRODUCT_DIR}" echo "Publishing opsi-package to ${OPSI_REPOS_PRODUCT_DIR}"
local src=${OUTPUT_DIR}/${OPSI_REPOS_FILE_PATTERN} local src=${OUTPUT_DIR}/${OPSI_REPOS_FILE_PATTERN}
local dst=${OPSI_REPOS_PRODUCT_DIR}/${OPSI_REPOS_FILE_PATTERN} local dst=${OPSI_REPOS_PRODUCT_DIR}/${OPSI_REPOS_FILE_PATTERN}
# copy files # copy files
if [ "${OPSI_REPOS_UPLOAD_OPSI}" = "true" ] ; then if [ "${OPSI_REPOS_UPLOAD_OPSI}" = "true" ] ; then
cp ${src}.opsi ${dst}.opsi cp ${src}.opsi ${dst}.opsi
builder_check_error "Can't upload file $dst.opsi --> $dst.opsi" builder_check_error "Can't upload file $dst.opsi --> $dst.opsi"
fi fi
if [ "${OPSI_REPOS_UPLOAD_BIN}" = "true" ] ; then if [ "${OPSI_REPOS_UPLOAD_BIN}" = "true" ] ; then
cp ${src}.zip ${dst}.zip cp ${src}.zip ${dst}.zip
builder_check_error "Can't upload file $dst.zip --> $dst.zip" builder_check_error "Can't upload file $dst.zip --> $dst.zip"
fi fi
if [ "${OPSI_REPOS_UPLOAD_SOURCE}" = "true" ] ; then if [ "${OPSI_REPOS_UPLOAD_SOURCE}" = "true" ] ; then
cp ${src}-src.zip ${dst}-src.zip cp ${src}-src.zip ${dst}-src.zip
builder_check_error "Can't upload file ${dst}-src.zip --> ${dst}-src.zip" builder_check_error "Can't upload file ${dst}-src.zip --> ${dst}-src.zip"
fi fi
if [ "${OPSI_REPOS_OPSIMANAGER_INSTALL}" = "true" ] ; then if [ "${OPSI_REPOS_OPSIMANAGER_INSTALL}" = "true" ] ; then
opsi-package-manager -i -v ${src}.opsi opsi-package-manager -i -v ${src}.opsi
builder_check_error "Can't install ${src}.opsi" builder_check_error "Can't install ${src}.opsi"
fi fi
if [ "${OPSI_REPOS_UPLOAD_OPSI_ZSYNC}" = "true" ] ; then if [ "${OPSI_REPOS_UPLOAD_OPSI_ZSYNC}" = "true" ] ; then
md5sum "${src}.opsi" | sed 's/ .*//' > ${dst}.opsi.md5 md5sum "${src}.opsi" | sed 's/ .*//' > ${dst}.opsi.md5
builder_check_error "Can't create md5 file" builder_check_error "Can't create md5 file"
${CMD_zsyncmake} -u ${OPSI_REPOS_FILE_PATTERN}.opsi -o "${dst}.opsi.zsync" "${src}.opsi" ${CMD_zsyncmake} -u ${OPSI_REPOS_FILE_PATTERN}.opsi -o "${dst}.opsi.zsync" "${src}.opsi"
builder_check_error "Can't create zsync file" builder_check_error "Can't create zsync file"
fi fi
# Create revision file for this # Create revision file for this
local rev_file=${OPSI_REPOS_PRODUCT_DIR}/${PN}-${VERSION}-${CREATOR_TAG}${RELEASE}.cfg local rev_file=${OPSI_REPOS_PRODUCT_DIR}/${PN}-${VERSION}-${CREATOR_TAG}${RELEASE}.cfg
cat > $rev_file <<EOF cat > $rev_file <<EOF
REV_VENDOR=${VENDOR} REV_VENDOR=${VENDOR}
REV_PN=${PN} REV_PN=${PN}
@ -319,64 +324,64 @@ REV_TIMESTAMP=`date +"%s"`
REV_CREATOR_TAG=${CREATOR_TAG} REV_CREATOR_TAG=${CREATOR_TAG}
REV_OPSI_REPOS_FILE_PATTERN=${OPSI_REPOS_FILE_PATTERN} REV_OPSI_REPOS_FILE_PATTERN=${OPSI_REPOS_FILE_PATTERN}
EOF EOF
# Purge old product versions - defined by limit OPSI_REPOS_PURGE_LIMIT # Purge old product versions - defined by limit OPSI_REPOS_PURGE_LIMIT
if [ "${OPSI_REPOS_PURGE}" = "true" ] && [ ! -z "${OPSI_REPOS_PURGE_LIMIT}" ] && [ "${OPSI_REPOS_PURGE_LIMIT}" > 0 ] && [ "${STATUS}" = "${OPSI_REPOS_PURGE_STATUS}" ] ; then if [ "${OPSI_REPOS_PURGE}" = "true" ] && [ ! -z "${OPSI_REPOS_PURGE_LIMIT}" ] && [ "${OPSI_REPOS_PURGE_LIMIT}" > 0 ] && [ "${STATUS}" = "${OPSI_REPOS_PURGE_STATUS}" ] ; then
echo "Autopurging enabled" echo "Autopurging enabled"
# determinte max version to delete # determinte max version to delete
local limit local limit
local pn_limit=`echo ${PN} | sed "s/[\.\-]/_/g"` local pn_limit=`echo ${PN} | sed "s/[\.\-]/_/g"`
eval "`echo limit=\\$\\{OPSI_REPOS_PURGE_LIMIT_${pn_limit}\\}`" eval "`echo limit=\\$\\{OPSI_REPOS_PURGE_LIMIT_${pn_limit}\\}`"
if [ -z "$limit" ] || [ ! `expr $limit + 1 2>/dev/null` ] ; then if [ -z "$limit" ] || [ ! `expr $limit + 1 2>/dev/null` ] ; then
limit=${OPSI_REPOS_PURGE_LIMIT} limit=${OPSI_REPOS_PURGE_LIMIT}
fi fi
echo " Purging, max. number of versions: $limit" echo " Purging, max. number of versions: $limit"
# Find all revision files and sort them # Find all revision files and sort them
local file_list=${OUTPUT_DIR}/product-file-list.txt local file_list=${OUTPUT_DIR}/product-file-list.txt
local file_sort_list=${OUTPUT_DIR}/product-file-sort-list.txt local file_sort_list=${OUTPUT_DIR}/product-file-sort-list.txt
rm -f ${file_list} rm -f ${file_list}
for cfg_file in `find ${OPSI_REPOS_BASE_DIR} -name "{PN}-${VERSION}-${CREATOR_TAG}*.cfg" -print ` ; do for cfg_file in `find ${OPSI_REPOS_BASE_DIR} -name "{PN}-${VERSION}-${CREATOR_TAG}*.cfg" -print ` ; do
. ${cfg_file} . ${cfg_file}
printf "%08d;$cfg_file\n" $REV_RELEASE >> ${file_list} printf "%08d;$cfg_file\n" $REV_RELEASE >> ${file_list}
done done
sort -n ${file_list} > ${file_sort_list} sort -n ${file_list} > ${file_sort_list}
# Delete the oldest files # Delete the oldest files
log_debug "base list for calculate purge:" log_debug "base list for calculate purge:"
for cfg_sort_file in `tail -${limit} ${file_sort_list} | ${CMD_comm} -13 - ${file_sort_list}` ; do for cfg_sort_file in `tail -${limit} ${file_sort_list} | ${CMD_comm} -13 - ${file_sort_list}` ; do
local cfg_file=`echo $cfg_sort_file | cut -f 2 -d ";"` local cfg_file=`echo $cfg_sort_file | cut -f 2 -d ";"`
. ${cfg_file} . ${cfg_file}
if [ "${REV_STATUS}" != "${OPSI_REPOS_PURGE_STATUS}" ] ; then continue; fi if [ "${REV_STATUS}" != "${OPSI_REPOS_PURGE_STATUS}" ] ; then continue; fi
dir_base=`dirname ${cfg_file}` dir_base=`dirname ${cfg_file}`
product_file="${dir_base}/${REV_OPSI_REPOS_FILE_PATTERN}" product_file="${dir_base}/${REV_OPSI_REPOS_FILE_PATTERN}"
echo " Purging product version: $product_file*" echo " Purging product version: $product_file*"
# Paranoid ... check the files to delete first # Paranoid ... check the files to delete first
if [ ! -z "${dir_base}" ] && [ -d "${OPSI_REPOS_BASE_DIR}" ] && [ ! -z "$product_file" ] ; then if [ ! -z "${dir_base}" ] && [ -d "${OPSI_REPOS_BASE_DIR}" ] && [ ! -z "$product_file" ] ; then
rm -f ${product_file}* ${cfg_file} rm -f ${product_file}* ${cfg_file}
# remove directory - if it's empty # remove directory - if it's empty
if [ $(ls -1A ${dir_base} | wc -l) -eq 0 ]; then if [ $(ls -1A ${dir_base} | wc -l) -eq 0 ]; then
rmdir ${dir_base} rmdir ${dir_base}
fi fi
fi fi
done done
fi fi
} }
################### ###################
# Commiting changes to repos # Commiting changes to repos
################### ###################
builder_commit() { builder_commit() {
if [ -d "${PRODUCT_DIR}/.git" ]; then if [ -d "${PRODUCT_DIR}/.git" ]; then
echo -n echo -n
log_debug "builder_commit() not implemented yet." log_debug "builder_commit() not implemented yet."
fi fi
} }
@ -384,8 +389,8 @@ builder_commit() {
# build opsi package # build opsi package
##################### #####################
builder_cleanup() { builder_cleanup() {
# Paranoia # Paranoia
if [ -d "$OUTPUT_DIR" ] && [[ $OUTPUT_DIR == $TMP_DIR/opsi-builder.* ]] ; then if [ -d "$OUTPUT_DIR" ] && [[ $OUTPUT_DIR == $TMP_DIR/opsi-builder.* ]] ; then
rm -rf $OUTPUT_DIR rm -rf $OUTPUT_DIR
fi fi
} }

View File

@ -2,7 +2,7 @@
# void retrieve_file (src, dst) # void retrieve_file (src, dst)
# #
# Description: retrieve file from an URL # Description: retrieve file from an URL
# #
# Parameter # Parameter
# downloader: program to download the files # downloader: program to download the files
# src: source url to get file from # src: source url to get file from
@ -10,40 +10,40 @@
# #
############################################# #############################################
function retrieve_file() { function retrieve_file() {
local downloader=$1 local downloader=$1
local src=$2 local src=$2
local dst=$3 local dst=$3
# Check, if the URL is a file URL starting with file:// # Check, if the URL is a file URL starting with file://
if [ -f $dst ] && [ -z ${DIST_FORCE_DOWNLOAD} ]; then if [ -f $dst ] && [ -z ${DIST_FORCE_DOWNLOAD} ]; then
echo " Info: File still cached/downloaded. To force a download, set DIST_FORCE_DOWNLOAD=1" echo " Info: File still cached/downloaded. To force a download, set DIST_FORCE_DOWNLOAD=1"
elif [[ $src == file://* ]]; then elif [[ $src == file://* ]]; then
fileurl=`echo $src | sed "s/^file:\/\///"` fileurl=`echo $src | sed "s/^file:\/\///"`
cp $fileurl $dst 2>/dev/null cp $fileurl $dst 2>/dev/null
else
rm -f $dst
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
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 else
rm -f $dst fatal_error "Downloader not implemented: $downloader"
if [ "$downloader" = "wget" ]; then fi
wget --tries=1 -O $dst --timeout=5 -q --no-verbose "$src" fi
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) # void extract_file (format, src, dst)
# #
# Description: Extract a file # Description: Extract a file
# #
# Parameter # Parameter
# format: compression format # format: compression format
# src: source file to be used # src: source file to be used
@ -51,32 +51,32 @@ function retrieve_file() {
# #
############################################# #############################################
function process_file() { function process_file() {
local format=$1 local format=$1
local src=$2 local src=$2
local dst=$3 local dst=$3
log_debug "Compression format: $format" log_debug "Compression format: $format"
if [ "$format" = "cp" ]; then if [ "$format" = "cp" ]; then
cp $src $dst cp $src $dst
elif [ "$format" = "7zip" ]; then elif [ "$format" = "7zip" ]; then
$CMD_7z x -y -o$dst $src $CMD_7z x -y -o$dst $src
elif [ "$format" = "unzip" ]; then elif [ "$format" = "unzip" ]; then
$CMD_unzip -o $src -d $dst $CMD_unzip -o $src -d $dst
elif [ "$format" = "unrar" ]; then elif [ "$format" = "unrar" ]; then
$CMD_unrar xy $src $dst $CMD_unrar xy $src $dst
elif [ "$format" = "lha" ]; then elif [ "$format" = "lha" ]; then
$CMD_lha x -w=$dst $src $CMD_lha x -w=$dst $src
elif [ "$format" = "targz" ]; then elif [ "$format" = "targz" ]; then
$CMD_tar xzvf $src -C $dst $CMD_tar xzvf $src -C $dst
elif [ "$format" = "tarbz2" ]; then elif [ "$format" = "tarbz2" ]; then
$CMD_tar xjvf $src -C $dst $CMD_tar xjvf $src -C $dst
elif [ "$format" = "cab" ]; then elif [ "$format" = "cab" ]; then
$CMD_cabextract -d $dst $src $CMD_cabextract -d $dst $src
else else
fatal_error "Unknown compression format: $format" fatal_error "Unknown compression format: $format"
fi fi
} }
@ -84,216 +84,240 @@ function process_file() {
# check if method is available and call it # check if method is available and call it
############################################# #############################################
function call_entry_point() { function call_entry_point() {
local _resultvar=$1 local _resultvar=$1
local func=$2 local func=$2
# Entry point # Entry point
type $func &>/dev/null type $func &>/dev/null
if [ $? == 0 ] ; then if [ $? == 0 ] ; then
$func $func
eval $_resultvar="0" eval $_resultvar="0"
else else
eval $_resultvar="1" eval $_resultvar="1"
fi fi
} }
################### ###################
# Fata Error # Fata Error
################### ###################
fatal_error() { fatal_error() {
echo "FATAL: $1" echo "FATAL: $1"
exit 1 exit 1
} }
################### ###################
# Check error # Check error
################### ###################
builder_check_error() { builder_check_error() {
if [ "$?" == "1" ] ; then if [ "$?" == "1" ] ; then
fatal_error "$1" fatal_error "$1"
fi fi
} }
################### ###################
# Logging Debug # Logging Debug
################### ###################
log_debug() { log_debug() {
local str=$1 local str=$1
if [ "$DEBUG_LEVEL" = "debug" ] || [ "$DEBUG_LEVEL" = "info" ] ; then if [ "$DEBUG_LEVEL" = "debug" ] || [ "$DEBUG_LEVEL" = "info" ] ; then
echo $str echo $str
fi fi
} }
################### ###################
# Logging Info # Logging Info
################### ###################
log_info() { log_info() {
local str=$1 local str=$1
if [ "$DEBUG_LEVEL" = "info" ] ; then if [ "$DEBUG_LEVEL" = "info" ] ; then
echo $str echo $str
fi fi
} }
################### ###################
# Convert image # Convert image
################### ###################
convert_image() { convert_image() {
local src=$1 local src=$1
local dst=$2 local dst=$2
local hight=`${CMD_identify} -format "%h" $src` local hight=`${CMD_identify} -format "%h" $src`
local wight=`${CMD_identify} -format "%w" $src` local wight=`${CMD_identify} -format "%w" $src`
${CMD_identify} -format "%wx%h" $src ${CMD_identify} -format "%wx%h" $src
# first resize the image to the new aspect ratio and add white borders # first resize the image to the new aspect ratio and add white borders
if [ $wight -lt $hight ] ; then if [ $wight -lt $hight ] ; then
# Its higher so force x160 and let imagemagic decide the right wight # Its higher so force x160 and let imagemagic decide the right wight
# then add white to the rest of the image to fit 160x160 # then add white to the rest of the image to fit 160x160
log_debug "Icon Wight: $wight < Hight: $hight" log_debug "Icon Wight: $wight < Hight: $hight"
convert $src -colorspace RGB -resize x160 \ convert $src -colorspace RGB -resize x160 \
-size 160x160 xc:white +swap -gravity center -composite \ -size 160x160 xc:white +swap -gravity center -composite \
-modulate 110 -colors 256 png8:$OUTPUT_DIR/resize.png -modulate 110 -colors 256 png8:$OUTPUT_DIR/resize.png
builder_check_error "converting image" builder_check_error "converting image"
elif [ $wight -gt $hight ] ; then elif [ $wight -gt $hight ] ; then
# Its wider so force 160x and let imagemagic decide the right hight # Its wider so force 160x and let imagemagic decide the right hight
# then add white to the rest of the image to fit 160x160 # then add white to the rest of the image to fit 160x160
log_debug "Icon Wight: $wight > Hight: $hight" log_debug "Icon Wight: $wight > Hight: $hight"
convert $src -colorspace RGB -resize 160x \ convert $src -colorspace RGB -resize 160x \
-size 160x160 xc:white +swap -gravity center -composite \ -size 160x160 xc:white +swap -gravity center -composite \
-modulate 110 -colors 256 png8:$OUTPUT_DIR/resize.png -modulate 110 -colors 256 png8:$OUTPUT_DIR/resize.png
builder_check_error "converting image" builder_check_error "converting image"
elif [ $wight -eq $hight ] ; then elif [ $wight -eq $hight ] ; then
# Its scare so force 160x160 # Its scare so force 160x160
log_debug "Icon Wight: $wight = Hight: $hight" log_debug "Icon Wight: $wight = Hight: $hight"
convert $src -colorspace RGB -resize 160x160 \ convert $src -colorspace RGB -resize 160x160 \
-size 160x160 xc:white +swap -gravity center -composite \ -size 160x160 xc:white +swap -gravity center -composite \
-modulate 110 -colors 256 png8:$OUTPUT_DIR/resize.png -modulate 110 -colors 256 png8:$OUTPUT_DIR/resize.png
builder_check_error "converting image" builder_check_error "converting image"
else else
# Imagemagic is unable to detect the aspect ratio so just force 160x160 # Imagemagic is unable to detect the aspect ratio so just force 160x160
# this could result in streched images # this could result in streched images
log_debug "Icon Wight: $wight unknown Hight: $hight" log_debug "Icon Wight: $wight unknown Hight: $hight"
convert $src -colorspace RGB -resize 160x160 \ convert $src -colorspace RGB -resize 160x160 \
-size 160x160 xc:white +swap -gravity center -composite \ -size 160x160 xc:white +swap -gravity center -composite \
-modulate 110 -colors 256 png8:$OUTPUT_DIR/resize.png -modulate 110 -colors 256 png8:$OUTPUT_DIR/resize.png
builder_check_error "converting image" builder_check_error "converting image"
fi fi
# create a diffence image from the source # create a diffence image from the source
convert $OUTPUT_DIR/resize.png \( +clone -fx 'p{0,0}' \) -compose Difference -composite \ convert $OUTPUT_DIR/resize.png \( +clone -fx 'p{0,0}' \) -compose Difference -composite \
-modulate 100,0 +matte $OUTPUT_DIR/difference.png -modulate 100,0 +matte $OUTPUT_DIR/difference.png
# remove the black, replace with transparency # remove the black, replace with transparency
convert $OUTPUT_DIR/difference.png -bordercolor white -border 1x1 -matte \ convert $OUTPUT_DIR/difference.png -bordercolor white -border 1x1 -matte \
-fill none -fuzz 7% -draw 'matte 1,1 floodfill' -shave 1x1 \ -fill none -fuzz 7% -draw 'matte 1,1 floodfill' -shave 1x1 \
$OUTPUT_DIR/removed_black.png $OUTPUT_DIR/removed_black.png
# create the matte # create the matte
convert $OUTPUT_DIR/removed_black.png -channel matte -negate -separate +matte \ convert $OUTPUT_DIR/removed_black.png -channel matte -negate -separate +matte \
$OUTPUT_DIR/matte.png $OUTPUT_DIR/matte.png
# negate the colors # negate the colors
convert $OUTPUT_DIR/matte.png -negate -blur 0x1 \ convert $OUTPUT_DIR/matte.png -negate -blur 0x1 \
$OUTPUT_DIR/matte-negated.png $OUTPUT_DIR/matte-negated.png
# you are going for: white interior, black exterior # you are going for: white interior, black exterior
composite -compose CopyOpacity $OUTPUT_DIR/matte-negated.png $OUTPUT_DIR/resize.png \ composite -compose CopyOpacity $OUTPUT_DIR/matte-negated.png $OUTPUT_DIR/resize.png \
$dst $dst
# New size # New size
# identify -format "%wx%h" $dst # identify -format "%wx%h" $dst
hight=`${CMD_identify} -format "%h" $dst` hight=`${CMD_identify} -format "%h" $dst`
wight=`${CMD_identify} -format "%w" $dst` wight=`${CMD_identify} -format "%w" $dst`
log_debug "Opsi Icon Wight: $wight Hight: $hight" log_debug "Opsi Icon Wight: $wight Hight: $hight"
} }
################### ###################
# Create variable file # Create variable file
# #
# Create a file containing all important winst variables # Create a file containing all important winst variables
# (declaration and setings) # (declaration and setings)
# #
# Parameter # Parameter
# file: file to create # file: file to create
# #
################### ###################
create_winst_varfile() { create_winst_varfile() {
local var_file=$1 local var_file=$1
echo -n >$var_file echo -n >$var_file
for (( i = 0 ; i < ${#DL_SOURCE[@]} ; i++ )) ; do for (( i = 0 ; i < ${#DL_SOURCE[@]} ; i++ )) ; do
if [ -z ${DL_WINST_NAME[$i]} ] ; then continue ; fi if [ -z ${DL_WINST_NAME[$i]} ] ; then continue ; fi
if [ ! -z "${DL_ARCH[$i]}" ] ; then arch_str="${DL_ARCH[$i]}\\" ; fi if [ ! -z "${DL_ARCH[$i]}" ] ; then arch_str="${DL_ARCH[$i]}\\" ; fi
echo "DefVar \$${DL_WINST_NAME[$i]}\$" >>$var_file echo "DefVar \$${DL_WINST_NAME[$i]}\$" >>$var_file
echo "Set \$${DL_WINST_NAME[$i]}\$ = \"%ScriptPath%\\${arch_str}${DL_FILE[$i]}\"" >>$var_file echo "Set \$${DL_WINST_NAME[$i]}\$ = \"%ScriptPath%\\${arch_str}${DL_FILE[$i]}\"" >>$var_file
done done
# publish some other variables # publish some other variables
for var in VENDOR PN VERSION RELEASE PRIORITY ADVICE TYPE CREATOR_TAG CREATOR_NAME CREATOR_EMAIL ; do for var in VENDOR PN VERSION RELEASE PRIORITY ADVICE TYPE CREATOR_TAG CREATOR_NAME CREATOR_EMAIL ; do
echo "DefVar \$${var}\$" >>$var_file echo "DefVar \$${var}\$" >>$var_file
echo "Set \$${var}\$ = \"${!var}\"" >>$var_file echo "Set \$${var}\$ = \"${!var}\"" >>$var_file
done done
# copy image and create variable # copy image and create variable
echo "DefVar \$IconFile\$" >>$var_file echo "DefVar \$IconFile\$" >>$var_file
echo "Set \$IconFile\$ = \"%ScriptPath%\\`basename $ICONFILE`\"" >>$var_file echo "Set \$IconFile\$ = \"%ScriptPath%\\`basename $ICONFILE`\"" >>$var_file
# publish custom variables # publish custom variables
for (( i = 0 ; i < ${#WINST_NAME[@]} ; i++ )) ; do for (( i = 0 ; i < ${#WINST_NAME[@]} ; i++ )) ; do
# replace DL_EXTRACT_WINST_PATH # replace DL_EXTRACT_WINST_PATH
local index=`echo ${WINST_VALUE[$i]} | sed -e "s#.*@DL_EXTRACT_WINST_PATH\[\([0-9]\)\]@.*#\1#"` 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" log_debug "calculated (DL_EXTRACT_WINST_PATH), Index: $index"
if [ "$index" != "${WINST_VALUE[$i]}" ] ; then if [ "$index" != "${WINST_VALUE[$i]}" ] ; then
if [ ! -z "${DL_ARCH[$index]}" ] ; then arch_part="\\\\${DL_ARCH[$index]}" ; fi 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 if [ ! -z "${DL_EXTRACT_WINST_PATH[$index]}" ] ; then extr_part="\\\\${DL_EXTRACT_WINST_PATH[$index]}" ; fi
local new_val="%ScriptPath%$arch_part$extr_part" 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#"` 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]}" log_debug "calculated (DL_EXTRACT_WINST_PATH) WINST_VALUE: ${WINST_VALUE[$i]}"
fi fi
echo "DefVar \$${WINST_NAME[$i]}\$" >>$var_file echo "DefVar \$${WINST_NAME[$i]}\$" >>$var_file
echo "Set \$${WINST_NAME[$i]}\$ = \"${WINST_VALUE[$i]}\"" >>$var_file echo "Set \$${WINST_NAME[$i]}\$ = \"${WINST_VALUE[$i]}\"" >>$var_file
done done
echo >>$var_file echo >>$var_file
} }
##################### #####################
# void calc_release() # void calc_release()
# #
# Description: # Description:
# Calculate new release based on # Calculate new release based on
# the latest one found in the repository. # the latest one found in the repository.
# #
# $RELEASE is set to the calculated release. # $RELEASE is set to the calculated release.
# #
#################### ####################
function calc_release() { function calc_release() {
# Find all revision files and sort them # Find all revision files and sort them
local file_list=`mktemp /tmp/opsi-builder.calc_release.XXXXXXXXXXX` local file_list=`mktemp /tmp/opsi-builder.calc_release.XXXXXXXXXXX`
for cfg_file in `find ${OPSI_REPOS_BASE_DIR} -name "${PN}-${VERSION}-${CREATOR_TAG}*.cfg" -print ` ; do for cfg_file in `find ${OPSI_REPOS_BASE_DIR} -name "${PN}-${VERSION}-${CREATOR_TAG}*.cfg" -print ` ; do
. ${cfg_file} . ${cfg_file}
printf "%08d;$cfg_file\n" $REV_RELEASE >> ${file_list} printf "%08d;$cfg_file\n" $REV_RELEASE >> ${file_list}
done done
local oldest_cfg=`sort -n ${file_list} | cut -f 2 -d ";" | tail -1` local oldest_cfg=`sort -n ${file_list} | cut -f 2 -d ";" | tail -1`
rm -f ${file_list} rm -f ${file_list}
if [ ! -f "${oldest_cfg}" ] ; then if [ ! -f "${oldest_cfg}" ] ; then
echo "Warning: no cfg-file found for this product. RELEASE will be set to 1" echo "Warning: no cfg-file found for this product. RELEASE will be set to 1"
RELEASE=1 RELEASE=1
else else
log_debug "calc_release() oldest_cfg: ${oldest_cfg}" log_debug "calc_release() oldest_cfg: ${oldest_cfg}"
. ${oldest_cfg} . ${oldest_cfg}
log_debug " latest release: $REV_RELEASE" log_debug " latest release: $REV_RELEASE"
RELEASE=`expr ${REV_RELEASE} + 1 2> /dev/null` RELEASE=`expr ${REV_RELEASE} + 1 2> /dev/null`
builder_check_error "Cannot incrememnt REV_RELEASE from file ${oldest_cfg}" builder_check_error "Cannot incrememnt REV_RELEASE from file ${oldest_cfg}"
fi 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
# publish some other variables
for var in VENDOR PN VERSION RELEASE TYPE CREATOR_TAG CREATOR_NAME CREATOR_EMAIL ; do
$CMD_iniset $ini_file --COMMON ${var}="${!var}"
done
# publish custom variables
for (( i = 0 ; i < ${#OPSI_INI_NAME[@]} ; i++ )) ; do
$CMD_iniset $ini_file --${OPSI_INI_SECTION[$i]} ${OPSI_INI_NAME[$i]}="${OPSI_INI_VALUE[$i]}"
done
}