Newer
Older
# script to build apk packages (light version of makepkg)
# Copyright (c) 2008 Natanael Copa <natanael.copa@gmail.com>
#
# Distributed under GPL-2
#
# Depends on: busybox utilities, fakeroot,
#
abuild_ver=@VERSION@
sysconfdir=@sysconfdir@
pkgbasedir=${pkgbasedir:-"$startdir/pkg"}
# defaults
SRCDEST=${SRCDEST:-$startdir}
PKGDEST=${PKGDEST:-$startdir}
BUILD_BASE="build-base"
SUDO=${SUDO:-"sudo"}
default_cmds="sanitycheck builddeps clean fetch unpack mkusers rootpkg apkcache"
ABUILD_CONF=${ABUILD_CONF:-"$sysconfdir/abuild.conf"}
datadir=/usr/share/abuild
#colors
if [ -n "$USE_COLORS" ]; then
NORMAL="\033[1;0m"
STRONG="\033[1;1m"
RED="\033[1;31m"
GREEN="\033[1;32m"
YELLOW="\033[1;33m"
BLUE="\033[1;34m"
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
}
if [ -z "$install_after" ] && [ -n "$uninstall_after" ]; then
$SUDO apk del $uninstall_after
# check if apkbuild is basicly sane
sanitycheck() {
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" ]; then
apk version --check -q "$pkgver" ||\
die "$pkgver is not a valid version"
fi
[ -z "$pkgrel" ] && warning "Missing pkgrel in APKBUILD. Using pkgrel=0"
[ -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
done
fi
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"
done
fi
# 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"
return 0
}
md5check() {
if [ -z "$source" ]; then
return 0
fi
if [ -z "$md5sums" ]; then
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
msg "Checking md5sums..."
cd "$srcdir" && echo "$md5sums" | md5sum -c
}
uri_fetch() {
local uri="$1"
local d="${s##*/}" # $(basename $s)
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
if [ -f "$SRCDEST/$d.part" ]; then
msg "Partial download found. Trying to resume"
opts="$opts -c"
wget $opts -O "$SRCDEST/$d.part" "$uri" \
&& mv "$SRCDEST/$d.part" "$SRCDEST/$d"
is_remote() {
case "$1" in
return 0;;
esac
return 1
}
for s in $source; do
if is_remote "$s"; then
uri_fetch "$s" || return 1
ln -sf "$SRCDEST/${s##*/}" "$srcdir"/
else
ln -sf "$startdir/$s" "$srcdir/"
fi
}
# unpack the sources
unpack() {
local u
mkdir -p "$srcdir"
for u in $source; do
local s="$SRCDEST/${u##*/}" # $(basename $s)
case "$s" in
*.tar.lzma)
msg "Unpacking $s..."
unlzma -c "$s" | tar -C "$srcdir" -x \
|| return 1;;
*.zip)
msg "Unpacking $s..."
unzip "$s" -d "$srcdir" || return 1;;
esac
done
}
# cleanup source and package dir
clean() {
msg "Cleaning temporary build dirs..."
}
# cleanup fetched sources
cleancache() {
local s
for s in $source; do
if is_remote "$s"; then
msg "Cleaning downloaded ${s##*/}..."
rm -f "$SRCDEST/${s##*/}"
fi
msg "Cleaning built packages..."
for i in $pkgname $subpackages; do
local p="${i%:*}-$pkgver-r$pkgrel"
rm -f "$PKGDEST/$p.apk" "$PKGDEST/$p.src.tar.gz" \
# remove given packages from index
# clean all packages except current
cleanoldpkg() {
local i j
msg "Cleaning all packages except $pkgver-r$pkgrel..."
for i in $pkgname $subpackages; do
for j in "$PKGDEST"/${i%:*}-[0-9]*.apk; do
[ "$j" != "$PKGDEST/${i%:*}-$pkgver-r$pkgrel.apk" ] \
&& rm -f "$j"
done
done
return 0
}
mkusers() {
local i
for i in $pkgusers; do
if ! getent passwd $i >/dev/null; then
msg "Creating user $i"
$SUDO adduser -D -H $i || return 1
fi
done
for i in $pkggroups; do
if ! getent group $i >/dev/null; then
msg "Creating group $i"
$SUDO addgroup $i || return 1
fi
done
}
[ -n "$DEBUG" ] && msg "$part"
$part || die "$part failed"
}
# override those in your build script
build() {
die "No build() function found in $APKBUILD"
}
get_split_func() {
# get the 'func' from "sub-pkg:func"
local func=${1##*:}
# get 'func' from "sub-pkg-func" if there was no :func
[ "$func" = "$1" ] && func=${func##*-}
echo $func
}
Natanael Copa
committed
prepare_subpackages() {
Loading
Loading full blame...