epm-install 4.97 KB
Newer Older
Vitaly Lipatov's avatar
Vitaly Lipatov committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
#!/bin/sh
#
# Copyright (C) 2012  Etersoft
# Copyright (C) 2012  Vitaly Lipatov <lav@etersoft.ru>
#
# This file is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
#

21 22 23 24 25
# TODO: use when run install with epm --skip-installed install
filter_out_installed_packages()
{
	[ -z "$skip_installed" ] && cat && return

26
	# TODO: rewrite with use epm_query
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
	# TODO: use this more effectively way
	#for i in $(cat) ; do
	#	rpm -q $i >/dev/null && continue
	#	echo $i
	#done | 
	case $PKGFORMAT in
		"rpm")
			LANG=C LC_ALL=C xargs -n1 rpm -q 2>&1 | grep 'is not installed' |
				sed -e 's|^.*package \(.*\) is not installed.*|\1|g'
			;;
		"deb")
			LANG=C LC_ALL=C xargs -n1 dpkg -L 2>&1 | grep 'is not installed.' |
				sed -e 's|^Package .\(.*\). is not installed.*|\1|g'
			;;
		*)
			cat
			;;
44
	esac | sed -e "s|rpm-build-altlinux-compat[^ ]*||g" | filter_strip_spaces
45 46 47
}


Vitaly Lipatov's avatar
Vitaly Lipatov committed
48
# copied from etersoft-build-utils/share/eterbuild/functions/rpmpkg
49
epm_install_names()
Vitaly Lipatov's avatar
Vitaly Lipatov committed
50
{
51 52 53 54 55
	if [ -n "$non_interactive" ] ; then
		epm_ni_install_names "$@"
		return
	fi

56
	[ -z "$1" ] && return
57
	case $PMTYPE in
58
		apt-rpm|apt-dpkg)
59
			sudocmd apt-get install $@
60 61
			return ;;
		urpm-rpm)
62
			sudocmd urpmi $@
63
			return ;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
64
		pkg_add)
65
			sudocmd pkg_add -r $@
Vitaly Lipatov's avatar
Vitaly Lipatov committed
66
			return ;;
67
		emerge)
68
			sudocmd emerge -uD $@
69
			return ;;
70
		pacman)
71
			sudocmd pacman -S $@
72
			return ;;
73
		yum-rpm)
74
			sudocmd yum install $@
75 76
			return ;;
		zypper-rpm)
77
			sudocmd zypper install $@
78 79
			return ;;
		mpkg)
80
			sudocmd mpkg install $@
81
			return ;;
82
		slackpkg)
83
			# TODO: use upgrade if package is already installed
84
			sudocmd /usr/sbin/slackpkg install $@
85
			return ;;
86 87
		*)
			fatal "Do not known install command for $PMTYPE"
Vitaly Lipatov's avatar
Vitaly Lipatov committed
88
			;;
89 90 91
	esac
}

92
# Non interactive install
93 94
epm_ni_install_names()
{
Danil Mikhailov's avatar
Danil Mikhailov committed
95
	[ -z "$1" ] && return
96
	case $PMTYPE in
97
		apt-rpm|apt-dpkg)
98
			sudocmd apt-get -y --force-yes install $@
99 100
			return ;;
		yum-rpm)
101
			sudocmd yum -y install $@
102 103
			return ;;
		urpm-rpm)
104
			sudocmd urpmi --auto --no-verify-rpm $@
105 106
			return ;;
		zypper-rpm)
107
			yes | sudocmd zypper --non-interactive install $@
108
			return ;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
109
		pkg_add)
110
			sudocmd pkg_add -r $@
Vitaly Lipatov's avatar
Vitaly Lipatov committed
111
			return ;;
112
		pacman)
113
			sudocmd pacman -S --noconfirm $@
114
			return ;;
115 116 117 118
		npackd)
			#  npackdcl update --package=<package> (remove old and install new)
			docmd npackdcl add --package=$@
			return ;;
119 120 121
		chocolatey)
			docmd chocolatey install $@
			return ;;
122
		slackpkg)
123
			# TODO: use upgrade if package is already installed
124
			sudocmd /usr/sbin/slackpkg -batch=on -default_answer=yes install $@
125
			return ;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
126
		*)
127
			fatal "Do not known appropriate install command for $PMTYPE"
Vitaly Lipatov's avatar
Vitaly Lipatov committed
128 129 130 131
			;;
	esac
}

132
epm_install_files()
Vitaly Lipatov's avatar
Vitaly Lipatov committed
133
{
Danil Mikhailov's avatar
Danil Mikhailov committed
134
    [ -z "$1" ] && return
135

136
    case $PMTYPE in
137
        apt-rpm|urpm-rpm)
138
            sudocmd rpm -Uvh $force $nodeps $@ && return
139 140
            # use install_names
            ;;
141
        apt-dpkg)
142 143
            sudocmd dpkg -i $@
            sudocmd apt-get -f install
144
            return ;;
145
        yum-rpm)
146 147
            sudocmd rpm -Uvh $force $@ && return
            sudocmd yum --nogpgcheck install $@
148
            return ;;
149
        pkg_add)
150
            sudocmd pkg_add $@
151
            return ;;
152
        pacman)
153
            sudocmd pacman -U --noconfirm $@
154
            return ;;
155
        slackpkg)
156
            sudocmd /sbin/installpkg $@
157
            return ;;
158 159
    esac

160
    # other systems can install file package via ordinary command
161
    epm_install_names "$@"
162 163
}

164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
epm_print_install_command()
{
    case $PMTYPE in
        apt-rpm|yum-rpm|urpm-rpm|zypper-rpm)
            echo "rpm -Uvh --force $nodeps $@"
            ;;
        apt-dpkg)
            echo "dpkg -i $@"
            ;;
        pkg_add)
            echo "pkg_add $@"
            ;;
        pacman)
            echo "pacman -U --noconfirm $@"
            ;;
        slackpkg)
180
            echo "/sbin/installpkg $@"
181
            ;;
182 183 184
        npackd)
            echo "npackdcl add --package=$@"
            ;;
185 186 187 188 189 190
        *)
            fatal "Do not known appropriate install command for $PMTYPE"
            ;;
    esac
}

191 192 193

epm_install()
{
194
    if [ -n "$show_command_only" ] ; then
195
        epm_print_install_command $pkg_filenames
196 197 198
        return
    fi

199 200
    [ -n "$pkg_files$pkg_names" ] || fatal "Run install without packages"

201 202
    local names="$(echo $pkg_names | filter_out_installed_packages)"
    local files="$(echo $pkg_files | filter_out_installed_packages)"
203 204 205

    [ -z "$files$names" ] && echo "Skip empty install list" && return 2

206
    epm_install_names $names || return
207
    epm_install_files $files
Vitaly Lipatov's avatar
Vitaly Lipatov committed
208
}