/duilder (081d1c2174db44f5834f6bf6eb2cf4e805faa2d2) (13141 bytes) (mode 100755) (type blob)

#!/bin/bash

set -e

function duilder_final()
{
	PRJ="${1}"
	VER="${2}"
	RELEASE_SCRIPT="${3}"

	# Run release script
	if [ ! -z "${RELEASE_SCRIPT}" -a -x "${RELEASE_SCRIPT}" ]; then
		echo "[*] Running ${RELEASE_SCRIPT}..."
		${RELEASE_SCRIPT}
	fi
}

function duilder_docs()
{
	PRJ="${1}"
	VER="${2}"
	EXPORT_PATH="${3}"

	if [ ! -d "${EXPORT_PATH}" ]; then
		echo "[*] WARN: ${EXPORT_PATH} does not exists. Creating it..."
		mkdir -p "${EXPORT_PATH}"
	fi

	echo "[*] Copying docs to [${EXPORT_PATH}]..."
	for f in README License LICENSE Changelog Changelog-last TODO FAQ INSTALL; do
		if [ -r "${f}" ]; then
			cp -vp "${f}" "${EXPORT_PATH}/"
		fi
	done
	echo

	if [ -d "screenshot" ]; then
		echo "[*] Copying screenshots..."
		mkdir -p "${EXPORT_PATH}"
		cp -vp screenshot/* "${EXPORT_PATH}/"
		echo
	fi
}

function duilder_git()
{
	PRJ="${1}"
	GIT_DEST="${2}"
	EXPORT_GIT="${3}"
	GIT_CHANGELOG="${4}"
	GIT_PUSH="${5}"

	if [ ! -x /usr/bin/git ]; then
		echo "[*] Warning: Git not found!"
		exit 0
	fi

	if [ ! -d .git ]; then
		echo "[*] Warning: I cannot find .git directory!"
		exit 0
	fi

	if [ "${EXPORT_GIT}" = "1" ]; then
		echo "[*] Generating GIT tree for HTTP transport..."
		if [ ! -d "${GIT_DEST}/${PRJ}.git" ]; then
			git clone --bare . "${GIT_DEST}/${PRJ}.git"

			# Activate post-update hook
			cp "${GIT_DEST}/${PRJ}.git/hooks/post-update.sample" \
				"${GIT_DEST}/${PRJ}.git/hooks/post-update"
			chmod a+x "${GIT_DEST}/${PRJ}.git/hooks/post-update"

			# add project name and description
			echo "${PRJ}" > "${GIT_DEST}/${PRJ}.git/description"

			# allow export by git daemon?
			#touch "${GIT_DEST}/${PRJ}.git/git-daemon-export-ok
		else
			# --force?
			echo "Running git push -v --all \"${GIT_DEST}/${PRJ}.git\"..."
			git push -v --all "${GIT_DEST}/${PRJ}.git"
			echo "Running git push -v --tags \"${GIT_DEST}/${PRJ}.git\"..."
			git push -v --tags "${GIT_DEST}/${PRJ}.git"
		fi
		(cd "${GIT_DEST}/${PRJ}.git" && git update-server-info)
	fi

	if [ "${GIT_PUSH}" = "1" ]; then
		echo "[*] Git push..."
		git push -v --all
	fi

	if [ "${GIT_CHANGELOG}" = "1" ]; then
		echo "[*] Generating Changelog from git..."
		echo -n > Changelog

		# get the list of tags
		number_of_tags=0
		while read sha1 full_tag; do
			tag=`echo ${full_tag} | sed -e 's#refs/tags/##' | cut -d'^' -f1`
			tags[${number_of_tags}]=${tag}
			tags_commit[${number_of_tags}]=${sha1}
			number_of_tags=$[${number_of_tags}+1]
		done < <(git show-ref --tags -d | grep refs/tags/v)

		# get the list of commits, test if is a tag and do the diff
		prev=""
		add=""
		first=1
		git log --pretty=oneline | cut -f1 | \
		while read commit junk; do
			# test if it is a tag
			tag=""
			i=0
			while [ "${i}" -lt "${number_of_tags}" ]; do
				if [ "${commit}" = "${tags_commit[${i}]}" ]; then
					tag="${tags[${i}]}"
					break
				fi

				i=$[${i}+1]
			done

			if [ -z "${tag}" ]; then
				continue
			fi

			if [ ! -z "${prev}" ]; then
				echo "[*] Generating Changelog from ${tag} -> ${prev}..."
				echo -en "${add}" >> Changelog
				add="\n"
				echo "[${tag} -> ${prev}]" >> Changelog
				git shortlog ${tag}..${prev} | \
					(IFS=""
					while read line; do
						echo "	${line}"
					done) \
					>> Changelog

				if [ "${first}" = "1" ]; then
					echo "[*] Generating Changelog-last..."
					cp Changelog Changelog-last
					first=0
				fi
			fi
			prev=${tag}
		done
	fi
}

function duilder_srpm()
{
	PRJ="${1}"
	VER="${2}"
	EXPORT_PATH="${3}"
	BUILD_SRPM="${4}"
	SRPM_DEST="${5}"
	SRPM_POST_RUN="${6}"

	P="${PRJ}-${VER}"

	if [ ! -d "${EXPORT_PATH}" ]; then
		echo "WARN: ${EXPORT_PATH} does not exists. Creating it..."
		mkdir -p "${EXPORT_PATH}"
	fi

	if [ "${BUILD_SRPM}" != "1" ]; then
		exit 0
	fi

	echo "[*] Building SRPM..."
	rpmbuild -ts "${P}.tar.gz"
	echo

	PKG="${RPMBUILD}/SRPMS/${P}-${REV}.src.rpm"

	# Run a rpmlint on it
	if [ -x /usr/bin/rpmlint ]; then
		echo "[*] RPMlinting..."
		rpmlint -iv "${PKG}" > rpmlint.out
	else
		echo "[*] WARN: rpmlint is missing!"
	fi

	if [ ! -z "${SRPM_DEST}" ]; then
		echo "[*] Copying [${PKG}] to [${SRPM_DEST}]..."
		cp -vp "${PKG}" "${SRPM_DEST}/"
		echo
	fi

	echo "[*] Copying to export dir [${EXPORT_PATH}]..."
	mkdir -p "${EXPORT_PATH}"
	cp -vp "${PKG}" "${EXPORT_PATH}/"
	echo

	if [ -x "${SRPM_POST_RUN}" ]; then
		echo "[*] Running post SRPM build script [${SRPM_POST_RUN}]..."
		${SRPM_POST_RUN} "${PKG}"
	fi
}

function duilder_tar()
{
	PRJ="${1}"
	VER="${2}"
	EXPORT_PATH="${3}"
	EXCLUDE="${4}"

	P="${PRJ}-${VER}"

	if [ ! -d "${EXPORT_PATH}" ]; then
		echo "[*] WARN: ${EXPORT_PATH} does not exists. Creating it..."
		mkdir -p "${EXPORT_PATH}"
	fi

	echo "[*] Generating tarball [${P}.tar.gz]..."
	ADD_EXCLUDE=""
	if [ ! -z "${EXCLUDE}" ]; then
		ADD_EXCLUDE="--exclude-from ${P}/${EXCLUDE}"
	fi

	(cd .. \
	&& rm -rf "${P}" \
	&& cp -a --link "${PRJ}" "${P}" \
	&& tar czf "${PRJ}/${P}.tar.gz" \
		--exclude-vcs \
		--exclude ${P}/Makefile \
		${ADD_EXCLUDE} \
		"${P}" \
	&& rm -rf "${P}"
	)

	echo "[*] Copying source to ${EXPORT_PATH}..."
	mkdir -p "${EXPORT_PATH}"
	cp -vp "${P}.tar.gz" "${EXPORT_PATH}/"
	echo
}

####################################################################

# Variables
if [ -d "${HOME}/rpmbuild" ]; then
	RPMBUILD="${HOME}/rpmbuild"
else
	RPMBUILD="/usr/src/redhat"
fi


if [ ! -r duilder.conf ]; then
	echo "[*] You must build a duilder.conf file!"
	exit 1
fi

source ${PWD}/duilder.conf

# fixes
if [ -z "${GIT_DEST}" ]; then
	GIT_DEST="${EXPORT_PATH}"
fi

if [ -z "${PRJ}" ]; then
	echo "ERROR: PRJ= parameter is missing."
	exit 1
fi

if [ -z "${VER}" ]; then
	echo "ERROR: VER= parameter is missing."
	exit 1
fi

if [ -z "${REV}" ]; then
	echo "ERROR: REV= parameter is missing."
	exit 1
fi

# export variables - just in case a script cares
export PRJ VER REV EXPORT_PATH EXPORT_GIT GIT_PUSH GIT_DEST SRPM_DEST LICENSE


# Multiplexer
if [ "${1}" = "docs" ]; then
	shift
	duilder_docs "$@"
	exit $?
fi

if [ "${1}" = "tar" ]; then
	shift
	duilder_tar "$@"
	exit $?
fi

if [ "${1}" = "git" ]; then
	shift
	duilder_git "$@"
	exit $?
fi

if [ "${1}" = "srpm" ]; then
	shift
	duilder_srpm "$@"
	exit $?
fi

if [ "${1}" = "final" ]; then
	shift
	duilder_final "$@"
	exit $?
fi


###### Main stuff
echo "[*] Duilder builder script"
echo "[*] Copyright Catalin(ux) M. BOIE - catab at embedromix dot ro"
echo "[*] PRJ=${PRJ}, VER=${VER}, REV=${REV}"
echo "[*] System: `uname -a`"

ETC="/etc"
BIN="/bin"
USR_BIN="/usr/bin"
USR_SBIN="/usr/sbin"
USR_INCLUDE="/usr/include"
USR_LIB="/usr/lib"
USR_SHARE="/usr/share"
USR_SHARE_DOC="/usr/share/doc/${PRJ}-${VER}"
SBIN="/usr/sbin"
VAR="/var"

while [ "${1}" != "" ]; do
	VAR="`echo ${1} | cut -d'=' -f1`"
	VAL="`echo ${1} | cut -d'=' -f2`"
	case ${VAR} in
		--sysconfdir)
			ETC="${VAL}"
			;;
		--bindir)
			USR_BIN="${VAL}"
			;;
		--sbindir)
			USR_SBIN="${VAL}"
			;;
		--includedir)
			USR_INCLUDE="${VAL}"
			;;
		--libdir)
			USR_LIB="${VAL}"
			;;
		--localstatedir)
			VAR="${VAL}"
			;;
		--datadir)
			USR_SHARE="${VAL}"
			;;
	esac
	shift
done

# Last fixes
VAR_LOG="${VAR}/log"
VAR_RUN="${VAR}/run"


# Truncate future sed file
> tmp.sed

DB_SUPPORT=0

echo -n "[*] Searching for PostgreSQL..."
set +e
PG_VERSION="`pg_config --version 2>/dev/null`"
set -e
if [ -z "${PG_VERSION}" ]; then
	echo " not found."
	PG_FOUND=0
else
	echo " found version ${PG_VERSION}."
	PG_FOUND=1
	PG_INC="-I`pg_config --includedir`"
	PG_LIB="-L`pg_config --libdir` -lpq"

	echo "s#@PG_VERSION@#${PG_VERSION}#g" >> tmp.sed
	echo "s#@PG_INC@#${PG_INC}#g" >> tmp.sed
	echo "s#@PG_LIB@#${PG_LIB}#g" >> tmp.sed

	DB_SUPPORT=1
	echo "s#@DB_SUPPORT@#${DB_SUPPORT}#g" >> tmp.sed
fi
echo "s#@PG_FOUND@#${PG_FOUND}#g" >> tmp.sed


echo -n "[*] Searching for MySQL..."
set +e
MYSQL_VERSION="`mysql_config --version 2>/dev/null`"
set -e
if [ -z "${MYSQL_VERSION}" ]; then
	echo " not found."
	MYSQL_FOUND=0
else
	echo " found version ${MYSQL_VERSION}."
	MYSQL_FOUND=1
	MYSQL_INC="`mysql_config --include`"
	MYSQL_LIB="`mysql_config --libs`"

	echo "s#@MYSQL_VERSION@#${MYSQL_VERSION}#g" >> tmp.sed
	echo "s#@MYSQL_INC@#${MYSQL_INC}#g" >> tmp.sed
	echo "s#@MYSQL_LIB@#${MYSQL_LIB}#g" >> tmp.sed

	DB_SUPPORT=1
	echo "s#@DB_SUPPORT@#${DB_SUPPORT}#g" >> tmp.sed
fi
echo "s#@MYSQL_FOUND@#${MYSQL_FOUND}#g" >> tmp.sed

echo -n "[*] Searching for poll..."
set +e
echo -e "#include <poll.h> \n int main(void) { return poll(0, 0, 0); }" | gcc -x c -pipe - -o /dev/null 2>/dev/null
E="${?}"
set -e
if [ "${E}" != "0" ]; then
	echo " not found."
	echo "s#@POLL_FOUND@#0#g" >> tmp.sed
else
	echo " found."
	echo "s#@POLL_FOUND@#1#g" >> tmp.sed
fi

echo -n "[*] Searching for epoll..."
set +e
echo -e "#include <sys/epoll.h> \n int main(void) { return epoll_create(64); }" | gcc -x c -pipe - -o /dev/null 2>/dev/null
E="${?}"
set -e
if [ "${E}" != "0" ]; then
	echo " not found."
	echo "s#@EPOLL_FOUND@#0#g" >> tmp.sed
else
	echo " found."
	echo "s#@EPOLL_FOUND@#1#g" >> tmp.sed
fi

echo -n "[*] Searching for ncurses..."
set +e
echo -e "#include <ncurses.h> \n int main(void) { initscr(); return 0; }" | gcc -x c -pipe - -o /dev/null -lncurses 2>/dev/null
E="${?}"
set -e
if [ "${E}" != "0" ]; then
	echo " not found."
	echo "s#@NCURSES_FOUND@#0#g" >> tmp.sed
else
	echo " found."
	echo "s#@NCURSES_FOUND@#1#g" >> tmp.sed
fi

# generic stuff
echo "s#@PRJ@#${PRJ}#g" >> tmp.sed
echo "s#@VER@#${VER}#g" >> tmp.sed
echo "s#@REV@#${REV}#g" >> tmp.sed
echo "s#@ETC@#${ETC}#g" >> tmp.sed
echo "s#@BIN@#${BIN}#g" >> tmp.sed
echo "s#@USR_BIN@#${USR_BIN}#g" >> tmp.sed
echo "s#@SBIN@#${SBIN}#g" >> tmp.sed
echo "s#@USR_SBIN@#${USR_SBIN}#g" >> tmp.sed
echo "s#@VAR@#${VAR}#g" >> tmp.sed
echo "s#@VAR_LOG@#${VAR_LOG}#g" >> tmp.sed
echo "s#@VAR_RUN@#${VAR_RUN}#g" >> tmp.sed
echo "s#@USR_INCLUDE@#${USR_INCLUDE}#g" >> tmp.sed
echo "s#@USR_INC@#${USR_INCLUDE}#g" >> tmp.sed
echo "s#@USR_LIB@#${USR_LIB}#g" >> tmp.sed
echo "s#@USR_SHARE@#${USR_SHARE}#g" >> tmp.sed
echo "s#@USR_SHARE_DOC@#${USR_SHARE_DOC}#g" >> tmp.sed
# Export stuff
echo "s#@EXPORT_PATH@#${EXPORT_PATH}#g" >> tmp.sed



if [ -r Makefile.in ]; then
	echo "[*] Building Makefile..."
	echo -n > Makefile
	echo "# duilder header starts #" >> Makefile
	echo "export PRJ := ${PRJ}" >> Makefile
	echo "export VER := ${VER}" >> Makefile
	echo "export REV := ${REV}" >> Makefile
	echo "export DESTDIR" >> Makefile
	echo >> Makefile
	echo "export I_ETC := \$(DESTDIR)${ETC}" >> Makefile
	echo "export I_BIN := \$(DESTDIR)${BIN}" >> Makefile
	echo "export I_SBIN := \$(DESTDIR)${SBIN}" >> Makefile
	echo "export I_USR_BIN := \$(DESTDIR)${USR_BIN}" >> Makefile
	echo "export I_USR_SBIN := \$(DESTDIR)${USR_SBIN}" >> Makefile
	echo "export I_USR_INCLUDE := \$(DESTDIR)${USR_INCLUDE}" >> Makefile
	echo "export I_USR_INC := \$(DESTDIR)${USR_INCLUDE}" >> Makefile
	echo "export I_USR_SHARE := \$(DESTDIR)${USR_SHARE}" >> Makefile
	echo "export I_USR_SHARE_DOC := \$(DESTDIR)${USR_SHARE_DOC}" >> Makefile
	echo "export I_USR_LIB := \$(DESTDIR)${USR_LIB}" >> Makefile
	echo "export I_LIB := \$(DESTDIR)${USR_LIB}" >> Makefile
	echo "export I_VAR := \$(DESTDIR)${VAR}" >> Makefile
	echo "export I_VAR_LOG := \$(DESTDIR)${VAR_LOG}" >> Makefile
	echo "export I_VAR_RUN := \$(DESTDIR)${VAR_RUN}" >> Makefile
	echo >> Makefile
	echo "# DB stuff" >> Makefile
	echo "export DB_SUPPORT := ${DB_SUPPORT}" >> Makefile
	echo "# PG" >> Makefile
	echo "export PG_FOUND := ${PG_FOUND}" >> Makefile
	echo "export PG_INC := ${PG_INC}" >> Makefile
	echo "export PG_LIB := ${PG_LIB}" >> Makefile
	echo "# MySQL" >> Makefile
	echo "export MYSQL_FOUND := ${MYSQL_FOUND}" >> Makefile
	echo "export MYSQL_INC := ${MYSQL_INC}" >> Makefile
	echo "export MYSQL_LIB := ${MYSQL_LIB}" >> Makefile
	echo >> Makefile
	echo "# duilder header ends #" >> Makefile
	echo >> Makefile

	sed -f tmp.sed Makefile.in >> Makefile

	echo >> Makefile
	echo "# duilder tail starts #" >> Makefile
	echo >> Makefile
	echo "# This is to allow exporting only the git tree" >> Makefile
	echo "dist_git:" >> Makefile
	echo "	@./duilder git \"\$(PRJ)\" \"${GIT_DEST}\" \"${EXPORT_GIT}\" \"${EXPORT_PATH}\" \"${GIT_CHANGELOG}\"" >> Makefile
	echo >> Makefile
	echo ".PHONY: dist" >> Makefile
	echo "dist: clean" >> Makefile
	echo "	@./duilder git \"\$(PRJ)\" \"${GIT_DEST}\" \"${EXPORT_GIT}\" \"${GIT_CHANGELOG}\"" \"${GIT_PUSH}\" >> Makefile
	echo "	@./duilder tar \"\$(PRJ)\" \"\$(VER)\" \"${EXPORT_PATH}\" \"${EXCLUDE}\"" >> Makefile
	echo "	@./duilder srpm \"\$(PRJ)\" \"\$(VER)\" \"${EXPORT_PATH}\" \"${BUILD_SRPM}\" \"${SRPM_DEST}\" \"${SRPM_POST_RUN}\"" >> Makefile
	echo "	@./duilder docs \"\$(PRJ)\" \"\$(VER)\" \"${EXPORT_PATH}\"" >> Makefile
	echo "	@./duilder final \"\$(PRJ)\" \"\$(VER)\" \"${RELEASE_SCRIPT}\"" >> Makefile
	echo "	@rm -f \"\$(PRJ)-\$(VER).tar.gz\"" >> Makefile
	echo >> Makefile
fi

if [ -r "${PRJ}.spec.in" ]; then
	echo "[*] Generating .spec file..."
	sed -f tmp.sed ${PRJ}.spec.in > ${PRJ}.spec
fi

if [ ! -z "${CONFIG_H}" ]; then
	echo "[*] Generating ${CONFIG_H} file..."
	sed -f tmp.sed ${CONFIG_H}.in > ${CONFIG_H}
fi

rm -f tmp.sed

if [ "`basename ${0}`" = "duilderx" ]; then
	echo "[*] Cloning myself to destination as 'duilder'..."
	cp -vpf "${0}" ${PWD}/duilder
fi

echo "[*] Done. Run make."


Mode Type Size Ref File
100644 blob 119 7e0257f54e1c2fc928dd03c5feba91e10fe86261 .gitignore
100644 blob 30 d987fa5df957830331139935d517009e2911b0cf INSTALL
100644 blob 35147 94a9ed024d3859793618152ea559a168bbcbb5e2 LICENSE
100644 blob 772 e87d60cf1b3910a7ae49f0193931313b800e5cce Makefile.in
100644 blob 4653 95feff7ec147eefd63a0fb3adbbdc2209e42132f README
100644 blob 1302 5c2fda3e1187d9716ea62996211eebeb5015c15a TODO
100755 blob 23 d33bb6c4ecdce1390ce1db3c79ea3b93e22ea755 configure
100755 blob 13141 081d1c2174db44f5834f6bf6eb2cf4e805faa2d2 duilder
100644 blob 292 d622c2ec22b51ef36559ff380a885afbad4a3b9e duilder.conf
100644 blob 25735 644e3a76dc4508d03dcd9c48bc69a467840823ed force_bind.c
100644 blob 1077 b7b631f28809009fd5678b4798a810e2dea822e1 force_bind.spec.in
100644 blob 35 6fa1dc02f112e09cbe388b61590c412dd1aae134 force_bind_config.h.in
100644 blob 1656 39482737be7bbbf3357a3750e79fec34dd323541 send_udp.c
100755 blob 198 69df55fb33fd2f66c8563d40f8e94c4a050d71f0 test1.sh
100755 blob 178 2d9a688355eeb88be7ab177ba95952a155c9e217 test2.sh
100755 blob 350 711d78469121dce161d13d338b0d281e0e646ef6 test_all.sh
100644 blob 1135 ef564034e516db96e7e9346000e4a7917da3b82d test_bind.c
100755 blob 193 964f25f5ab76011470436d4fb8894b975e0a1cba test_bw1.sh
100755 blob 236 484f1016e84d41ad4d393b5f6f23e5cfa9071f08 test_bw2.sh
100755 blob 286 805a280956a5a00dd52f54a8803efc6776739314 test_bw3.sh
100755 blob 448 088e71224a13f412fec15399f7bd1c0701160119 test_bw4.sh
100644 blob 1497 13d4c8bfde7655151199dc0d4ba9f5acea6512e0 test_client.c
100755 blob 179 39bb823c1a0f4c32c35141422abc61a19084f384 test_client1.sh
100755 blob 171 f988d1903cd9c89720fd6ea12b487a9e8189ef5d test_client2.sh
100755 blob 164 32459ed2d2194fa83f99ec724bf195c86dab8716 test_client3.sh
100755 blob 253 eeea81bc7eb348714945b7a5794a21f9dd813275 test_client6-1.sh
100644 blob 1698 6b148a733dbb8f72e31b6c929e1766558ba03a95 test_client6.c
100755 blob 292 a225478d8f6b8df5cbfa115192b839bbae0276cf test_deny.sh
100755 blob 285 acf74df00776908d43b38b910140074668e9fc66 test_fake.sh
100755 blob 138 15e7a1b1bf39128dc737ba3df39498ad91e56044 test_ka1.sh
100755 blob 136 2f0bf21c57db70f4a61e1b4337f41a3c548d099b test_mss1.sh
100755 blob 144 e9620dd6d54a12e3582d38ca4fb74861fa540b88 test_tos1.sh
100755 blob 246 cdeba6d1ee85f938c06e548e3f70d07d2c6db9ff test_udp_local_bind.sh
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/catalinux/force_bind

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/catalinux/force_bind

Clone this repository using git:
git clone git://git.rocketgit.com/user/catalinux/force_bind

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main