All pastes #407875 Raw Edit

makedebs

public shellscript v1 · immutable
#407875 ·published 2007-03-24 12:37 UTC
rendered paste body
#!/bin/bash# makedebs script for easy compiling and building deb packages for beryl git## (c) 2006-2007 Treviño - Released under GPLv2 Terms##  USAGE#  You should simply run this script to create and your beryl git#  tree and package it, but there are also some "advanced" tasks:##    ./makedebs                   performs all the tasks (sync and package)#    ./makedebs update            just sync the local data to remote git#    ./makedebs build             try to build the needed items#    ./makedebs <item>            build only the <item> (if needed)#    ./makedebs rebuild <item>    force a rebuild of the <item>#    ./makedebs repack <item>     force a repack of the <item>##   To change the content of a package (or applying patch) you can add#   some bash script files called "pkgxtra.sh" on each <item> dir to#   perform extra tasks after that each package has been compiled##   To Package an <item> file not included yet on the $DISTRODIR you can#   define add an "<item>/debian" folder to your $DISTRODIR_USER (see below)#packager="Trevi"packager_email="trevi55@gmail.com"package_sufix="3v1ubuntu"#to test settings-dump properlyexport DISPLAY=""DEFPREFIX="/usr"MYPREFIX=${PREFIX:-$DEFPREFIX}DISTRODIR="distro-specific-build-files"DISTRODIR_USER="distro-specific-build-files-user"PRIOPKGS="beryl-core beryl-settings-bindings beryl-plugins"GITURL="git://anongit.beryl-project.org"GITWEB="http://gitweb.beryl-project.org"#for i in $(find |grep "\.git/remotes/origin"); do echo $i; perl -i -p -e 's/git./anongit./' $i; done#sed -i -e 's;git://git\.;git://anongit.;' ${file}autogenpkg_cmd="./autogen.sh --prefix=$MYPREFIX"buildpkg_cmd="fakeroot dpkg-buildpackage -b -us -uc"repkg_cmd="fakeroot ./debian/rules binary"git_items="$(wget -q -O - "$GITWEB/?a=project_index"|grep "^beryl/" | cut -d' ' -f1)"if [ -z "$git_items" ]; then	echo "There are problems while retrieving the beryl items list; exiting..."	exit 2;fimkdir -p "beryl"if [ -z "$(which git-clone)" ]; then	echo -e "\nYou must install the 'git-core' package in order to use needed git tools\n"	exit 2fifor git_item in $git_items; do	git_item_name="$(basename $git_item)"	if [ ! -d "$git_item/.git" ]; then		echo -e "\n\033[4mNo $git_item_name git folder found! Downloading...\033[0m"		cd "beryl"		if ! git-clone $GITURL/$git_item; then			echo "There are problems retrieving git data for $git_item_name. Skipping..."			#exit 2;		fi		echo ""		cd ../	elif [ -d "$git_item" ]; then		cd "$git_item"		if ! git-log &> /dev/null; then			echo "The $git_item_name git directory isn't here, please remove the '$git_item' dir and run again this script."			echo "Whould you like this script make this (all your '$git_item' data will be removed)?"			read -p " [Y/n]: " -n1 continue;			if [ "$continue" != "$(echo Y | tr [:upper:] [:lower:])" ]; then				echo ''				exit 2			else				cd ../				rm -rf "$git_item"				if ! git-clone $GITURL/$git_item; then					echo "There are problems retriving git data for $git_item_name. Skipping..."					#exit 2;				fi			fi		else			if [ -z "$(echo $* | grep -wE "batch|noupdate|build")" ]; then				echo -e "\n\033[4mUpdating the $git_item_name package...\033[0m"				if ! git-pull origin; then					report="$report\n\033[4mGIT PULL FAILED\033[0m"					sleep 3				fi			fi		fi		cd ../..	else		echo "There are some errors with build directories, please report this to the Author"		exit 2	fidoneif [ -n "$(echo $* | grep -wE "update|pull")" ]; then	exit 0;ficd "beryl"if [ -f "./VERSION" ]; then	. "./VERSION"	base_ver="$VERSION"	VERSION=""fifunction git_commit() {	#git-log|grep -m1 commit|cut -d' ' -f2	git-rev-parse HEAD}function git_commit_date () {	date -d "$(expr "$(git-log|grep "Date" -m1)" : "Date:[ ]\+\(.*\)[+-]\{1\}[0-9]\{4\}")" +"%Y%m%d"}function errorcontrol() {	item="$1"	if [ -z "$(echo $* | grep "batch")" ]; then		echo -e "\nProblems occurred while building $item packages... Continue Building?"		read -p " [Y/n]: " -n1 continue;		if [ "$continue" != "$(echo Y | tr [:upper:] [:lower:])" ]; then			echo -e "$report\n";			exit 2		fi	else		echo -e "\nProblems occurred while building $item packages. Skipping as requested..."	fi}function buildpkg() {	rm -f ../*.deb	if [ -f "./VERSION" ]; then		. "./VERSION"		base_comp_ver="$VERSION"		VERSION=""	fi	if [ -z "$base_comp_ver" ]; then		if [ -n "$base_ver" ]; then			base_comp_ver="$base_ver"		else			base_comp_ver=$(dpkg-parsechangelog|grep --max-count=1 -F "Version:" |cut -d" " -f2|sed "s/-[0-9]ubuntu[0-9]/-1/");		fi	fi	base_comp_ver=$(echo "$base_comp_ver" | sed 's/-svn//g');	if [ -n "$(echo $* | grep "repack")" ]; then		action="repack"	elif [ -n "$(echo $* | grep "rebuild")" ]; then		action="rebuild"	else		action="build"	fi	build="0"	if ( [ $action = "rebuild" ] || [ $action = "build" ] ); then		tstpkg="$(cat debian/control |grep "^Package:" -m1| cut -d" " -f2)"		for oldpkg in ../../debs/${tstpkg}_*.deb; do			pkgbuild="$(expr "$(dpkg-deb --field "$oldpkg" Version)" : ".\+~${package_sufix}\([0-9]\+\)")"			if ( [ -n "$pkgbuild" ] && [ "$pkgbuild" -ge "$build" ] ); then				build=$(($pkgbuild + 1))			fi		done	fi	#".\++git[0-9]\{8\}-r\([0-9]\+\)~3v1ubuntu[0-9]\+" -> beryl-core_0.3+git20070401-r1~3v1ubuntu5	source_package=$(dpkg-parsechangelog|grep --max-count=1 -F "Source:" |cut -d" " -f2)	if [ -f "/etc/lsb-release" ]; then		distro="$(cat /etc/lsb-release|grep DISTRIB_CODENAME | cut -d'=' -f2)"	fi	if [ -z "$distro" ]; then		distro="unstable";	fi	version="${base_comp_ver}+git$(git_commit_date)~${package_sufix}${build}"	echo -e "$source_package ($version) $distro; urgency=low\n\n  * Upgrade to GIT commit $(git_commit)\n\n -- $packager <$packager_email>  $(LANG=en_US date +"%a, %d %b %Y %T %z")\n" > "./debian/changelog"	sed "$(cat "../$DISTRODIR_ITEM/$item/debian/control" | grep "^Maintainer:" -n -m1 | cut -d':' -f1)cMaintainer: $packager <$packager_email>" "../$DISTRODIR_ITEM/$item/debian/control" > "./debian/control"	cat "../$DISTRODIR_ITEM/$item/debian/changelog" >> "./debian/changelog"# 	if ( [ -f "./VERSION" ] && [ ! -f "./VERSION.base" ] ); then# 		mv -v "./VERSION" "./VERSION.base"# 		cp -v "./VERSION.base" "./VERSION"# 		perl -i -p -e "s/VERSION=.*/VERSION=$version/" "./VERSION"# 	fi	if [ $action = "repack" ]; then		cmd2run="$repkg_cmd"	else		cmd2run="$buildpkg_cmd"	fi	if ! $cmd2run; then #fakeroot dh_gencontrol -u"-v$version"		errorcontrol $item		report="$report\nBUILD FAILED for $item"		return 2	fi	if [ -f pkgxtra.sh ]; then		chmod +x pkgxtra.sh		echo -e "\nRunning extra scripts for $item..."		if ! ./pkgxtra.sh $action; then			errorcontrol $item			report="$report\nBUILD FAILED for extrascripts on $item"			return 2		fi	fi	mv -f ../*$package_sufix*.deb ../../debs/	mkdir -p ../../debs-old	mv -f ../*.changes ../../changelogs &> /dev/null	for package in $(cat debian/control |grep Package| cut -d" " -f2); do		for deb in $(find ../../debs/ -maxdepth 1 -type f | grep "${package}_.*\.deb"); do			if  [ -z $(dpkg-deb --field "$deb" Version | grep -F "$version") ]; then				mv -f "$deb" ../../debs-old;			fi		done	done	rm -rf ./debian# 	if [ -f "./VERSION.base" ]; then# 		mv -v "./VERSION.base" "./VERSION"# 	fi}mkdir -p ../changelogs ../debs#rm -f ../debs/*.debITEMS="$PRIOPKGS"for beryldir in $DISTRODIR/* $DISTRODIR_USER/*; do	if [ -n "$(echo $beryldir | grep -F "$DISTRODIR_USER")" ]; then		itemdir="${beryldir/$DISTRODIR_USER\//}"	else		itemdir="${beryldir/$DISTRODIR\//}"	fi	if ( [ -d $beryldir ] && [ -d $beryldir/debian ] && [ -f $itemdir/autogen.sh ] ); then				for userberyldir in $*; do			if ( [ "$userberyldir" = "$itemdir" ] ); then				USERITEMS="$USERITEMS $itemdir"			fi		done				found="false"		for item in $ITEMS; do			if [ "$item" = "$itemdir" ]; then				found="true"			fi		done				if [ "$found" != "true" ]; then			ITEMS="$ITEMS $itemdir";		fi	fi;done;if [ "$USERITEMS" != "" ]; then	ITEMS="$USERITEMS"fifor item in $ITEMS; do	cd $item	chmod +x autogen.sh &> /dev/null	rm -rf ./debian	#ln -s ../$DISTRODIR/$item/debian	if [ -d "../$DISTRODIR/$item/debian" ]; then		DISTRODIR_ITEM="$DISTRODIR"	elif [ -d "../$DISTRODIR_USER/$item/debian" ]; then		DISTRODIR_ITEM="$DISTRODIR_USER"	else		report="$report\nNo debian files for $item"		errorcontrol "$item"	fi		cp -ar ../$DISTRODIR_ITEM/$item/debian ./	if [ ! -e ./.build-done ]; then		echo 0 > "./.build-done";	fi	latest_ver="$(cat ./.build-done)"	if [ "$(git_commit)" != "$latest_ver" ]; then		echo -e "\nBuilding $item..."		if $autogenpkg_cmd && buildpkg; then			report="$report\n$item built OK"			if [ "$item" = "beryl-core" ]; then				wait				echo -e "\a"				if ! (sudo dpkg -i ../../debs/{beryl-dev,libberyl}*.deb && wait); then					errorcontrol "$item"				fi			fi			echo "$(git_commit)" > ./.build-done		else			report="$report\nBUILD FAILED for $item"			wait			errorcontrol "$item"		fi	else #elif [ "$(git_commit)" = "$latest_ver" ]; then		if ( [ -n "$(echo $* | grep "rebuild")" ] || [ -f "./.rebuild" ] ); then		#|| ( [ "$DISTRODIR_ITEM" = "$DISTRODIR" ] ) && [ "$(cd ../$DISTRODIR_ITEM && git_commit_date)" -gt "$(git_commit_date)" ]			echo -e "\nRebuilding $item..."			if make clean && buildpkg rebuild; then # && make clean ?				rm -f "./.rebuild"				report="$report\n$item rebuilt OK"			else				report="$report\nREBUILD FAILED for $item"				errorcontrol "$item"			fi		elif ( [ -n "$(echo $* | grep "repack")" ] || [ -f "./.repack" ] ); then			echo -e "\nRepacking $item..."			rm -f "./.repack"			buildpkg repack;			report="$report\n$item repackaged OK"		else			report="$report\n$item already built"		fi	fi	cd ../doneecho -e "\n$report\n";