summaryrefslogtreecommitdiff
path: root/newapkbuild.in
blob: 3fa0b8717b61fa93b8980e391ac55af97b911bf5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/sh

# script to generate a new APKBUILD
# Copyright (c) 2009 Natanael Copa <natanael.copa@gmail.com>
#
# Distributed under GPL-2
#
# Depends on: busybox utilities, fakeroot, 
#

version=@VERSION@
sysconfdir=@sysconfdir@
datadir=@datadir@

prog=${0##*/}

error() {
	echo "$@" >&2
}

# create new aport from templates
newaport() {
	local newname="$1"
	local pn=${newname%-[0-9]*}
	local pv
	if [ "$pn" != "$newname" ]; then
		pv=${newname#$pn-}
	fi
	if [ -e "$pn"/APKBUILD ] && [ -z "$force" ]; 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.pre-install $pn.pre-install
		cp "$datadir"/sample.post-install $pn.post-install
		sed -i -e "s/^install=.*/install=\"\$pkgname.pre-install \$pkgname.post-install\"/" \
			-e "s/^source=\"\(.*\)\"/source=\"\1\n\t$pn.initd\n\t$pn.confd\n\t\$install\n\t\"/" \
			APKBUILD
		
	fi
}

usage() {
	echo "$prog $version"
	echo "usage: $prog [-cfh] PKGNAME[-PKGVER]"
	echo "Options:"
	echo " -c  Copy a sample init.d, conf.d and install script to new directory"
	echo " -f  Force even if directory already exist"
	echo " -h  Show this help"
	echo ""
	exit 0
}

while getopts "cfh" opt; do
	case $opt in
		'c') cpinitd=1;;
		'f') force=1;;
		'h') usage;;
	esac
done
shift $(( $OPTIND - 1 ))

while [ $# -gt 0 ]; do 
	newaport $1 || exit 1
	shift
done