~fredg/NuTyX

ref: 2a229235668327987428490abfdb0847194dde32 NuTyX/pkgdir.sh -rwxr-xr-x 3.3 KiB
2a229235 — alienus tain de redirection ambigüe 8 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#!/bin/bash

# 
# pkgdir
#
# script to make NuTyX packager life easier ;)
#
# LICENSE: MIT
#


VERSION=0.1

print_help()
{
    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
}

die()
{
    echo "$@"
    exit 1
}

# check dir name scheme : name@version
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 $PORT
    echo "$PORT created"
}

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

build(){
    cd $name-$version
    make
    make DESTDIR=$PKG install    
}



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

    echo "$PORT/Pkgfile created"
}

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

build() {
    cd $name-$version
    python2 setup.py install --prefix=/usr --root=$PKG
}



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

    echo "$PORT/Pkgfile created"
}

pkg_perl()
{
    cat > $PORT/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 created"
}

pkg_waf()
{
    cat > $PORT/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 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 "$@"