Commit dc8f7abd authored by Vitaly Lipatov's avatar Vitaly Lipatov

epm install/repack: big refactoring to support rpm/deb platform in common way

parent 996dcc92
......@@ -295,12 +295,13 @@ __epm_check_if_needed_repack()
local pkgname="$(epm print name from "$1")"
local repackcode="$CONFIGDIR/repack.d/$pkgname.sh"
[ -x "$repackcode" ] || return
warning "There is exists repack rules for $pkgname package. It is better install this package via epm --repack install or epm play."
warning "There is repack rule for $pkgname package. It is better install this package via 'epm --repack install' or 'epm play'."
}
epm_install_files()
{
[ -z "$1" ] && return
local files="$@"
[ -z "$files" ] && return
# TODO: check read permissions
# sudo test -r FILE
......@@ -308,25 +309,31 @@ epm_install_files()
case "$DISTRNAME" in
ALTLinux|ALTServer)
# TODO: replace with name changed function
__epm_check_if_try_install_pkgtype deb $@ && return $RES
__epm_check_if_try_install_pkgtype AppImage $@ && return $RES
__epm_check_if_src_rpm $@
if __epm_repack_if_needed $files ; then
[ -n "$repacked_pkgs" ] || fatal "Can't convert $files"
files="$repacked_pkgs"
# TODO
#__epm_remove_tmp_files
fi
__epm_check_if_src_rpm $files
# do not use low-level for install by file path (FIXME: reasons?)
if ! is_dirpath "$@" || [ "$(get_package_type "$@")" = "rpm" ] ; then
__epm_check_vendor $@
__epm_check_if_needed_repack $@
sudocmd rpm -Uvh $force $noscripts $nodeps $@ && save_installed_packages $@ && return
if ! is_dirpath "$files" || [ "$(get_package_type "$files")" = "rpm" ] ; then
if [ -z "$repacked_pkgs" ] ; then
__epm_check_vendor $files
__epm_check_if_needed_repack $files
fi
sudocmd rpm -Uvh $force $noscripts $nodeps $files && save_installed_packages $files && return
local RES=$?
# TODO: check rpm result code and convert it to compatible format if possible
__epm_check_if_rpm_already_installed $@ && return
__epm_check_if_rpm_already_installed $files && return
# if run with --nodeps, do not fallback on hi level
[ -n "$nodeps" ] && return $RES
fi
epm_install_names "$@"
epm_install_names $files
return
;;
esac
......@@ -338,23 +345,28 @@ epm_install_files()
DPKGOPTIONS="--force-confdef --force-confold"
fi
__epm_check_if_try_install_rpm $@ && return
if __epm_repack_if_needed $files ; then
[ -n "$repacked_pkgs" ] || fatal "Can't convert $files"
files="$repacked_pkgs"
# TODO
#__epm_remove_tmp_files
fi
# TODO: if dpkg can't install due missed deps, trying with apt (as for now, --refuse-depends, --refuse-breaks don't help me)
if [ -n "$nodeps" ] ; then
sudocmd dpkg $DPKGOPTIONS -i $@
sudocmd dpkg $DPKGOPTIONS -i $files
return
fi
# TODO: don't resolve fuzzy dependencies ()
# are there apt that don't support dpkg files to install?
epm_install_names $(make_filepath "$@")
epm_install_names $(make_filepath $files)
return
# old way:
sudocmd dpkg $DPKGOPTIONS -i $@
sudocmd dpkg $DPKGOPTIONS -i $files
local RES=$?
# return OK if all is OK
......@@ -367,18 +379,23 @@ epm_install_files()
epm_check
# repeat install for get correct status
sudocmd dpkg $DPKGOPTIONS -i $@
sudocmd dpkg $DPKGOPTIONS -i $files
return
;;
*-rpm)
__epm_check_if_try_install_pkgtype deb $@ && return $RES
__epm_check_if_try_install_pkgtype AppImage $@ && return $RES
__epm_check_if_src_rpm $@
sudocmd rpm -Uvh $force $noscripts $nodeps $@ && return
if __epm_repack_if_needed $files ; then
[ -n "$repacked_pkgs" ] || fatal "Can't convert $files"
files="$repacked_pkgs"
# TODO
#__epm_remove_tmp_files
fi
__epm_check_if_src_rpm $files
sudocmd rpm -Uvh $force $noscripts $nodeps $files && return
local RES=$?
__epm_check_if_rpm_already_installed $@ && return
__epm_check_if_rpm_already_installed $files && return
# if run with --nodeps, do not fallback on hi level
[ -n "$nodeps" ] && return $RES
......@@ -402,45 +419,45 @@ epm_install_files()
esac
;;
packagekit)
docmd pkcon install-local $@
docmd pkcon install-local $files
return ;;
pkgsrc)
sudocmd pkg_add $@
sudocmd pkg_add $files
return ;;
pkgng)
local PKGTYPE="$(get_package_type $@)"
local PKGTYPE="$(get_package_type $files)"
case "$PKGTYPE" in
tbz)
sudocmd pkg_add $@
sudocmd pkg_add $files
;;
*)
sudocmd pkg add $@
sudocmd pkg add $files
;;
esac
return ;;
android)
sudocmd pm install $@
sudocmd pm install $files
return ;;
emerge)
load_helper epm-install-emerge
sudocmd epm_install_emerge $@
sudocmd epm_install_emerge $files
return ;;
pacman)
sudocmd pacman -U --noconfirm $nodeps $@ && return
sudocmd pacman -U --noconfirm $nodeps $files && return
local RES=$?
[ -n "$nodeps" ] && return $RES
sudocmd pacman -U $@
sudocmd pacman -U $files
return ;;
slackpkg)
# FIXME: check for full package name
# FIXME: broken status when use batch and default answer
__separate_sudocmd_foreach "/sbin/installpkg" "/sbin/upgradepkg" $@
__separate_sudocmd_foreach "/sbin/installpkg" "/sbin/upgradepkg" $files
return ;;
esac
# other systems can install file package via ordinary command
epm_install_names "$@"
epm_install_names $files
}
epm_print_install_command()
......@@ -604,20 +621,14 @@ epm_install()
# repack binary files
if [ -n "$repack" ] ; then
# FIXME: see to_remove below
__epm_repack_to_rpm $files || fatal
files="$repacked_rpms"
__epm_repack $files || return
files="$repacked_pkgs"
fi
epm_install_files $files
local RETVAL=$?
# TODO: move it to exit handler
if [ -z "$DEBUG" ] ; then
# TODO: reinvent
[ -n "$to_remove_pkg_files" ] && rm -fv $to_remove_pkg_files
[ -n "$to_remove_pkg_files" ] && rmdir -v $(dirname $to_remove_pkg_files | head -n1) 2>/dev/null
fi
__epm_remove_tmp_files
return $RETVAL
}
......@@ -32,14 +32,14 @@ __epm_split_by_pkg_type()
for pkg in "$@" ; do
[ "$(get_package_type "$pkg")" = "$type" ] || return 1
[ -e "$pkg" ] || fatal "Can't read $pkg"
split_replaced_pkgs="$split_target_pkgs $pkg"
split_replaced_pkgs="$split_replaced_pkgs $pkg"
done
[ -n "$split_replaced_pkgs" ]
}
# fills repacked_debs
__epm_repack_rpm_to_deb()
# fills repacked_pkgs
__epm_repack_to_deb()
{
local pkg
local rpmpkgs="$1"
......@@ -48,17 +48,28 @@ __epm_repack_rpm_to_deb()
assure_exists fakeroot
assure_exists rpm
repacked_debs=''
repacked_pkgs=''
local TDIR=$(mktemp -d)
for pkg in $rpmpkgs ; do
pkg="$(realpath "$pkg")"
abspkg="$(realpath "$pkg")"
info "Repacking $abspkg to local deb format ..."
alpkg=$(basename $pkg)
# don't use abs package path: copy package to temp dir and use there
cp $verbose $pkg $TDIR/$alpkg
cd $TDIR || fatal
showcmd_store_output fakeroot alien -d -k $scripts "$pkg"
__prepare_source_package "$pkg"
showcmd_store_output fakeroot alien -d -k $scripts "$alpkg"
local DEBCONVERTED=$(grep "deb generated" $RC_STDOUT | sed -e "s| generated||g")
repacked_debs="$repacked_rpms $(realpath $DEBCONVERTED)"
to_remove_pkg_files="$to_remove_pkg_files $(realpath $DEBCONVERTED)"
if [ -n "$DEBCONVERTED" ] ; then
repacked_pkgs="$repacked_pkgs $(realpath $DEBCONVERTED)"
to_remove_pkg_files="$to_remove_pkg_files $(realpath $DEBCONVERTED)"
fi
to_remove_pkg_dirs="$to_remove_pkg_files $TDIR"
clean_store_output
cd - >/dev/null
done
......@@ -76,18 +87,6 @@ __epm_repack_rpm_to_deb()
}
# TODO: rewrite to convert (get some code from Korinf?)
__epm_check_if_try_install_rpm()
{
__epm_split_by_pkg_type rpm "$@" || return 1
__epm_repack_rpm_to_deb $split_replaced_pkgs
# TODO: move to install
docmd epm install $repacked_debs
return 0
}
# $spec $PKGNAME $VERSION
__set_name_version()
{
......@@ -184,7 +183,72 @@ EOF
to_remove_pkg_files="$to_remove_pkg_files $HOME/.rpmmacros"
}
# will fill repacked_rpms var
__set_version_pkgname()
{
local alpkg="$1"
VERSION="$(echo "$alpkg" | grep -o -P "[-_.]([0-9])([0-9])*(\.[0-9])*" | head -n1 | sed -e 's|^[-_.]||')" #"
[ -n "$VERSION" ] && PKGNAME="$(echo "$alpkg" | sed -e "s|[-_.]$VERSION.*||")"
}
# arg: <package file>
# sets:
# alpkg - package file name without path
# PKGNAME - package name
# VERSION - version of the package
# SUBGENERIC - name of generic file's extension
__prepare_source_package()
{
local pkg="$1"
alpkg=$(basename $pkg)
# TODO: use func for get name from deb pkg
# TODO: epm print name from deb package
# TODO: use stoplist only for deb?
[ -z "$force" ] && __check_stoplist $(echo $alpkg | sed -e "s|_.*||") && fatal "Please use official package instead of $alpkg repacking (It is not recommended to use --force to skip this checking."
PKGNAME=''
VERSION=''
SUBGENERIC=''
# convert tarballs to tar (for alien)
if rhas "$alpkg" "\.(rpm|deb)$" ; then
return
fi
if rhas "$alpkg" "\.AppImage$" ; then
__set_version_pkgname $alpkg
[ -n "$VERSION" ] || fatal "Can't get version from $alpkg."
SUBGENERIC='appimage'
# TODO: move repack archive to erc?
[ -x "$alpkg" ] || docmd chmod u+x -v "$alpkg"
./$alpkg --appimage-extract || fatal
alpkg=$PKGNAME-$VERSION.tar
assure_exists erc || fatal
# make a tar for alien
a= erc a $alpkg squashfs-root
return
fi
__set_version_pkgname $alpkg
if [ -n "$VERSION" ] ; then
assure_exists erc || fatal
pkgtype="$(a= erc type $alpkg)"
[ -n "$PKGNAME" ] || PKGNAME=$(basename $alpkg .$pkgtype)
if [ "$pkgtype" = "tar" ] || [ "$pkgtype" = "tar.gz" ] || [ "$pkgtype" = "tgz" ] ; then
:
else
newalpkg=$(basename $alpkg .$pkgtype).tar
assure_exists erc || fatal
a= erc repack $alpkg $newalpkg || fatal
rm -f $verbose $alpkg
alpkg=$newalpkg
fi
fi
}
# will fill repacked_pkgs var
__epm_repack_to_rpm()
{
local pkgs="$*"
......@@ -192,7 +256,7 @@ __epm_repack_to_rpm()
ALTLinux|ALTServer)
;;
*)
assure_distr ALTLinux "install --repack"
assure_distr ALTLinux "install --repack for rpm target"
;;
esac
......@@ -214,62 +278,20 @@ __epm_repack_to_rpm()
local alpkg
local abspkg
local tmpbuilddir
repacked_rpms=''
repacked_pkgs=''
for pkg in $pkgs ; do
tmpbuilddir=$HOME/$(basename $pkg).tmpdir
mkdir $tmpbuilddir
abspkg="$(realpath $pkg)"
info ""
info "Repacking $abspkg to local rpm format ..."
# alien failed with spaced names
# alpkg=$abspkg
alpkg=$(basename $pkg)
# TODO: use func for get name from deb pkg
# TODO: epm print name from deb package
# TODO: use stoplist only for deb?
[ -z "$force" ] && __check_stoplist $(echo $alpkg | sed -e "s|_.*||") && fatal "Please use official rpm package instead of $alpkg (It is not recommended to use --force to skip this checking."
alpkg=$(basename $pkg)
# don't use abs package path: copy package to temp dir and use there
cp $verbose $pkg $tmpbuilddir/../$alpkg
cd $tmpbuilddir/../ || fatal
PKGNAME=''
VERSION=''
SUBGENERIC=''
# convert tarballs to tar (for alien)
if rhas "$pkg" "\.(rpm|deb)$" ; then
:
elif rhas "$pkg" "\.AppImage$" ; then
VERSION="$(echo "$alpkg" | grep -o -P "[-_.]([0-9])([0-9])*(\.[0-9])*" | head -n1 | sed -e 's|^[-_.]||')" #"
[ -n "$VERSION" ] || fatal "Can't get version from $alpkg."
PKGNAME="$(echo "$alpkg" | sed -e "s|[-_.]$VERSION.*||")"
# TODO: move repack archive to erc?
[ -x "$alpkg" ] || docmd chmod u+x -v "$alpkg"
#[ -x "$alpkg" ] || sudocmd chmod u+x -v "$abspkg"
SUBGENERIC='appimage'
./$alpkg --appimage-extract || fatal
alpkg=$PKGNAME-$VERSION.tar
assure_exists erc || fatal
a= erc a $alpkg squashfs-root
else
VERSION="$(echo "$alpkg" | grep -o -P "[-_.]([0-9])([0-9])*(\.[0-9])*" | head -n1 | sed -e 's|^[-_.]||')" #"
if [ -n "$VERSION" ] ; then
PKGNAME="$(echo "$alpkg" | sed -e "s|[-_.]$VERSION.*||")"
pkgtype="$(a= erc type $alpkg)"
[ -n "$PKGNAME" ] || PKGNAME=$(basename $alpkg .$pkgtype)
if [ "$pkgtype" = "tar" ] || [ "$pkgtype" = "tar.gz" ] || [ "$pkgtype" = "tgz" ] ; then
:
else
newalpkg=$(basename $alpkg .$pkgtype).tar
assure_exists erc || fatal
a= erc repack $alpkg $newalpkg || fatal
rm -f $verbose $alpkg
alpkg=$newalpkg
fi
fi
fi
__prepare_source_package "$pkg"
cd $tmpbuilddir/ || fatal
if [ -n "$verbose" ] ; then
......@@ -309,7 +331,7 @@ __epm_repack_to_rpm()
rm -f $tmpbuilddir/../$alpkg
local repacked_rpm="$(realpath $tmpbuilddir/../*.rpm)"
if [ -s "$repacked_rpm" ] ; then
repacked_rpms="$repacked_rpms $repacked_rpm"
repacked_pkgs="$repacked_pkgs $repacked_rpm"
to_remove_pkg_files="$to_remove_pkg_files $repacked_rpm"
else
warning "Can't find converted rpm for source binary package '$pkg'"
......@@ -325,28 +347,49 @@ __epm_repack_to_rpm()
true
}
# FIXME: Нужно как-то обеспечить непродолжение выполнения.
__epm_check_if_try_install_pkgtype()
__epm_remove_tmp_files()
{
local PKG="$1"
shift
__epm_split_by_pkg_type $PKG "$@" || return 1
__epm_repack_to_rpm $split_replaced_pkgs || { RES=$? ; return 0 ; }
# TODO: move it to exit handler
if [ -z "$DEBUG" ] ; then
# TODO: reinvent
[ -n "$to_remove_pkg_files" ] && rm -f $to_remove_pkg_files
# hack??
[ -n "$to_remove_pkg_files" ] && rmdir $(dirname $to_remove_pkg_files | head -n1) 2>/dev/null
[ -n "$to_remove_pkg_dirs" ] && rmdir $to_remove_pkg_dirs 2>/dev/null
fi
return 0
}
# TODO: move to install
docmd epm install $repacked_rpms
RES=$?
# TODO: move it to exit handler
if [ -z "$DEBUG" ] ; then
# TODO: reinvent
[ -n "$to_remove_pkg_files" ] && rm -f $to_remove_pkg_files
[ -n "$to_remove_pkg_files" ] && rmdir $(dirname $to_remove_pkg_files | head -n1) 2>/dev/null
[ -n "$to_remove_pkg_dirs" ] && rmdir $to_remove_pkg_dirs 2>/dev/null
fi
# FIXME: Нужно как-то обеспечить непродолжение выполнения.
# used in epm install
# fill repacked_pkgs
__epm_repack()
{
repacked_pkgs=''
case $PKGFORMAT in
rpm)
__epm_repack_to_rpm "$@" || return
;;
deb)
__epm_repack_to_deb "$@" || return
;;
*)
fatal "$PKGFORMAT is not supported for repack yet"
;;
esac
return 0
}
__epm_repack_if_needed()
{
# return 1 if there is a package in host package format
__epm_split_by_pkg_type $PKGFORMAT "$@" && return 1
__epm_repack "$@"
return 0
}
epm_repack()
{
......@@ -360,36 +403,16 @@ epm_repack()
[ -n "$pkg_names" ] && warning "Can't find $pkg_names"
[ -z "$pkg_files" ] && info "Skip empty repack list" && return 22
case $PKGFORMAT in
rpm)
__epm_repack_to_rpm $pkg_files || fatal
if __epm_repack $pkg_files && [ -n "$repacked_pkgs" ] ; then
cp $repacked_pkgs "$CURDIR"
if [ -z "$quiet" ] ; then
echo
echo "Adapted packages:"
cp $repacked_rpms "$CURDIR"
for i in $repacked_rpms ; do
echo " $(pwd)/$(basename "$i")"
for i in $repacked_pkgs ; do
echo " $CURDIR/$(basename "$i")"
done
;;
deb)
if __epm_split_by_pkg_type rpm $pkg_files ; then
__epm_repack_rpm_to_deb $split_replaced_pkgs
cp -v $repacked_debs .
pkg_files="$(estrlist exclude $split_replaced_pkgs $pkg_files)"
[ -n "$pkg_files" ] && warning "There are left unconverted packages $pkg_files."
fi
;;
*)
fatal "$PKGFORMAT is not supported for repack yet"
;;
esac
# TODO: move it to exit handler
if [ -z "$DEBUG" ] ; then
# TODO: reinvent
[ -n "$to_remove_pkg_files" ] && rm -f $to_remove_pkg_files
# hack??
[ -n "$to_remove_pkg_files" ] && rmdir $(dirname $to_remove_pkg_files | head -n1) 2>/dev/null
[ -n "$to_remove_pkg_dirs" ] && rmdir $to_remove_pkg_dirs 2>/dev/null
fi
fi
__epm_remove_tmp_files
}
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