#!/bin/bash
#
#
# pkgdir
#
# The MIT License (MIT)
#
# Copyright (c) 2014 Fred. Galusik <alienus at nutyx dot org>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
PKGDIR_VERSION=0.2
#
# ex: pkgdir -p plop@0.1
# make a plop@0.1 dir with a Pkgfile perl template and a info template
#
print_help()
{
echo "Usage: pkgdir [options] Dir"
echo "Options:"
echo " -d, --default Install default Pkgfile & info in Dir"
echo " -k, --kde Install kde Pkgfile & info in Dir"
echo " -p, --perl Install perl Pkgfile & info in Dir"
echo " -py, --python Install python Pkgfile & info in Dir"
echo " -w, --waf Install waf Pkgfile & info in Dir"
echo " -v, --version Print pkgdir version and exit"
echo " -h, --help Print this help and exit"
exit 0
}
die()
{
echo "$@"
exit 1
}
# check dir name scheme : name@version and make it
check_dir()
{
IFS="@"
set -- $DIR
if [ "${#@}" -ne 2 ]; then
die "Please, write dir name like that: name@version, aborting..."
fi
PKGNAME="$1"
PKGVERSION="$2"
# mkdir
PORT="${PKGNAME}@${PKGVERSION}"
mkdir -p $PKGNAME\@$PKGVERSION
echo "$PORT created"
}
# basic default template
pkg_default()
{
cat > $PKGNAME\@$PKGVERSION/Pkgfile << EOF
source=()
build(){
cd \$name-\$version
make
make DESTDIR=\$PKG install
}
# NuTyX Pkgfile (http://nutyx.org)
EOF
echo "$PORT/Pkgfile default created"
}
# python template
pkg_python()
{
cat > $PKGNAME\@$PKGVERSION/Pkgfile << EOF
source=()
build() {
cd \$name-\$version
python2 setup.py install --prefix=/usr --root=\$PKG
}
# NuTyX Pkgfile (http://nutyx.org)
EOF
echo "$PORT/Pkgfile python created"
}
# perl template
pkg_perl()
{
cat > $PKGNAME\@$PKGVERSION/Pkgfile << EOF
source=()
build() {
cd \$name-\$version
perl Makefile.PL
make OPTIMIZE="\$CFLAGS" || exit 1
make install INSTALLDIRS=vendor DESTDIR=\$PKG || exit 1
# Remove perllocal.pod and .packlist if present in the package
for i in perllocal.pod .packlist; do
find \$PKG -name "\$i" -exec rm -rf {} \;
done
}
# NuTyX Pkgfile (http://nutyx.org)
EOF
echo "$PORT/Pkgfile perl created"
}
# waf template
pkg_waf()
{
cat > $PKGNAME\@$PKGVERSION/Pkgfile << EOF
source=()
build() {
cd \$name-\$version
./waf configure --prefix=/usr
./waf build
./waf install --destdir=\$PKG
}
# NuTyX Pkgfile (http://nutyx.org)
EOF
echo "$PORT/Pkgfile waf created"
}
# kde template
pkg_kde()
{
cat > $PKGNAME\@$PKGVERSION/Pkgfile << EOF
source=()
build() {
cd \${_name}-\$version
mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX=\$KDE_PREFIX \
-DCMAKE_BUILD_TYPE=Release \
-Wno-dev .. \
make
make DESTDIR=\$PKG install
}
# NuTyX Pkgfile (http://nutyx.org)
EOF
echo "$PORT/Pkgfile kde created"
}
#
# info template
#
pkg_info()
{
cat > $PKGNAME\@$PKGVERSION/$PKGNAME.info << EOF
blabla
URL:
Packager:
x at nutyx dot org
# NuTyX package info file (http://nutyx.org)
EOF
echo "$PORT/$PKGNAME.info created"
}
#
# parse the packager options
#
parse_options()
{
if [ $# -ge 1 ]; then
case $1 in
-d|--default)
DIR=$2
DEFAULT=YES ;;
-k|--kde)
DIR=$2
KDE=YES ;;
-p|--perl)
DIR=$2
PERL=YES ;;
-py|--python)
DIR=$2
PYTHON=YES ;;
-w|--waf)
DIR=$2
WAF=YES ;;
-v|--version)
VERSION=YES ;;
-h|--help)
HELP=YES ;;
*)
die "Invalid option, see pkgdir --help, aborting!" ;;
esac
else
die "Invalid option, see pkgdir --help, aborting!"
fi
}
#
# main function
#
main()
{
parse_options "$@"
if [ $DEFAULT ]; then
check_dir
pkg_default
pkg_info
elif [ $KDE ]; then
check_dir
pkg_kde
pkg_info
elif [ $PERL ]; then
check_dir
pkg_perl
pkg_info
elif [ $PYTHON ]; then
check_dir
pkg_python
pkg_info
elif [ $WAF ]; then
check_dir
pkg_waf
pkg_info
elif [ $VERSION ]; then
die "pkgdir $PKGDIR_VERSION"
elif [ $HELP ]; then
print_help
else
die "Wrong option, see pkgdir --help !"
fi
}
main "$@"