All pastes #565708 Raw Edit

Miscellany

public shellscript v1 · immutable
·published 2007-06-14 03:21 UTC
rendered paste body
#!/bin/basherr(){	echo "$1"	exit 1}startdir="$(pwd)"if [ -f "${startdir}/ZENBUILD" ]; then	. ${startdir}/ZENBUILDelse	err "No ZENBUILD found in directory"fi##################Sanity Tests Begin#######################################Check that variables existfor VAR in pkgname pkgver pkgrel arch source url slackdesc; do	[[ ! "${!VAR}" ]] &&		err "variable \"${VAR}\" is not set"done[[ ! "$(grep build\(\) ${startdir}/ZENBUILD)" ]] &&	err "No build() function found"#check that variables are sane[[ "$(echo $pkgver | grep \-)" ]] &&	err "No dashes allowed in pkgver"[ ! "${#pkgrel}" = "1" ] &&	err "pkgrel must be one character, 1-9"[ ! "${arch}" = "i486" -a ! "${arch}" = "noarch" ] &&	err "arch must be i486 or noarch"[[ "${slackdesc[10]}" ]] &&	err "No more than 10 lines allowed in slackdesc"for SOURCES in "${source[@]}"; do	if [ ! -f "$(basename $SOURCES)" ]; then		protocol=$(echo $SOURCES | sed 's|:.*||')		if [ "$protocol" = "http" -o "$protocol" = "https" -o "$protocol" = "ftp" ]; then			echo -e "\nDownloading $(basename $SOURCES)\n"			wget $SOURCES		else			err "$SOURCES does not appear to be a url nor is it in the directory"		fi	fidonefor ((LINE=0 ; LINE < 10 ; LINE++)); do	REALLINE=$(expr $LINE + 1)	[[ "${#slackdesc[$LINE]}" -gt "70" ]] &&		err "Line ${REALLINE}: '${slackdesc[$LINE]}' is greater than 70 characters, make it shorter"done#########Sanity Tests End########################################cat <<EOA > ${startdir}/build-${pkgname}.sh#!/bin/bash#Automatically Created by buildpkg 0.0.1#url: $url######Begin Redundant Code#######################################This is the reason a universal wrapper script is neededcheck_for_root() {	[ ! "\$UID" = "0" ] && echo "You need to be root" && exit 1}EOAcat <<"EOD" >> $startdir/build-${pkgname}.shset_pre_permissions() {	cd $startdir/src	find . -perm 664 -exec chmod 644 {} \;	find . -perm 600 -exec chmod 644 {} \;	find . -perm 444 -exec chmod 644 {} \;	find . -perm 400 -exec chmod 644 {} \;	find . -perm 440 -exec chmod 644 {} \;	find . -perm 777 -exec chmod 755 {} \;	find . -perm 775 -exec chmod 755 {} \;	find . -perm 511 -exec chmod 755 {} \;	find . -perm 711 -exec chmod 755 {} \;	find . -perm 555 -exec chmod 755 {} \;}EODcat <<"EOE" >> $startdir/build-${pkgname}.shstrip_binaries() {	cd $startdir/pkg	find . | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | \	xargs strip --strip-unneeded 2> /dev/null	find . | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : | \	xargs strip --strip-unneeded 2> /dev/null}EOEcat <<"EOF" >> $startdir/build-$pkgname.shgzip_man_and_info_pages() {	for DOCS in man info; do		if [ -d "$startdir/pkg/usr/$DOCS" ]; then			for DIRECTORY in $(ls $startdir/pkg/usr/$DOCS); do				cd $startdir/pkg/usr/$DOCS/$DIRECTORY				gzip -9 *			done		fi	done}EOFcat <<"EOG" >> $startdir/build-$pkgname.shset_post_permissions() {	if [ -d "$startdir/pkg/usr/bin" ]; then		chown -R root:root $startdir/pkg/usr/bin	fi}EOGcat <<"EOG" >> $startdir/build-$pkgname.shcopy_build_script() {	mkdir -p $startdir/pkg/usr/src/$pkgname-$pkgver	cp $startdir/build-$pkgname.sh $startdir/pkg/usr/src/$pkgname-$pkgver/build-$name.sh}EOGcat <<"EOH" >> $startdir/build-$pkgname.shcreate_package() {	cd $startdir/pkg	makepkg -l y -c n $startdir/$package.tgz	cd $startdir	md5sum $startdir/$package.tgz > $startdir/$package.md5	requiredbuilder -z $startdir/$package.tgz > $startdir/$package.dep}EOHcat <<"EOJ" >> $startdir/build-$pkgname.shclean() {	rm -rf $startdir/pkg $startdir/src}#########End Redundant Code######################################See what I mean#########Begin Non Redundant Code##############################EOJcat <<EOI >>$startdir/build-$pkgname.shprepare_directory() {	mkdir \$startdir/srcEOIfor SRCFILE in ${source[@]}; docat <<EOB >>$startdir/build-${pkgname}.sh	cp -R $(basename $SRCFILE) \$startdir/srcEOBdonecat <<"EOC" >>$startdir/build-${pkgname}.sh	cd $startdir/src	for FILES in *; do		if [[ "$(echo $FILES | grep tar)" ]]; then			tar xf $FILES		fi	done	mkdir $startdir/pkg}EOCsed -n '/build\(\)/,/}/p' $startdir/ZENBUILD >> $startdir/build-$pkgname.shcat <<EOK >>$startdir/build-$pkgname.shcreate_slackdesc() {mkdir \$startdir/pkg/installcat <<"EOF" >\$startdir/pkg/install/slack-desc$pkgname: ${slackdesc[0]}$pkgname: $pkgname: ${slackdesc[1]}$pkgname: ${slackdesc[2]}$pkgname: ${slackdesc[3]}$pkgname: ${slackdesc[4]}$pkgname: ${slackdesc[5]}$pkgname: ${slackdesc[6]}$pkgname: ${slackdesc[7]}$pkgname: ${slackdesc[8]}$pkgname: ${slackdesc[9]}EOF}####End Non Redundant Code############################EOKcat <<EOM >>$startdir/build-$pkgname.sh#Variablesstartdir=\$(pwd)pkgname=$pkgnamepkgver=$pkgverpkgrel=$pkgrelarch=$archpackage=\$pkgname-\$pkgver-\$arch-\$pkgrelexport CFLAGS="-O2 -march=\$arch -mtune=i686"export CXFLAGS="-O2 -march=\$arch -mtune=i686"EOMcat <<"EOL" >> $startdir/build-$pkgname.sh#Executioncheck_for_rootprepare_directoryset_pre_permissionsbuildif [ ! "$?" = "0" ]; then	echo "The compilation failed"	exit 2ficreate_slackdescstrip_binariesgzip_man_and_info_pagesset_post_permissionscopy_build_scriptcreate_package#cleanEOLchmod +x $startdir/build-$pkgname.shecho "build-$pkgname.sh has been created"