Luna/ports/add-port.sh

97 lines
1.7 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
set -e
cd $(dirname $0)/..
source tools/env.sh
cd ports
export DESTDIR=${DESTDIR:-"$LUNA_ROOT/initrd"}
export listdir=$PWD
if [ -z $1 ]
then
echo "Usage: add-port.sh <port-name>"
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
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."