All pastes #1483407 Raw Edit

salvador

public text v1 · immutable
#1483407 ·published 2009-07-03 21:53 UTC
rendered paste body
#!/bin/bash## Copyright (C) 2008, 2009 Renato Cunha ## This is free software.# You can redistribute it and/or modify# it under the terms of the GNU General Public License as published by# the Free Software Foundation; either version 2 of the License, or# (at your option) any later version.## This software is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the# GNU General Public License for more details.## You should have received a copy of the GNU General Public License# along with this program; if not, write to the Free Software# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA### new-build-script.sh Documentation#### Motivation for this script:#### <trovao> I think that the DBS should have some kind of template generator## <trovao> like:## <trovao> newbuildscript nameofpackage## <trovao> then it would create## <trovao> SCRIPTS/nameofpackage/{build,desc,ChangeLog}## <trovao> SOURCES/nameofpackage/## <trovao> and, preferrably, the build script would have a skeleton build script, like zenity's one## <trovao> and, why not## <trovao> a self generated first changelog entry with todays date and I think you got it## <trovao> that's also not hard## <trovao> actually, its fairly easy to do## <saxa> cool## <saxa> thats true## <saxa> just something like ./build new_pack## <saxa> then you receive a question## <saxa> new_pack doesnt exist## <saxa> do you want to create it ?## <saxa> if yes, then it creates everything asking you for the name url and version of the pack## <saxa> name could be passed by the ./build script## <saxa> for example ./build dubidubi## <saxa> dubidubi doesnt exist in the repos, do you want to create it ?## <trovao> wow## <saxa> if yes, you enter all the needed data## <saxa> and you are set up## <trovao> that's a nice use cas## <saxa> :)## <trovao> s/cas/case## <saxa> go ahead , code it :)export DLG_ROOT=${DLG_ROOT:-$(pwd)}. ${DLG_ROOT}/config. ${DLG_ROOT}/SCRIPTS/dropline-header. ${DLG_ROOT}/SCRIPTS/dropline-functions.shif [ -e "/usr/games/rot13" ]; then    ROT13=/usr/games/rot13else    ROT13=/usr/bin/catfi## Variable documentation#### YOUR_NAME##   holds your (yeah, you, the one reading this file) name.##   HINT: It should be better to save this variable to your Dropline Build##   System config file##YOUR_NAME=${YOUR_NAME:-"Your name"}## YOUR_EMAIL##   holds your (yeah, you, the one reading this file) email address##   HINT: It should be better to save this variable to your Dropline Build##   System config file## YOUR_EMAIL=${YOUR_EMAIL:-"your@email.com"}## SUPPORTED_BUILD_SYSTEMS##   holds the build systems supported by this script##   Please, *don't* edit this variable##SUPPORTED_BUILD_SYSTEMS="autotools distutils perl"## Bash function call documentation#### create_dirs name##   This will create a new directory named 'name' inside $DLG_ROOT/SCRIPTS##   and $DLG_ROOT/SOURCES (or on its extras/contrib counterparts)##function create_dirs(){    NAME=${1:?'Internal error, create_dirs requires a name.'}    if [ "${2}" == "extras" ]; then      DIRS="extras/dropline/SCRIPTS extras/dropline/SOURCES"    elif [ "${2}" == "contrib" ]; then      DIRS="extras/contrib/SCRIPTS extras/contrib/SOURCES"    else      DIRS="SCRIPTS SOURCES"    fi        for dir in $DIRS    do        createdir ${DLG_ROOT}/${dir}/${NAME}    done}## fallback##   If this is called, it will fallback and remove the newly created##   directories.function fallback(){    if [ "${1}" == "extras" ]; then      DIRS="extras/dropline/SCRIPTS extras/dropline/SOURCES"    elif [ "${1}" == "contrib" ]; then      DIRS="extras/contrib/SCRIPTS extras/contrib/SOURCES"    else      DIRS="SCRIPTS extras/dropline/SOURCES"    fi        for dir in $DIRS        do            # removedir is implemented by the dropline-build-system            removedir ${DLG_ROOT}/${dir}/${NAME}        done}## create_changelog name version##   This will create a file named ChangeLog in the directory named 'name'##   inside $DLG_ROOT/SCRIPTS (or in its extras/contrib counterparts)##function create_changelog(){    NAME=${1:?'Internal error, create_changelog requires a name.'}    VERSION=${2:?'Internal error, create_changelog requires a version.'}    PKGER=${4:'dl'}    TODAY=$(date +%Y-%m-%d)        if [ "${3}" == "extras" ]; then      DIR="extras/dropline/SCRIPTS"    elif [ "${3}" == "contrib" ]; then      DIR="extras/contrib/SCRIPTS"    else      DIR="SCRIPTS"    fi    # rot13'ing the email is better to protect it from spammers    YOUR_EMAIL=$(echo $YOUR_EMAIL | rot13)    cat << EOF > ${DLG_ROOT}/${DIR}/${NAME}/ChangeLog$TODAY $YOUR_NAME <$YOUR_EMAIL>	Released revision ${VERSION}-${DLG_ARCH}-1${DLG_PKGER}.	* desc: Initial release.	* build: Initial release.EOF    status=$?    if [ $status != 0 ]; then        fallback $PACKAGE_TYPE        die "The cat command, called from within the create_changelog function,\        exited with status $status!"    fi}## create_descfile name##   This will call the script $DLG_ROOT/editdesc and edit the file named ##   'desc' inside $DLG_ROOT/SCRIPTS (or its extras/contrib counterpart)function create_descfile(){    NAME=${1:?'Internal error, create_descfile requires a name.'}        bash $DLG_ROOT/editdesc $NAME ${2}    status=$?    if [ $status != 0 ]; then        fallback $PACKAGE_TYPE        die "The editdesc script failed with status $status!"    fi}function populate_autotools_commands(){    if [ "${2}" == "extras" ]; then      DIR="extras/dropline/SCRIPTS"    elif [ "${2}" == "contrib" ]; then      DIR="extras/contrib/SCRIPTS"    else      DIR="SCRIPTS"    fi        cat << EOF >> ${DLG_ROOT}/${DIR}/${NAME}/buildcflagscxxflagsprepareanalyzesourceconfiguremakemakeinstalltidydocumentationanalyzebinariesfinalizepackagepackagizecleanupEOF}function populate_distutils_commands(){    if [ "${2}" == "extras" ]; then      DIR="extras/dropline/SCRIPTS"    elif [ "${2}" == "contrib" ]; then      DIR="extras/contrib/SCRIPTS"    else      DIR="SCRIPTS"    fi    cat << EOF >> ${DLG_ROOT}/${DIR}/${NAME}/build# This package gets it's CFLAGS info from what was compiled into Python.# Changing this variable is mainly a formality caused by this.if [ "\${PKG_ARCH%86}" != "\$PKG_ARCH" ]; then    PKG_ARCH=i486fiPKG_LOCALSTATEDIR=/varprepareanalyzesource        spewdo "cd \$PKG_SRCROOT"spewdo "python setup.py build"spewdo "python setup.py install --prefix=\$PKG_PREFIX --root=\$PKG_STAGEROOT"tidydocumentationanalyzebinariesfinalizepackagepackagizecleanupEOF}function populate_perl_commands(){    if [ "${2}" == "extras" ]; then      DIR="extras/dropline/SCRIPTS"    elif [ "${2}" == "contrib" ]; then      DIR="extras/contrib/SCRIPTS"    else      DIR="SCRIPTS"    fi        cat << EOF >> ${DLG_ROOT}/${DIR}/${NAME}/build# This makes sure our 32bit builds get the right ARCH tag.  The main reason# for doing this is to avoid a naming collision with the x86-64 builds.if [ "\${PKG_ARCH%86}" != "\$PKG_ARCH" ]; then  PKG_ARCH=i486ficflagscxxflagsprepareanalyzesourceloggedcommand configure "cd \$PKG_SRCROOT ; perl Makefile.PL"makemakeinstalltidydocumentationanalyzebinariesfinalizepackagepackagizecleanupEOF}function populate_build_system_commands(){    BUILD_SYSTEM=${1:-'autotools'}    SUPPORTED=false    for build_system in $SUPPORTED_BUILD_SYSTEMS    do        if [ "$BUILD_SYSTEM" == "$build_system" ]; then            SUPPORTED=true        fi    done    if [ "$SUPPORTED" == "false" ]; then        die "$BUILD_SYSTEM build system not supported. Aborting."    fi    eval "populate_${BUILD_SYSTEM}_commands" ${2}}## create_buildscript name version sourceurl##   This will create the build script for the package named 'name' inside##   $DLG_ROOT/SCRIPTS/name based on a very simple template that will cover##   most of autotools based programs. 'version' and 'sourceurl' will be used##   to populate the proper entries in the build script.function create_buildscript(){    NAME=$1    VERSION=$2    SOURCEURL=$3    BUILD_SYSTEM=${5:-'autotools'}        if [ "${4}" == "extras" ]; then      DIR="extras/dropline/SCRIPTS"    elif [ "${4}" == "contrib" ]; then      DIR="extras/contrib/SCRIPTS"    else      DIR="SCRIPTS"    fi        YEAR=$(date +%Y)    cat << EOF > ${DLG_ROOT}/${DIR}/${NAME}/build#!/bin/sh## Copyright $YEAR $YOUR_NAME# Available under the terms of the GNU GPL.#NAME="$NAME"VERSION="$VERSION"REVISION="1"PKG_SOURCEURL='$SOURCEURL'. \$DLG_ROOT/config. \$DLG_ROOT/SCRIPTS/dropline-functions.shEOFpopulate_build_system_commands $BUILD_SYSTEM ${4}    status=$?    if [ $status != 0 ]; then        fallback $PACKAGE_TYPE        die "The cat command, called from within the create_buildscript function,\        exited with status $status!"    fi}## Actual body#if [ "$1" == "" ]; then    echo -n "Please tell me the name of the build script you intend to create: "    read NAMEelse    NAME=$1fiif [ "$2" == "" ]; then    echo -n "Please tell me what version of $NAME you want to build: "    read VERSIONelse    VERSION=$2fiif [ "$3" == "" ]; then    echo "If you know from where to download $NAME version $VERSION from\, please type it here: "    read URLelse    URL=$3fiif [ "$4" == "" ]; then    echo -n "Please select one of the following build systems: autotools, distutils, perl. \(autotools is the default, distutils is commonly used by python programs and perl is used \by perl programs): "    read BUILD_SYSTEM    if [ "$BUILD_SYSTEM" == "" ]; then        BUILD_SYSTEM=autotools    fielse    BUILD_SYSTEM=$4fiif [ "$5" == "" ]; then    echo -n "Is this an official Dropline package, an extra or a contrib package?  Please \select one of the following options: dlg, extra, contrib. \(dlg is the default and will place your build script on the main tree, extra will place it \on extras/dropline and contrib will place it on extras/contrib): "    read PACKAGE_TYPE    PACKAGE_TYPE=$(echo $PACKAGE_TYPE | tr [A-Z] [a-z])    if [ "$PACKAGE_TYPE" == "extra" ]; then        PACKAGE_TYPE="extra"    elif [ "$PACKAGE_TYPE" == "contrib" ]; then        PACKAGE_TYPE="contrib"    else        PACKAGE_TYPE="dlg"    fifi# This variable uses an inverted logic: 0 -> true / 1 -> falseecho $URL | grep $NAME &> /dev/nullcan_subst_name=$?# This variable uses an inverted logic: 0 -> true / 1 -> falseecho $URL | grep $VERSION &> /dev/nullcan_subst_version=$?if [ "$can_subst_name" == "0" ]; then    NEWURL=$(echo $URL | sed -e 's/'$NAME'/'\${NAME}'/g')    echo -n "I noticed that $NAME occurs in the URL you typed, should I\ substitute it with the \$NAME variable resulting in the URL $NEWURL? (Y/n) "    read should_subst_name    if [ "$should_subst_name" != "n" ]; then        URL=$NEWURL    fi    if [ "$can_subst_version" == "0" ]; then        echo -n "I also noticed the same with $VERSION. Should I do the analog\ with it? (Y/n) "        read should_subst_version        NEWURL=$(echo $URL | sed -e 's/'$VERSION'/'\${VERSION}'/g')        if [ "$should_subst_version" != "n" ]; then            URL=$NEWURL        fi    fielse    if [ "$can_subst_version" == "0" ]; then        NEWURL=$(echo $URL | sed -e 's/'$VERSION'/'\$VERSION'/g')        if [ "$should_subst_version" != "n" ]; then            URL=$NEWURL        fi        echo -n "I noticed that $VERSION occurs in the URL you typed, should I\ substitute it with the \$VERSION variable resulting in the URL $NEWURL? (Y/n) "        read should_subst_version    fificreate_dirs $NAME $PACKAGE_TYPEcreate_changelog $NAME $VERSION $PACKAGE_TYPEcreate_descfile $NAME $PACKAGE_TYPEcreate_buildscript $NAME $VERSION $URL $PACKAGE_TYPE $BUILD_SYSTEM# vim: ts=4 sw=4 expandtab