2012-01-27 01:04:47 +01:00
|
|
|
#####################
|
|
|
|
# Call user entry point
|
|
|
|
####################
|
|
|
|
|
|
|
|
# source generic utility functions
|
|
|
|
. $BASEDIR/lib/builder-utils.sh
|
|
|
|
|
|
|
|
#####################
|
|
|
|
# Read config
|
|
|
|
####################
|
|
|
|
builder_config() {
|
2012-01-28 10:29:54 +01:00
|
|
|
|
2012-01-27 01:04:47 +01:00
|
|
|
# Check temp dir
|
|
|
|
test -d ${TMP_DIR}
|
|
|
|
builder_check_error "temp directory not available: $TMP_DIR"
|
|
|
|
|
2012-01-28 11:20:26 +01:00
|
|
|
# project dependent configuration
|
2012-01-28 10:27:46 +01:00
|
|
|
local config=${PRODUCT_DIR}/builder-product.cfg
|
|
|
|
test -f ${config} || builder_check_error "can't read product config: ${config}"
|
|
|
|
. ${config}
|
2012-01-27 01:04:47 +01:00
|
|
|
|
2012-01-28 11:20:26 +01:00
|
|
|
# set default build configuration and source the user dependent file
|
|
|
|
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
|
|
|
|
config=$OPSI_BUILDER
|
|
|
|
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=" $config`"
|
|
|
|
|
|
|
|
# change some variable from the builder-product.cfg dynamically:
|
|
|
|
# autogenerate release number, if we are in status "integration"
|
2012-01-28 10:29:54 +01:00
|
|
|
if [ "$STATUS" = "integration" ] ; then
|
|
|
|
# OPSI/control:RELEASE is limited to max 16 chars - take care in regards to the CREATOR_TAG
|
|
|
|
RELEASE="`date +%Y%m%d%H%M`"
|
|
|
|
fi
|
|
|
|
|
2012-01-28 11:20:26 +01:00
|
|
|
# Read configurationfile
|
|
|
|
. ${config}
|
|
|
|
echo "Loaded builder configuration: $config"
|
2012-01-27 01:04:47 +01:00
|
|
|
|
|
|
|
# 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
|
|
|
|
}
|
|
|
|
|
|
|
|
#####################
|
|
|
|
# Prepare build
|
|
|
|
####################
|
|
|
|
builder_prepare() {
|
|
|
|
|
|
|
|
# Check if the package is still build
|
2012-01-28 12:27:03 +01:00
|
|
|
if [ -z "$OPSI_REPOS_FORCE_UPLOAD" ] && [ -d ${OPSI_REPOS_PRODUCT_DIR} ] ; then
|
|
|
|
echo "Directory ${OPSI_REPOS_PRODUCT_DIR} already exists."
|
2012-01-27 01:04:47 +01:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
mkdir -p $DIST_CACHE_DIR
|
|
|
|
echo "Distribution directory: $DIST_CACHE_DIR"
|
|
|
|
|
|
|
|
# setup work directory
|
2012-01-28 10:29:54 +01:00
|
|
|
OUTPUT_DIR=$(mktemp -d $TMP_DIR/opsi-builder.XXXXXXXXXX) || { echo "Failed to create temp dir"; exit 1; }
|
2012-01-27 01:04:47 +01:00
|
|
|
|
2012-01-29 15:10:08 +01:00
|
|
|
# prepare
|
|
|
|
INST_DIR=$OUTPUT_DIR/$PN
|
|
|
|
mkdir $INST_DIR
|
|
|
|
|
2012-01-27 01:04:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#####################
|
|
|
|
# Download all dist files from one of the defined URLs.
|
|
|
|
# and validate the checksum
|
|
|
|
####################
|
|
|
|
builder_retrieve() {
|
|
|
|
|
|
|
|
for (( i = 0 ; i < ${#SOURCE[@]} ; i++ )) ; do
|
2012-01-28 10:29:54 +01:00
|
|
|
local basename=${FILE[$i]}
|
|
|
|
local urls=${SOURCE[$i]}
|
|
|
|
local arch=${ARCH[$i]}
|
|
|
|
local downloaded=0
|
2012-01-29 09:11:01 +01:00
|
|
|
|
|
|
|
# Add private repos to the urls
|
2012-01-27 01:04:47 +01:00
|
|
|
if [ ! -z ${DIST_PRIVATE_REPOS} ]; then
|
|
|
|
urls="${DIST_PRIVATE_REPOS}/$basename;$urls"
|
|
|
|
fi
|
2012-01-29 09:11:01 +01:00
|
|
|
|
|
|
|
# check existence of CRC file only in non devel mode
|
|
|
|
if [ ! -z "${DEVEL}" ] ; then
|
|
|
|
if [ ! -e ${PRODUCT_DIR}/${basename}.sha1sum ] ; then
|
|
|
|
echo "You need to create the checksums with: sha1sum ${DIST_CACHE_DIR}/${basename} > ${PRODUCT_DIR}/${basename}.sha1sum"
|
|
|
|
exit 1
|
|
|
|
fi
|
2012-01-27 01:04:47 +01:00
|
|
|
fi
|
2012-01-29 09:11:01 +01:00
|
|
|
|
2012-01-27 01:04:47 +01:00
|
|
|
echo "Downloading $basename"
|
2012-01-29 09:11:01 +01:00
|
|
|
# check downloading from the defined URLs
|
2012-01-27 01:04:47 +01:00
|
|
|
for src in `echo $urls | sed -e 's/;/\n/g'` ; do
|
|
|
|
if [ $downloaded == 1 ]; then continue; fi
|
|
|
|
|
|
|
|
echo " Info: Downloding from $src"
|
|
|
|
mkdir -p ${DIST_CACHE_DIR}/$arch
|
|
|
|
DIST_FILE[$i]=${DIST_CACHE_DIR}/$arch/$basename
|
|
|
|
retrieve_file $src ${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
|
|
|
|
downloaded=1
|
|
|
|
echo " Info: Downloaded successfully"
|
|
|
|
else
|
|
|
|
echo " Error: The checksums do not match - try next URL"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo " Warning: Failed to download file - try next URL"
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
#####################
|
|
|
|
# Create files
|
|
|
|
####################
|
|
|
|
builder_create() {
|
|
|
|
|
2012-01-28 12:27:03 +01:00
|
|
|
# Copy files and convert text files to dos format
|
|
|
|
cp -Rv ${PRODUCT_DIR}/OPSI $INST_DIR
|
|
|
|
cp -Rv ${PRODUCT_DIR}/CLIENT_DATA $INST_DIR
|
2012-01-28 19:17:23 +01:00
|
|
|
find $INST_DIR/CLIENT_DATA -type f | xargs -n1 -iREP sh -c 'file -i $0 | grep "text/plain" && unix2dos $0' REP
|
2012-01-28 12:27:03 +01:00
|
|
|
|
2012-01-27 01:04:47 +01:00
|
|
|
# converting icon file
|
2012-01-28 10:29:54 +01:00
|
|
|
local iconfile_src=${DIST_FILE[$ICON_FILE_INDEX]}
|
|
|
|
ICONFILE=$OUTPUT_DIR/$PN.png
|
2012-01-29 16:58:12 +01:00
|
|
|
convert_image $iconfile_src $ICONFILE
|
2012-01-28 12:27:03 +01:00
|
|
|
cp -a $ICONFILE $INST_DIR/CLIENT_DATA
|
2012-01-28 10:29:54 +01:00
|
|
|
|
2012-01-27 01:04:47 +01:00
|
|
|
# copy binaries
|
|
|
|
for (( i = 0 ; i < ${#SOURCE[@]} ; i++ )) ; do
|
2012-01-29 10:37:05 +01:00
|
|
|
distfile=${DIST_FILE[$i]}
|
2012-01-29 09:11:01 +01:00
|
|
|
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
|
2012-01-27 01:04:47 +01:00
|
|
|
done
|
|
|
|
|
|
|
|
# create variables
|
2012-01-28 10:29:54 +01:00
|
|
|
local var_file=$OUTPUT_DIR/variable.ins
|
2012-01-27 01:04:47 +01:00
|
|
|
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
|
2012-01-29 09:11:01 +01:00
|
|
|
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
|
2012-01-28 10:29:54 +01:00
|
|
|
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
|
2012-01-27 01:04:47 +01:00
|
|
|
done
|
2012-01-28 10:29:54 +01:00
|
|
|
|
|
|
|
# copy image and create variable
|
|
|
|
echo "DefVar \$IconFile\$" >>$var_file
|
|
|
|
echo "Set \$IconFile\$ = \"%ScriptPath%\\`basename $ICONFILE`\"" >>$var_file
|
|
|
|
|
2012-01-27 01:04:47 +01:00
|
|
|
echo >>$var_file
|
|
|
|
|
|
|
|
# add the new vaiables to all *.ins winst files
|
2012-01-28 12:27:03 +01:00
|
|
|
for inst_file in `find ${INST_DIR}/CLIENT_DATA -type f -name "*.ins"` ; do
|
2012-01-27 02:35:40 +01:00
|
|
|
sed -i -e "/@@BUILDER_VARIABLES@@/ {
|
|
|
|
r "$var_file"
|
|
|
|
d
|
|
|
|
}" $inst_file
|
2012-01-27 01:04:47 +01:00
|
|
|
done
|
|
|
|
|
|
|
|
# replace variables from OPSI control
|
2012-01-28 10:29:54 +01:00
|
|
|
local release_new=${CREATOR_TAG}${RELEASE}
|
2012-01-28 12:27:03 +01:00
|
|
|
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
|
2012-01-27 01:04:47 +01:00
|
|
|
|
|
|
|
# Create changelog based on git - if available
|
|
|
|
if [ -d "${PRODUCT_DIR}/.git" ] ; then
|
|
|
|
git log --date-order --date=short | \
|
|
|
|
sed -e '/^commit.*$/d' | \
|
|
|
|
awk '/^Author/ {sub(/\\$/,""); getline t; print $0 t; next}; 1' | \
|
|
|
|
sed -e 's/^Author: //g' | \
|
|
|
|
sed -e 's/>Date: \([0-9]*-[0-9]*-[0-9]*\)/>\t\1/g' | \
|
2012-01-28 12:27:03 +01:00
|
|
|
sed -e 's/^\(.*\) \(\)\t\(.*\)/\3 \1 \2/g' > $INST_DIR/OPSI/changelog.txt
|
2012-01-27 01:04:47 +01:00
|
|
|
else
|
|
|
|
echo "No git repository present."
|
|
|
|
fi
|
|
|
|
|
2012-01-28 12:27:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#####################
|
|
|
|
# build opsi package
|
|
|
|
#####################
|
|
|
|
builder_package() {
|
2012-01-27 01:04:47 +01:00
|
|
|
|
2012-01-28 12:27:03 +01:00
|
|
|
# creating package
|
|
|
|
local release_new=${CREATOR_TAG}${RELEASE}
|
2012-01-28 10:29:54 +01:00
|
|
|
local opsi_file=${PN}_${VERSION}-${release_new}.opsi
|
|
|
|
pushd ${OUTPUT_DIR}
|
2012-01-28 12:27:03 +01:00
|
|
|
rm -f ${opsi_file} ${OPSI_REPOS_FILE_PATTERN}.opsi
|
2012-01-28 19:13:08 +01:00
|
|
|
LANG="C" opsi-makeproductfile -v $INST_DIR
|
2012-01-27 01:04:47 +01:00
|
|
|
builder_check_error "Building OPSI-package"
|
|
|
|
popd
|
|
|
|
|
|
|
|
# rename opsi package file
|
2012-01-28 12:27:03 +01:00
|
|
|
if [ "${opsi_file}" != "${OPSI_REPOS_FILE_PATTERN}.opsi" ]; then
|
|
|
|
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"
|
2012-01-27 01:04:47 +01:00
|
|
|
fi
|
|
|
|
|
2012-01-28 12:27:03 +01:00
|
|
|
# create source package
|
|
|
|
zip -r ${OUTPUT_DIR}/${OPSI_REPOS_FILE_PATTERN}.zip $INST_DIR
|
|
|
|
|
|
|
|
|
2012-01-27 01:04:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#####################
|
2012-01-28 12:27:03 +01:00
|
|
|
# publish
|
2012-01-27 01:04:47 +01:00
|
|
|
#####################
|
|
|
|
builder_publish() {
|
|
|
|
|
|
|
|
# Upload file to repository
|
|
|
|
mkdir -p ${OPSI_REPOS_PRODUCT_DIR}
|
2012-01-28 12:27:03 +01:00
|
|
|
|
|
|
|
echo "Publishing opsi-package to ${OPSI_REPOS_PRODUCT_DIR}"
|
|
|
|
local src=${OUTPUT_DIR}/${OPSI_REPOS_FILE_PATTERN}
|
2012-01-27 10:00:40 +01:00
|
|
|
local dst=${OPSI_REPOS_PRODUCT_DIR}/${OPSI_REPOS_FILE_PATTERN}
|
2012-01-28 12:27:03 +01:00
|
|
|
|
|
|
|
# copy files
|
|
|
|
cp ${src}.opsi ${dst}.opsi
|
2012-01-27 10:00:40 +01:00
|
|
|
builder_check_error "Can't upload file $dst --> $dst"
|
2012-01-27 01:04:47 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
###################
|
|
|
|
# Commiting changes to repos
|
|
|
|
###################
|
|
|
|
builder_commit() {
|
|
|
|
if [ -d "${PRODUCT_DIR}/.git" ]; then
|
|
|
|
echo -n
|
|
|
|
# echo "builder_commit() not implemented yet."
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#####################
|
|
|
|
# build opsi package
|
|
|
|
#####################
|
|
|
|
builder_cleanup() {
|
|
|
|
# Paranoia
|
2012-01-28 10:29:54 +01:00
|
|
|
if [ -d "$OUTPUT_DIR" ] && [[ $OUTPUT_DIR == $TMP_DIR/opsi-builder.* ]] ; then
|
|
|
|
rm -rf $OUTPUT_DIR
|
2012-01-27 01:04:47 +01:00
|
|
|
fi
|
|
|
|
}
|