X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=id-deb-build%2Fid-pbuild.sh;h=8e07f24c05e99c2b49650c877a8784522222637b;hb=59bd10fb387c1460bf9438b27942bfc499944b98;hp=fdb144268c4da7a6050dd7f31e59923789dffbef;hpb=cd209730f560d38dc77e0dd9b2d940a2a7b3dd5e;p=git-tools-moved-to-github.git diff --git a/id-deb-build/id-pbuild.sh b/id-deb-build/id-pbuild.sh index fdb1442..8e07f24 100755 --- a/id-deb-build/id-pbuild.sh +++ b/id-deb-build/id-pbuild.sh @@ -1,187 +1,250 @@ #!/bin/sh -# This script builds Debian packages for one or more distributions -# in i386/amd64 architectures. It uses pbuilder. pbuilder requires root -# privilege and so this script should be invoked with sudo. - usage() { cat <&2 fi -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 - -MKDEBSRC=${ID_DEB_BUILD}/id-mk-deb-src.sh -if test ! -x $MKDEBSRC; then - echo "$MKDEBSRC not found" +if test -f IDMETA; then + . ./IDMETA +else + echo "IDMETA missing" exit 1 fi +UPLOAD_HOST=${UPLOAD_HOST:=ftp.indexdata.dk} +UPLOAD_PATH=${UPLOAD_PATH:=/home/ftp/pub} -if test -d deb-src; then - cd deb-src -else - $MKDEBSRC +if test "$DEBIAN_DIST_A" -o "$UBUNTU_DIST_A" -o "$CENTOS_DIST_A"; then + DEBIAN_DIST=$DEBIAN_DIST_A + UBUNTU_DIST=$UBUNTU_DIST_A + CENTOS_DIST=$CENTOS_DIST_A fi - -if test -d deb-src; then - cd deb-src -fi - -for f in *.dsc; do - if test -f "$f"; then - PKG=$f +ID_DEB_BUILD=~/proj/git-tools/id-deb-build +if test "$DEBIAN_DIST" -o "$UBUNTU_DIST"; then + debian=true + DNAME=`awk '/Source:/ {print $2}' debian/control` + if test "$NAME" -a "$NAME" != "$DNAME"; then + echo "NAME in IDMETA ($NAME) does not match debian/control ($DNAME)" + exit 1 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 test -z "$PRODUCT"; then - PRODUCT=`echo *.dsc|sed 's/_.*//g'` -fi -ARCHS="i386 amd64" -if grep "Architecture: all" $PKG >/dev/null; then - USE_ARCHS=i386 + PRODUCT=$DNAME else - USE_ARCHS=$ARCHS + debian=false fi -echo "Dsc $PKG . Product $PRODUCT" -echo "Ubuntu distros: $UBUNTU_DIST" -echo "Debian distros: $DEBIAN_DIST" -if test "${SUDO_USER}"; then - echo "Running as sudo." - echo "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} +if test "$CENTOS_DIST"; then + centos=true + RNAME=`awk '/Name:/ {print $2}' *.spec` + if test "$NAME" -a "$NAME" != "$RNAME"; then + echo "NAME in IDMETA ($NAME) does not match RPM spec NAME ($RNAME)" + exit 1 + fi + PRODUCT=$RNAME + if test ! -d ~/rpmbuild; then + mkdir -p ~/pmbuild/BUILD + mkdir -p ~/rpmbuild/RPMS/noarch + mkdir -p ~/rpmbuild/RPMS/x86_64 + mkdir -p ~/rpmbuild/SOURCES + mkdir -p ~/rpmbuild/SPECS + mkdir -p ~/rpmbuild/SRPMS + fi else - HOME_EXPORT=$HOME -fi -if test ! -f ${HOME_EXPORT}/.pbuilderrc; then - echo "${HOME_EXPORT}/.pbuilderrc missing" - exit 1 + centos=false fi +TAR=${PRODUCT}-${VERSION}.tar.gz if $upload; then - 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 "" - echo "====================================================" - echo "Remember to update APT on ftp.indexdata.dk !!!" - echo "" - echo "ssh ftp.indexdata.dk" - echo "cd ~/proj/git-tools/update-archive" - echo "sudo su" - echo "./update-archive.sh" - echo "====================================================" + UPLOAD_URI=${UPLOAD_HOST}:${UPLOAD_PATH}/${PRODUCT} + echo "Uploading to ${UPLOAD_URI}" + if $centos; then + pkg_names=`rpm -q --specfile ${PRODUCT}.spec --queryformat "%{NAME}-%{VERSION}-%{RELEASE}\n"` + for dist in ${CENTOS_DIST}; do + case $dist in + centos5) + ftpdir=centos/5.5 + r=id-epel-5-x86_64 ;; + centos6) + ftpdir=centos/6 + r=id-epel-6-x86_64 ;; + centos7) + ftpdir=centos/7 + r=id-epel-7-x86_64 ;; + *) + ftpdir=centos/$dist + r=$dist ;; + esac + echo "$r" + for pkg in ${pkg_names}; do + ssh ${UPLOAD_HOST} "mkdir -p ${UPLOAD_PATH}/${PRODUCT}/redhat/${ftpdir}/SRPMS" + if test -f ~/rpmbuild/SRPMS/${pkg}.src.rpm; then + scp ~/rpmbuild/SRPMS/${pkg}.src.rpm ${UPLOAD_URI}/redhat/${ftpdir}/SRPMS + fi + for arch in x86_64 noarch; do + if test -f ~/rpmbuild/$r/${pkg}.${arch}.rpm; then + ssh ${UPLOAD_HOST} "mkdir -p ${UPLOAD_PATH}/${PRODUCT}/redhat/${ftpdir}/RPMS/${arch}" + scp ~/rpmbuild/$r/${pkg}.${arch}.rpm ${UPLOAD_URI}/redhat/${ftpdir}/RPMS/${arch} + fi + done + done + done + if ! ssh ${UPLOAD_HOST} "sudo -n /home/indexdata/proj/git-tools/update-archive/update-yum-archive.sh" >~/rpmbuild/yum-update.log 2>&1; then + echo "update-yum-archive.sh failed. Inspect ~/rpmbuild/yum-update.log" + exit 1 + fi + fi + + if $debian; then + cd deb-src + if test -n "${UBUNTU_DIST}"; then + for dist in ${UBUNTU_DIST}; do + ssh ${UPLOAD_HOST} "mkdir -p ${UPLOAD_PATH}/${PRODUCT}/ubuntu/${dist}" + if ! scp ${dist}-*/* ${UPLOAD_URI}/ubuntu/${dist}; then + echo "Upload failed for $dist" + exit 1 + fi + done + fi + if test -n "${DEBIAN_DIST}"; then + for dist in ${DEBIAN_DIST}; do + ssh ${UPLOAD_HOST} "mkdir -p ${UPLOAD_PATH}/${PRODUCT}/debian/${dist}" + if ! scp ${dist}-*/* ${UPLOAD_URI}/debian/${dist}; then + echo "Upload failed for $dist" + exit 1 + fi + done + fi + if ! ssh ${UPLOAD_HOST} "sudo -n /home/indexdata/proj/git-tools/update-archive/update-archive.sh --ubuntu=\"${UBUNTU_DIST}\" --debian=\"${DEBIAN_DIST}\""; then + echo "update-archive.sh failed" + exit 1 + fi + fi + echo "Upload successful - we hope" exit 0 fi -rm -f *.log -# 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 $centos; then + SPEC=${PRODUCT}.spec + cp ${TAR} ~/rpmbuild/SOURCES + cat ${SPEC}|sed "s/%define idmetaversion.*/%define idmetaversion ${VERSION}/" >~/rpmbuild/SPECS/${SPEC} + sudo lxc-attach -n mockbuild -- rpmbuild -bs ~/rpmbuild/SPECS/${SPEC} + for dist in ${CENTOS_DIST}; do + case $dist in + centos5) + r=id-epel-5-x86_64 ;; + centos6) + r=id-epel-6-x86_64 ;; + centos7) + r=id-epel-7-x86_64 ;; + *) + r=$dist ;; + esac + echo -n "$r" + mkdir -p ~/rpmbuild/$r + if sudo lxc-attach -n mockbuild -- mock -q --resultdir=~/rpmbuild/$r -r $r ~/rpmbuild/SRPMS/${PRODUCT}-${VERSION}*src.rpm; then + echo " done" + else + echo " failed. Inspect ~/rpmbuild/$r/build.log" + 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 ${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 - : +fi +if $debian; then + sudo rm -fr deb-src + MKDEBSRC=${ID_DEB_BUILD}/id-mk-deb-src.sh + if test ! -x $MKDEBSRC; then + echo "$MKDEBSRC not found" + exit 1 + fi + if ! ${ID_DEB_BUILD}/id-mk-deb-changelog.sh; then + echo "id-mk-deb-changelog.sh failed" + fi + if ! ${MKDEBSRC}; then + echo "id-mk-deb-src.sh failed" + fi + cd deb-src + for f in *.dsc; do + if test -f "$f"; then + DSC=$f + fi + done + if test -z "$DSC"; then + echo "${DSC}does not exist" + exit 1 + fi + if grep "Architecture: all" $DSC >/dev/null; then + USE_ARCHS=i386 + else + USE_ARCHS="i386 amd64" + fi + for dist in ${DEBIAN_DIST} ${UBUNTU_DIST}; do + for arch in ${USE_ARCHS}; do + echo -n "dist=$dist arch=$arch" + rm -f ~/.pbuilderrc + echo "DIST=$dist" > ~/.pbuilderrc + echo "ARCH=$arch" >> ~/.pbuilderrc + cat ${ID_DEB_BUILD}/pbuilderrc >> ~/.pbuilderrc + echo -n " update" + if ! sudo lxc-attach -n pbuilder -- pbuilder --update --override-config >update-${dist}-${arch}.log 2>&1; then + echo -n " create" + if ! sudo lxc-attach -n pbuilder -- pbuilder --create >create-${dist}-${arch}.log 2>&1; then + echo " failed. Inspect deb-src/create-${dist}-${arch}.log" + exit 1 + fi + echo -n " update" + if ! sudo lxc-attach -n pbuilder -- pbuilder --update --override-config >update-${dist}-${arch}.log 2>&1; then + echo " failed. Inspect deb-src/update-${dist}-${arch}.log" + exit 1 + fi + fi + echo -n " build" + if sudo lxc-attach -n pbuilder -- pbuilder --build $DSC >build-${dist}-${arch}.log 2>&1; then + echo " done" else - echo "No .dsc file for ${dist}-${arch}" + echo " failed. Inspect deb-src/build-${dist}-${arch}.log" exit 1 fi - fi - done -done -wait -for dist in ${DEBIAN_DIST} ${UBUNTU_DIST}; do - for arch in ${USE_ARCHS}; do - if test -f ${dist}-${arch}/*.dsc; then - : - else - echo "No .dsc file for ${dist}-${arch}" - exit 1 - fi + done done -done -date -echo "Done" +fi + # Local Variables: # mode:shell-script -# sh-indentation: 2 +# sh-indentation: 4 # sh-basic-offset: 4 # End: +