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
247
248
249
250
251
252
253
254
255
256
257
|
#!/bin/bash
#
# createpkg: package builder using http://slack.sarava.org/slackbuilds scripts
# feedback: rhatto at riseup.net | gpl
#
# createpkg is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or any later version.
#
# createpkg is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place - Suite 330, Boston, MA 02111-1307, USA
#
# /etc/simplepkg/slackbuildrc parameters:
#
# SLACKBUILDS="/folder/to/place/slackbuilds", defaults to /var/slackbuilds
# SVN="svn://repository", defaults do svn://slack.sarava.org/slackbuilds
# SYNC="yes|no", whether to always update the repository
#
COMMON="/usr/libexec/simplepkg/common.sh"
SLACKBUILDRC="/etc/slackbuildrc"
# firts load simplepkg helper functions
if [ -f "$COMMON" ]; then
source $COMMON
else
echo "error: file $COMMON found, check your `basename $0` installation"
exit 1
fi
function safe_exit {
# this function deals with internal createpkg errors
# and also non-zero exit codes from slackbuilds
# check slackbuild exit status are:
#
# ERROR_WGET=31; ERROR_MAKE=32; ERROR_INSTALL=33
# ERROR_MD5=34; ERROR_CONF=35; ERROR_HELP=36
# ERROR_TAR=37; ERROR_MKPKG=38 ERROR_GPG=?
# ERROR_PATCH=?
# Thanks to Rudson rudsonalves at yahoo.com.br for this spec.
# exit codes
case $1 in
2) usage ;;
3) echo Could not update the repository $2 ;;
4) echo Could not create folder $2 ;;
5) echo Script not found ;;
31) echo Error downloading package ;;
32) echo Error compiling the program ;;
33) echo Error installing program ;;
34) echo Error on source code integrity check ;;
35) echo Error configuring the program ;;
36) exit 0 ;; # its supposed to never happen here :P
37) echo Error decompressing source code ;;
38) echo Error creating the package ;;
*) exit 1
esac
exit $1
}
function build_repo {
# checkout a new slackbuild working copy
BASEDIR="`dirname $SLACKBUILDS`"
mkdir -p $BASEDIR || safe_exit 4 $BASEDIR
cd $BASEDIR
svn checkout $SVN
cd $SLACKBUILDS
}
function usage {
echo "usage: createpkg [--install] package-name"
echo " createpkg --no-deps package-name"
echo " createpkg --search package-name"
echo " createpkg --sync"
}
function check_config {
# check the configuration
if [ -f "$SLACKBUILDRC" ]; then
source $SLACKBUILDRC
fi
TMP=${TMP:=/tmp}
REPOS=${REPOS:=$TMP}
SLACKBUILDS=${SLACKBUILDS:=/var/slackbuilds}
SVN=${SVN:=svn://slack.sarava.org/slackbuilds}
SYNC=${SYNC:=no}
BASEDIR="`dirname $SLACKBUILDS`"
}
function solve_dep {
pack="$1"
cond="$2"
ver="$3"
if [ "$cond" != "equal" ] && [ "$cond" != "less" ] && [ "$cond" != "equalorgreater" ] && [ "$cond" != "lessequal" ] && [ ! -z "$cond" ]; then
# slack-required has a wrong logical sentence, so we ignore it
check_version="no"
fi
for candidate in `ls /var/log/packages/$pack* 2> /dev/null`; do
candidate="`package_name $candidate`"
if [ "$pack" == "$candidate" ]; then
if [ "$check_version" != "no" ]; then
# TODO: check if the pack has the correct version
true
fi
found="1"
break
fi
done
if [ "$found" != "1" ]; then
createpkg --install $pack
# check if the package was built and installed
check_exit_status $?
else
found="0"
fi
}
function check_repo {
if [ ! -d "$SLACKBUILDS" ]; then
build_repo
fi
}
function sync_repo {
cd $SLACKBUILDS
svn update || build_repo
}
function find_script {
find $SLACKBUILDS | grep -v .svn | grep -e "/$1.SlackBuild$"
}
function check_exit_status {
# check whether exit status is 0 or not
# if not, call safe_exit to end the program
if [ "$1" != "0" ]; then
safe_exit $1
fi
}
check_config
check_repo
if [ -z "$1" ]; then
safe_exit 2
elif [ "$#" == "2" ]; then
if [ "$1" == "--search" ]; then
find_script $2
exit
elif [ "$1" == "--install" ]; then
PACKAGE="$2"
INSTALL="1"
elif [ "$1" == "--no-deps" ]; then
NO_DEPS="1"
PACKAGE="$2"
else
safe_exit 2
fi
elif [ "$1" == "--sync" ]; then
sync_repo
exit
elif [ "${1:0:1}" != "-" ]; then
PACKAGE="$1"
else
safe_exit 2
fi
if [ "$SYNC" == "yes" ]; then
sync_repo
fi
BUILD_SCRIPT="`find_script $PACKAGE`"
if [ -z "$BUILD_SCRIPT" ]; then
safe_exit 5
fi
SCRIPT_BASE="`dirname $BUILD_SCRIPT`"
# sets the package's slack-required
if [ -f "$SCRIPT_BASE/$PACKAGE.slack-required" ]; then
SLACK_REQ="$SCRIPT_BASE/$PACKAGE.slack-required"
elif [ -f "$SCRIPT_BASE/slack-required" ]; then
SLACK_REQ="$SCRIPT_BASE/slack-required"
fi
if [ ! -z "$SLACK_REQ" ] && [ "$NO_DEPS" != "1" ]; then
# this routine checks for dependencies in package's slack-required
cat $SLACK_REQ | while read dep; do
if [ ! -z "$dep" ]; then
program="`echo $dep | awk '{ print $1 }'`"
condition="`echo $dep | awk '{ print $2 }' | sed -e 's/>=/equalorgreater/' -e 's/=</equalorless/' -e 's/</less/' -e 's/>/greater/' -e 's/=/equal/'`"
version="`echo $dep | awk '{ print $3 }' | tr -dc '[:digit:]'`"
solve_dep $program $condition $version
fi
done
fi
# built package
cd $SCRIPT_BASE
INTERACT=no ./`basename $BUILD_SCRIPT`
# check if package was built
check_exit_status $?
# this doesn't work always
#
# VERSION="`grep -e '^VERSION=' $BUILD_SCRIPT | head -n 1 | sed -e "s/VERSION//g" -e 's/=//g' -e 's/-//g' | cut -d ":" -f 2 | cut -d "}" -f 1`"
# BUILD="`grep -e '^BUILD=' $BUILD_SCRIPT | head -n 1 | sed -e "s/BUILD//g" -e 's/=//g' | cut -d ":" -f 2 | cut -d "}" -f 1`"
# _ARCH="`grep -e '^ARCH' $BUILD_SCRIPT | head -n 1 | cut -d "=" -f 2 | sed -e 's/"//g'`"
#
# if [ "$_ARCH" == "noarch" ]; then
# ARCH="noarch"
# fi
if [ "$INSTALL" == "1" ]; then
# we can do the following cause we dont have the full package name:
# upgradepkg --install-new $REPOS/$PACKAGE-$VERSION-$ARCH-$BUILD.tgz
# so we do this:
upgradepkg --install-new $REPOS/$PACKAGE*tgz
fi
|