Luna/ports/add-port.sh

140 lines
2.6 KiB
Bash
Executable File

#!/usr/bin/env bash
set -e
cd $(dirname $0)/..
unset LUNA_BASE
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 <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
if ! [ -z ${pkgdeps+x} ]
then
echo "Installing dependencies of $pkgname..."
for pkg in ${pkgdeps[@]}
do
set +e
grep $pkg ports.list >/dev/null
if [ "$?" = "0" ]
then
echo "Dependency $pkg is already installed."
else
echo "Installing dependency $pkg..."
./add-port.sh $pkg
fi
set -e
done
fi
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
set +e
command -v port_unpack >/dev/null
set -e
if [ "$?" = "0" ]
then
echo "Unpacking $pkgname version $pkgver..."
port_unpack | filter-lines $pkgname "unpack"
fi
set +e
command -v port_patch >/dev/null
set -e
if [ "$?" = "0" ]
then
echo "Patching $pkgname version $pkgver..."
port_patch | filter-lines $pkgname "patch"
fi
fi
cd $workdir
mkdir -p $builddir
cd $builddir
set +e
command -v port_configure >/dev/null
set -e
if [ "$?" = "0" ]
then
echo "Configuring $pkgname version $pkgver..."
port_configure | filter-lines $pkgname "configure"
fi
echo "Making $pkgname version $pkgver..."
port_build | filter-lines $pkgname "build" # this one is required
cd $workdir
mkdir -p $installdir
cd $installdir
echo "Installing $pkgname version $pkgver..."
port_install | filter-lines $pkgname "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