Blob Blame History Raw
#
# . ./build.vars and set -o errexit -o noglob are assumed.
#

do_tarball_dist() {
	TARBALL_FNAME=${TARBALL_FNAME_PREFIX}${BUILD_USER}@${BUILD_HNAME}-${BUILD_DATE_START}.tar.${TARBALL_SUFFIX};	
	secure_rm ${PREFIX_BASENAME}.bak;
	insecure_mkdir ${PREFIX_BASENAME}.bak;
	log_msg info "Converting symbolic links in ${PREFIX_BASENAME} to hard links...";
	for _dtd_lname in $(find ${PREFIX_BASENAME} -type l); do
		_dtd_fname="$(readlink -f -- ${_dtd_lname})";
		if [ -f "${_dtd_fname}" ]; then
			_dtd_dname_new="${_dtd_lname%/*}";
			_dtd_dname_new="${_dtd_dname_new%/}/";
			_dtd_dname_new="${PREFIX_BASENAME}.bak/${_dtd_dname_new#${PREFIX_BASENAME}/}";
			insecure_mkdir "${_dtd_dname_new}";
			cp -P "${_dtd_lname}" "${_dtd_dname_new}";
			secure_rm "${_dtd_lname}";
			ln -f -- "${_dtd_fname}" "${_dtd_lname}";
		fi;
	done;
	log_msg info "Converted symbolic links in ${PREFIX_BASENAME} to hard links.";
	tar -cpf - $(find . -maxdepth 2 -mindepth 1 -type d				\
			-not -path ./${PREFIX_BASENAME} 				\
			-not -path ./${PREFIX_BASENAME}.bak				\
			-not -path ./${PREFIX_BASENAME}.bak/\*				\
			-not -path ./tmp -not -path ./tmp/\*)				\
		midipix_shortcut.vbs midipix.sh	README					|\
	${TARBALL_COMPRESS_CMD} ${TARBALL_COMPRESS_ARGS} -c > ${TARBALL_FNAME};
	log_msg info "Finished building binary distribution tarball.";
	if [ -x "$(which gpg 2>/dev/null)" -a -n "${TARBALL_SIGN_GPG_KEY}" ] &&\
				gpg --list-keys "${TARBALL_SIGN_GPG_KEY}" >/dev/null 2>&1; then
		gpg --armor --passphrase-file /dev/null					\
			--local-user "${TARBALL_SIGN_GPG_KEY}" --sign ${TARBALL_FNAME};
		log_msg info "Signed binary distribution tarball.";
	fi;

	for _dtd_lname in $(find ${PREFIX_BASENAME}.bak -type l); do
		_dtd_lname_orig="${PREFIX_BASENAME}${_dtd_lname#${PREFIX_BASENAME}.bak}";
		secure_rm "${_dtd_lname_orig}";
		cp -P "${_dtd_lname}" "${_dtd_lname_orig}";
	done;
	secure_rm ${PREFIX_BASENAME}.bak;
	log_msg info "Restored ${PREFIX_BASENAME}.";
};

do_tarball_toolchain() {
	TARBALL_CROSS_FNAME=${TARBALL_CROSS_FNAME_PREFIX}${BUILD_USER}@${BUILD_HNAME}-${BUILD_DATE_START}.tar.${TARBALL_SUFFIX};	
	tar -cpf - bin include lib lib64 libexec share ${PKG_TARGET}			|\
	${TARBALL_COMPRESS_CMD} ${TARBALL_COMPRESS_ARGS} -c > ${TARBALL_CROSS_FNAME};
	log_msg info "Finished building toolchain tarball.";
	if [ -x "$(which gpg 2>/dev/null)" -a -n "${TARBALL_CROSS_SIGN_GPG_KEY}" ] &&\
				gpg --list-keys "${TARBALL_CROSS_SIGN_GPG_KEY}" >/dev/null 2>&1; then
		gpg --armor --passphrase-file /dev/null					\
			--local-user "${TARBALL_CROSS_SIGN_GPG_KEY}" --sign ${TARBALL_CROSS_FNAME};
		log_msg info "Signed toolchain tarball.";
	fi;
};

do_tarball_minipix() {
	TARBALL_MINIPIX_FNAME=${TARBALL_MINIPIX_FNAME_PREFIX}${BUILD_USER}@${BUILD_HNAME}-${BUILD_DATE_START}.tar.${TARBALL_SUFFIX};	
	tar -cpf - minipix 								\
		midipix_shortcut.vbs midipix.sh README					|\
	${TARBALL_COMPRESS_CMD} ${TARBALL_COMPRESS_ARGS} -c > ${TARBALL_MINIPIX_FNAME};
	log_msg info "Finished building binary Minipix distribution tarball.";
	if [ -x "$(which gpg 2>/dev/null)" -a -n "${TARBALL_MINIPIX_SIGN_GPG_KEY}" ] &&\
				gpg --list-keys "${TARBALL_MINIPIX_SIGN_GPG_KEY}" >/dev/null 2>&1; then
		gpg --armor --passphrase-file /dev/null					\
			--local-user "${TARBALL_MINIPIX_SIGN_GPG_KEY}" --sign ${TARBALL_MINIPIX_FNAME};
		log_msg info "Signed binary Minipix distribution tarball.";
	fi;
};

do_tarball_src() {
	TARBALL_SRC_FNAME=${TARBALL_SRC_FNAME_PREFIX}${BUILD_USER}@${BUILD_HNAME}-${BUILD_DATE_START}.tar.${TARBALL_SUFFIX};
	log_msg info "Building source tarball...";
	tar -cpf - $(find tmp -mindepth 2 -maxdepth 2				\
		-not -path tmp/.\*						\
		-not -path tmp/ntctty/.git					\
		-not -path tmp/psxscl/.git					\
		-not -path tmp/ptycon/.git)					|\
	${TARBALL_COMPRESS_CMD} ${TARBALL_COMPRESS_ARGS} -c > ${TARBALL_SRC_FNAME};
	log_msg info "Finished building source tarball.";
	if [ -x "$(which gpg 2>/dev/null)" -a -n "${TARBALL_SRC_SIGN_GPG_KEY}" ] &&\
				gpg --list-keys "${TARBALL_SRC_SIGN_GPG_KEY}" >/dev/null 2>&1; then
		gpg --armor --passphrase-file /dev/null				\
			--local-user "${TARBALL_SRC_SIGN_GPG_KEY}" --sign ${TARBALL_SRC_FNAME};
		log_msg info "Signed source tarball.";
	fi;
};

do_tarballs() {
	if [ ${BUILD_SCRIPT_RC:-0} -eq 0 ]\
	&& [ ${ARG_TARBALL:-0} -eq 1 ]; then
		log_msg info "Building distribution tarballs...";
		case ${TARBALL_SUFFIX} in
		bz2)	if [ -n "$(which pbzip2 2>/dev/null)" ]; then
				TARBALL_COMPRESS_CMD="pbzip2";
			else
				TARBALL_COMPRESS_CMD="bzip2";
			fi; ;;
		gz)	if [ -n "$(which pigz 2>/dev/null)" ]; then
				TARBALL_COMPRESS_CMD="pigz";
			else
				TARBALL_COMPRESS_CMD="gzip";
			fi; ;;
		xz)	TARBALL_COMPRESS_CMD="xz";
			TARBALL_COMPRESS_ARGS="-T0"; ;;
		*)	log_msg failexit "Unknown tarball suffix \`.${TARBALL_SUFFIX}'.";
		esac;
		cd ${PREFIX}; PREFIX_BASENAME=${PREFIX_NATIVE##*/};
		do_tarball_dist; do_tarball_toolchain; do_tarball_minipix;
		if [ "${BUILD}" = "debug" ]; then
			do_tarball_src;
		fi;
	fi;
};

# vim:filetype=sh