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
#!/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
}
# check if <arg> is a real command
is_command()
{
epm tool which "$1" >/dev/null
}
. $(dirname $0)/common-outformat.sh
check_tty
#__showcmd_shifted()
#{
# local s="$1"
# shift
# shift $s
# showcmd "$*"
#}
# add to all epm calls
EPM="$(epm tool which 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"
}
# 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"
if epm installed $STDCPKG ; then
local stdcver
stdcver=$(epm print version for package "$STDCPKG" | head -n1)
if [ -n "$stdcver" ] && [ "$(epm print compare version "$stdcver" "$needed")" = "-1" ] ; then
return 1
fi
fi
return 0
}
get_first()
{
echo "$1"
}
check_alternative_pkgname()
{
[ -n "$BASEPKGNAME" ] || BASEPKGNAME="$PKGNAME"
[ -n "$BASEPKGNAME" ] || return
# default: with first entry in $PEODUCTALT
PKGNAME="$BASEPKGNAME-$(get_first $PRODUCTALT)"
# override with VERSION
local i
for i in $PRODUCTALT ; do
if [ "$i" = "''" ] ; then
PKGNAME=$BASEPKGNAME
continue
fi
if [ "$VERSION" = "$i" ] ; then
PKGNAME=$BASEPKGNAME-$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
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"
# actually only for ALT
[ "$(epm print info -s)" = "alt" ] || return 0
epm status --installed $pkg || 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
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
}
# support for direct run a play script
if [ -x "../bin/epm" ] ; then
export PATH="$(realpath ../bin):$PATH"
fi
# 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
;;
"--product-alternatives")
print_product_alt $PRODUCTALT
exit
;;
"--installed")
epm installed $PKGNAME
exit
;;
"--installed-version")
epm print version for package $PKGNAME
exit
;;
"--description")
is_supported_arch "$2" || exit 0
echo "$DESCRIPTION"
exit
;;
"--update")
if ! epm installed $PKGNAME ; then
echo "Skipping update of $PKGNAME (package is not installed)"
exit
fi
if epm mark showhold | grep -q "^$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 have installed more new version:$pkgver."
fi
exit
fi
echo "Updating $PKGNAME from $pkgver to 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="*"