Blame subr/tarballs.subr

Lucio Andrés Illanes Albornoz (arab, vxp) afcefa
#
Lucio Andrés Illanes Albornoz (arab, vxp) 820be1
# . ./build.vars and set -o errexit -o noglob are assumed.
Lucio Andrés Illanes Albornoz (arab, vxp) afcefa
#
Lucio Andrés Illanes Albornoz (arab, vxp) afcefa
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
do_tarball_dist() {
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	TARBALL_FNAME=${TARBALL_FNAME_PREFIX}${BUILD_USER}@${BUILD_HNAME}-${BUILD_DATE_START}.tar.${TARBALL_SUFFIX};	
Lucio Andrés Illanes Albornoz (arab, vxp) e1e61f
	secure_rm ${PREFIX_BASENAME}.bak;
Lucio Andrés Illanes Albornoz (arab, vxp) e1e61f
	insecure_mkdir ${PREFIX_BASENAME}.bak;
Lucio Andrés Illanes Albornoz (arab, vxp) e1e61f
	log_msg info "Converting symbolic links in ${PREFIX_BASENAME} to hard links...";
Lucio Andrés Illanes Albornoz (arab, vxp) e1e61f
	for _dtd_lname in $(find ${PREFIX_BASENAME} -type l); do
Lucio Andrés Illanes Albornoz (arab, vxp) 680b7c
		_dtd_fname="$(readlink -f -- ${_dtd_lname})";
Lucio Andrés Illanes Albornoz (arab, vxp) 680b7c
		if [ -f "${_dtd_fname}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) e1e61f
			_dtd_dname_new="${_dtd_lname%/*}";
Lucio Andrés Illanes Albornoz (arab, vxp) e1e61f
			_dtd_dname_new="${_dtd_dname_new%/}/";
Lucio Andrés Illanes Albornoz (arab, vxp) e1e61f
			_dtd_dname_new="${PREFIX_BASENAME}.bak/${_dtd_dname_new#${PREFIX_BASENAME}/}";
Lucio Andrés Illanes Albornoz (arab, vxp) e1e61f
			insecure_mkdir "${_dtd_dname_new}";
Lucio Andrés Illanes Albornoz (arab, vxp) e1e61f
			cp -P "${_dtd_lname}" "${_dtd_dname_new}";
Lucio Andrés Illanes Albornoz (arab, vxp) e1e61f
			secure_rm "${_dtd_lname}";
Lucio Andrés Illanes Albornoz (arab, vxp) e1e61f
			ln -f -- "${_dtd_fname}" "${_dtd_lname}";
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
		fi;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	done;
Lucio Andrés Illanes Albornoz (arab, vxp) e1e61f
	log_msg info "Converted symbolic links in ${PREFIX_BASENAME} to hard links.";
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	tar -cpf - $(find . -maxdepth 2 -mindepth 1 -type d				\
Lucio Andrés Illanes Albornoz (arab, vxp) e1e61f
			-not -path ./${PREFIX_BASENAME} 				\
Lucio Andrés Illanes Albornoz (arab, vxp) e1e61f
			-not -path ./${PREFIX_BASENAME}.bak				\
Lucio Andrés Illanes Albornoz (arab, vxp) 48dbe5
			-not -path ./${PREFIX_BASENAME}.bak/\*				\
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
			-not -path ./tmp -not -path ./tmp/\*)				\
Lucio Andrés Illanes Albornoz (arab, vxp) 5ee71e
		midipix_shortcut.vbs midipix.sh	README					|\
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	${TARBALL_COMPRESS_CMD} ${TARBALL_COMPRESS_ARGS} -c > ${TARBALL_FNAME};
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	log_msg info "Finished building binary distribution tarball.";
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	if [ -x "$(which gpg 2>/dev/null)" -a -n "${TARBALL_SIGN_GPG_KEY}" ] &&\
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
				gpg --list-keys "${TARBALL_SIGN_GPG_KEY}" >/dev/null 2>&1; then
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
		gpg --armor --passphrase-file /dev/null					\
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
			--local-user "${TARBALL_SIGN_GPG_KEY}" --sign ${TARBALL_FNAME};
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
		log_msg info "Signed binary distribution tarball.";
Lucio Andrés Illanes Albornoz (arab, vxp) afe7b9
	fi;
Lucio Andrés Illanes Albornoz (arab, vxp) e1e61f
Lucio Andrés Illanes Albornoz (arab, vxp) e1e61f
	for _dtd_lname in $(find ${PREFIX_BASENAME}.bak -type l); do
Lucio Andrés Illanes Albornoz (arab, vxp) e1e61f
		_dtd_lname_orig="${PREFIX_BASENAME}${_dtd_lname#${PREFIX_BASENAME}.bak}";
Lucio Andrés Illanes Albornoz (arab, vxp) e1e61f
		secure_rm "${_dtd_lname_orig}";
Lucio Andrés Illanes Albornoz (arab, vxp) e1e61f
		cp -P "${_dtd_lname}" "${_dtd_lname_orig}";
Lucio Andrés Illanes Albornoz (arab, vxp) e1e61f
	done;
Lucio Andrés Illanes Albornoz (arab, vxp) e1e61f
	secure_rm ${PREFIX_BASENAME}.bak;
Lucio Andrés Illanes Albornoz (arab, vxp) e1e61f
	log_msg info "Restored ${PREFIX_BASENAME}.";
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
};
Lucio Andrés Illanes Albornoz (arab, vxp) afcefa
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
do_tarball_toolchain() {
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	TARBALL_CROSS_FNAME=${TARBALL_CROSS_FNAME_PREFIX}${BUILD_USER}@${BUILD_HNAME}-${BUILD_DATE_START}.tar.${TARBALL_SUFFIX};	
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	tar -cpf - bin include lib lib64 libexec share ${PKG_TARGET}			|\
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	${TARBALL_COMPRESS_CMD} ${TARBALL_COMPRESS_ARGS} -c > ${TARBALL_CROSS_FNAME};
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	log_msg info "Finished building toolchain tarball.";
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	if [ -x "$(which gpg 2>/dev/null)" -a -n "${TARBALL_CROSS_SIGN_GPG_KEY}" ] &&\
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
				gpg --list-keys "${TARBALL_CROSS_SIGN_GPG_KEY}" >/dev/null 2>&1; then
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
		gpg --armor --passphrase-file /dev/null					\
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
			--local-user "${TARBALL_CROSS_SIGN_GPG_KEY}" --sign ${TARBALL_CROSS_FNAME};
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
		log_msg info "Signed toolchain tarball.";
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	fi;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
};
Lucio Andrés Illanes Albornoz (arab, vxp) 9499b0
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
do_tarball_minipix() {
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	TARBALL_MINIPIX_FNAME=${TARBALL_MINIPIX_FNAME_PREFIX}${BUILD_USER}@${BUILD_HNAME}-${BUILD_DATE_START}.tar.${TARBALL_SUFFIX};	
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	tar -cpf - minipix 								\
Lucio Andrés Illanes Albornoz (arab, vxp) 5ee71e
		midipix_shortcut.vbs midipix.sh README					|\
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	${TARBALL_COMPRESS_CMD} ${TARBALL_COMPRESS_ARGS} -c > ${TARBALL_MINIPIX_FNAME};
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	log_msg info "Finished building binary Minipix distribution tarball.";
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	if [ -x "$(which gpg 2>/dev/null)" -a -n "${TARBALL_MINIPIX_SIGN_GPG_KEY}" ] &&\
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
				gpg --list-keys "${TARBALL_MINIPIX_SIGN_GPG_KEY}" >/dev/null 2>&1; then
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
		gpg --armor --passphrase-file /dev/null					\
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
			--local-user "${TARBALL_MINIPIX_SIGN_GPG_KEY}" --sign ${TARBALL_MINIPIX_FNAME};
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
		log_msg info "Signed binary Minipix distribution tarball.";
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	fi;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
};
Lucio Andrés Illanes Albornoz (arab, vxp) f42965
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
do_tarball_src() {
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	TARBALL_SRC_FNAME=${TARBALL_SRC_FNAME_PREFIX}${BUILD_USER}@${BUILD_HNAME}-${BUILD_DATE_START}.tar.${TARBALL_SUFFIX};
Lucio Andrés Illanes Albornoz (arab, vxp) 820be1
	log_msg info "Building source tarball...";
Lucio Andrés Illanes Albornoz (arab, vxp) f42965
	tar -cpf - $(find tmp -mindepth 2 -maxdepth 2				\
Lucio Andrés Illanes Albornoz (arab, vxp) f42965
		-not -path tmp/.\*						\
Lucio Andrés Illanes Albornoz (arab, vxp) ed295a
		-not -path tmp/ntctty/.git					\
Lucio Andrés Illanes Albornoz (arab, vxp) ed295a
		-not -path tmp/psxscl/.git					\
Lucio Andrés Illanes Albornoz (arab, vxp) ed295a
		-not -path tmp/ptycon/.git)					|\
Lucio Andrés Illanes Albornoz (arab, vxp) 820be1
	${TARBALL_COMPRESS_CMD} ${TARBALL_COMPRESS_ARGS} -c > ${TARBALL_SRC_FNAME};
Lucio Andrés Illanes Albornoz (arab, vxp) 820be1
	log_msg info "Finished building source tarball.";
Lucio Andrés Illanes Albornoz (arab, vxp) 820be1
	if [ -x "$(which gpg 2>/dev/null)" -a -n "${TARBALL_SRC_SIGN_GPG_KEY}" ] &&\
Lucio Andrés Illanes Albornoz (arab, vxp) 820be1
				gpg --list-keys "${TARBALL_SRC_SIGN_GPG_KEY}" >/dev/null 2>&1; then
Lucio Andrés Illanes Albornoz (arab, vxp) f42965
		gpg --armor --passphrase-file /dev/null				\
Lucio Andrés Illanes Albornoz (arab, vxp) 820be1
			--local-user "${TARBALL_SRC_SIGN_GPG_KEY}" --sign ${TARBALL_SRC_FNAME};
Lucio Andrés Illanes Albornoz (arab, vxp) 820be1
		log_msg info "Signed source tarball.";
Lucio Andrés Illanes Albornoz (arab, vxp) 820be1
	fi;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
};
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
do_tarballs() {
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	if [ ${BUILD_SCRIPT_RC:-0} -eq 0 ]\
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	&& [ ${ARG_TARBALL:-0} -eq 1 ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
		log_msg info "Building distribution tarballs...";
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
		case ${TARBALL_SUFFIX} in
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
		bz2)	if [ -n "$(which pbzip2 2>/dev/null)" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
				TARBALL_COMPRESS_CMD="pbzip2";
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
			else
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
				TARBALL_COMPRESS_CMD="bzip2";
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
			fi; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
		gz)	if [ -n "$(which pigz 2>/dev/null)" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
				TARBALL_COMPRESS_CMD="pigz";
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
			else
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
				TARBALL_COMPRESS_CMD="gzip";
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
			fi; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
		xz)	TARBALL_COMPRESS_CMD="xz";
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
			TARBALL_COMPRESS_ARGS="-T0"; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
		*)	log_msg failexit "Unknown tarball suffix \`.${TARBALL_SUFFIX}'.";
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
		esac;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
		cd ${PREFIX}; PREFIX_BASENAME=${PREFIX_NATIVE##*/};
Lucio Andrés Illanes Albornoz (arab, vxp) 222f61
		do_tarball_dist; do_tarball_toolchain; do_tarball_minipix;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
		if [ "${BUILD}" = "debug" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
			do_tarball_src;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
		fi;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	fi;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
};
Lucio Andrés Illanes Albornoz (arab, vxp) afcefa
Lucio Andrés Illanes Albornoz (arab, vxp) afcefa
# vim:filetype=sh