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() ...@@ -295,12 +295,13 @@ __epm_check_if_needed_repack()
local pkgname="$(epm print name from "$1")" local pkgname="$(epm print name from "$1")"
local repackcode="$CONFIGDIR/repack.d/$pkgname.sh" local repackcode="$CONFIGDIR/repack.d/$pkgname.sh"
[ -x "$repackcode" ] || return [ -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() epm_install_files()
{ {
[ -z "$1" ] && return local files="$@"
[ -z "$files" ] && return
# TODO: check read permissions # TODO: check read permissions
# sudo test -r FILE # sudo test -r FILE
...@@ -308,25 +309,31 @@ epm_install_files() ...@@ -308,25 +309,31 @@ epm_install_files()
case "$DISTRNAME" in case "$DISTRNAME" in
ALTLinux|ALTServer) ALTLinux|ALTServer)
# TODO: replace with name changed function if __epm_repack_if_needed $files ; then
__epm_check_if_try_install_pkgtype deb $@ && return $RES [ -n "$repacked_pkgs" ] || fatal "Can't convert $files"
__epm_check_if_try_install_pkgtype AppImage $@ && return $RES files="$repacked_pkgs"
__epm_check_if_src_rpm $@ # TODO
#__epm_remove_tmp_files
fi
__epm_check_if_src_rpm $files
# do not use low-level for install by file path (FIXME: reasons?) # do not use low-level for install by file path (FIXME: reasons?)
if ! is_dirpath "$@" || [ "$(get_package_type "$@")" = "rpm" ] ; then if ! is_dirpath "$files" || [ "$(get_package_type "$files")" = "rpm" ] ; then
__epm_check_vendor $@ if [ -z "$repacked_pkgs" ] ; then
__epm_check_if_needed_repack $@ __epm_check_vendor $files
sudocmd rpm -Uvh $force $noscripts $nodeps $@ && save_installed_packages $@ && return __epm_check_if_needed_repack $files
fi
sudocmd rpm -Uvh $force $noscripts $nodeps $files && save_installed_packages $files && return
local RES=$? local RES=$?
# TODO: check rpm result code and convert it to compatible format if possible # 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 # if run with --nodeps, do not fallback on hi level
[ -n "$nodeps" ] && return $RES [ -n "$nodeps" ] && return $RES
fi fi
epm_install_names "$@" epm_install_names $files
return return
;; ;;
esac esac
...@@ -338,23 +345,28 @@ epm_install_files() ...@@ -338,23 +345,28 @@ epm_install_files()
DPKGOPTIONS="--force-confdef --force-confold" DPKGOPTIONS="--force-confdef --force-confold"
fi 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) # 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 if [ -n "$nodeps" ] ; then
sudocmd dpkg $DPKGOPTIONS -i $@ sudocmd dpkg $DPKGOPTIONS -i $files
return return
fi fi
# TODO: don't resolve fuzzy dependencies () # TODO: don't resolve fuzzy dependencies ()
# are there apt that don't support dpkg files to install? # are there apt that don't support dpkg files to install?
epm_install_names $(make_filepath "$@") epm_install_names $(make_filepath $files)
return return
# old way: # old way:
sudocmd dpkg $DPKGOPTIONS -i $@ sudocmd dpkg $DPKGOPTIONS -i $files
local RES=$? local RES=$?
# return OK if all is OK # return OK if all is OK
...@@ -367,18 +379,23 @@ epm_install_files() ...@@ -367,18 +379,23 @@ epm_install_files()
epm_check epm_check
# repeat install for get correct status # repeat install for get correct status
sudocmd dpkg $DPKGOPTIONS -i $@ sudocmd dpkg $DPKGOPTIONS -i $files
return return
;; ;;
*-rpm) *-rpm)
__epm_check_if_try_install_pkgtype deb $@ && return $RES if __epm_repack_if_needed $files ; then
__epm_check_if_try_install_pkgtype AppImage $@ && return $RES [ -n "$repacked_pkgs" ] || fatal "Can't convert $files"
__epm_check_if_src_rpm $@ files="$repacked_pkgs"
sudocmd rpm -Uvh $force $noscripts $nodeps $@ && return # TODO
#__epm_remove_tmp_files
fi
__epm_check_if_src_rpm $files
sudocmd rpm -Uvh $force $noscripts $nodeps $files && return
local RES=$? 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 # if run with --nodeps, do not fallback on hi level
[ -n "$nodeps" ] && return $RES [ -n "$nodeps" ] && return $RES
...@@ -402,45 +419,45 @@ epm_install_files() ...@@ -402,45 +419,45 @@ epm_install_files()
esac esac
;; ;;
packagekit) packagekit)
docmd pkcon install-local $@ docmd pkcon install-local $files
return ;; return ;;
pkgsrc) pkgsrc)
sudocmd pkg_add $@ sudocmd pkg_add $files
return ;; return ;;
pkgng) pkgng)
local PKGTYPE="$(get_package_type $@)" local PKGTYPE="$(get_package_type $files)"
case "$PKGTYPE" in case "$PKGTYPE" in
tbz) tbz)
sudocmd pkg_add $@ sudocmd pkg_add $files
;; ;;
*) *)
sudocmd pkg add $@ sudocmd pkg add $files
;; ;;
esac esac
return ;; return ;;
android) android)
sudocmd pm install $@ sudocmd pm install $files
return ;; return ;;
emerge) emerge)
load_helper epm-install-emerge load_helper epm-install-emerge
sudocmd epm_install_emerge $@ sudocmd epm_install_emerge $files
return ;; return ;;
pacman) pacman)
sudocmd pacman -U --noconfirm $nodeps $@ && return sudocmd pacman -U --noconfirm $nodeps $files && return
local RES=$? local RES=$?
[ -n "$nodeps" ] && return $RES [ -n "$nodeps" ] && return $RES
sudocmd pacman -U $@ sudocmd pacman -U $files
return ;; return ;;
slackpkg) slackpkg)
# FIXME: check for full package name # FIXME: check for full package name
# FIXME: broken status when use batch and default answer # 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 ;; return ;;
esac esac
# other systems can install file package via ordinary command # other systems can install file package via ordinary command
epm_install_names "$@" epm_install_names $files
} }
epm_print_install_command() epm_print_install_command()
...@@ -604,20 +621,14 @@ epm_install() ...@@ -604,20 +621,14 @@ epm_install()
# repack binary files # repack binary files
if [ -n "$repack" ] ; then if [ -n "$repack" ] ; then
# FIXME: see to_remove below __epm_repack $files || return
__epm_repack_to_rpm $files || fatal files="$repacked_pkgs"
files="$repacked_rpms"
fi fi
epm_install_files $files epm_install_files $files
local RETVAL=$? local RETVAL=$?
# TODO: move it to exit handler __epm_remove_tmp_files
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
return $RETVAL return $RETVAL
} }
...@@ -32,14 +32,14 @@ __epm_split_by_pkg_type() ...@@ -32,14 +32,14 @@ __epm_split_by_pkg_type()
for pkg in "$@" ; do for pkg in "$@" ; do
[ "$(get_package_type "$pkg")" = "$type" ] || return 1 [ "$(get_package_type "$pkg")" = "$type" ] || return 1
[ -e "$pkg" ] || fatal "Can't read $pkg" [ -e "$pkg" ] || fatal "Can't read $pkg"
split_replaced_pkgs="$split_target_pkgs $pkg" split_replaced_pkgs="$split_replaced_pkgs $pkg"
done done
[ -n "$split_replaced_pkgs" ] [ -n "$split_replaced_pkgs" ]
} }
# fills repacked_debs # fills repacked_pkgs
__epm_repack_rpm_to_deb() __epm_repack_to_deb()
{ {
local pkg local pkg
local rpmpkgs="$1" local rpmpkgs="$1"
...@@ -48,17 +48,28 @@ __epm_repack_rpm_to_deb() ...@@ -48,17 +48,28 @@ __epm_repack_rpm_to_deb()
assure_exists fakeroot assure_exists fakeroot
assure_exists rpm assure_exists rpm
repacked_debs='' repacked_pkgs=''
local TDIR=$(mktemp -d) local TDIR=$(mktemp -d)
for pkg in $rpmpkgs ; do 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 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") local DEBCONVERTED=$(grep "deb generated" $RC_STDOUT | sed -e "s| generated||g")
repacked_debs="$repacked_rpms $(realpath $DEBCONVERTED)" if [ -n "$DEBCONVERTED" ] ; then
repacked_pkgs="$repacked_pkgs $(realpath $DEBCONVERTED)"
to_remove_pkg_files="$to_remove_pkg_files $(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 clean_store_output
cd - >/dev/null cd - >/dev/null
done done
...@@ -76,18 +87,6 @@ __epm_repack_rpm_to_deb() ...@@ -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 # $spec $PKGNAME $VERSION
__set_name_version() __set_name_version()
{ {
...@@ -184,7 +183,72 @@ EOF ...@@ -184,7 +183,72 @@ EOF
to_remove_pkg_files="$to_remove_pkg_files $HOME/.rpmmacros" 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() __epm_repack_to_rpm()
{ {
local pkgs="$*" local pkgs="$*"
...@@ -192,7 +256,7 @@ __epm_repack_to_rpm() ...@@ -192,7 +256,7 @@ __epm_repack_to_rpm()
ALTLinux|ALTServer) ALTLinux|ALTServer)
;; ;;
*) *)
assure_distr ALTLinux "install --repack" assure_distr ALTLinux "install --repack for rpm target"
;; ;;
esac esac
...@@ -214,62 +278,20 @@ __epm_repack_to_rpm() ...@@ -214,62 +278,20 @@ __epm_repack_to_rpm()
local alpkg local alpkg
local abspkg local abspkg
local tmpbuilddir local tmpbuilddir
repacked_rpms='' repacked_pkgs=''
for pkg in $pkgs ; do for pkg in $pkgs ; do
tmpbuilddir=$HOME/$(basename $pkg).tmpdir tmpbuilddir=$HOME/$(basename $pkg).tmpdir
mkdir $tmpbuilddir mkdir $tmpbuilddir
abspkg="$(realpath $pkg)" abspkg="$(realpath $pkg)"
info "" info ""
info "Repacking $abspkg to local rpm format ..." 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 # don't use abs package path: copy package to temp dir and use there
cp $verbose $pkg $tmpbuilddir/../$alpkg cp $verbose $pkg $tmpbuilddir/../$alpkg
cd $tmpbuilddir/../ || fatal cd $tmpbuilddir/../ || fatal
__prepare_source_package "$pkg"
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
cd $tmpbuilddir/ || fatal cd $tmpbuilddir/ || fatal
if [ -n "$verbose" ] ; then if [ -n "$verbose" ] ; then
...@@ -309,7 +331,7 @@ __epm_repack_to_rpm() ...@@ -309,7 +331,7 @@ __epm_repack_to_rpm()
rm -f $tmpbuilddir/../$alpkg rm -f $tmpbuilddir/../$alpkg
local repacked_rpm="$(realpath $tmpbuilddir/../*.rpm)" local repacked_rpm="$(realpath $tmpbuilddir/../*.rpm)"
if [ -s "$repacked_rpm" ] ; then 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" to_remove_pkg_files="$to_remove_pkg_files $repacked_rpm"
else else
warning "Can't find converted rpm for source binary package '$pkg'" warning "Can't find converted rpm for source binary package '$pkg'"
...@@ -325,28 +347,49 @@ __epm_repack_to_rpm() ...@@ -325,28 +347,49 @@ __epm_repack_to_rpm()
true true
} }
# FIXME: Нужно как-то обеспечить непродолжение выполнения.
__epm_check_if_try_install_pkgtype()
{
local PKG="$1"
shift
__epm_split_by_pkg_type $PKG "$@" || return 1
__epm_repack_to_rpm $split_replaced_pkgs || { RES=$? ; return 0 ; }
# TODO: move to install __epm_remove_tmp_files()
docmd epm install $repacked_rpms {
RES=$?
# TODO: move it to exit handler # TODO: move it to exit handler
if [ -z "$DEBUG" ] ; then if [ -z "$DEBUG" ] ; then
# TODO: reinvent # TODO: reinvent
[ -n "$to_remove_pkg_files" ] && rm -f $to_remove_pkg_files [ -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_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 [ -n "$to_remove_pkg_dirs" ] && rmdir $to_remove_pkg_dirs 2>/dev/null
fi fi
return 0
}
# 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 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() epm_repack()
{ {
...@@ -360,36 +403,16 @@ epm_repack() ...@@ -360,36 +403,16 @@ epm_repack()
[ -n "$pkg_names" ] && warning "Can't find $pkg_names" [ -n "$pkg_names" ] && warning "Can't find $pkg_names"
[ -z "$pkg_files" ] && info "Skip empty repack list" && return 22 [ -z "$pkg_files" ] && info "Skip empty repack list" && return 22
case $PKGFORMAT in if __epm_repack $pkg_files && [ -n "$repacked_pkgs" ] ; then
rpm) cp $repacked_pkgs "$CURDIR"
__epm_repack_to_rpm $pkg_files || fatal if [ -z "$quiet" ] ; then
echo echo
echo "Adapted packages:" echo "Adapted packages:"
cp $repacked_rpms "$CURDIR" for i in $repacked_pkgs ; do
for i in $repacked_rpms ; do echo " $CURDIR/$(basename "$i")"
echo " $(pwd)/$(basename "$i")"
done 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 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