Commit 24f4cc09 authored by Vitaly Lipatov's avatar Vitaly Lipatov

epm install: add --repack support (binary rpm repacking before install)

parent 3cef551b
...@@ -74,13 +74,15 @@ print_version() ...@@ -74,13 +74,15 @@ print_version()
Usage="Usage: epm [options] <command> [package name(s), package files]..." Usage="Usage: epm [options] <command> [package name(s), package files]..."
Descr="epm - EPM package manager" Descr="epm - EPM package manager"
EPMVERSION=@VERSION@
verbose= verbose=
quiet= quiet=
nodeps= nodeps=
noremove= noremove=
dryrun= dryrun=
force= force=
repack=
scripts=
short= short=
direct= direct=
sort= sort=
...@@ -345,6 +347,12 @@ check_option() ...@@ -345,6 +347,12 @@ check_option()
--direct) # HELPOPT: direct install package file from ftp (not via hilevel repository manager) --direct) # HELPOPT: direct install package file from ftp (not via hilevel repository manager)
direct="--direct" direct="--direct"
;; ;;
--repack) # HELPOPT: repack rpm package(s) before install
repack="--repack"
;;
--scripts) # HELPOPT: include scripts in repacked rpm package(s) (see --repack)
scripts="--scripts"
;;
--sort) # HELPOPT: sort output, f.i. --sort=size (supported only for packages command) --sort) # HELPOPT: sort output, f.i. --sort=size (supported only for packages command)
# TODO: how to read arg? # TODO: how to read arg?
sort="$1" sort="$1"
......
...@@ -351,6 +351,77 @@ __epm_check_if_try_install_rpm() ...@@ -351,6 +351,77 @@ __epm_check_if_try_install_rpm()
return 0 return 0
} }
# args: buildroot spec
__fix_spec()
{
local buildroot="$1"
local spec="$2"
local i
for i in $(grep '^"/' $spec | sed -e 's|^"\(.*\)"$|\1|') ; do
#' hack for highlight
# add %dir to dir in list
if [ -d "$buildroot$i" ] ; then
subst 's|^\("'$i'"\)$|%dir \1|' $spec
fi
done
subst "s|^Release: |Release: alt1.repacked.with.epm.|" $spec
subst "s|^\((Converted from a rpm package.*\)|(Repacked from binary rpm with epm $EPMVERSION)\n\1|" $spec
#" hack for highlight
}
# will fill repacked_rpms var
__epm_repack_rpm()
{
[ "$DISTRNAME" = "ALTLinux" ] || fatal "install --repack supported only for ALT Linux distros"
assure_exists fakeroot || fatal
assure_exists alien || fatal
assure_exists rpmbuild rpm-build || fatal
local pkg
local tmpbuilddir=$(mktemp -d)/repack
mkdir $tmpbuilddir
local abspkg
repacked_rpms=''
for pkg in $* ; do
abspkg=$(realpath $pkg)
info "Repacking $abspkg to local rpm format ..."
cd $tmpbuilddir || fatal
docmd fakeroot alien --generate --to-rpm $verbose $scripts $abspkg || fatal
local subdir="$(echo *)"
[ -d "$subdir" ] || fatal "can't find subdir"
# detect spec and move to prev dir
local spec="$(echo $tmpbuilddir/$subdir/*.spec)"
[ -s "$spec" ] || fatal "can't find spec"
mv $spec $tmpbuilddir || fatal
spec="$tmpbuilddir/$(basename "$spec")"
__fix_spec $tmpbuilddir/$subdir $spec
showcmd fakeroot rpmbuild --buildroot $tmpbuilddir/$subdir --define='_allow_root_build 1' -bb $spec
if [ -n "$verbose" ] ; then
fakeroot rpmbuild --buildroot $tmpbuilddir/$subdir --define='_allow_root_build 1' -bb $spec || fatal
else
fakeroot rpmbuild --buildroot $tmpbuilddir/$subdir --define='_allow_root_build 1' -bb $spec >/dev/null || fatal
fi
local repacked_rpm="$(realpath $tmpbuilddir/../*.rpm)"
if [ -s "$repacked_rpm" ] ; then
repacked_rpms="$repacked_rpms $repacked_rpm"
to_remove_pkg_files="$to_remove_pkg_files $repacked_rpm"
else
warning "Can't find converted rpm for source binary $pkg package"
fi
cd - >/dev/null
rm -rf $tmpbuilddir/$subdir/
#rm -rf $tmpbuilddir/../*.rpm
rm -rf $spec
done
rmdir $tmpbuilddir
#rmdir $tmpbuilddir/..
true
}
__handle_direct_install() __handle_direct_install()
{ {
case "$DISTRNAME" in case "$DISTRNAME" in
...@@ -610,11 +681,11 @@ epm_install() ...@@ -610,11 +681,11 @@ epm_install()
return return
fi fi
if [ -n "$direct" ] ; then if [ -n "$direct" ] || [ -n "$repack" ] ; then
__handle_direct_install __handle_direct_install
fi fi
# if possible, it will put pkg_urls into pkg_files or pkg_names # if possible, it will put pkg_urls into pkg_files and reconstruct pkg_filenames
if [ -n "$pkg_urls" ] ; then if [ -n "$pkg_urls" ] ; then
load_helper epm-download load_helper epm-download
__handle_pkg_urls_to_install __handle_pkg_urls_to_install
...@@ -642,6 +713,13 @@ epm_install() ...@@ -642,6 +713,13 @@ epm_install()
fi fi
epm_install_names $names || return epm_install_names $names || return
# repack binary files
if [ -n "$repack" ] ; then
__epm_repack_rpm $files || fatal
files="$repacked_rpms"
fi
epm_install_files $files epm_install_files $files
local RETVAL=$? local RETVAL=$?
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment