diff options
author | Natanael Copa <ncopa@alpinelinux.org> | 2009-01-29 09:06:43 +0000 |
---|---|---|
committer | Natanael Copa <ncopa@alpinelinux.org> | 2009-01-29 09:06:43 +0000 |
commit | 21cd6680eee14cb6ab89ff95d8ca2413833800c7 (patch) | |
tree | fc0888eb5323e41fa09a05d71ce11bb150de7f9e | |
parent | 81f8737a6aa13c1d6944f061a1f21e5549ff4003 (diff) | |
download | abuild-21cd6680eee14cb6ab89ff95d8ca2413833800c7.tar.gz abuild-21cd6680eee14cb6ab89ff95d8ca2413833800c7.tar.bz2 abuild-21cd6680eee14cb6ab89ff95d8ca2413833800c7.tar.xz abuild-21cd6680eee14cb6ab89ff95d8ca2413833800c7.zip |
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.
-rw-r--r-- | Makefile | 7 | ||||
-rwxr-xr-x | abuild | 54 | ||||
-rw-r--r-- | sample.APKBUILD (renamed from APKBUILD.proto) | 4 | ||||
-rw-r--r-- | sample.confd | 9 | ||||
-rw-r--r-- | sample.initd | 39 | ||||
-rw-r--r-- | sample.install | 30 |
6 files changed, 134 insertions, 9 deletions
@@ -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=<path> ]" @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 @@ -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/APKBUILD.proto b/sample.APKBUILD index 0e08dea..606bea8 100644 --- a/APKBUILD.proto +++ b/sample.APKBUILD @@ -9,7 +9,6 @@ pkgname=NAME pkgver=VERSION pkgrel=0 pkgdesc="" -arch="" url="" license="GPL" depends="" @@ -27,6 +26,9 @@ build() { --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 |