#!/bin/bash err() { echo "$1" exit 1 } startdir="$(pwd)" if [ -f "${startdir}/ZENBUILD" ]; then . ${startdir}/ZENBUILD else err "No ZENBUILD found in directory" fi ##################Sanity Tests Begin###################################### #Check that variables exist for 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 fi done for ((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 < ${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 needed check_for_root() { [ ! "\$UID" = "0" ] && echo "You need to be root" && exit 1 } EOA cat <<"EOD" >> $startdir/build-${pkgname}.sh set_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 {} \; } EOD cat <<"EOE" >> $startdir/build-${pkgname}.sh strip_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 } EOE cat <<"EOF" >> $startdir/build-$pkgname.sh gzip_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 } EOF cat <<"EOG" >> $startdir/build-$pkgname.sh set_post_permissions() { if [ -d "$startdir/pkg/usr/bin" ]; then chown -R root:root $startdir/pkg/usr/bin fi } EOG cat <<"EOG" >> $startdir/build-$pkgname.sh copy_build_script() { mkdir -p $startdir/pkg/usr/src/$pkgname-$pkgver cp $startdir/build-$pkgname.sh $startdir/pkg/usr/src/$pkgname-$pkgver/build-$name.sh } EOG cat <<"EOH" >> $startdir/build-$pkgname.sh create_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 } EOH cat <<"EOJ" >> $startdir/build-$pkgname.sh clean() { rm -rf $startdir/pkg $startdir/src } #########End Redundant Code##################################### #See what I mean #########Begin Non Redundant Code############################## EOJ cat <>$startdir/build-$pkgname.sh prepare_directory() { mkdir \$startdir/src EOI for SRCFILE in ${source[@]}; do cat <>$startdir/build-${pkgname}.sh cp -R $(basename $SRCFILE) \$startdir/src EOB done cat <<"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 } EOC sed -n '/build\(\)/,/}/p' $startdir/ZENBUILD >> $startdir/build-$pkgname.sh cat <>$startdir/build-$pkgname.sh create_slackdesc() { mkdir \$startdir/pkg/install cat <<"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############################ EOK cat <>$startdir/build-$pkgname.sh #Variables startdir=\$(pwd) pkgname=$pkgname pkgver=$pkgver pkgrel=$pkgrel arch=$arch package=\$pkgname-\$pkgver-\$arch-\$pkgrel export CFLAGS="-O2 -march=\$arch -mtune=i686" export CXFLAGS="-O2 -march=\$arch -mtune=i686" EOM cat <<"EOL" >> $startdir/build-$pkgname.sh #Execution check_for_root prepare_directory set_pre_permissions build if [ ! "$?" = "0" ]; then echo "The compilation failed" exit 2 fi create_slackdesc strip_binaries gzip_man_and_info_pages set_post_permissions copy_build_script create_package #clean EOL chmod +x $startdir/build-$pkgname.sh echo "build-$pkgname.sh has been created"