epm-install 6.12 KB
Newer Older
Vitaly Lipatov's avatar
Vitaly Lipatov committed
1 2 3 4 5
#!/bin/sh
#
# Copyright (C) 2012  Etersoft
# Copyright (C) 2012  Vitaly Lipatov <lav@etersoft.ru>
#
6 7 8
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
Vitaly Lipatov's avatar
Vitaly Lipatov committed
9 10 11 12 13
# (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
14
# GNU Affero General Public License for more details.
Vitaly Lipatov's avatar
Vitaly Lipatov committed
15
#
16 17
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
Vitaly Lipatov's avatar
Vitaly Lipatov committed
18 19
#

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

25
	# TODO: rewrite with use is_installed
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
	# 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
			;;
43
	esac | sed -e "s|rpm-build-altlinux-compat[^ ]*||g" | filter_strip_spaces
44 45 46
}


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

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

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

137
epm_install_files()
Vitaly Lipatov's avatar
Vitaly Lipatov committed
138
{
Danil Mikhailov's avatar
Danil Mikhailov committed
139
    [ -z "$1" ] && return
140

141
    case $PMTYPE in
142
        apt-rpm)
143
            sudocmd rpm -Uvh $force $nodeps $@ && return
144 145
            # if run with --nodeps, do not fallback on hi level
            [ -n "$nodeps" ] && return
146

147 148
            # use install_names
            ;;
149
        apt-dpkg)
150 151 152 153 154
            # the new version of the conf. file is installed with a .dpkg-dist suffix
            if [ -n "$non_interactive" ] ; then
                DPKGOPTIONS="--force-confdef --force-confold"
            fi
            sudocmd dpkg $DPKGOPTIONS -i $@
155
            sudocmd apt-get -f install
156
            return ;;
157 158 159 160 161 162 163 164
        yum-rpm|dnf-rpm)
            sudocmd rpm -Uvh $force $nodeps $@ && return
            # if run with --nodeps, do not fallback on hi level

            [ -n "$nodeps" ] && return
            YUMOPTIONS=--nogpgcheck
            # use install_names
            ;;
165 166 167 168 169 170 171 172
        zypper-rpm)
            sudocmd rpm -Uvh $force $nodeps $@ && return
            # if run with --nodeps, do not fallback on hi level

            [ -n "$nodeps" ] && return
            ZYPPEROPTIONS=--no-gpg-checks
            # use install_names
            ;;
173 174
        urpm-rpm)
            sudocmd rpm -Uvh $force $nodeps $@ && return
175 176 177 178
            # if run with --nodeps, do not fallback on hi level
            [ -n "$nodeps" ] && return

            URPMOPTIONS=--no-verify-rpm
179 180
            # use install_names
            ;;
181
        pkg_add)
182
            sudocmd pkg_add $@
183
            return ;;
184
        pacman)
185
            sudocmd pacman -U --noconfirm $@
186
            return ;;
187
        slackpkg)
188
            sudocmd /sbin/installpkg $@
189
            return ;;
190 191
    esac

192
    # other systems can install file package via ordinary command
193
    epm_install_names "$@"
194 195
}

196 197 198
epm_print_install_command()
{
    case $PMTYPE in
199
        apt-rpm|yum-rpm|urpm-rpm|zypper-rpm|dnf-rpm)
200 201 202 203 204 205 206 207 208 209 210 211
            echo "rpm -Uvh --force $nodeps $@"
            ;;
        apt-dpkg)
            echo "dpkg -i $@"
            ;;
        pkg_add)
            echo "pkg_add $@"
            ;;
        pacman)
            echo "pacman -U --noconfirm $@"
            ;;
        slackpkg)
212
            echo "/sbin/installpkg $@"
213
            ;;
214 215 216
        npackd)
            echo "npackdcl add --package=$@"
            ;;
217 218 219 220 221 222
        *)
            fatal "Do not known appropriate install command for $PMTYPE"
            ;;
    esac
}

223 224 225

epm_install()
{
226
    if [ -n "$show_command_only" ] ; then
227
        epm_print_install_command $pkg_filenames
228 229 230
        return
    fi

231 232
    [ -n "$pkg_files$pkg_names" ] || fatal "Run install without packages"

233 234
    local names="$(echo $pkg_names | filter_out_installed_packages)"
    local files="$(echo $pkg_files | filter_out_installed_packages)"
235

236
    [ -z "$files$names" ] && echo "Skip empty install list" && return 22
237

238
    epm_install_names $names || return
239
    epm_install_files $files
Vitaly Lipatov's avatar
Vitaly Lipatov committed
240
}