Commit 21cd6680 authored by Natanael Copa's avatar Natanael Copa

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.
parent 81f8737a
......@@ -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
......
......@@ -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'
# Sample conf.d file for alpine linux
#
# Specify daemon $OPTS here.
#
OPTS=""
USER="nobody"
GROUP="nobody"
#!/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 $?
}
#!/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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment