From 7967ee7ab3979f407d40107cce77629873830c70 Mon Sep 17 00:00:00 2001 From: brent s Date: Wed, 6 Jul 2016 09:41:11 -0400 Subject: [PATCH] untested. but this should work quite nicely --- _bin/new.package.sh | 261 ++++++++++-------- _docs/PKGBUILD.templates.d/gitignore | 18 ++ _docs/PKGBUILD.templates.d/release/00.header | 2 + .../PKGBUILD.templates.d/release/01.moreinfo | 2 + _docs/PKGBUILD.templates.d/release/02.pkgmeta | 13 + _docs/PKGBUILD.templates.d/release/03.sources | 7 + _docs/PKGBUILD.templates.d/release/04.build | 4 + _docs/PKGBUILD.templates.d/release/05.package | 4 + _docs/PKGBUILD.templates.d/vcs/00.header | 2 + _docs/PKGBUILD.templates.d/vcs/01.moreinfo | 2 + _docs/PKGBUILD.templates.d/vcs/02.pkgmeta | 13 + _docs/PKGBUILD.templates.d/vcs/03.sources | 6 + _docs/PKGBUILD.templates.d/vcs/04.vcsver.bzr | 4 + _docs/PKGBUILD.templates.d/vcs/04.vcsver.git | 18 ++ _docs/PKGBUILD.templates.d/vcs/04.vcsver.hg | 4 + _docs/PKGBUILD.templates.d/vcs/04.vcsver.svn | 5 + .../vcs/04.vcsver.unknown | 4 + _docs/PKGBUILD.templates.d/vcs/05.build | 4 + _docs/PKGBUILD.templates.d/vcs/06.package | 4 + 19 files changed, 255 insertions(+), 122 deletions(-) create mode 100644 _docs/PKGBUILD.templates.d/gitignore create mode 100644 _docs/PKGBUILD.templates.d/release/00.header create mode 100644 _docs/PKGBUILD.templates.d/release/01.moreinfo create mode 100644 _docs/PKGBUILD.templates.d/release/02.pkgmeta create mode 100644 _docs/PKGBUILD.templates.d/release/03.sources create mode 100644 _docs/PKGBUILD.templates.d/release/04.build create mode 100644 _docs/PKGBUILD.templates.d/release/05.package create mode 100644 _docs/PKGBUILD.templates.d/vcs/00.header create mode 100644 _docs/PKGBUILD.templates.d/vcs/01.moreinfo create mode 100644 _docs/PKGBUILD.templates.d/vcs/02.pkgmeta create mode 100644 _docs/PKGBUILD.templates.d/vcs/03.sources create mode 100644 _docs/PKGBUILD.templates.d/vcs/04.vcsver.bzr create mode 100644 _docs/PKGBUILD.templates.d/vcs/04.vcsver.git create mode 100644 _docs/PKGBUILD.templates.d/vcs/04.vcsver.hg create mode 100644 _docs/PKGBUILD.templates.d/vcs/04.vcsver.svn create mode 100644 _docs/PKGBUILD.templates.d/vcs/04.vcsver.unknown create mode 100644 _docs/PKGBUILD.templates.d/vcs/05.build create mode 100644 _docs/PKGBUILD.templates.d/vcs/06.package diff --git a/_bin/new.package.sh b/_bin/new.package.sh index 1c6fd7e..e7b0719 100755 --- a/_bin/new.package.sh +++ b/_bin/new.package.sh @@ -10,42 +10,145 @@ set -e GPGKEY='748231EBCBD808A14F5E85D28C004C2F93481F6B' # https://wiki.archlinux.org/index.php/PKGBUILD#validpgpkeys MAINTNAME='brent s. ' PKGBUILD_DIR='/opt/dev/arch' +AUR_PKGS_DIR="${PKGBUILD_DIR}" # should be the dir where the aur_pkgs dir lives -# These shouldn't be touched. -PKGNAME=${1} -PKGVER="${2}" +# Get PKGTYPE +PS3='What type of package is this?: ' +options=("Release/Versioned" "VCS (Git, SVN, Mercurial, etc.)" "Quit") +select opt in "${options[@]}" +do + case ${opt} in + "Release/Versioned") + PKGTYPE="release" + ;; + "VCS (Git, SVN, Mercurial, etc.)") + PKGTYPE="vcs" + ;; + "Quit") + exit 0 + ;; + *) echo invalid option;; + esac +done +# get VCSTYPE, if it's a source package +if [[ "${PKGTYPE}" == 'vcs' ]]; +then + PS3='What type of version-control?: ' + options=("Git" "Subversion" "Mercurial" "Bazaar" "(Other)" "Quit") + select opt in "${options[@]}" + do + case ${opt} in + "Git") + VCSTYPE='git' + ;; + "Subversion") + VCSTYPE='svn' + ;; + "Bazaar") + VCSTYPE='bzr' + ;; + "(Other)") + VCSTYPE='unknown' + ;; + "Quit") + exit 0 + ;; + *) echo invalid option;; + esac + done +fi -## SANITY ## +# get PKGNAME +echo -ne "\nWhat is the NAME of the package? (Exclude VCS type if it's a source-control package,\nthat will be prepended automatically): " +read PKGNAME +echo + +# check PKGNAME set +e # disable bail-on-error because we want a non-zero if a package name is not right, etc. -mkdir -p ${PKGBUILD_DIR} -cd ${PKGBUILD_DIR} -echo "${PKGNAME}" | egrep -Eq '^([a-z0-9\_]|-)+$' +echo "${PKGNAME}" | egrep -Eq '^([a-z0-9\_])+$' if [[ "${?}" -ne '0' ]]; then echo "ERROR: That does not seem to be a valid package name!" exit fi -echo "${PKGVER}" | egrep -Eq '^([0-9\.]|git|svn)+$' -if [[ "${?}" -ne '0' ]]; -then - echo "ERROR: That does not seem to be a valid package version!" - echo "Acceptable values are numbers, .'s, or simply 'git'." - exit -elif [[ "${PKGVER}" == 'git' || "${PKGVER}" == 'svn' ]]; -then - PKGVER='0.0.00001' - GITPKG='y' -fi - -if [[ -z "${2}" ]]; -then - echo "USAGE: ${0} " - exit -fi set -e +_PKGNAME="${PKGNAME}" +if [[ -n "${VCSTYPE}" && "${VCSTYPE}" != '' ]]; +then + PKGNAME="${PKGNAME}-${VCSTYPE}" +fi -echo "Will create a package named ${PKGNAME} with initial version of ${PKGVER}. Press enter to continue, or ctrl-C to quit." +# Get the version to pre-populate the PKGBUILD with, if a release. +if [[ "${PKGTYPE}" == 'release' ]]; +then + echo -n "What is the VERSION of the current release you are packaging for ${PKGNAME}? " + read PKGVER + set +e + echo "${PKGVER}" | egrep -Eq '^([0-9\.])+$' + if [[ "${?}" -ne '0' ]]; + then + echo "ERROR: That does not seem to be a valid package version!" + echo "Acceptable values are numbers or .'s." + exit + fi + set -e + echo +fi + +# Get other bits of info. +# PKGDESC +echo -ne "What is a DESCRIPTION of ${_PKGNAME}? (Do not include the package name- e.g.:\n Provides a library for mutating teenage turtles\n) " +read PKGDESC +echo + +# PKGURL +if [[ "${PKGTYPE}" == 'vcs' ]]; +then + echo -ne "What is the CHECKOUT URL for ${_PKGNAME}?\n(Do not include the directory or VCS type prefix as per https://wiki.archlinux.org/index.php/VCS_package_guidelines#VCS_sources - this is added automatically) e.g.:\n https://github.com/shinnok/johnny.git\nURL: " + read SRCURL + echo + PKGURL="${_PKGNAME}::${VCSTYPE}+${PKGURL}" + SRCFILE='' +else + echo -n "What is the URL to the source tarball for ${PKGNAME} (version ${PKGVER})? " + read SRCURL + echo + SRCFILE=$(echo "${SRCURL}" | sed -re 's|^https?.*/(.*)$|\1|g') +fi + +# LICENSE +echo -n "What is the LICENSE for ${_PKGNAME}? " +read LICENSE +echo + +# DEPENDS +echo -n "What does ${_PKGNAME} DEPEND on (for runtime)? if no packages, just hit enter. Make sure they correspond to Arch/AUR package names. " +read PKGDEPS +echo + +# OPTDEPENDS +echo -ne "What is an OPTIONAL DEPENDENCY (runtime) for ${_PKGNAME}? If no packages, just hit enter. They should match the format:\n pkgname:reason why\nOptional deps: " +read OPTDEPS +echo + +echo -e "What is a MAKE DEPEND for ${_PKGNAME}? If no packages, just hit enter. " +read BUILDDEPS +echo + +echo -e "What package names, if any besides itself, does ${_PKGNAME} PROVIDE? (If a VCS package, do not include the non-VCS package- that's added by default!) " +read PROVIDES +echo + +echo -e "What package names, if any besides itself, does ${_PKGNAME} CONFLICT with? (If a VCS package, do not include the non-VCS package- that's added by default!) " +read CONFLICTS +echo + +## SANITY ## +mkdir -p ${PKGBUILD_DIR} +cd ${PKGBUILD_DIR} + +echo "Will create a package named ${PKGNAME}. Press enter to continue, or ctrl-C to quit." read PKGCHK @@ -53,110 +156,24 @@ read PKGCHK cd /tmp git clone aur@aur.archlinux.org:${PKGNAME} cd /tmp/${PKGNAME} -cat >> .gitignore << EOF -*/ -.*.swp -*.pkg.tar.xz -src/ -pkg/ -*.tar -*.tar.bz2 -*.tar.xz -*.tar.gz -*.tgz -*.txz -*.tbz -*.tbz2 -*.zip -*.run -*.7z -*.rar -*.deb -EOF +cp ${AUR_PKGS_DIR}/_docs/PKGBUILD.templates.d/gitignore .gitignore git add .gitignore ## DROP IN A VANILLA PKGBUILD ## -cat > PKGBUILD << EOF -# Maintainer: ${MAINTNAME} -# Bug reports can be filed at https://bugs.square-r00t.net/index.php?project=3 -# News updates for packages can be followed at https://devblog.square-r00t.net -validpgpkeys=('${GPGKEY}') -pkgname=${PKGNAME} -pkgver=${PKGVER} -pkgrel=1 -pkgdesc="%%SOME DESCRIPTION HERE%%" -arch=('i686' 'x86_64') -url="%%SOME URL HERE%%" -license=('%%SOME LICENSE(S) HERE%%') -install= -changelog= -noextract=() -#depends=('%%RUNTIME DEPENDENCIES HERE%%') -#optdepends=('%%OPTIONAL DEPENDENCIES HERE (pkg: why needed)%%') -#makedepends=('%%BUILDTIME DEPENDENCIES HERE%%') -EOF - -if [[ -n "${GITPKG}" ]]; +if [[ "${PKGTYPE}" == 'vcs' ]]; then - STRIPPKG=$(echo "${PKGNAME}" | sed -re 's/-(git|svn)//g') + cat ${AUR_PKGS_DIR}/_docs/PKGBUILD.templates.d/vcs/{00.*,01.*,02.*,03.*,04.*.${VCSTYPE},05.*,06.*} > PKGBUILD else - STRIPPKG="${PKGNAME}" + cat ${AUR_PKGS_DIR}/_docs/PKGBUILD.templates.d/release/* > PKGBUILD + touch "${SRCFILE}.sig" fi -cat >> PKGBUILD << EOF -_pkgname=${STRIPPKG} -#_pkgname2='%%OPTIONAL SHORTHAND PACKAGE NAME%%' -EOF - - -if [[ -n "${GITPKG}" ]]; -then - cat >> PKGBUILD << EOF -source=("\${_pkgname}::git+https://github.com/\${_pkgname}/\${_pkgname}.git") -sha512sums=('SKIP') -EOF -else - cat >> PKGBUILD << EOF -source=("https://\${pkgname}.com/\${_pkgname}/\${_pkgname}-\${pkgver}.tar.gz" - "\${_pkgname}-\${pkgver}.tar.gz.sig") -sha512sums=('cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e' - 'SKIP') -EOF -fi - -cat >> PKGBUILD << EOF -provides=("\${_pkgname}") -#conflicts=("\${_pkgname}") -EOF - -if [[ -n "${GITPKG}" ]]; -then - cat >> PKGBUILD << EOF -pkgver() { - cd "\${srcdir}/\${_pkgname}" - ( - printf "r%s.%s" "\$(git rev-list --count HEAD)" "\$(git rev-parse --short HEAD)" - #( set -o pipefail - # git describe --long --tags 2>/dev/null | sed 's/\\([^-]*-g\\)/r\\1/;s/-/./g' || - # printf "r%s.%s" "\$(git rev-list --count HEAD)" "\$(git rev-parse --short HEAD)" - #) - ) -} -EOF -fi - -cat >> PKGBUILD << EOF - -build() { - cd "\${srcdir}/\${_pkgname}/src" - make prefix=\${pkgdir}/usr -} - -package() { - install -D -m755 \${srcdir}/\${_pkgname}/src/\${_pkgname2} \${pkgdir}/usr/bin/\${_pkgname2} - install -D -m644 \${srcdir}/\${_pkgname}/docs/README.html.en \${pkgdir}/usr/share/doc/\${_pkgname}/README.html -} -EOF +for i in MAINTNAME GPGKEY PKGNAME PKGVER PKGDESC SRCURL LICENSE PKGDEPS OPTDEPS BUILDDEPS _PKGNAME SRCFILE; +do + NEWVAL=${!i} + #echo "${i} is ${NEWVAL}" + sed -i -re "s@%{2}${i}%{2}@${NEWVAL}@g" PKGBUILD +done # now we need to commit the thing since apparently we can't add empty repos as submodules...? mksrcinfo diff --git a/_docs/PKGBUILD.templates.d/gitignore b/_docs/PKGBUILD.templates.d/gitignore new file mode 100644 index 0000000..e16177d --- /dev/null +++ b/_docs/PKGBUILD.templates.d/gitignore @@ -0,0 +1,18 @@ +*/ +.*.swp +*.pkg.tar.xz +src/ +pkg/ +*.tar +*.tar.bz2 +*.tar.xz +*.tar.gz +*.tgz +*.txz +*.tbz +*.tbz2 +*.zip +*.run +*.7z +*.rar +*.deb diff --git a/_docs/PKGBUILD.templates.d/release/00.header b/_docs/PKGBUILD.templates.d/release/00.header new file mode 100644 index 0000000..b14650c --- /dev/null +++ b/_docs/PKGBUILD.templates.d/release/00.header @@ -0,0 +1,2 @@ +# Maintainer: %%MAINTNAME%% +validpgpkeys=('%%GPGKEY%%') diff --git a/_docs/PKGBUILD.templates.d/release/01.moreinfo b/_docs/PKGBUILD.templates.d/release/01.moreinfo new file mode 100644 index 0000000..933af0f --- /dev/null +++ b/_docs/PKGBUILD.templates.d/release/01.moreinfo @@ -0,0 +1,2 @@ +# Bug reports can be filed at https://bugs.square-r00t.net/index.php?project=3 +# News updates for packages can be followed at https://devblog.square-r00t.net diff --git a/_docs/PKGBUILD.templates.d/release/02.pkgmeta b/_docs/PKGBUILD.templates.d/release/02.pkgmeta new file mode 100644 index 0000000..8db8371 --- /dev/null +++ b/_docs/PKGBUILD.templates.d/release/02.pkgmeta @@ -0,0 +1,13 @@ +pkgname=%%PKGNAME%% +pkgver=%%PKGVER%% +pkgrel=1 +pkgdesc="%%PKGDESC%%" +arch=('i686' 'x86_64') +url="%%PKGURL%%" +license=('%%LICENSE%%') +depends=('%%PKGDEPS%%') +optdepends=('%%OPTDEPS%%') +makedepends=('%%BUILDDEPS%%') +_pkgname=%%PKGNAME%% +provides=("%%_PKGNAME%%") +#conflicts=("%%_PKGNAME%%") diff --git a/_docs/PKGBUILD.templates.d/release/03.sources b/_docs/PKGBUILD.templates.d/release/03.sources new file mode 100644 index 0000000..a6f04fe --- /dev/null +++ b/_docs/PKGBUILD.templates.d/release/03.sources @@ -0,0 +1,7 @@ +install= +changelog= +noextract=() +source=("%%SRCURL%%" + "%%SRCFILE%%.sig") +sha512sums=('cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e' + 'SKIP') diff --git a/_docs/PKGBUILD.templates.d/release/04.build b/_docs/PKGBUILD.templates.d/release/04.build new file mode 100644 index 0000000..794bbea --- /dev/null +++ b/_docs/PKGBUILD.templates.d/release/04.build @@ -0,0 +1,4 @@ +build() { + cd "${srcdir}/${_pkgname}/src" + make prefix=${pkgdir}/usr +} diff --git a/_docs/PKGBUILD.templates.d/release/05.package b/_docs/PKGBUILD.templates.d/release/05.package new file mode 100644 index 0000000..f24d818 --- /dev/null +++ b/_docs/PKGBUILD.templates.d/release/05.package @@ -0,0 +1,4 @@ +package() { + install -D -m755 ${srcdir}/${_pkgname}/src/${_pkgname} ${pkgdir}/usr/bin/${_pkgname} + install -D -m644 ${srcdir}/${_pkgname}/docs/README.html.en ${pkgdir}/usr/share/doc/${_pkgname}/README.html +} diff --git a/_docs/PKGBUILD.templates.d/vcs/00.header b/_docs/PKGBUILD.templates.d/vcs/00.header new file mode 100644 index 0000000..b14650c --- /dev/null +++ b/_docs/PKGBUILD.templates.d/vcs/00.header @@ -0,0 +1,2 @@ +# Maintainer: %%MAINTNAME%% +validpgpkeys=('%%GPGKEY%%') diff --git a/_docs/PKGBUILD.templates.d/vcs/01.moreinfo b/_docs/PKGBUILD.templates.d/vcs/01.moreinfo new file mode 100644 index 0000000..933af0f --- /dev/null +++ b/_docs/PKGBUILD.templates.d/vcs/01.moreinfo @@ -0,0 +1,2 @@ +# Bug reports can be filed at https://bugs.square-r00t.net/index.php?project=3 +# News updates for packages can be followed at https://devblog.square-r00t.net diff --git a/_docs/PKGBUILD.templates.d/vcs/02.pkgmeta b/_docs/PKGBUILD.templates.d/vcs/02.pkgmeta new file mode 100644 index 0000000..617822e --- /dev/null +++ b/_docs/PKGBUILD.templates.d/vcs/02.pkgmeta @@ -0,0 +1,13 @@ +pkgname=%%PKGNAME%% +pkgver=0.0000001 +pkgrel=1 +pkgdesc="%%PKGDESC%%" +arch=('i686' 'x86_64') +url="%%PKGURL%%" +license=('%%LICENSE%%') +depends=('%%PKGDEPS%%') +optdepends=('%%OPTDEPS%%') +makedepends=('%%BUILDDEPS%%') +_pkgname=%%_PKGNAME%% +provides=("%%_PKGNAME%%") +conflicts=("%%_PKGNAME%%") diff --git a/_docs/PKGBUILD.templates.d/vcs/03.sources b/_docs/PKGBUILD.templates.d/vcs/03.sources new file mode 100644 index 0000000..6e4d05e --- /dev/null +++ b/_docs/PKGBUILD.templates.d/vcs/03.sources @@ -0,0 +1,6 @@ +install= +changelog= +noextract=() +source=("%%SRCURL%%") +# see https://wiki.archlinux.org/index.php/VCS_package_guidelines#Git_Submodules if you require git submodules +sha512sums=('SKIP') diff --git a/_docs/PKGBUILD.templates.d/vcs/04.vcsver.bzr b/_docs/PKGBUILD.templates.d/vcs/04.vcsver.bzr new file mode 100644 index 0000000..791a0ec --- /dev/null +++ b/_docs/PKGBUILD.templates.d/vcs/04.vcsver.bzr @@ -0,0 +1,4 @@ +pkgver() { + cd "${pkgname}" + printf "r%s" "$(bzr revno)" +} diff --git a/_docs/PKGBUILD.templates.d/vcs/04.vcsver.git b/_docs/PKGBUILD.templates.d/vcs/04.vcsver.git new file mode 100644 index 0000000..f98e08e --- /dev/null +++ b/_docs/PKGBUILD.templates.d/vcs/04.vcsver.git @@ -0,0 +1,18 @@ +pkgver() { + cd "${srcdir}/${_pkgname}" + # no tags, so number of revisions e.g. r1142.a17a017 + printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)" + ## most recent annotated tag e.g. 2.0.r6.ga17a017 + #git describe --long | sed 's/\([^-]*-g\)/r\1/;s/-/./g' + ## most recent un-annotated tag e.g. 0.71.r115.gd95ee07 + #git describe --long --tags | sed 's/\([^-]*-g\)/r\1/;s/-/./g' + ## or: + ##git describe --long --tags | sed 's/-/.r/;s/-/./' + ## project uses tags with prefix. e.g. v... + #git describe --long | sed 's/^foo-//;s/\([^-]*-g\)/r\1/;s/-/./g' + ## both with fallback, e.g. 0.9.9.r27.g2b039da with tags, else r1581.2b039da + #( set -o pipefail + # git describe --long 2>/dev/null | sed 's/\([^-]*-g\)/r\1/;s/-/./g' || + # printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)" + #) +} diff --git a/_docs/PKGBUILD.templates.d/vcs/04.vcsver.hg b/_docs/PKGBUILD.templates.d/vcs/04.vcsver.hg new file mode 100644 index 0000000..21c6a4e --- /dev/null +++ b/_docs/PKGBUILD.templates.d/vcs/04.vcsver.hg @@ -0,0 +1,4 @@ +pkgver() { + cd "${pkgname}" + printf "r%s.%s" "$(hg identify -n)" "$(hg identify -i)" +} diff --git a/_docs/PKGBUILD.templates.d/vcs/04.vcsver.svn b/_docs/PKGBUILD.templates.d/vcs/04.vcsver.svn new file mode 100644 index 0000000..c70e492 --- /dev/null +++ b/_docs/PKGBUILD.templates.d/vcs/04.vcsver.svn @@ -0,0 +1,5 @@ +pkgver() { + cd "${pkgname}" + local ver="$(svnversion)" + printf "r%s" "${ver//[[:alpha:]]}" +} diff --git a/_docs/PKGBUILD.templates.d/vcs/04.vcsver.unknown b/_docs/PKGBUILD.templates.d/vcs/04.vcsver.unknown new file mode 100644 index 0000000..90c6248 --- /dev/null +++ b/_docs/PKGBUILD.templates.d/vcs/04.vcsver.unknown @@ -0,0 +1,4 @@ +pkgver() { + cd "$pkgname" + printf "r%s" "$(bzr revno)" +} diff --git a/_docs/PKGBUILD.templates.d/vcs/05.build b/_docs/PKGBUILD.templates.d/vcs/05.build new file mode 100644 index 0000000..794bbea --- /dev/null +++ b/_docs/PKGBUILD.templates.d/vcs/05.build @@ -0,0 +1,4 @@ +build() { + cd "${srcdir}/${_pkgname}/src" + make prefix=${pkgdir}/usr +} diff --git a/_docs/PKGBUILD.templates.d/vcs/06.package b/_docs/PKGBUILD.templates.d/vcs/06.package new file mode 100644 index 0000000..f24d818 --- /dev/null +++ b/_docs/PKGBUILD.templates.d/vcs/06.package @@ -0,0 +1,4 @@ +package() { + install -D -m755 ${srcdir}/${_pkgname}/src/${_pkgname} ${pkgdir}/usr/bin/${_pkgname} + install -D -m644 ${srcdir}/${_pkgname}/docs/README.html.en ${pkgdir}/usr/share/doc/${_pkgname}/README.html +}