~fredg/NuTyX

ref: 95f2ac59331c7c501c7ff47b1cbac3156a2a70da NuTyX/pkgdir -rwxr-xr-x 4.9 KiB
95f2ac59 — alienus add info and MIT license 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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
#!/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.

#
# LICENSE: MIT
#

PKGDIR_VERSION=0.1

#
# 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 "  -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"
}

#
# 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 ;;
            -py|--python)
                DIR=$2
                PYTHON=YES ;;
            -p|--perl)
                DIR=$2
                PERL=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 [ $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 "$@"