~fredg/NuTyX

2a229235668327987428490abfdb0847194dde32 — alienus 8 years ago 8258f6b
tain de redirection ambigüe
1 files changed, 125 insertions(+), 14 deletions(-)

M pkgdir.sh -rw-r--r-- => -rwxr-xr-x
M pkgdir.sh => pkgdir.sh +125 -14
@@ 1,27 1,55 @@
#!/bin/bash

DIR=$1
# 
# pkgdir
#
# script to make NuTyX packager life easier ;)
#
# LICENSE: MIT
#

die()

VERSION=0.1

print_help()
{
    echo "$@"
    exit 1
    echo "Usage: pkgdir [options] Dir"
    echo "Options:"
    echo "  -d,    --default        Install default 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
}

# check name@version scheme
check_arg()
die()
{
    [ $DIR == .*@.* ] || die "Please, write name@version, aborting..."
    echo "$@"
    exit 1
}

mkDir()
# check dir name scheme : name@version
check_dir()
{
    mkdir -p -v $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 $PORT
    echo "$PORT created"
}

pkg_simple()
pkg_default()
{
    cat > $DIR/Pkgfile << EOF
    cat > $PORT/Pkgfile << EOF
source=()

build(){


@@ 34,11 62,13 @@ build(){

# NuTyX Pkgfile (http://nutyx.org)
EOF

    echo "$PORT/Pkgfile created"
}

pkg_python()
{
    cat > $DIR/Pkgfile << EOF
    cat > $PORT/Pkgfile << EOF
source=()

build() {


@@ 50,11 80,13 @@ build() {

# NuTyX Pkgfile (http://nutyx.org)
EOF

    echo "$PORT/Pkgfile created"
}

pkg_perl()
{
    cat > $DIR/Pkgfile << EOF
    cat > $PORT/Pkgfile << EOF
source=()

build() {


@@ 73,11 105,13 @@ build() {

# NuTyX Pkgfile (http://nutyx.org)
EOF

    echo "$PORT/Pkgfile created"
}

pkg_waf()
{
    cat > $DIR/Pkgfile << EOF
    cat > $PORT/Pkgfile << EOF
source=()

build() {


@@ 91,5 125,82 @@ build() {

# NuTyX Pkgfile (http://nutyx.org)
EOF

    echo "$PORT/Pkgfile created"
}

pkg_info()
{
    cat > $PORT/$PKGNAME.info << EOF


URL: 

Packager:

at nutyx dot org



# NuTyX package info file (http://nutyx.org)
EOF

echo "$DIR/$PKGNAME.info created"
}

parse_options()
{
    if [ $# -gt 1 ]; then
        case $1 in
            -d|--default)
                DIR=$2
                DEFAULT=1 ;;
            -py|--python)
                DIR=$2
                PYTHON=1 ;;
            -p|--perl)
                DIR=$2
                PERL=1 ;;
            -w|--waf)
                DIR=$2
                WAF=1 ;;
            -v|--version)
                VERSION=1 ;;
            -h|--help)
                HELP=1 ;;
             *)
                 die "Invalid option, see pkgdir --help, aborting!"
         esac
    else
        die "Invalid option, see pkgdir --help, aborting!"
    fi
}

main()
{
    parse_options "$@"

    if [ DEFAULT ]; then
        check_dir
        pkg_default
        pkg_info    
    elif [ PERL ]; then
        check_dir
        pkg_perl
    elif [ PYTHON ]; then
        check_dir
        pkg_python
    elif [ WAF ]; then
        check_dir
        pkg_waf
    elif [ VERSION ]; then
        die "pkgdir $VERSION"
    elif [ HELP ]; then
        print_help
    else
        die "Wrong option, see pkgdir --help !"
    fi    
}

main "$@"