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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
#!/bin/sh
# kind of hack: inheritance --force from main epm
echo "$EPM_OPTIONS" | grep -q -- "--force" && force="--force"
echo "$EPM_OPTIONS" | grep -q -- "--auto" && auto="--auto"
fatal()
{
echo "FATAL: $*" >&2
exit 1
}
[ -n "$BIGTMPDIR" ] || [ -d "/var/tmp" ] && BIGTMPDIR="/var/tmp" || BIGTMPDIR="/tmp"
cd_to_temp_dir()
{
PKGDIR=$(mktemp -d --tmpdir=$BIGTMPDIR)
trap "rm -fr $PKGDIR" EXIT
cd $PKGDIR || fatal
}
# print a path to the command if exists in $PATH
if a= type -a type 2>/dev/null >/dev/null ; then
print_command_path()
{
a= type -fpP -- "$1" 2>/dev/null
}
elif a= which which 2>/dev/null >/dev/null ; then
# the best case if we have which command (other ways needs checking)
# TODO: don't use which at all, it is a binary, not builtin shell command
print_command_path()
{
a= which -- "$1" 2>/dev/null
}
else
print_command_path()
{
a= type "$1" 2>/dev/null | sed -e 's|.* /|/|'
}
fi
# check if <arg> is a real command
is_command()
{
print_command_path "$1" >/dev/null
}
#__showcmd_shifted()
#{
# local s="$1"
# shift
# shift $s
# showcmd "$*"
#}
# support for direct run a play script
if [ -x "../bin/epm" ] ; then
export PATH="$(realpath ../bin):$PATH"
fi
# add to all epm calls
#EPM="$(epm tool which epm)" || fatal
EPM="$(print_command_path epm)" || fatal
epm()
{
#if [ "$1" = "tool" ] ; then
# __showcmd_shifted 1 "$@"
if [ "$1" != "print" ] && [ "$1" != "tool" ] && [ "$1" != "status" ] ; then
showcmd "$(basename $EPM) $*"
fi
$EPM "$@"
}
eget()
{
epm tool eget "$@"
}
is_supported_arch()
{
local i
# skip checking if there are no arches
[ -n "$SUPPORTEDARCHES" ] || return 0
[ -n "$1" ] || return 0
for i in $SUPPORTEDARCHES ; do
[ "$i" = "$1" ] && return 0
done
return 1
}
get_latest_version()
{
local ver
local epmver="$(epm --short --version)"
local URL
for URL in "https://eepm.ru/releases/$epmver/app-versions" "https://eepm.ru/app-versions" ; do
ver="$(eget -q -O- "$URL/$1")" || continue
ver="$(echo "$ver" | head -n1 | cut -d" " -f1)"
[ -n "$ver" ] && echo "$ver" && return
done
}
print_product_alt()
{
[ -n "$1" ] || return
shift
echo "$*"
}
get_pkgvendor()
{
epm print field Vendor for package "$1"
}
is_pkg_enough()
{
local needed="$2"
local PKG="$1"
if epm installed $PKG ; then
local ver
ver=$(epm print version for package "$PKG" | head -n1)
if [ -n "$ver" ] && [ "$(epm print compare version "$ver" "$needed")" = "-1" ] ; then
return 1
fi
fi
return 0
}
# arg: minimal require of libstdc++ version
# return true is we have such version
is_stdcpp_enough()
{
local needed="$1"
local STDCPKG="libstdc++"
epm installed $STDCPKG || STDCPKG="libstdc++6"
is_pkg_enough $STDCPKG $needed
}
is_glibc_enough()
{
local needed="$1"
local PKG="glibc-core"
epm installed $PKG || PKG="glibc"
is_pkg_enough $PKG $needed
}
is_openssl_enough()
{
local needed="$1"
local PKG="openssl"
is_pkg_enough $PKG $needed
}
get_first()
{
echo "$1"
}
check_alternative_pkgname()
{
[ -n "$BASEPKGNAME" ] || BASEPKGNAME="$PKGNAME"
[ -n "$BASEPKGNAME" ] || return
# default: with first entry in $PEODUCTALT
BRANCH=$(get_first $PRODUCTALT)
PKGNAME="$BASEPKGNAME-$BRANCH"
# override with VERSION
local i
for i in $PRODUCTALT ; do
if [ "$i" = "''" ] ; then
PKGNAME=$BASEPKGNAME
continue
fi
if [ "$VERSION" = "$i" ] ; then
PKGNAME=$BASEPKGNAME-$i
BRANCH="$i"
VERSION=""
return
fi
done
# when VERSION is not in PRODUCTALT, check installed package
for i in $PRODUCTALT ; do
if [ "$i" = "''" ] ; then
continue
fi
if epm installed $BASEPKGNAME-$i ; then
PKGNAME=$BASEPKGNAME-$i
BRANCH="$i"
break
fi
done
}
is_repacked_package()
{
local pkg="$1"
[ -n "$pkg" ] || pkg="$PKGNAME"
[ -n "$pkg" ] || return 0 #fatal "is_repacked_package() is called without package name"
epm status --installed $pkg || return 0
# actually only for ALT
[ "$(epm print info -s)" = "alt" ] || return 0
[ -n "$force" ] && return 0
if epm status --original $pkg ; then
echo "Package $pkg is already installed from ALT repository (use --force to override it)."
return 1
fi
if epm status --certified $pkg ; then
# allow install/update if we agreed with their package
return 0
fi
if epm status --thirdparty $pkg ; then
[ -n "$SKIPREPACK" ] && return 0
echo "Package $pkg is already installed, packaged by vendor $(epm print field Vendor for $pkg)."
return 1
fi
if ! epm status --repacked $pkg ; then
echo "Package $pkg is already installed (possible, manually packed)."
return 1
fi
return 0
}
case "$1" in
"--description")
is_supported_arch "$2" || exit 0
echo "$DESCRIPTION"
exit
;;
"--product-alternatives")
print_product_alt $PRODUCTALT
exit
;;
esac
. $(dirname $0)/common-outformat.sh
check_tty
# set PKGNAME to $BASEPKGNAME-$VERSION if $VERSION is found in PRODUCTALT
[ -n "$PRODUCTALT" ] && check_alternative_pkgname
case "$1" in
"--remove")
#is_repacked_package || exit 0
epm remove $PKGNAME
exit
;;
"--info")
if [ -n "$PRODUCTALT" ] ; then
echo "Help about additional parameters."
echo "Use epm play $(basename $0 .sh) [= $(echo "$PRODUCTALT" | sed -e 's@ @|@g')]"
fi
[ -n "$TIPS" ] && echo "$TIPS"
[ -n "$URL" ] && echo "Url: $URL"
exit
;;
"--package-name")
#[ -n "$DESCRIPTION" ] || exit 0
echo "$PKGNAME"
exit
;;
"--installed")
#epm installed $PKGNAME
is_repacked_package $PKGNAME
exit
;;
"--installed-version")
epm print version for package $PKGNAME
exit
;;
"--update")
if ! epm installed $PKGNAME ; then
echo "Skipping update of $PKGNAME (package is not installed)"
exit
fi
if epm mark checkhold "$PKGNAME" ; then
echo "Skipping update of $PKGNAME (package is on hold, see '# epm mark showhold')"
exit
fi
pkgver="$(epm print version for package $PKGNAME)"
latestpkgver="$(get_latest_version $PKGNAME)"
# ignore update if have no latest package version or the latest package version no more than installed one
if [ -n "$pkgver" ] ; then
if [ -z "$latestpkgver" ] ; then
echo "Can't get info about latest version of $PKGNAME, so skip updating installed version $pkgver."
exit
fi
# latestpkgver <= $pkgver
if [ -z "$force" ] && [ "$(epm print compare package version $latestpkgver $pkgver)" != "1" ] ; then
if [ "$latestpkgver" = "$pkgver" ] ; then
echo "Latest available version of $PKGNAME $latestpkgver is already installed."
else
echo "Latest available version of $PKGNAME: $latestpkgver, but you a newer version installed: $pkgver."
fi
exit
fi
echo "Updating $PKGNAME from $pkgver to the latest available version (equal to $latestpkgver or newer) ..."
#if [ -n "$force" ] ; then
# echo "Updating $PKGNAME from $pkgver to latest available version ..."
#else
# echo "Updating $PKGNAME from $pkgver to $latestpkgver version ..."
# VERSION="$latestpkgver"
#fi
fi
# pass to run play code
;;
"--run")
# just pass to run play code
;;
*)
fatal "Unknown command '$1'. Use this script only via epm play."
;;
esac
# --update/--run
is_supported_arch "$(epm print info -a)" || fatal "Only '$SUPPORTEDARCHES' architectures is supported"
# skip install if there is package installed not via epm play
is_repacked_package $REPOPKGNAME || exit 0
# default version value (can be overrided with arg $2 or by update)
[ -n "$VERSION" ] || VERSION="*"