Skip to content
Snippets Groups Projects
abuild.in 26.8 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=@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"}
APK=${APK:-apk}
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() {
	local prompt="$GREEN>>>${NORMAL}"
	local fake="${FAKEROOTKEY:+${BLUE}*${NORMAL}}"
	local name="${STRONG}${subpkgname:-$pkgname}${NORMAL}"
	[ -z "$quiet" ] && printf "${prompt} ${name}${fake}: $@\n" >&2
}

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

error() {
	local prompt="${RED}>>> ERROR:${NORMAL}"
	local fake="${FAKEROOTKEY:+${BLUE}*${NORMAL}}"
	local name="${STRONG}${subpkgname:-$pkgname}${NORMAL}"
	printf "${prompt} ${name}${fake}: $@\n" >&2
}
Linux User's avatar
Linux User committed
set_xterm_title() {
	if [ "$TERM" = xterm ]; 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
		$SUDO $APK del $uninstall_after
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
sanitycheck() {
	local i
	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"

	for i in $install; do
		[ -e "$startdir/$i" ] || die "install script $startdir/$i is missing"
	done
	
	[ -n "${triggers%%:*}" ] && [ ! -e "$startdir"/${triggers%%:*} ] \
		&& die "trigger script $startdir/${triggers%%:*} is missing"

	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 || die "wget must be in makedepends when source has https://" ;;
			esac
	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"
	# common spelling errors
	[ -n "$depend" ] && die "APKBUILD contains 'depend'. It should be depends"
	[ -n "$makedepend" ] && die "APKBUILD contains 'makedepend'. It should be makedepends"

	grep '^# Maintainer:' $APKBUILD >/dev/null || warning "No maintainer"

	makedepends_has 'g++' && warning "g++ should not be in makedepends"
	local dummy f
	if [ -z "$source" ]; then
		return 0
	fi
		die "Use 'abuild checksum' to generate/update the checksum(s)"
	if [ "$(echo $source | wc -l)" -ne "$(echo $md5sums | wc -l)" ]; then
		die "Number of md5sums does not correspond to number of sources"
	fi
	fetch || return 1
	msg "Checking md5sums..."
	cd "$srcdir" && echo "$md5sums" | md5sum -c 
Natanael Copa's avatar
Natanael Copa committed
}

uri_fetch() {
	local uri="$1"
	local d="${uri##*/}"	# $(basename $uri)
	local opts
	[ -n "$quiet" ] && opts="-q"
	[ -f "$SRCDEST/$d" ] && return 0

	# we need GNU wget for this
	case "$uri" in
		https://*) opts="--no-check-certificate";;
	esac
	
Natanael Copa's avatar
Natanael Copa committed
	mkdir -p "$SRCDEST"
	if [ -f "$SRCDEST/$d.part" ]; then
		msg "Partial download found. Trying to resume"
		opts="$opts -c"
Natanael Copa's avatar
Natanael Copa committed
	fi
Linux User's avatar
Linux User committed
	msg "Fetching $uri"
	wget $opts -O "$SRCDEST/$d.part" "$uri" \
		&& mv "$SRCDEST/$d.part" "$SRCDEST/$d"
Natanael Copa's avatar
Natanael Copa committed
}

		http://*|ftp://*|https://*)
# try download from file from mirror first
uri_fetch_mirror() {
	local uri="$1"
	local d="${uri##*/}"	# $(basename $uri)
	if [ -n "$DISTFILES_MIRROR" ]; then
		if is_remote "$DISTFILES_MIRROR"; then
			uri_fetch "$DISTFILES_MIRROR"/$d && return 0
		else
Loading
Loading full blame...