2013-07-10 18:31:13 +02:00
|
|
|
################################################################################
|
|
|
|
|
|
|
|
srcdir=src
|
2013-09-10 20:00:31 +02:00
|
|
|
pkgdir=pkg/$pkgname
|
2013-09-11 13:13:37 +02:00
|
|
|
arch="$(uname -m)"
|
2013-07-10 18:31:13 +02:00
|
|
|
|
|
|
|
DLAGENTS=('ftp::/usr/bin/curl -fC - --ftp-pasv --retry 3 --retry-delay 3 -o %o %u'
|
|
|
|
'http::/usr/bin/curl -fLC - --retry 3 --retry-delay 3 -o %o %u'
|
|
|
|
'https::/usr/bin/curl -fLC - --retry 3 --retry-delay 3 -o %o %u'
|
|
|
|
'rsync::/usr/bin/rsync -z %u %o'
|
|
|
|
'scp::/usr/bin/scp -C %u %o')
|
|
|
|
|
|
|
|
INDENT=' '
|
|
|
|
msg ()
|
|
|
|
{
|
|
|
|
echo "$(tput bold)$(tput setf 2)==>$(tput setf 7) $1"
|
|
|
|
shift 1
|
|
|
|
for i; do
|
|
|
|
echo "${INDENT}$i"
|
|
|
|
done
|
|
|
|
echo -n "$(tput sgr0)"
|
|
|
|
}
|
|
|
|
|
|
|
|
msg2 ()
|
|
|
|
{
|
|
|
|
echo "$(tput bold)$(tput setf 1) ->$(tput setf 7) $1"
|
|
|
|
shift 1
|
|
|
|
for i; do
|
|
|
|
echo "${INDENT}$i"
|
|
|
|
done
|
|
|
|
echo -n "$(tput sgr0)"
|
|
|
|
}
|
|
|
|
|
|
|
|
warning ()
|
|
|
|
{
|
|
|
|
echo "$(tput bold)$(tput setf 6)==> WARNING:$(tput setf 7) $1"
|
|
|
|
shift 1
|
|
|
|
for i; do
|
|
|
|
echo "${INDENT}$i"
|
|
|
|
done
|
|
|
|
echo -n "$(tput sgr0)"
|
|
|
|
}
|
|
|
|
|
|
|
|
error ()
|
|
|
|
{
|
|
|
|
echo "$(tput bold)$(tput setf 4)==> ERROR:$(tput setf 7) $1"
|
|
|
|
shift 1
|
|
|
|
for i; do
|
|
|
|
echo "${INDENT}$i"
|
|
|
|
done
|
|
|
|
echo -n "$(tput sgr0)"
|
|
|
|
}
|
|
|
|
|
|
|
|
_init()
|
|
|
|
{
|
2013-09-10 20:00:31 +02:00
|
|
|
mkdir -p "$srcdir"
|
|
|
|
mkdir -p "$pkgdir"
|
2013-07-10 18:31:13 +02:00
|
|
|
|
|
|
|
srcdir="$(realpath "$srcdir")"
|
|
|
|
pkgdir="$(realpath "$pkgdir")"
|
|
|
|
}
|
|
|
|
|
|
|
|
_listdeps()
|
|
|
|
{
|
|
|
|
msg "$pkgname $pkgver-$pkgrel"
|
2013-09-10 18:51:47 +02:00
|
|
|
msg2 "Runtime dependencies"
|
2013-07-10 18:31:13 +02:00
|
|
|
printf -- '%s\n' "${depends[@]}"
|
2013-09-10 18:51:47 +02:00
|
|
|
msg2 "Buildtime dependencies"
|
2013-07-10 18:31:13 +02:00
|
|
|
printf -- '%s\n' "${makedepends[@]}"
|
2013-09-10 18:51:47 +02:00
|
|
|
msg2 "Optional dependencies"
|
2013-07-10 18:31:13 +02:00
|
|
|
printf -- '%s\n' "${optdepends[@]}"
|
|
|
|
}
|
|
|
|
|
|
|
|
_fetch()
|
|
|
|
{
|
|
|
|
msg "Retrieving sources..."
|
|
|
|
|
2013-08-26 14:09:56 +02:00
|
|
|
for URI in "${source[@]}"; do
|
2013-09-10 15:02:14 +02:00
|
|
|
case "$URI" in
|
|
|
|
http://*|https://*|ftp://*)
|
|
|
|
FILE="${URI##*/}"
|
|
|
|
|
|
|
|
## TODO: add support for DLAGENT
|
|
|
|
msg2 "Downloading $FILE..."
|
2013-09-11 13:13:37 +02:00
|
|
|
wget $OPT_FORCE_WGET "$URI" -O "$FILE"
|
2013-09-10 15:02:14 +02:00
|
|
|
|
|
|
|
## Strangely enough, wget will not return 0 on success. On error, it
|
|
|
|
## will still create a 0-byte file.
|
|
|
|
if [ $(du -sb "$FILE" | awk '{print $1}') -eq 0 ]; then
|
|
|
|
error "Failure while downloading $FILE" "Aborting..."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
git+*)
|
|
|
|
GITURI="${URI#git+}"
|
2013-09-10 18:51:47 +02:00
|
|
|
if [ -d "${_gitname:-$FILE}/.git" ]; then
|
2013-09-11 13:13:37 +02:00
|
|
|
if ! $OPT_NOCLOBBER; then
|
|
|
|
cd "${_gitname:-$FILE}"
|
|
|
|
git pull
|
|
|
|
fi
|
2013-09-10 15:02:14 +02:00
|
|
|
else
|
|
|
|
git clone "$GITURI"
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
*)
|
2013-09-10 18:51:47 +02:00
|
|
|
## Embedded files (patches, resources...)
|
|
|
|
# Do nothing.
|
2013-09-10 15:02:14 +02:00
|
|
|
esac
|
2013-07-10 18:31:13 +02:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
_checksum ()
|
|
|
|
{
|
|
|
|
if $OPT_CHECKSKIP; then
|
|
|
|
warning "Skipping verification of source file checksums."
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
RESULT=true
|
|
|
|
|
|
|
|
case ${#source[*]} in
|
|
|
|
${#md5sums[*]})
|
|
|
|
CHECKSUMMER=md5sum;;
|
|
|
|
${#sha1sums[*]})
|
|
|
|
CHECKSUMMER=sha1sum;;
|
|
|
|
${#sha256sums[*]})
|
|
|
|
CHECKSUMMER=sha256sum;;
|
|
|
|
${#sha384sums[*]})
|
|
|
|
CHECKSUMMER=sha384sum;;
|
|
|
|
${#sha512sums[*]})
|
|
|
|
CHECKSUMMER=sha512sum;;
|
|
|
|
*)
|
|
|
|
error "Integrity checks are either missing or differ in size."
|
|
|
|
exit 1;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
msg "Validating source files with ${CHECKSUMMER}s..."
|
|
|
|
|
2013-07-11 21:25:10 +02:00
|
|
|
## Here we need to use a numeric index to browse arrays to make sure we get
|
|
|
|
## same index for both arrays.
|
|
|
|
## WARNING: this will only work in bash because indexing start at 0.
|
|
|
|
for i in $(seq 0 $((${#source[@]} -1))); do
|
2013-09-10 15:02:14 +02:00
|
|
|
|
|
|
|
eval test '${'${CHECKSUMMER}'s[$i]}' = 'SKIP'
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
echo "Skipped"
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
2013-07-10 18:31:13 +02:00
|
|
|
FILE="${source[$i]##*/}"
|
2013-07-11 21:25:10 +02:00
|
|
|
if [ ! -f "$FILE" ]; then
|
|
|
|
error "$FILE was not found in the build directory and is not a URL."
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
2013-07-10 18:31:13 +02:00
|
|
|
CHECKSUM="$($CHECKSUMMER "$FILE" | cut -f1 -d' ')"
|
|
|
|
|
|
|
|
echo -n "$INDENT$FILE ... "
|
|
|
|
|
|
|
|
## Note: here we take care to control expansion at the right time.
|
|
|
|
eval test '$CHECKSUM' = '${'${CHECKSUMMER}'s[$i]}'
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
echo "Passed"
|
|
|
|
else
|
2013-09-10 15:02:14 +02:00
|
|
|
echo "FAILED"
|
|
|
|
RESULT=false
|
2013-07-10 18:31:13 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
done
|
|
|
|
|
|
|
|
if ! $RESULT; then
|
|
|
|
error "One or more files did not pass the validity check!"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
_extract ()
|
|
|
|
{
|
|
|
|
msg "Extracting sources..."
|
2013-09-10 15:02:14 +02:00
|
|
|
for URI in "${source[@]}"; do
|
|
|
|
FILE="${URI##*/}"
|
2013-07-10 18:31:13 +02:00
|
|
|
case "$FILE" in
|
2013-09-11 13:13:37 +02:00
|
|
|
*.tar.bz2|*.tbz2|*.tar.gz|*.tgz|*.tar.xz|*.txz)
|
2013-07-10 18:31:13 +02:00
|
|
|
msg2 "Extracting $FILE with tar"
|
2013-09-11 13:13:37 +02:00
|
|
|
tar xf "$FILE" -C "$srcdir" $OPT_FORCE_TAR;;
|
2013-07-10 18:31:13 +02:00
|
|
|
*)
|
2013-09-10 15:02:14 +02:00
|
|
|
case "$URI" in
|
|
|
|
git+*)
|
2013-09-10 18:51:47 +02:00
|
|
|
ln -sf "../${_gitname:-$FILE}" "$srcdir";;
|
|
|
|
*)
|
|
|
|
ln -sf "../$FILE" "$srcdir";;
|
2013-09-10 15:02:14 +02:00
|
|
|
esac
|
2013-07-10 18:31:13 +02:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
_buildhook()
|
|
|
|
{
|
|
|
|
msg "Starting build()..."
|
|
|
|
(cd "$srcdir" && build)
|
|
|
|
}
|
|
|
|
|
2013-07-11 21:25:10 +02:00
|
|
|
_tidying ()
|
2013-07-10 18:31:13 +02:00
|
|
|
{
|
2013-07-11 21:25:10 +02:00
|
|
|
for i in "${options[@]}"; do
|
|
|
|
if [ "$(echo $i | sed 's/\(.\).*/\1/')" = "!" ]; then
|
|
|
|
eval TIDY_$(echo $i | sed 's/^!//')=false
|
|
|
|
else
|
|
|
|
eval TIDY_$i=true
|
|
|
|
fi
|
|
|
|
done
|
2013-07-10 18:31:13 +02:00
|
|
|
|
2013-07-11 21:25:10 +02:00
|
|
|
if $TIDY_purge; then
|
|
|
|
msg2 "Purging unwanted files..."
|
|
|
|
find * -type f \( -name '.packlist' -o -name '*.pod' \) -delete
|
|
|
|
rm -f "usr/share/info/dir" "usr/info/dir"
|
|
|
|
fi
|
|
|
|
if $TIDY_docs; then
|
|
|
|
msg2 "Compressing man and info pages..."
|
|
|
|
find * -type f -name '*.[0-9]' -exec gzip {} \;
|
|
|
|
fi
|
|
|
|
if $TIDY_strip; then
|
|
|
|
msg2 "Stripping unneeded symbols from binaries and libraries..."
|
2013-09-10 18:51:47 +02:00
|
|
|
find * -type f -executable -exec strip -s {} \; 2>/dev/null
|
2013-07-11 21:25:10 +02:00
|
|
|
fi
|
2013-07-11 21:26:31 +02:00
|
|
|
|
|
|
|
## We make sure folder permissions are world accessible.
|
|
|
|
find * -type d -exec chmod o+rx {} \;
|
2013-07-10 18:31:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
_compress()
|
|
|
|
{
|
|
|
|
msg "Creating package \"$pkgname\"..."
|
|
|
|
|
|
|
|
UNINS="$pkgname-$pkgver-$pkgrel-uninstall.sh"
|
|
|
|
msg2 "Generating $UNINS..."
|
|
|
|
echo '#!/bin/sh' > "$UNINS"
|
|
|
|
(cd "$pkgdir" && \
|
2013-09-10 20:00:31 +02:00
|
|
|
find * -type f -exec echo "rm /"{} \; && \
|
|
|
|
find * -type d -exec echo "rmdir /"{} \;
|
|
|
|
) >> "$UNINS"
|
2013-07-10 18:31:13 +02:00
|
|
|
chmod +x "$UNINS"
|
|
|
|
|
|
|
|
msg2 "Compressing package..."
|
2013-09-11 13:13:37 +02:00
|
|
|
if [ "$(uname)" = "Linux" ]; then
|
|
|
|
ls "$pkgdir" | tar --numeric-owner --owner=root --group=root \
|
|
|
|
-C "$pkgdir" -cJf "$pkgname-$pkgver-$pkgrel-$arch.tar.xz" -T -
|
|
|
|
else
|
|
|
|
## BSD and others. WARNING: this may not be portable.
|
|
|
|
ls "$pkgdir" | tar --numeric-owner --uid 0 --gid 0 \
|
|
|
|
-C "$pkgdir" -cJf "$pkgname-$pkgver-$pkgrel-$arch.tar.xz" -T -
|
|
|
|
fi
|
2013-07-10 18:31:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
_packagehook()
|
|
|
|
{
|
|
|
|
if $OPT_NOCLOBBER && [ $(ls -a1 "$pkgdir" | wc -l) -ne 2 ]; then
|
2013-09-11 13:13:37 +02:00
|
|
|
warning "A package has already been built. Skipping. (Use -f to overwrite.)"
|
|
|
|
return
|
2013-07-10 18:31:13 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
rm -rf "$pkgdir"
|
|
|
|
|
|
|
|
msg "Starting package()..."
|
|
|
|
(cd "$srcdir" && package)
|
2013-07-11 21:25:10 +02:00
|
|
|
|
|
|
|
msg "Tidying install..."
|
2013-07-11 21:26:31 +02:00
|
|
|
(cd "$pkgdir" && umask 022 && _tidying)
|
2013-07-11 21:25:10 +02:00
|
|
|
|
2013-07-10 18:31:13 +02:00
|
|
|
_compress
|
|
|
|
}
|
|
|
|
|
|
|
|
_clean ()
|
|
|
|
{
|
|
|
|
msg "Cleaning up..."
|
|
|
|
rm -r "$srcdir" "$pkgdir"
|
|
|
|
}
|
|
|
|
|
|
|
|
_install()
|
|
|
|
{
|
|
|
|
msg "Installing package $pkgname..."
|
2013-09-11 13:13:37 +02:00
|
|
|
## Only use sudo if user has write permission to DESTROOT.
|
|
|
|
if [ -w "$OPT_DESTROOT" ]; then
|
|
|
|
tar -xkf "$pkgname-$pkgver-$pkgrel-$arch.tar.xz" -C "$OPT_DESTROOT"
|
|
|
|
else
|
|
|
|
sudo tar -xkf "$pkgname-$pkgver-$pkgrel-$arch.tar.xz" -C "$OPT_DESTROOT"
|
|
|
|
fi
|
2013-07-10 18:31:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
_printhelp ()
|
|
|
|
{
|
2013-09-10 20:00:31 +02:00
|
|
|
cat <<EOF
|
2013-07-10 18:31:13 +02:00
|
|
|
Usage: ${1##*/} [OPTIONS]
|
|
|
|
|
2013-09-10 20:00:31 +02:00
|
|
|
Port build script for $pkgname $pkgver.
|
2013-07-10 18:31:13 +02:00
|
|
|
|
|
|
|
This script can perform multiple operations:
|
2013-09-10 20:00:31 +02:00
|
|
|
- Fetch source code.
|
|
|
|
- Build.
|
|
|
|
- Create package.
|
|
|
|
- Install package.
|
|
|
|
- Clean folder from build data.
|
|
|
|
|
|
|
|
Default operation is to fetch source code if required. Most operations only
|
|
|
|
proceed if required (i.e. if run for the first time). Building, packaging and
|
|
|
|
installing are hierarchical operation, e.g. if only packaging is requested and
|
|
|
|
package was never built, the building will be processed automatically.
|
2013-07-10 18:31:13 +02:00
|
|
|
|
|
|
|
Options:
|
|
|
|
|
2013-09-11 13:13:37 +02:00
|
|
|
-b: Build.
|
|
|
|
-c: Clean source folders from temp file (keep upstream source and built package).
|
|
|
|
-d: List dependencies and exit.
|
|
|
|
-f: Force operation (overwrite, rebuild, reinstall).
|
|
|
|
-h: Display this help.
|
|
|
|
-i: Install package.
|
|
|
|
-r ROOT: Specifiy ROOT folder where to install the package.
|
|
|
|
-R: Create package.
|
|
|
|
-s: Skip integrity checks.
|
2013-07-10 18:31:13 +02:00
|
|
|
|
2013-09-10 20:00:31 +02:00
|
|
|
EOF
|
2013-07-10 18:31:13 +02:00
|
|
|
}
|
|
|
|
|
2013-09-11 13:13:37 +02:00
|
|
|
OPT_DESTROOT="$HOME/.local"
|
|
|
|
OPT_FORCE_WGET="-nc"
|
|
|
|
OPT_FORCE_TAR="-k"
|
2013-07-10 18:31:13 +02:00
|
|
|
OPT_NOCLOBBER=true
|
|
|
|
|
|
|
|
OPT_BUILD=false
|
|
|
|
OPT_PACKAGE=false
|
|
|
|
OPT_INSTALL=false
|
|
|
|
OPT_CLEAN=false
|
|
|
|
OPT_CHECKSKIP=false
|
|
|
|
|
2013-07-11 21:25:10 +02:00
|
|
|
#-- strip: Strip symbols from binaries/libraries
|
|
|
|
#-- docs: Save doc directories specified by DOC_DIRS
|
|
|
|
#-- libtool: Leave libtool (.la) files in packages
|
|
|
|
#-- emptydirs: Leave empty directories in packages
|
|
|
|
#-- zipman: Compress manual (man and info) pages in MAN_DIRS with gzip
|
|
|
|
#-- purge: Remove files specified by PURGE_TARGETS
|
|
|
|
#-- upx: Compress binary executable files using UPX
|
|
|
|
TIDY_strip=true
|
|
|
|
TIDY_docs=true
|
|
|
|
TIDY_libtool=true
|
|
|
|
TIDY_emptydirs=true
|
|
|
|
TIDY_zipman=true
|
|
|
|
TIDY_purge=true
|
|
|
|
TIDY_upx=false
|
|
|
|
|
2013-09-11 13:13:37 +02:00
|
|
|
while getopts ":bcdfhirRs" opt; do
|
2013-07-10 18:31:13 +02:00
|
|
|
case $opt in
|
|
|
|
b)
|
|
|
|
OPT_BUILD=true ;;
|
|
|
|
c)
|
|
|
|
OPT_CLEAN=true ;;
|
|
|
|
d)
|
|
|
|
_listdeps
|
|
|
|
exit;;
|
|
|
|
f)
|
2013-09-11 13:13:37 +02:00
|
|
|
OPT_FORCE_TAR=""
|
|
|
|
OPT_FORCE_WGET=""
|
2013-07-10 18:31:13 +02:00
|
|
|
OPT_NOCLOBBER=false ;;
|
|
|
|
h)
|
|
|
|
_printhelp "$0"
|
|
|
|
exit 1 ;;
|
|
|
|
i)
|
2013-09-10 18:51:47 +02:00
|
|
|
OPT_BUILD=true
|
|
|
|
OPT_PACKAGE=true
|
2013-07-10 18:31:13 +02:00
|
|
|
OPT_INSTALL=true ;;
|
2013-09-11 13:13:37 +02:00
|
|
|
r)
|
|
|
|
OPT_DESTROOT="$OPTARG";;
|
2013-07-10 18:31:13 +02:00
|
|
|
R)
|
2013-09-10 18:51:47 +02:00
|
|
|
OPT_BUILD=true
|
2013-07-10 18:31:13 +02:00
|
|
|
OPT_PACKAGE=true ;;
|
|
|
|
s)
|
|
|
|
OPT_CHECKSKIP=true ;;
|
|
|
|
?)
|
|
|
|
_printhelp "$0"
|
|
|
|
exit 1 ;;
|
|
|
|
:)
|
|
|
|
echo "Missing argument."
|
|
|
|
_printhelp "$0"
|
|
|
|
exit 1 ;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift $(($OPTIND - 1))
|
|
|
|
|
|
|
|
msg "Making package: $pkgname $pkgver-$pkgrel ($(date))"
|
|
|
|
|
|
|
|
_init
|
|
|
|
_fetch
|
|
|
|
_extract
|
|
|
|
_checksum
|
|
|
|
|
2013-09-10 18:51:47 +02:00
|
|
|
$OPT_BUILD && _buildhook
|
|
|
|
$OPT_PACKAGE && _packagehook
|
|
|
|
$OPT_INSTALL && _install
|
|
|
|
$OPT_CLEAN && _clean
|
2013-07-10 18:31:13 +02:00
|
|
|
|
2013-07-11 21:25:10 +02:00
|
|
|
msg "Finished making: $pkgname ${pkgver}-$pkgrel ($(date))"
|