#!/usr/bin/env bash set -e cd $(dirname $0)/.. source tools/env.sh cd ports unset pkgname unset pkgver unset pkgurl unset pkgmode unset setupdir unset builddir unset installdir unset srcdir unset port_unpack unset port_patch unset port_configure unset port_build unset port_install unset port_uninstall export DESTDIR=${DESTDIR:-"$LUNA_ROOT/initrd"} export listdir=$PWD if [ -z $1 ] then echo "Usage: add-port.sh " exit 1 fi if [ -d $1 ] then pkgscript=$1/package.sh elif [ -f $1 ] then pkgscript=$1 else echo "Unrecognized argument: $1" exit 1 fi export portdir=$(realpath $(dirname $pkgscript)) export workdir=$portdir/workdir mkdir -p $workdir source $pkgscript echo "Building $pkgname version $pkgver..." cd $workdir if ! [ -d $srcdir ] then mkdir -p $setupdir cd $setupdir echo "Downloading $pkgname version $pkgver..." case $pkgmode in "web") wget $pkgurl;; "git") git clone $pkgurl;; *) echo "Don't know how to download package mode '$pkgmode'"; exit 1;; esac command -v port_unpack >/dev/null if [ "$?" = "0" ] then echo "Unpacking $pkgname version $pkgver..." port_unpack fi command -v port_patch >/dev/null if [ "$?" = "0" ] then echo "Patching $pkgname version $pkgver..." port_patch fi fi cd $workdir mkdir -p $builddir cd $builddir command -v port_configure >/dev/null if [ "$?" = "0" ] then echo "Configuring $pkgname version $pkgver..." port_configure fi echo "Making $pkgname version $pkgver..." port_build # this one is required cd $workdir mkdir -p $installdir cd $installdir echo "Installing $pkgname version $pkgver..." port_install if ! [ "$SKIP_ADD_TO_PORTS_LIST" = "1" ] then echo "$pkgname" >> $listdir/ports.list cat $listdir/ports.list | sort | uniq | tee $listdir/ports.list >/dev/null # avoid duplicates echo "Success! Registered port: $pkgname version $pkgver." fi