3
# Copyright (C) 2013-2016 Etersoft
4
# Copyright (C) 2013-2016 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
__check_command_in_path()
22
# with hack for sudo case
23
( PATH=$PATH:/sbin:/usr/sbin print_command_path "$1" )
26
# returns TRUE if package version is omitted, or package is not installed, or version is too old
30
local PACKAGEVERSION="$2"
32
[ -n "$PACKAGEVERSION" ] || return 0
35
is_installed "$PACKAGE" || return 0
38
# epm print version for package N
39
local INSTALLEDVERSION=$(query_package_field "version" "$PACKAGE")
40
# if needed >= installed, return 0
41
[ "$(compare_version "$PACKAGEVERSION" "$INSTALLEDVERSION")" -gt 0 ] && return 0
46
__epm_assure_checking()
50
local PACKAGEVERSION="$3"
52
[ -n "$PACKAGEVERSION" ] && return 1
54
if is_dirpath "$CMD" ; then
55
# TODO: check for /usr/bin, /bin, /usr/sbin, /sbin
56
if [ -e "$CMD" ] ; then
57
if [ -n "$verbose" ] ; then
58
info "File or directory $CMD is already exists."
64
[ -n "$PACKAGE" ] || fatal "You need run with package name param when use with absolute path to non executable file"
68
if __check_command_in_path "$CMD" >/dev/null ; then
69
if [ -n "$verbose" ] ; then
70
local compath="$(__check_command_in_path "$1")"
71
info "Command $CMD is exists: $compath"
80
# Do fast checking for command and install package if the command does not exist
84
# $3 - [needed package version]
90
local PACKAGEVERSION="$3"
91
[ -n "$PACKAGE" ] || PACKAGE="$1"
93
__epm_assure_checking $CMD $PACKAGE $PACKAGEVERSION && return 0
95
info "Installing appropriate package for $CMD command..."
96
__epm_need_update $PACKAGE $PACKAGEVERSION || return 0
98
# can't be used in epm ei case
99
#docmd epm --auto install $PACKAGE || return
100
load_helper epm-install
101
(repack='' pkg_names="$PACKAGE" pkg_files='' pkg_urls='' epm_install ) || return
103
# https://bugzilla.altlinux.org/42240
105
epm_mark_auto "$PACKAGE"
107
# no check if we don't need a version
108
[ -n "$PACKAGEVERSION" ] || return 0
110
# check if we couldn't update and still need update
111
__epm_need_update $PACKAGE $PACKAGEVERSION || return 0
114
[ -n "$PACKAGEVERSION" ] && textpackage=" >= $PACKAGEVERSION"
115
warning "Can't assure in '$CMD' command from $PACKAGE$textpackage package"