3
# Copyright (C) 2023 Etersoft
4
# Copyright (C) 2023 Vitaly Lipatov <lav@etersoft.ru>
6
# This program is free software: you can redistribute it and/or modify
7
# it under the terms of the GNU Affero General Public License as published by
8
# the Free Software Foundation, either version 3 of the License, or
9
# (at your option) any later version.
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU Affero General Public License for more details.
16
# You should have received a copy of the GNU Affero General Public License
17
# along with this program. If not, see <http://www.gnu.org/licenses/>.
20
load_helper epm-sh-altlinux
24
[ -n "$EPM_PACK_SCRIPTS_DIR" ] || EPM_PACK_SCRIPTS_DIR="$CONFIGDIR/pack.d"
26
# <packname> <abstarname> [packversion]
27
# fills returntarname with returned tar name or empty
28
__epm_pack_run_handler()
32
local packversion="$3"
36
local repackcode="$EPM_PACK_SCRIPTS_DIR/$packname.sh"
37
[ -x "$repackcode" ] || return
38
[ -f "$repackcode.rpmnew" ] && warning "There is .rpmnew file(s) in $EPM_PACK_SCRIPTS_DIR dir. The pack script can be outdated."
40
# a file to keep filename of generated tarball
41
filefortarname="$(pwd)/filefortarname"
43
[ "$PROGDIR" = "/usr/bin" ] && SCPATH="$PATH" || SCPATH="$PROGDIR:$PATH"
45
[ -n "$debug" ] && bashopt='-x'
46
#info "Running $($script --description 2>/dev/null) ..."
47
# TODO: add url info here
48
( unset EPMCURDIR ; export PATH=$SCPATH ; docmd $CMDSHELL $bashopt $repackcode "$tarname" "$filefortarname" "$packversion" "$url") || fatal
49
returntarname="$(cat "$filefortarname")" || fatal "pack script $repackcode didn't set tarname"
52
for i in $returntarname ; do
53
[ -s "$i" ] || fatal "pack script for $packname returned unexist $i file"
59
# we run this function in a tmpdir
65
# fills returntarname with packed tar
66
__epm_pack_run_handler "$@" || fatal "Can't find pack script for packname $packname"
68
if [ -n "$download_only" ] ; then
69
mv $returntarname $EPMCURDIR
73
# TODO: merge eepm.yaml here (common with $returntarname.eepm.yaml)
74
# add upstream_url: $URL too
76
# note: this repack related code here for follow reasons:
77
# * repack by default if we have repack rule
78
# * get repacked files
79
# * install (repacked) files
80
# the most replacement is epm repack [--install] or epm install [--repack]
82
# FIXME: check for every package would be more reliable
85
# don't repack by default there is our pkg format
86
__epm_split_by_pkg_type $PKGFORMAT $returntarname && dorepack=''
87
# repack if we have a repack rule for it
88
[ -z "$norepack" ] && __epm_have_repack_rule $returntarname && dorepack='--repack'
90
[ -n "$repack" ] && dorepack='--repack'
93
if [ -n "$dorepack" ] ; then
94
__epm_repack $returntarname
95
[ -n "$repacked_pkgs" ] || fatal "Can't repack $returntarname"
96
# remove packed file if we have repacked one
98
pkgnames="$repacked_pkgs"
100
pkgnames="$returntarname"
103
if [ -n "$install" ] ; then
104
docmd epm install $pkgnames
108
# we need put result in the cur dir
109
mv -v $pkgnames $EPMCURDIR || fatal
112
for i in $pkgnames ; do
113
[ -r "$i.eepm.yaml" ] && mv -v "$i.eepm.yaml" $EPMCURDIR
122
epm pack - create rpm package from files
123
Usage: epm pack [options] <packname> <tar|url|dir> [version]
126
<dir> - create tarball from the dir before
127
<url> - download tar from url
128
[version] - force version for unversioned sources
129
--install - install after pack result
130
--repack - force repack ever if returned package can be installed without repack
131
--download-only - save pack result and exit
132
--save-only - save repacked packages and exit (this is default behaviour)
140
if [ "$1" = "-h" ] || [ "$1" = "--help" ] ; then
146
tmpdir="$(mktemp -d --tmpdir=$BIGTMPDIR)" || fatal
147
remove_on_exit "$tmpdir"
151
local packversion="$3"
154
[ -n "$packname" ] || fatal "run with packname, see --help"
156
if is_url "$tarname"; then
159
load_helper epm-download
161
__handle_pkg_urls_to_install
162
[ -n "$pkg_files" ] || fatal "Can't download $tarname"
163
tarname="$(realpath "$pkg_files")"
164
elif [ -d "$tarname" ] ; then
165
tarname="$(realpath "$tarname")"
166
elif [ -s "$tarname" ] ; then
167
# get full path for real name
168
tarname="$(realpath "$tarname")"
175
__epm_pack "$packname" "$tarname" "$packversion" "$url"