From 21cd6680eee14cb6ab89ff95d8ca2413833800c7 Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Thu, 29 Jan 2009 09:06:43 +0000 Subject: abuild: support for creation of new APKBUILD from template abuild [-c] -n PKGNAME[-PKGVER] creates a directory with new APKBUILD. If -c is specified will sample init.d, conf.d and install script be copied as well. --- APKBUILD.proto | 32 -------------------------------- Makefile | 7 ++++--- abuild | 54 +++++++++++++++++++++++++++++++++++++++++++++++++----- sample.APKBUILD | 34 ++++++++++++++++++++++++++++++++++ sample.confd | 9 +++++++++ sample.initd | 39 +++++++++++++++++++++++++++++++++++++++ sample.install | 30 ++++++++++++++++++++++++++++++ 7 files changed, 165 insertions(+), 40 deletions(-) delete mode 100644 APKBUILD.proto create mode 100644 sample.APKBUILD create mode 100644 sample.confd create mode 100644 sample.initd create mode 100644 sample.install diff --git a/APKBUILD.proto b/APKBUILD.proto deleted file mode 100644 index 0e08dea..0000000 --- a/APKBUILD.proto +++ /dev/null @@ -1,32 +0,0 @@ -# This is an example APKBUILD file. Use this as a start to creating your own, -# and remove these comments. -# NOTE: Please fill out the license field for your package! If it is unknown, -# then please put 'unknown'. - -# Contributor: Your Name -# Maintainer: Your Name -pkgname=NAME -pkgver=VERSION -pkgrel=0 -pkgdesc="" -arch="" -url="" -license="GPL" -depends="" -makedepends="" -install= -subpackages="$pkgname-doc $pkgname-dev" -source="http://downloads.sourceforge.net/$pkgname/$pkgname-$pkgver.tar.gz" - -build() { - cd "$srcdir/$pkgname-$pkgver" - - ./configure --prefix=/usr \ - --sysconfdir=/etc \ - --mandir=/usr/share/man \ - --infodir=/usr/share/info - make || return 1 - make DESTDIR="$pkgdir" install -} - -md5sums="" #generate with 'abuild checksum' diff --git a/Makefile b/Makefile index cba57fa..46877ab 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,8 @@ PACKAGE=abuild VERSION:=$(shell awk -F= '$$1 == "abuild_ver" {print $$2}' abuild) USR_BIN_FILES=abuild devbuild mkalpine buildrepo -DISTFILES=$(USR_BIN_FILES) Makefile abuild.conf APKBUILD.proto +SAMPLES=sample.APKBUILD sample.initd sample.confd sample.install +DISTFILES=$(USR_BIN_FILES) $(SAMPLES) Makefile abuild.conf \ prefix ?= /usr @@ -16,7 +17,7 @@ help: @echo "usage: make install [ DESTDIR= ]" @echo " make dist" -install: $(USR_BIN_FILES) abuild.conf APKBUILD.proto functions.sh +install: $(USR_BIN_FILES) $(SAMPLES) abuild.conf functions.sh mkdir -p $(DESTDIR)/$(prefix)/bin $(DESTDIR)/$(sysconfdir) \ $(DESTDIR)/$(datadir) for i in $(USR_BIN_FILES); do\ @@ -25,7 +26,7 @@ install: $(USR_BIN_FILES) abuild.conf APKBUILD.proto functions.sh if [ -n "$(DESTDIR)" ] || [ ! -f "/$(sysconfdir)"/abuild.conf ]; then\ cp abuild.conf $(DESTDIR)/$(sysconfdir)/; \ fi - cp APKBUILD.proto $(DESTDIR)/$(prefix)/share/abuild + cp $(SAMPLES) $(DESTDIR)/$(prefix)/share/abuild cp functions.sh $(DESTDIR)/$(datadir)/ dist: $(P).tar.bz2 diff --git a/abuild b/abuild index fd02e51..d200b0b 100755 --- a/abuild +++ b/abuild @@ -34,10 +34,12 @@ if [ -n "$REPODEST" ]; then fi # source functions +datadir=/usr/share/abuild + # if abuild was not run from PATH, then look for func lib at same location if [ -z "$FUNCLIB" ]; then FUNCLIB="${0##/*}/functions.sh" - [ -f "$FUNCLIB" ] || FUNCLIB=/usr/share/abuild/functions.sh + [ -f "$FUNCLIB" ] || FUNCLIB=$datadir/functions.sh fi if ! [ -f "$FUNCLIB" ]; then @@ -558,9 +560,41 @@ post_add() { sudo apk add -u "$pkgf" || die "Failed to install $1" } +# create new aport from templates +newaport() { + local pn=${newname%-[0-9]*} + local pv + if [ "$pn" != "$newname" ]; then + pv=${newname#$pn-} + fi + if [ -e "$pn"/APKBUILD ]; then + error "$pn/APKBUILD already exist" + return 1 + fi + mkdir -p "$pn" + cd "$pn" + sed -e '1,/^\#*$/d' \ + -e "s/^\(# Contributor: \).*/\1$PACKAGER/" \ + -e "s/^\(# Maintainer: \).*/\1$PACKAGER/" \ + -e "s/^pkgname=.*/pkgname=$pn/" \ + -e "s/^pkgver=.*/pkgver=$pv/" \ + "$datadir"/sample.APKBUILD > APKBUILD || return 1 + #-e '1,/^\#$/d' \ + if [ -n "$cpinitd" ]; then + cp "$datadir"/sample.initd $pn.initd + cp "$datadir"/sample.confd $pn.confd + cp "$datadir"/sample.install $pn.install + sed -i -e "s/^install=.*/install=\"$pn.install\"/" \ + -e "s/^source=\"\(.*\)\"/source=\"\1\n\t$pn.initd\n\t$pn.confd\n\t\$install\n\t\"/" \ + APKBUILD + + fi +} + usage() { echo "$(basename $0) $abuild_ver" - echo "usage: $0 [options] [-i PKG] [-p PKGDEST] [-s SRCDEST] [cmd] ..." + echo "usage: ${0##*/} [options] [-i PKG] [-p PKGDEST] [-s SRCDEST] [cmd] ..." + echo " ${0##*/} [-c] -n PKGNAME[-PKGVER]" echo "Options:" echo " -f Force specified cmd, even if they are already done" echo " -h Show this help" @@ -572,6 +606,9 @@ usage() { echo " -s Set source package destination directory" echo " -u Recursively build and upgrade dependencies (using sudo)" echo "" + echo " -n Create a new APKBUILD in a directory named PKGNAME" + echo " -c Copy a sample init.d, conf.d and install script to new directory" + echo "" echo "Commands:" echo " checksum Generate checksum to be included in APKBUILD" echo " fetch Fetch sources to \$SRCDEST and verify checksums" @@ -595,12 +632,14 @@ usage() { APKBUILD="${APKBUILD:-./APKBUILD}" unset force unset recursive -while getopts "fhi:kip:qrs:u" opt; do +while getopts "cfhi:kin:p:qrs:u" opt; do case $opt in + 'c') cpinitd=1;; 'f') force=1;; 'h') usage;; 'i') install_after="$install_after $OPTARG";; 'k') keep=1;; + 'n') newname=$OPTARG;; 'p') PKGDEST=$OPTARG;; 'q') quiet=1;; 'r') recursive=1;; @@ -612,8 +651,10 @@ done shift $(( $OPTIND - 1 )) # source the buildfile -[ -f "$APKBUILD" ] || die "Could not find $APKBUILD (PWD=$PWD)" -. "$APKBUILD" +if [ -z "$newname" ]; then + [ -f "$APKBUILD" ] || die "Could not find $APKBUILD (PWD=$PWD)" + . "$APKBUILD" +fi # If we are handling a sub package then reset subpackages if [ -n "$subpkgname" ]; then @@ -623,6 +664,9 @@ fi trap 'die "Aborted by user"' INT set_xterm_title "abuild: $pkgname" +if [ -z "$1" ] && [ -n "$newname" ]; then + set "newaport" +fi if [ -z "$1" ]; then if up2date && [ -z "$force" ]; then diff --git a/sample.APKBUILD b/sample.APKBUILD new file mode 100644 index 0000000..606bea8 --- /dev/null +++ b/sample.APKBUILD @@ -0,0 +1,34 @@ +# This is an example APKBUILD file. Use this as a start to creating your own, +# and remove these comments. +# NOTE: Please fill out the license field for your package! If it is unknown, +# then please put 'unknown'. + +# Contributor: Your Name +# Maintainer: Your Name +pkgname=NAME +pkgver=VERSION +pkgrel=0 +pkgdesc="" +url="" +license="GPL" +depends="" +makedepends="" +install= +subpackages="$pkgname-doc $pkgname-dev" +source="http://downloads.sourceforge.net/$pkgname/$pkgname-$pkgver.tar.gz" + +build() { + cd "$srcdir/$pkgname-$pkgver" + + ./configure --prefix=/usr \ + --sysconfdir=/etc \ + --mandir=/usr/share/man \ + --infodir=/usr/share/info + make || return 1 + make DESTDIR="$pkgdir" install + + # install -m755 -D "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname + # install -m644 -D "$srcdir"/$pkgname.confd "$pkgdir"/etc/conf.d/$pkgname +} + +md5sums="" #generate with 'abuild checksum' diff --git a/sample.confd b/sample.confd new file mode 100644 index 0000000..0abb80c --- /dev/null +++ b/sample.confd @@ -0,0 +1,9 @@ +# Sample conf.d file for alpine linux + +# +# Specify daemon $OPTS here. +# + +OPTS="" +USER="nobody" +GROUP="nobody" diff --git a/sample.initd b/sample.initd new file mode 100644 index 0000000..980c53e --- /dev/null +++ b/sample.initd @@ -0,0 +1,39 @@ +#!/sbin/runscript + +# Sample init.d file for alpine linux. + +NAME= +DAEMON=/usr/sbin/$NAME + +depend() { + need net +} + +start() { + ebegin "Starting ${NAME}" + start-stop-daemon --start --quiet --background \ + --make-pidfile --pidfile /var/run/${NAME}.pid \ + --chuid ${USER}:${GROUP} \ + --exec ${DAEMON} -- ${OPTS} + eend $? +} + +stop() { + ebegin "Stopping ${NAME}" + start-stop-daemon --stop --quiet \ + --exec ${DAEMON} \ + --pidfile /var/run/${NAME}.pid \ + eend $? +} + +reload() { + ebegin "Reloading ${NAME}" + if ! service_started "${NAME}" ; then + eend 1 "${NAME} is not started" + return 1 + fi + start-stop-daemon --stop --oknodo --signal HUP \ + --exec ${DAEMON} --pidfile /var/run/${NAME}.pid + eend $? +} + diff --git a/sample.install b/sample.install new file mode 100644 index 0000000..a05d28b --- /dev/null +++ b/sample.install @@ -0,0 +1,30 @@ +#!/bin/sh + +case "$1" in + pre_install) + # add something which happends before install + # $2 contains package version + ;; + post_install) + # add something which happends after install + # $2 contains package version + ;; + pre_upgrade) + # add something which happends before update + # $2 contains new package version + # $3 contains old package version + ;; + post_upgrade) + # add something which happends after update + # $2 contains new package version + # $3 contains old package version + ;; + pre_deinstall) + # add something which happends before delete + # $2 contains package version + ;; + post_deinstall) + # add something which happends after delete + # $2 contains package version + ;; +esac -- cgit v1.2.3-60-g2f50