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
#!/bin/sh
#
# Copyright (C) 2023 Etersoft
# Copyright (C) 2023 Vitaly Lipatov <lav@etersoft.ru>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
load_helper epm-sh-altlinux
load_helper epm-assure
load_helper epm-repack
[ -n "$EPM_PACK_SCRIPTS_DIR" ] || EPM_PACK_SCRIPTS_DIR="$CONFIGDIR/pack.d"
# <packname> <abstarname> [packversion]
# fills returntarname with returned tar name or empty
__epm_pack_run_handler()
{
local packname="$1"
local tarname="$2"
local packversion="$3"
local url="$4"
returntarname=''
local repackcode="$EPM_PACK_SCRIPTS_DIR/$packname.sh"
[ -s "$repackcode" ] || return
[ -f "$repackcode.rpmnew" ] && warning "There is .rpmnew file(s) in $EPM_PACK_SCRIPTS_DIR dir. The pack script can be outdated."
# a file to keep filename of generated tarball
filefortarname="$(pwd)/filefortarname"
[ "$PROGDIR" = "/usr/bin" ] && SCPATH="$PATH" || SCPATH="$PROGDIR:$PATH"
local bashopt=''
[ -n "$debug" ] && bashopt='-x'
#info "Running $($script --description 2>/dev/null) ..."
# TODO: add url info here
( unset EPMCURDIR ; export PATH=$SCPATH ; export HOME=$(pwd) ; docmd $CMDSHELL $bashopt $repackcode "$tarname" "$filefortarname" "$packversion" "$url") || fatal
returntarname="$(cat "$filefortarname")" || fatal "pack script $repackcode didn't set tarname"
local i
for i in $returntarname ; do
[ -s "$i" ] || fatal "pack script for $packname returned a non-existent file $i"
done
return 0
}
# we run this function in a tmpdir
__epm_pack()
{
local packname="$1"
local URL="$4"
# fills returntarname with packed tar
__epm_pack_run_handler "$@" || fatal "Can't find pack script for packname $packname"
if [ -n "$download_only" ] ; then
mv $returntarname $EPMCURDIR
return
fi
# TODO: merge eepm.yaml here (common with $returntarname.eepm.yaml)
# add upstream_url: $URL too
# note: this repack related code here for follow reasons:
# * repack by default if we have repack rule
# * get repacked files
# * install (repacked) files
# the most replacement is epm repack [--install] or epm install [--repack]
# FIXME: check for every package would be more reliable
# by default
dorepack='--repack'
# don't repack by default there is our pkg format
__epm_split_by_pkg_type $PKGFORMAT $returntarname && dorepack=''
# repack if we have a repack rule for it
[ -z "$norepack" ] && __epm_check_repack_rule $returntarname && dorepack='--repack'
# repack if forced
[ -n "$repack" ] && dorepack='--repack'
local pkgnames
if [ -n "$dorepack" ] ; then
__epm_repack $returntarname
[ -n "$repacked_pkgs" ] || fatal "Can't repack $returntarname"
# remove packed file if we have repacked one
rm -f $returntarname
pkgnames="$repacked_pkgs"
else
pkgnames="$returntarname"
fi
if [ -n "$install" ] ; then
docmd epm install $pkgnames
return
fi
# we need put result in the cur dir
mv -v $pkgnames $EPMCURDIR || fatal
local i
for i in "$returntarname" ; do
[ -r "$i.eepm.yaml" ] && mv -v "$i.eepm.yaml" $EPMCURDIR
done
return 0
}
epm_pack_help()
{
cat <<EOF
epm pack - create rpm package from files
Usage: epm pack [options] <packname> <tar|url|dir> [version]
Options:
<packname> - receipt
<dir> - create tarball from the dir before
<url> - download tar from url
[version] - force version for unversioned sources
--install - install after pack result
--repack - force repack ever if returned package can be installed without repack
--download-only - save pack result and exit
--save-only - save repacked packages and exit (this is default behaviour)
EOF
}
epm_pack()
{
if [ "$1" = "-h" ] || [ "$1" = "--help" ] ; then
epm_pack_help
exit
fi
local tmpdir
tmpdir="$(mktemp -d --tmpdir=$BIGTMPDIR)" || fatal
remove_on_exit "$tmpdir"
local packname="$1"
local tarname="$2"
local packversion="$3"
local url=''
[ -n "$packname" ] || fatal "run with packname, see --help"
if is_url "$tarname"; then
url="$tarname"
pkg_urls="$tarname"
load_helper epm-download
cd $tmpdir || fatal
__download_pkg_urls
pkg_urls=
[ -n "$pkg_files" ] || fatal "Can't download $tarname"
tarname="$(realpath "$pkg_files")"
elif [ -d "$tarname" ] ; then
tarname="$(realpath "$tarname")"
elif [ -s "$tarname" ] ; then
# get full path for real name
tarname="$(realpath "$tarname")"
else
# just pass name
true
fi
cd $tmpdir || fatal
__epm_pack "$packname" "$tarname" "$packversion" "$url"
}