#!/bin/bash # $HeadURL$ $LastChangedRevision$ # Modules . $(bs-config bs_share_prefix)/include/bssupport.sh || { echo "${0##*/}: INTERNAL ERROR: failed to load bssupport.sh" >&2; exit 3; } . $(miniade) || { echo "${0##*/}: ERROR: miniade failed (hint: run 'miniade' to see error)" >&2; exit 1; } # Configurable stuff # Other globals main() { local MY_ARGS local PROGRAM VERBOSELEVEL PROGNAME # Defaults for options # Process options miniade_process_options --help-handler=usage MY_ARGS "$@" && set -- "${MY_ARGS[@]}" # Process arguments # Sanity checks and derivations # bs sets PROGRAM, but passes it to us through environment as BS_PROGRAM, copy it back. PROGRAM=$BS_PROGRAM VERBOSELEVEL=$BS_VERBOSELEVEL PACKAGE_DEBREPO_DIR=$BS_PACKAGE_DEBREPO_DIR PACKAGE_RPMREPO_DIR=$BS_PACKAGE_RPMREPO_DIR PKGCTRL_SVNREPO_URL=$BS_PKGCTRL_SVNREPO_URL PKGCTRL_SVNWC_DIR=$BS_PKGCTRL_SVNWC_DIR bssupport_checkset VERBOSELEVEL PROGRAM PACKAGE_DEBREPO_DIR PACKAGE_RPMREPO_DIR PKGCTRL_SVNREPO_URL PKGCTRL_SVNWC_DIR miniade_get_progname PROGNAME miniade_set_verboselevel $VERBOSELEVEL bssupport_changestate --id=$PROGRAM.debian --from=released,unreleased --step=$PROGNAME miniade_validate_command alien bssupport_sandbox bssupport_getstate $PROGRAM.debian STATE # Guts miniade_info "working out version ..." if [ $STATE = released ]; then for TAG_DIR in $(svn ls $PKGCTRL_SVNREPO_URL/tags); do if ! [[ $TAG_DIR =~ ^(.*)/$ ]]; then miniade_warning "$TAG_DIR: badly named tag directory" continue elif [ "X$VERSION" != X ] && dpkg --compare-versions ${BASH_REMATCH[1]} le $VERSION; then miniade_debug 10 "$TAG_DIR: not higher than previously noted highest" continue fi VERSION=${BASH_REMATCH[1]} done elif [ $STATE = unreleased ]; then bssupport_get_unreleased_pkgctrl_version $PKGCTRL_SVNWC_DIR/changelog VERSION # Note that $VERSION is not used. fi miniade_info "getting pkgctrl ..." if [ $STATE = released ]; then svn co --quiet $PKGCTRL_SVNREPO_URL/tags/$VERSION debian elif [ $STATE = unreleased ]; then cp -r $PKGCTRL_SVNWC_DIR debian # In make-bundle we set the release ID to be X.Y.Z.UNRELEASED. The analagous # thing to do here would be to set the release ID to X.Y.Z-A.UNRELEASED (by # modifying debian/changelog) but that triggers errors like: # # parsechangelog/debian: warning: debian/changelog(l37): found eof where expected first heading # parsechangelog/debian: error: fatal error occurred while parsing input # dpkg-parsechangelog: error: changelog parser /usr/lib/dpkg/parsechangelog/debian gave error exit status 255 # # So we must just accept the standard Debian way of doing it; namely we # accept the version number but put it into the 'UNRELEASED' distribution. # Damn! We can't do that because we don't insert the deb into a pool in # this script; that is left up to the user and dpkg-deb does not see # the release mentioned in the changelog. Okay, then the only option # is name the deb with X.Y.Z-A.UNRELEASED in the filename. fi #make miniade_info "making package ..." MAKEFLAGS=-s debian/rules get-orig-source > /dev/null || miniade_error "failed to get original sources (hint: see messages above)" tar xJf *.orig.tar.xz UNPACKED_TAR_DIR=$(ls | egrep -v '^(.*\.orig\.tar\.xz|make-package\..*\.output|debian)$') miniade_debug 10 "UNPACKED_TAR_DIR=$UNPACKED_TAR_DIR" mv debian "$UNPACKED_TAR_DIR/" cd "$UNPACKED_TAR_DIR/" if ! MAKEFLAGS=-s dpkg-buildpackage -us -uc -rfakeroot > ../$PROGNAME.$$.output 2>&1; then if $DESANDBOXING_FLAG; then # Sandbox will be destroyed making it impossible to examine output. Copy it elsewhere. cp ../$PROGNAME.$$.output /tmp miniade_error "dpkg-buildpackage failed (hint: see /tmp/$PROGNAME.$$.output)" else # Sandbox will be preserved, so we can reference it in error messages. miniade_error "dpkg-buildpackage failed (hint: see $(realpath ../$PROGNAME.$$.output))" fi fi cd .. DEB=$(echo *.deb) if ! [[ $DEB =~ ^([^_]+_[^-]+)-([^_]+)_(.*)\.(deb)$ ]]; then miniade_error "$DEB: filename seems to be malformed (hint: name should be '${PROGRAM}_-_all.deb')" fi DEB_ARCH=${BASH_REMATCH[3]} # Just as for rpms below, now we rename unreleased debs from # pkg_srcversion-pkgversion_arch.deb to pkg_srcversion-pkgversion.UNRELEASED_arch.deb. if [ $STATE = unreleased ]; then MV_CMDLINE="mv $DEB ${BASH_REMATCH[1]}-${BASH_REMATCH[2]}.UNRELEASED_${BASH_REMATCH[3]}.${BASH_REMATCH[4]}" eval "$MV_CMDLINE" DEB=${BASH_REMATCH[1]}-${BASH_REMATCH[2]}.UNRELEASED_${BASH_REMATCH[3]}.${BASH_REMATCH[4]} fi if [ "X$PACKAGE_RPMREPO_DIR" != X ]; then # Work in a new dir (workaround for BTS#651321; still broken in Debian 10, but allegedly # fixed in Debian 11). ( mkdir alien cd alien # Generate RPM step by step to allow fixing spec file (workaround for BTS#759533; # see https://www.electricmonk.nl/log/2017/02/23/how-to-solve-rpms-created-by-alien-having-file-conflicts/) # Alien is noisy, so capture output and output it only if error on unexpected or non-zero exit. RC=0 alien --scripts -r -g ../*.deb > /tmp/$PROGNAME.$$.stdout 2>/tmp/$PROGNAME.$$.stderr || RC=$? STDERR_RC=0 [[ $(cat /tmp/$PROGNAME.$$.stderr) =~ ^Warning:\ alien\ is\ not\ running\ as\ root\!.Warning:\ Ownerships\ of\ files\ in\ the\ generated\ packages\ will\ probably\ be\ wrong\.$ ]] || STDERR_RC=$? STDOUT_RC=0 [[ $(cat /tmp/$PROGNAME.$$.stdout) =~ ^Directory\ .*\ prepared\.$ ]] || STDOUT_RC=$? if [ $RC != 0 ] || [ $STDERR_RC != 0 ] || [ $STDOUT_RC != 0 ]; then echo "RC=$RC, STDERR_RC=$STDERR_RC, STDOUT_RC=$STDOUT_RC" cat /tmp/$PROGNAME.$$.stdout cat /tmp/$PROGNAME.$$.stderr >&2 rm -f /tmp/$PROGNAME.$$.stdout /tmp/$PROGNAME.$$.stderr exit $RC fi ( cd * sed '/^%dir/d' *.spec > /tmp/$PROGNAME.$$.spec rm -f *.spec case $DEB_ARCH in all) RPM_ARCH=noarch ;; amd64) RPM_ARCH=x86_64 ;; *) RPM_ARCH=$DEB_ARCH ;; esac rpmbuild --target=$RPM_ARCH --buildroot $PWD -bb /tmp/$PROGNAME.$$.spec > /dev/null 2>&1 ) || miniade_error "rpm generation failed (hint: see messages above)" mv *.rpm .. ) || miniade_error "rpm generation failed (hint: see messages above)" RPM=$(echo *.rpm) # Just as for debs above, now we rename unreleased rpms from # pkg-srcversion-pkgversion.arch.rpm to pkg-srcversion-pkgversion.UNRELEASED.arch.rpm. if [ $STATE = unreleased ]; then miniade_info "renaming RPM to indicate unreleased status ..." [[ $RPM =~ ^(.*-.*)-([0-9]+)\.([^-]*\.rpm)$ ]] mv $RPM ${BASH_REMATCH[1]}-${BASH_REMATCH[2]}.UNRELEASED.${BASH_REMATCH[3]} RPM=${BASH_REMATCH[1]}-${BASH_REMATCH[2]}.UNRELEASED.${BASH_REMATCH[3]} fi # It's leaving a directory in my home! I should submit a bug report. rm -fr ~/rpmbuild else miniade_warning "not building rpm" fi #upload miniade_info "uploading package to $PACKAGE_DEBREPO_DIR/$DEB ..." mkdir -p $PACKAGE_DEBREPO_DIR cp $DEB $PACKAGE_DEBREPO_DIR/ # test-pkgctrl will want to lintian a copy so if it asked for a copy then give it one. [ "X$PARENT_SANDBOX" = X ] || cp $DEB $PARENT_SANDBOX/ if [ "X$PACKAGE_RPMREPO_DIR" != X ]; then miniade_info "uploading package to $PACKAGE_RPMREPO_DIR/$RPM ..." mkdir -p $PACKAGE_RPMREPO_DIR cp $RPM $PACKAGE_RPMREPO_DIR fi #deloldunreleased # If we uploaded a package of released pkgctrl files then delete any unreleased packages. if [ $STATE = released ]; then miniade_info "deleting old *unreleased* packages ..." rm -f $PACKAGE_DEBREPO_DIR/$PROGRAM*UNRELEASED* if [ "X$PACKAGE_RPMREPO_DIR" != X ]; then rm -f $PACKAGE_RPMREPO_DIR/$PROGRAM*UNRELEASED* fi fi } main "$@"