Skip to content
Snippets Groups Projects
abuild.in 49.3 KiB
Newer Older
Natanael Copa's avatar
Natanael Copa committed
#!/bin/sh

# abuild - build apk packages (light version of makepkg)
Natanael Copa's avatar
Natanael Copa committed
# Copyright (c) 2008 Natanael Copa <natanael.copa@gmail.com>
#
# Distributed under GPL-2
#

Natanael Copa's avatar
Natanael Copa committed
abuild_ver=@VERSION@
sysconfdir=@sysconfdir@
abuildrepo_base=@abuildrepo@
Natanael Copa's avatar
Natanael Copa committed
datadir=@datadir@
Natanael Copa's avatar
Natanael Copa committed

program=${0##*/}
abuild_path=$(readlink -f $0)
Natanael Copa's avatar
Natanael Copa committed

# defaults
BUILD_BASE="build-base"
FAKEROOT=${FAKEROOT:-"fakeroot"}
: ${SUDO_APK:=abuild-apk}
: ${APK:=apk}
: ${ADDUSER:=abuild-adduser}
: ${ADDGROUP:=abuild-addgroup}

apk_opt_wait="--wait 30"
Natanael Copa's avatar
Natanael Copa committed
# read config
Natanael Copa's avatar
Natanael Copa committed
ABUILD_CONF=${ABUILD_CONF:-"$sysconfdir/abuild.conf"}
Natanael Copa's avatar
Natanael Copa committed
[ -f "$ABUILD_CONF" ] && . "$ABUILD_CONF"

Natanael Copa's avatar
Natanael Copa committed
	NORMAL="\033[1;0m"
	STRONG="\033[1;1m"
	RED="\033[1;31m"
	GREEN="\033[1;32m"
	YELLOW="\033[1;33m"
	BLUE="\033[1;34m"
}

monochrome() {
	NORMAL=""
	STRONG=""
	RED=""
	GREEN=""
	YELLOW=""
	BLUE=""
}

#colors
if [ -n "$USE_COLORS" ]; then
    default_colors
fi

# run optional log command for remote logging
logcmd() {
	${ABUILD_LOG_CMD:-true} "$@"
	return 0
}
Natanael Copa's avatar
Natanael Copa committed

# functions
msg() {
	[ -n "$quiet" ] && return 0
Natanael Copa's avatar
Natanael Copa committed
	local prompt="$GREEN>>>${NORMAL}"
	local fake="${FAKEROOTKEY:+${BLUE}*${NORMAL}}"
	local name="${STRONG}${subpkgname:-$pkgname}${NORMAL}"
	printf "${prompt} ${name}${fake}: %s\n" "$1" >&2
}

msg2() {
	[ -n "$quiet" ] && return 0
	#      ">>> %s"
	printf "    %s\n" "$1" >&2
Natanael Copa's avatar
Natanael Copa committed
}

warning() {
	local prompt="${YELLOW}>>> WARNING:${NORMAL}"
	local fake="${FAKEROOTKEY:+${BLUE}*${NORMAL}}"
	local name="${STRONG}${subpkgname:-$pkgname}${NORMAL}"
	printf "${prompt} ${name}${fake}: %s\n" "$1" >&2
}

warning2() {
	printf "             %s\n" "$1" >&2
Natanael Copa's avatar
Natanael Copa committed
}

error() {
	local prompt="${RED}>>> ERROR:${NORMAL}"
	local fake="${FAKEROOTKEY:+${BLUE}*${NORMAL}}"
	local name="${STRONG}${subpkgname:-$pkgname}${NORMAL}"
	printf "${prompt} ${name}${fake}: %s\n" "$1" >&2
	logcmd "ERROR: $pkgname: $1"
	printf "           %s\n" "$1" >&2
Linux User's avatar
Linux User committed
set_xterm_title() {
	if [ "$TERM" = xterm ] && [ -n "$USE_COLORS" ]; then
		 printf "\033]0;$1\007" >&2
Linux User's avatar
Linux User committed
	fi
Linux User's avatar
Linux User committed

cleanup() {
Linux User's avatar
Linux User committed
	set_xterm_title ""
	if [ -n "$CLEANUP_FILES" ]; then
		rm -f $CLEANUP_FILES
	fi
	for i; do
		case $i in
		pkgdir) msg "Cleaning up pkgdir"; rm -rf "$pkgbasedir";;
		srcdir) msg "Cleaning up srcdir"; rm -rf "$srcdir";;
		deps)
			if [ -z "$install_after" ] && [ -n "$uninstall_after" ]; then
				msg "Uninstalling dependencies..."
				$SUDO_APK del --quiet $apk_opt_wait $uninstall_after
				[ "$CBUILD" != "$CHOST" -a -n "$CBUILDROOT" ] && \
					$SUDO_APK del --root "$CBUILDROOT" --quiet $apk_opt_wait $uninstall_after
Natanael Copa's avatar
Natanael Copa committed
die() {
Linux User's avatar
Linux User committed
	error "$@"
	cleanup $ERROR_CLEANUP
Natanael Copa's avatar
Natanael Copa committed
	exit 1
}

spell_error() {
	die "APKBUILD contains '$1'. It should be '$2'"
}

# check if apkbuild is basicly sane
default_sanitycheck() {
	local i= j= suggestion=
	msg "Checking sanity of $APKBUILD..."
	[ -z "$pkgname" ] && die "Missing pkgname in APKBUILD"
	[ -z "${pkgname##* *}" ] && die "pkgname contains spaces"
	[ -z "$pkgver" ] && die "Missing pkgver in APKBUILD"
	if [ "$pkgver" != "volatile" ] && [ -z "$nodeps" ]; then
		$APK version --check --quiet "$pkgver" ||\
			die "$pkgver is not a valid version"
	fi
	[ -z "$pkgrel" ] && die "Missing pkgrel in APKBUILD"
	[ -z "$pkgdesc" ] && die "Missing pkgdesc in APKBUILD"
	[ -z "$url" ] && die "Missing url in APKBUILD"
	[ -z "$license" ] && die "Missing license in APKBULID"
	if [ $(echo "$pkgdesc" | wc -c) -gt 128 ]; then
		die "pkgdesc is too long"
	fi
	is_function package || warning "Missing package() function in APKBUILD"
	if [ -n "$replaces_priority" ] \
		&& ! echo $replaces_priority | egrep -q '^[0-9]+$'; then
		die "replaces_priority must be a number"
	fi
	# check so no package names starts with -
	for i in $pkgname $subpackages; do
		case $i in
		-*) die "${i%:*} is not a valid package name";;
		esac
	done

	# check if CARCH, CBUILD, CHOST and CTARGET is set
	[ -z "$CHOST" ] && die "Please set CHOST in /etc/abuild.conf"

	if [ -z "$CARCH" ]; then
Natanael Copa's avatar
Natanael Copa committed
		die "Please fix CHOST, or set CARCH in abuild.conf"
	for i in $install; do
		local n=${i%.*}
		local suff=${i##*.}
		case "$suff" in
		pre-install|post-install|pre-upgrade|post-upgrade|pre-deinstall|post-deinstall);;
		*) die "$i: unknown install script suffix"
		esac
		if ! subpackages_has "$n" && [ "$n" != "$pkgname" ]; then
			die "$i: install script does not match pkgname or any subpackage"
		[ -e "$startdir/$i" ] || die "install script $i is missing"
		for j in chown chmod chgrp; do
			if grep -q $j "$startdir"/$i; then
				warning "$i: found $j"
				warning2 "Permissions should be fixed in APKBUILD package()"
			fi
		done
	done
	for i in $triggers; do
		local f=${i%=*}
		local p=${f%.trigger}
		[ "$f" = "$i" ] && die "$f: triggers must contain '='"
		[ "$p" = "$f" ] && die "$f: triggers scripts must have .trigger suffix"
Loading
Loading full blame...