#!/bin/bash # vim: set ts=8 fdm=marker : BASEDIR="${HOME}/builds" PROTODIR='/usr/share/pacman' ### # Lines below this point should not need to be edited. ## MYVERSION=1.0 DOCOPYINSTALL=0 # Copy the .install file DOCOPYRC=0 # Copy the prototype rc.d script DOFORCE=0 # Overwrite existing files PROTO_PKGBUILD="${PROTODIR}/PKGBUILD.proto" PROTO_INSTALL="${PROTODIR}/proto.install" PROTO_RC="${PROTODIR}/rc-script.proto" # {{{ usage() function usage { cat << _USAGE $(basename $0) version $MYVERSION -- A script to speed up creating new PKGBUILDs Usage: $(basename $0) [options] PKGNAME Options: -h --help - Print this usage -f --force - Overwrite existing files in the target dir -i --proto-install - Copy the prototype .install file --rc - Copy the protype for an rc.d script --cvs - Copy the prototype for a cvs PKGBUILD --darcs - Copy the prototype for a darcs PKGBUILD --git - Copy the prototype for a git PKGBUILD --svn - Copy the prototype for a svn PKGBUILD _USAGE exit 0 } # }}} # {{{ die() warn() quit() msg() function die { warn "${1:-Unknown error}" quit ${2:-1} } function warn { if [ -n "$1" ]; then echo "$1" 1>&2 fi } function quit { exit ${1:-0} } function msg { echo "$1" } # }}} if [ -z "$1" ]; then usage fi while [ "$#" -ne 0 ]; do case $1 in -h|--help) usage ;; -i|--proto-install) DOCOPYINSTALL=1 ;; -f|--force) DOFORCE=1 ;; --cvs) PROTO_PKGBUILD='PKGBUILD-cvs.proto' ;; --darcs) PROTO_PKGBUILD='PKGBUILD-darcs.proto' ;; --git) PROTO_PKGBUILD='PKGBUILD-git.proto' ;; --svn) PROTO_PKGBUILD='PKGBUILD-svn.proto' ;; --rc) DOCOPYRC=1 ;; *) pkgname=$(echo $1 | sed 's/ //g') # Remove spaces from the name ;; esac shift done pkgdir="${BASEDIR}/${pkgname}" if [ -d "$pkgdir" ]; then if [ "$DOFORCE" -eq 1 ]; then warn "$pkgname already exists in $BASEDIR -- continuing anyway!" else die "$pkgname already exists in $BASEDIR -- aborting" fi else mkdir -p "$pkgdir" msg "Creating package dir for $pkgname" fi cd "$pkgdir" if [ -r "$PROTO_PKGBUILD" ]; then msg "Copying prototype PKGBUILD" cp "$PROTO_PKGBUILD" ./PKGBUILD sed -i "s#^pkgname=.*#pkgname=$pkgname#" PKGBUILD else warn "Could not find prototype PKGBUILD" fi if [ "$DOCOPYINSTALL" -eq 1 ]; then if [ -r "$PROTO_INSTALL" ]; then msg "Copying prototype .install file" cp "$PROTO_INSTALL" "./${pkgname}.install" sed -i "s#^install=.*#install='${pkgname}.install'#" PKGBUILD else warn "Could not find prototype .install" fi fi if [ "$DOCOPYRC" -eq 1 ]; then if [ -r "$PROTO_RC" ]; then msg "Copying prototype r#!/bin/bash # vim: set ts=8 fdm=marker : BASEDIR="${HOME}/builds" PROTODIR='/usr/share/pacman' ### # Lines below this point should not need to be edited. ## MYVERSION=1.0 DOCOPYINSTALL=0 # Copy the .install file DOCOPYRC=0 # Copy the prototype rc.d script DOFORCE=0 # Overwrite existing files PROTO_PKGBUILD="${PROTODIR}/PKGBUILD.proto" PROTO_INSTALL="${PROTODIR}/proto.install" PROTO_RC="${PROTODIR}/rc-script.proto" # {{{ usage() function usage { cat << _USAGE $(basename $0) version $MYVERSION -- A script to speed up creating new PKGBUILDs Usage: $(basename $0) [options] PKGNAME Options: -h --help - Print this usage -f --force - Overwrite existing files in the target dir -i --proto-install - Copy the prototype .install file --rc - Copy the protype for an rc.d script --cvs - Copy the prototype for a cvs PKGBUILD --darcs - Copy the prototype for a darcs PKGBUILD --git - Copy the prototype for a git PKGBUILD --svn - Copy the prototype for a svn PKGBUILD _USAGE exit 0 } # }}} # {{{ die() warn() quit() msg() function die { warn "${1:-Unknown error}" quit ${2:-1} } function warn { if [ -n "$1" ]; then echo "$1" 1>&2 fi } function quit { exit ${1:-0} } function msg { echo "$1" } # }}} if [ -z "$1" ]; then usage fi while [ "$#" -ne 0 ]; do case $1 in -h|--help) usage ;; -i|--proto-install) DOCOPYINSTALL=1 ;; -f|--force) DOFORCE=1 ;; --cvs) PROTO_PKGBUILD='PKGBUILD-cvs.proto' ;; --darcs) PROTO_PKGBUILD='PKGBUILD-darcs.proto' ;; --git) PROTO_PKGBUILD='PKGBUILD-git.proto' ;; --svn) PROTO_PKGBUILD='PKGBUILD-svn.proto' ;; --rc) DOCOPYRC=1 ;; *) pkgname=$(echo $1 | sed 's/ //g') # Remove spaces from the name ;; esac shift done pkgdir="${BASEDIR}/${pkgname}" if [ -d "$pkgdir" ]; then if [ "$DOFORCE" -eq 1 ]; then warn "$pkgname already exists in $BASEDIR -- continuing anyway!" else die "$pkgname already exists in $BASEDIR -- aborting" fi else mkdir -p "$pkgdir" msg "Creating package dir for $pkgname" fi cd "$pkgdir" if [ -r "$PROTO_PKGBUILD" ]; then msg "Copying prototype PKGBUILD" cp "$PROTO_PKGBUILD" ./PKGBUILD sed -i "s#^pkgname=.*#pkgname=$pkgname#" PKGBUILD else warn "Could not find prototype PKGBUILD" fi if [ "$DOCOPYINSTALL" -eq 1 ]; then if [ -r "$PROTO_INSTALL" ]; then msg "Copying prototype .install file" cp "$PROTO_INSTALL" "./${pkgname}.install" sed -i "s#^install=.*#install='${pkgname}.install'#" PKGBUILD else warn "Could not find prototype .install" fi fi if [ "$DOCOPYRC" -eq 1 ]; then if [ -r "$PROTO_RC" ]; then msg "Copying prototype rc.d script" cp "$PROTO_RC" "./${pkgname}" sed -i "s#^source=(\(.*\))#source=(\1 $pkgname)#" PKGBUILD else warn "Could not find prototype rc.d script" fi fi msg "All done! New package prepared in $pkgdir" quit 0 c.d script" cp "$PROTO_RC" "./${pkgname}" sed -i "s#^source=(\(.*\))#source=(\1 $pkgname)#" PKGBUILD else warn "Could not find prototype rc.d script" fi fi msg "All done! New package prepared in $pkgdir" quit 0