X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;ds=sidebyside;f=id-deb-build%2Fid-pbuild.sh;h=8e131a606dddf3e66508f97c45b5f2c231363c6c;hb=863c4277ac9212d165ad5fbde7a9c7bbbaa3c996;hp=cde1dc5720384ecea5c09365ec36cc51c5cd460a;hpb=3695c369af793871ee5e0c8e4fc56df3fd32c8d5;p=git-tools-moved-to-github.git diff --git a/id-deb-build/id-pbuild.sh b/id-deb-build/id-pbuild.sh index cde1dc5..8e131a6 100755 --- a/id-deb-build/id-pbuild.sh +++ b/id-deb-build/id-pbuild.sh @@ -1,22 +1,19 @@ #!/bin/sh # This script builds Debian packages for one or more distributions # in i386/amd64 architectures. It uses pbuilder. pbuilder requires root -# privilege and is invoked with sudo. -# -# In order to avoid having to type-in the password for it, you might -# use something like this in sudoers -# user ALL=NOPASSWD,SETENV: /usr/sbin/pbuilder -# where user is your username. +# privilege and so this script should be invoked with sudo. usage() { cat <&2 fi -if test -d deb-src; then - cd deb-src +if test "$DEBIAN_DIST" -o "$UBUNTU_DIST"; then + debian=true +else + debian=false fi -for f in *.dsc; do - if test -f "$f"; then - PKG=$f - fi -done -if test -z "$PKG"; then - echo "Specify .dsc file" + +D0=`dirname $0` +ID_DEB_BUILD=`cd $D0; pwd` +PBUILDROOT=${ID_DEB_BUILD}/id-pbuild-root.sh +if test ! -x $PBUILDROOT; then + echo "$PBUILDROOT not found" exit 1 fi -if test ! -e "$PKG"; then - echo "${PKG} does not exist" + +MKDEBSRC=${ID_DEB_BUILD}/id-mk-deb-src.sh +if test ! -x $MKDEBSRC; then + echo "$MKDEBSRC not found" exit 1 fi -PBUILDER=/usr/sbin/pbuilder -PRODUCT=`echo *.dsc|sed 's/_.*//g'` -ARCHS="i386 amd64" + +if $upload; then + : +else + if $debian; then + if test "${SUDO_USER}"; then + if test ! -d deb-src; then + $MKDEBSRC + fi + else + if test -d deb-src; then + rm -f deb-src/*.gz + if test $? -ne 0; then + echo "deb-src could not be removed. Remove deb-src manually" + exit 1 + fi + fi + $MKDEBSRC + fi + else + mkdir -p deb-src + fi +fi + +cd deb-src + +if $debian; then + for f in *.dsc; do + if test -f "$f"; then + PKG=$f + fi + done + if test -z "$PKG"; then + echo "Specify .dsc file" + exit 1 + fi + if test ! -e "$PKG"; then + echo "${PKG} does not exist" + exit 1 + fi + if grep "Architecture: all" $PKG >/dev/null; then + USE_ARCHS=i386 + else + USE_ARCHS=$ARCHS + fi +fi + +if test -z "$PRODUCT"; then + PRODUCT=$NAME +fi +if test -z "$PRODUCT"; then + if $debian; then + PRODUCT=`echo *.dsc|sed 's/_.*//g'` + else + PRODUCT=`cd ..;rpm -q --specfile *.spec --queryformat "%{NAME};" | cut -d ";" -f1` + fi +fi echo "Dsc $PKG . Product $PRODUCT" echo "Ubuntu distros: $UBUNTU_DIST" echo "Debian distros: $DEBIAN_DIST" +echo "Centos distros: $CENTOS_DIST" + +if $debian; then + if test "${SUDO_USER}"; then + echo "Running as sudo." + echo "Tip: You can avoid it by adding the following in /etc/sudoers" + echo "${SUDO_USER} ALL=NOPASSWD: ${ID_DEB_BUILD}/id-pbuild-root.sh" + HOME_EXPORT=/home/${SUDO_USER} + else + sudo -k + HOME_EXPORT=$HOME + fi + if test ! -f ${HOME_EXPORT}/.pbuilderrc; then + echo "${HOME_EXPORT}/.pbuilderrc missing" + exit 1 + fi +fi + if $upload; then + for dist in ${CENTOS_DIST}; do + arch=amd64 + prodver=${PRODUCT}-${VERSION} + if scp ${ID_DEB_BUILD}/../id-rpm-build/upload-rpms.sh ${dist}:rpmbuild/SOURCES/${prodver}/; then + : + else + echo "Copy of upload-rpms.sh to $dist failed" + exit 1 + fi + if ssh $dist "cd rpmbuild/SOURCES/${prodver} && chmod +x upload-rpms.sh && ./upload-rpms.sh ${PRODUCT}.spec"; then + : + else + echo "Upload failed for $dist" + exit 1 + fi + done for dist in ${UBUNTU_DIST}; do scp ${dist}-*/* ftp.indexdata.dk:/home/ftp/pub/${PRODUCT}/ubuntu/${dist} done for dist in ${DEBIAN_DIST}; do scp ${dist}-*/* ftp.indexdata.dk:/home/ftp/pub/${PRODUCT}/debian/${dist} done - echo "Remember to update APT on ftp.indexdata.dk" - echo "cd git-tools/update-archive" - echo "sudo su" - echo "./update-archive.sh" + echo "" + echo "====================================================" + echo "APT/YUM should be updated via cron every 15 minutes " + echo " from July 11 2013 and later." + echo "No need to call update archive on kebab" + echo "====================================================" exit 0 fi + +rm -f *.log + +# copy tars to centos build hosts +for dist in ${CENTOS_DIST}; do + arch=amd64 + prodver=${PRODUCT}-${VERSION} + tarname=${prodver}.tar.gz + if test ! -f ../${tarname}; then + echo "$tarname: missing" + exit 1 + fi + + if ssh $dist "test -f .rpmmacros && test -d rpmbuild/SOURCES && test -d rpmbuild/RPMS && test -d rpmbuild/SRPMS"; then + : + else + echo "Host $dist does not seem to be prepared with rpmbuild directories" + exit 1 + fi + + if scp ../${tarname} $dist:rpmbuild/SOURCES/ ; then + : + else + echo "Could not copy $tarname to $dist" + exit 1 + fi + if ssh $dist "cd rpmbuild/SOURCES && rm -fr $prodver && tar zxf $tarname && cd ${prodver} && rpmbuild -ba ${PRODUCT}.spec" >${dist}-${arch}.log 2>&1; then + : + else + echo "FAILED: See ${dist}-${arch}.log" + exit 1 + fi +done + +# call our privileged wrapper to clean the directories, no --dsc option +for dist in ${DEBIAN_DIST} ${UBUNTU_DIST}; do + for arch in ${USE_ARCHS}; do + sudo -n $PBUILDROOT --home=${HOME_EXPORT} --dist=$dist --arch=$arch + if test $? -ne 0; then + echo "FAILED" + echo "Run id-pbuild.sh using sudo or add yourself to /etc/sudoers:" + echo "${USER} ALL=NOPASSWD: ${ID_DEB_BUILD}/id-pbuild-root.sh" + exit 1 + fi + done +done + +# call our privileged wrapper to do the real work, with --dsc option i=0 date for dist in ${DEBIAN_DIST} ${UBUNTU_DIST}; do - for arch in ${ARCHS}; do - rm -fr ${dist}-${arch} - ( - if test ! -f /var/cache/pbuilder/${dist}-${arch}-base.tgz; then - sudo DIST=$dist ARCH=$arch $PBUILDER create - fi - for f in `find /var/cache/pbuilder/${dist}-${arch}-base.tgz -ctime +7`; do - sudo DIST=$dist ARCH=$arch $PBUILDER update --override-config - done - sudo DIST=$dist ARCH=$arch $PBUILDER --build $PKG - ) >${dist}-${arch}.log 2>&1 & + for arch in ${USE_ARCHS}; do + sudo -n $PBUILDROOT --home=${HOME_EXPORT} \ + --dist=$dist --arch=$arch --dsc=$PKG >${dist}-${arch}.log 2>&1 & i=`expr $i + 1` if test $i -eq $concurrency; then i=0 wait + if test -f ${dist}-${arch}/*.dsc; then + : + else + echo "FAILED: No .dsc file for ${dist}-${arch}" + exit 1 + fi fi done done wait for dist in ${DEBIAN_DIST} ${UBUNTU_DIST}; do - for arch in ${ARCHS}; do + for arch in ${USE_ARCHS}; do if test -f ${dist}-${arch}/*.dsc; then : else - echo "No .dsc file for ${dist}-${arch}" + echo "FAILED: No .dsc file for ${dist}-${arch}" exit 1 fi done done + date echo "Done" # Local Variables: