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

# script to 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
#
# Depends on: busybox utilities, fakeroot, 
#

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
Natanael Copa's avatar
Natanael Copa committed
fi	
	

# 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() {
	#      ">>> WARNING: 
	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
}

error2() {
	#      ">>> ERROR: 
	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
} 

cleanup() {
	set_xterm_title ""
	if [ -z "$install_after" ] && [ -n "$uninstall_after" ]; then
		msg "Uninstalling dependencies..."
		$SUDO_APK del --quiet $apk_opt_wait $uninstall_after
	if [ -n "$CLEANUP_FILES" ]; then
		rm -f $CLEANUP_FILES
	fi
Natanael Copa's avatar
Natanael Copa committed
die() {
Linux User's avatar
Linux User committed
	error "$@"
Linux User's avatar
Linux User committed
	cleanup
Natanael Copa's avatar
Natanael Copa committed
	exit 1
}

# 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 -q "$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"

	# 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
	if [ -z "$CARCH" ]; then
		case "$(uname -m)" in
		i[0-9]86) suggestion=" (Suggestion: CARCH=x86)";;
		x86_64) suggestion=" (Suggestion: CARCH=x86_64)";;
		esac
		die "Please set CARCH in /etc/abuild.conf$suggestion"
	fi
	[ -z "$CHOST" ] && die "Please set CHOST in /etc/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
	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"
		if ! subpackages_has "$p" && [ "$p" != "$pkgname" ]; then
			die "$p: trigger script does not match pkgname or any subpackage"
		fi
		[ -e "$startdir"/$f ] || die "trigger script $f is missing"
	done
	if [ -n "$source" ]; then
		for i in $source; do
			if install_has "$i"; then
				warning "You should not have \$install in source"
				continue
			fi
			md5sums_has ${i##*/} || die "${i##*/} is missing in md5sums"
			case "$i" in
				https://*) makedepends_has wget && warning "wget no longer need to be in makedepends when source has https://" ;;
	if [ -n "$md5sums" ]; then
		for i in $(echo "$md5sums" | awk '{ print $2 }'); do
			source_has $i || die "$i exists in md5sums but is missing in source"
Loading
Loading full blame...