Init new builder.sh

This commit is contained in:
Daniel Schwager 2012-01-25 23:09:39 +01:00
parent e9e940976a
commit bb533380c6
4 changed files with 323 additions and 0 deletions

View File

@ -0,0 +1,21 @@
##############################
# Prerequirements:
# - Setup your environment variable inside the shell, e.g. ~/.bashrc
# export BUILD_LOCAL_CFG=/home/dschwager/work/build_local.cfg
# check the sample build_local.cfg located inside the itwatch project
##############################
# requirements
yum install plowshare
yum install ImageMagick
yum install git
# define your local, private, individual, not-project dependent build setup
export BUILD_LOCAL_CFG=/home/dschwager/work/itwatch/build_local.cfg
# Start build
./build.sh
# Force downloading vendor files
DIST_FORCE_DOWNLOAD=1 ./build.sh

View File

@ -0,0 +1,32 @@
############################
# build_local.cfg
# private configration for dschwager@opsi-staging.dtnet.de
############################
# temp directory
TMP_DIR=/tmp
# defines the base directory for the generic builder scripts
BUILDER_DIR=/home/dschwager/work/itwatch/builder
# Directory storing OPSI-packages after building
#OPSI_REPOS_BASE=/var/tmp/opsi/upload
#OPSI_REPOS_BASE=/home/dschwager/opsi.build-repos
# Directory- and filename pattern
OPSI_REPOS_BASE_DIR=/home/dschwager/opsi.build-repos
OPSI_REPOS_PRODUCT_DIR=${OPSI_REPOS_BASE_DIR}/${STATUS}/${VENDOR}/${PN}/${VERSION}-${RELEASE}
OPSI_REPOS_FILE_PATTERN=${PN}_${VERSION}-${RELEASE}.opsi
# Directory downloading/cacheing the artifacts like MSI package or icons from the vendor webside
DIST_CACHE_DIR=/home/dschwager/tmp/${PN}-${VERSION}-${RELEASE}
# private dist repository. You can use all variables from release.cfg insde the URL
# this optinal URL will be the FIRST url to check for downloading vendor stuff.
# To copy a local file, the repos should start with file://
# Default: <empty>
#DIST_PRIVATE_REPOS=http://repos.domain.d/opsi/$VENDOR/$PN/$VERSION
#DIST_PRIVATE_REPOS=http://ivyrepos.dtnet.de/v-$PN
DIST_PRIVATE_REPOS=file:///home/dschwager/vendor.repos/$VENDOR/$PN/$VERSION

216
builder/builder-lib.sh Normal file
View File

@ -0,0 +1,216 @@
######################
# Setup configuration
####################
# enabled debug
# set -x
builder_init() {
}
#####################
# Call user entry point
####################
call_entry_point() {
# Entry point
type $1 &>/dev/null
if [ $? == 0 ] ; then
$1
fi
}
#####################
# Read config
####################
builder_read_config() {
# get the 'real' directory this program stored in (resolve symbolic links)
PRG=$(readlink -f $0)
BASEDIR=`dirname "$PRG"`
BASEDIR=`cd "$BASEDIR" && pwd`
# Check temp dir
test -d ${TMP_DIR}
builder_check_error "temp directory not available: $TMP_DIR"
# Source release configuration
test -f ${BASEDIR}/release.cfg
builder_check_error "can't read release configuration: ${BASEDIR}/release.cfg"
. $BASEDIR/release.cfg
# Source local build configuration (must be done AFTER sourcing the release.cfg)
test -f "$BUILD_LOCAL_CFG"
builder_check_error "can't read local buld configuration: $BUILD_LOCAL_CFG"
echo "Using local build configuration: $BUILD_LOCAL_CFG"
. $BUILD_LOCAL_CFG
# Check variables
if [ -z ${OPSI_REPOS_BASE_DIR} ] || [ ! -d ${OPSI_REPOS_BASE_DIR} ] ; then
echo "configuration error: OPSI_REPOS_BASE_DIR is empty or does not exist: $OPSI_REPOS_BASE_DIR"
exit 2
fi
}
#####################
# Download all dist files from one of the defined URLs.
# and validate the checksum
####################
builder_download_dist_files() {
mkdir -p $DIST_CACHE_DIR
echo "Distribution directory: $DIST_CACHE_DIR"
for f1 in $ICON $FILE1 $FILE2 ; do
basename=`echo $f1 | cut -d ";" -f1`
urls=`echo $f1 | cut -d ";" -f2-`
downloaded=0
# Add private repos to the urls
if [ ! -z ${DIST_PRIVATE_REPOS} ]; then
urls="${DIST_PRIVATE_REPOS}/$basename;$urls"
fi
# check existence of CRC file
if [ ! -e ${basename}.sha1sum ] ; then
echo "You need to create the checksums with: sha1sum ${DIST_CACHE_DIR}/${basename} > ${basename}.sha1sum"
exit 1
fi
echo "Downloading $basename"
# check downloading from the defined URLs
for f2 in `echo $urls | sed -e 's/;/\n/g'` ; do
if [ $downloaded == 1 ]; then continue; fi
echo " Info: Downloding from $f2"
# Check, if the URL is a file URL starting with file://
if [ -f ${DIST_CACHE_DIR}/$basename ] && [ -z ${DIST_FORCE_DOWNLOAD} ]; then
echo " Info: File still cached/downloaded. To force a download, set DIST_FORCE_DOWNLOAD=1"
elif [[ $f2 == file://* ]]; then
fileurl=`echo $f2 | sed "s/^file:\/\///"`
cp $fileurl ${DIST_CACHE_DIR}/$basename 2>/dev/null
else
rm -f ${DIST_CACHE_DIR}/$basename
wget --tries=1 -O ${DIST_CACHE_DIR}/$basename --timeout=5 -q --no-verbose $f2
fi
if [ $? == 0 ] ; then
# testing the checksum of the downloaded files
SHA1SUM=`cat ${basename}.sha1sum | cut -d " " -f1`
CHECKSUM=`sha1sum ${DIST_CACHE_DIR}/$basename | 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
}
#####################
# build opsi package
#####################
builder_package() {
OUT=$(mktemp -d $TMP_DIR/opsi-builder.XXXXXXXXXX) || { echo "Failed to create temp dir"; exit 1; }
# Copy files and convert text files to dos format
mkdir $OUT/$PN
cp -Rv OPSI CLIENT_DATA $OUT/$PN
find $OUT/$PN/CLIENT_DATA -type f | xargs -n1 -iREP sh -c 'file -i $0 | grep "text/plain" && dos2unix $0' REP
# copy binaries
for f1 in $FILE1 $FILE2 ; do
basename=`echo $f1 | cut -d ";" -f1`
echo cp ${DIST_CACHE_DIR}/$basename $OUT/$PN/CLIENT_DATA
done
# converting icon file
ICONFILE=`echo $ICON | cut -d ";" -f1`
convert -colorspace rgb ${DIST_CACHE_DIR}/$ICONFILE -transparent white -background transparent -resize 160x160 \
-size 160x160 xc:transparent +swap -gravity center -composite $OUT/$PN/CLIENT_DATA/$PN.png
builder_check_error "converting image"
# replace variables
echo Building OPSI-Package
sed -e "s!VERSION!$VERSION!g" -e "s!RELEASE!$RELEASE!g" -e "s!PRIORITY!$PRIORITY!g" -e "s!ADVICE!$ADVICE!g" -i $OUT/$PN/OPSI/control
sed -e "s!X86FILE!$X86FILE!g" -i $OUT/$PN/CLIENT_DATA/setup32.ins
# Create changelog based on git - if available
if test -d ".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' | \
sed -e 's/^\(.*\) \(\)\t\(.*\)/\3 \1 \2/g' > $OUT/$PN/OPSI/changelog.txt
else
echo "No git repository present."
fi
# building package
echo tempdir: $TMP_DIR
pushd ${TMP_DIR}
rm -f ${PN}_${VERSION}-${RELEASE}.opsi
opsi-makeproductfile -v $OUT/$PN
builder_check_error "Building OPSI-package"
popd
# cleanup
rm -rf $OUT
}
#####################
# build opsi package
#####################
builder_upload() {
# Upload file to repository
mkdir -p ${OPSI_REPOS_PRODUCT_DIR}
cp -av $TMP_DIR/${PN}_${VERSION}-${RELEASE}.opsi ${OPSI_REPOS_PRODUCT_DIR}/${OPSI_REPOS_FILE_PATTERN}
builder_check_error "Can't upload file $TMP_DIR/${PN}_${VERSION}-${RELEASE}.opsi to ${OPSI_REPOS_PRODUCT_DIR}/${OPSI_REPOS_FILE_PATTERN}"
}
###################
# Commiting changes to repos
###################
builder_commit() {
if test -d ".git"; then
echo
echo "builder_commit() not implemented yet."
fi
}
###################
# Check error
###################
builder_check_error() {
if [ $? == 1 ] ; then
echo "FATAL: $1"
exit 0
fi
}

54
builder/builder.sh Normal file
View File

@ -0,0 +1,54 @@
#!/bin/bash
#####################
# Main
####################
main() {
# read config
call_entry_point builder_read_config_pre
builder_read_config
call_entry_point builder_read_config_post
# Check if the package is still build
test ! -f ${OPSI_REPOS_PRODUCT_DIR}/${OPSI_REPOS_FILE_PATTERN}
builder_check_error "package ${OPSI_REPOS_PRODUCT_DIR}/${OPSI_REPOS_FILE_PATTERN} already generated"
# download and process dist files
call_entry_point builder_download_dist_files_pre
builder_download_dist_files
call_entry_point builder_download_dist_files_post
# Start building
call_entry_point builder_package_pre
builder_package
call_entry_point builder_package_post
# Upload to repos
call_entry_point builder_upload_pre
builder_upload
call_entry_point builder_upload_post
# git commit
call_entry_point builder_commit_pre
builder_commit
call_entry_point builder_commit_post
}
# read private build configuration
. $BUILD_LOCAL_CFG
. $BUILDER_DIR/builder-lib.sh
# get target directory
PRODUCT_DIR=$1
if [ -f "$PRODUCT_DIR/build-extension.sh" ] ;
. "$PRODUCT_DIR/build-extension.sh"
fi
builder_main
# Exit
exit 0