epm-addrepo 8.47 KB
Newer Older
1 2
#!/bin/sh
#
3 4
# Copyright (C) 2012, 2017, 2019  Etersoft
# Copyright (C) 2012, 2017, 2019  Vitaly Lipatov <lav@etersoft.ru>
5
#
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
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.
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/>.
18 19
#

20 21
load_helper epm-sh-altlinux

22 23 24
ETERSOFTPUBURL=http://download.etersoft.ru/pub
ALTLINUXPUBURL=http://ftp.altlinux.org/pub/distributions

25 26
__epm_addrepo_rhel()
{
27
	local repo="$*"
28 29 30 31
	if [ -z "$repo" ] ; then
		echo "Add repo."
		echo "1. Use with repository URL, f.i. http://www.example.com/example.repo"
		echo "2. Use with epel to add EPEL repository"
32
		echo "3. Use with powertools to add PowerTools repository"
33 34 35 36
		return 1
	fi
	case "$1" in
		epel)
37
			# dnf -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
38 39 40
			epm install epel-release
			return 1
			;;
41 42 43 44 45 46
		powertools)
			# https://serverfault.com/questions/997896/how-to-enable-powertools-repository-in-centos-8
			epm install --skip-installed dnf-plugins-core
			sudocmd dnf config-manager --set-enabled powertools
			return 1
			;;
47 48 49 50
	esac
	return 0
}

51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
__epm_addrepo_etersoft_addon()
{
	epm install --skip-installed apt-conf-etersoft-common apt-conf-etersoft-hold || fatal
	# TODO: ignore only error code 22 (skipped) || fatal

	local pb="$DISTRVERSION/branch"
	[ "$DISTRVERSION" = "Sisyphus" ] && pb="$DISTRVERSION"

	# FIXME
	[ -n "$DISTRVERSION" ] || fatal "Empty DISTRVERSION"

	# TODO: use apt-repo add ?
	echo "" | sudocmd tee -a /etc/apt/sources.list
	echo "# added with eepm addrepo etersoft" | sudocmd tee -a /etc/apt/sources.list
	echo "rpm [etersoft] $ETERSOFTPUBURL/Etersoft LINUX@Etersoft/$pb/$DISTRARCH addon" | sudocmd tee -a /etc/apt/sources.list
	if [ "$DISTRARCH" = "x86_64" ] ; then
		echo "rpm [etersoft] $ETERSOFTPUBURL/Etersoft LINUX@Etersoft/$pb/x86_64-i586 addon" | sudocmd tee -a /etc/apt/sources.list
	fi
	echo "rpm [etersoft] $ETERSOFTPUBURL/Etersoft LINUX@Etersoft/$pb/noarch addon" | sudocmd tee -a /etc/apt/sources.list
}

72
__epm_addrepo_altlinux()
73
{
74
	local repo="$*"
75 76
	local branch="$(echo "$DISTRVERSION" | tr "[:upper:]" "[:lower:]")"
	[ -n "$branch" ] || fatal "Empty DISTRVERSION"
77 78 79 80 81 82 83 84 85 86 87 88 89

	if [ -z "$repo" ] || [ "$repo" == "--help" ] ; then
		info "Add branch repo. Use follow params:"
		sudocmd apt-repo $dryrun add branch
		echo "etersoft           - for LINUX@Etersoft repo"
		echo "basealt            - for BaseALT repo"
		echo "yandex             - for BaseALT repo mirror on yandex (recommended)"
		echo "<task number>      - add task repo"
		echo "archive 2018/02/09 - for archive from that date"
		echo "autoimports        - for BaseALT autoimports repo"
		return
	fi

90 91 92
	case "$1" in
		etersoft)
			info "add Etersoft's addon repo"
93 94
			assure_exists apt-repo
			__epm_addrepo_etersoft_addon
95
			sudocmd apt-repo add $branch
96 97 98
			epm repofix etersoft
			return 0
			;;
99
		basealt|ALTLinux|ALTServer)
100 101
			# TODO: setrepo?
			assure_exists apt-repo
102
			sudocmd apt-repo add $branch
103 104 105 106
			return 0
			;;
		yandex)
			assure_exists apt-repo
107
			sudocmd apt-repo add $branch
108
			epm repofix yandex
109 110 111
			return 0
			;;
		autoimports)
112
			repo="autoimports.$branch"
113 114
			;;
		archive)
115
			datestr="$2"
116
			echo "$datestr" | grep -Eq "^20[0-2][0-9]/[01][0-9]/[0-3][0-9]$" || fatal "use follow date format: 2017/12/31"
117

118
			echo "" | sudocmd tee -a /etc/apt/sources.list
119 120 121
			local distrversion="$(echo "$DISTRVERSION" | tr "[:upper:]" "[:lower:]")"
			local rpmsign='[alt]'
			[ "$distrversion" != "sisyphus" ] && rpmsign="[$distrversion]"
122 123 124
			echo "rpm $rpmsign $ALTLINUXPUBURL archive/$distrversion/date/$datestr/$DISTRARCH classic" | sudocmd tee -a /etc/apt/sources.list
			if [ "$DISTRARCH" = "x86_64" ] ; then
				echo "rpm $rpmsign $ALTLINUXPUBURL archive/$distrversion/date/$datestr/x86_64-i586 classic" | sudocmd tee -a /etc/apt/sources.list
125
			fi
126
			echo "rpm $rpmsign $ALTLINUXPUBURL archive/$distrversion/date/$datestr/noarch classic" | sudocmd tee -a /etc/apt/sources.list
127
			return 0
128 129
			;;
	esac
130

131
	assure_exists apt-repo
132

133
	if tasknumber "$repo" >/dev/null ; then
134
		sudocmd_foreach "apt-repo $dryrun add" $(tasknumber "$repo")
135 136 137
		return
	fi

138 139 140 141
	sudocmd apt-repo $dryrun add "$repo"

}

142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
__epm_addkey_altlinux()
{
    local url="$1"
    local fingerprint="$2"
    local comment="$3"

    local name="$(basename "$url" .gpg)"

    [ -s /etc/apt/vendors.list.d/$name.list ] && return

# TODO: get this info from the gpg key
    cat << EOF | sudorun tee /etc/apt/vendors.list.d/$name.list
simple-key "$name" {
        FingerPrint "$fingerprint";
        Name "$comment";
}
EOF
        eget -q -O /tmp/$name.gpg $url || fatal
        sudorun gpg --no-default-keyring --keyring /usr/lib/alt-gpgkeys/pubring.gpg --import /tmp/$name.gpg
        rm -f /tmp/$name.gpg
}

164 165 166 167
__epm_addkey_deb()
{
    local url="$1"
    local fingerprint="$2"
168 169 170 171 172 173
    local comment="$3"

    local name="$(basename $url .gpg)"

    [ -s /etc/apt/trusted.gpg.d/$name.gpg ] && return

174
    if [ -z "$fingerprint" ] ; then
Vitaly Lipatov's avatar
Vitaly Lipatov committed
175
        set_sudo
176 177 178 179 180 181 182
        eget -q -O- "$url" | sudorun apt-key add -
#
#        if [ ! -f /etc/apt/trusted.gpg.d/$name.gpg ]; then
#                epm tool eget -q -O /etc/apt/trusted.gpg.d/$name.gpg https://example.com/$name.gpg > /dev/null
#                chmod 0644 /etc/apt/trusted.gpg.d/$name.gpg
#        fi

183 184 185 186 187
        return
    fi
    sudocmd apt-key adv --keyserver "$url" --recv "$fingerprint"
}

188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
epm_addkey()
{

case $DISTRNAME in
	ALTLinux|ALTServer)
		__epm_addkey_altlinux "$@"
		return
		;;
esac

case $PMTYPE in
	apt-dpkg)
		__epm_addkey_deb "$@"
		;;
esac

}

206 207 208 209 210 211 212 213 214 215 216 217 218 219 220
__epm_addrepo_deb()
{
	assure_exists apt-add-repository software-properties-common
	local ad="$($DISTRVENDOR --distro-arch)"
	# TODO: move to distro_info
	local nd="$(lsb_release -cs)"
	local repo="$*"

	if [ -z "$repo" ] || [ "$repo" = "--help" ]; then
		info "Add repo. You can use follow params:"
		echo "  docker - add official docker repo"
		echo "  ppa:<user>/<ppa-name> - add PPA repo"
		echo "  distribution component name"
		echo "  full sources list line"
		echo "  URL version component"
221 222
		return
	fi
223

224
	if [ "$DISTRNAME" = "AstraLinuxCE" ] || [ "$DISTRNAME" = "AstraLinuxSE" ] ; then
225 226 227 228
		echo "Use workaround for AstraLinux"
		# aptsources.distro.NoDistroTemplateException: Error: could not find a distribution template for AstraLinuxCE/orel
		echo "" | sudocmd tee -a /etc/apt/sources.list
		echo "$repo" | sudocmd tee -a /etc/apt/sources.list
Vitaly Lipatov's avatar
Vitaly Lipatov committed
229
		return
230 231 232
	fi


233 234 235
	# keywords
	case "$1" in
		docker)
236
			__epm_addkey_deb https://download.docker.com/linux/$PKGVENDOR/gpg "9DC858229FC7DD38854AE2D88D81803C0EBFCD88"
237 238 239 240 241
			repo="https://download.docker.com/linux/$PKGVENDOR $nd stable"
			;;
	esac

	# if started from url, use heroistic
Vitaly Lipatov's avatar
Vitaly Lipatov committed
242
	if echo "$repo" | grep -E -q "^https?://" ; then
243 244 245 246 247 248 249
		repo="deb [arch=$ad] $repo"
	fi

	if echo "$repo" | grep -q "https://" ; then
		assure_exists /usr/share/doc/apt-transport-https apt-transport-https
		assure_exists /usr/sbin/update-ca-certificates ca-certificates 
	fi
250

251 252
	# FIXME: quotes in showcmd/sudocmd
	showcmd apt-add-repository "$repo"
253
	sudorun apt-add-repository "$repo"
254
	info "Check file /etc/apt/sources.list if needed"
255
}
Vitaly Lipatov's avatar
Vitaly Lipatov committed
256

257 258
epm_addrepo()
{
259
local repo="$*"
260 261

case $DISTRNAME in
262
	ALTLinux|ALTServer)
263
		# Note! Don't use quotes here
264
		__epm_addrepo_altlinux $repo
265
		return
266
		;;
267 268 269
esac

case $PMTYPE in
270
	apt-dpkg)
271 272
		# Note! Don't use quotes here
		__epm_addrepo_deb $repo
273 274
		;;
	aptitude-dpkg)
275
		info "You need manually add repo to /etc/apt/sources.list (TODO)"
276 277
		;;
	yum-rpm)
278
		assure_exists yum-utils
279
		__epm_addrepo_rhel "$repo" || return
280
		sudocmd yum-config-manager --add-repo "$repo"
281
		;;
282 283 284 285
	dnf-rpm)
		__epm_addrepo_rhel "$repo" || return
		sudocmd dnf config-manager --add-repo "$repo"
		;;
286
	urpm-rpm)
287
		sudocmd urpmi.addmedia "$repo"
288 289
		;;
	zypper-rpm)
290
		sudocmd zypper ar "$repo"
291 292
		;;
	emerge)
293
		sudocmd layman -a "$repo"
294 295
		;;
	pacman)
296
		info "You need manually add repo to /etc/pacman.conf"
297 298
		# Only for alone packages:
		#sudocmd repo-add $pkg_filenames
299
		;;
300
	npackd)
301
		sudocmd npackdcl add-repo --url="$repo"
302
		;;
303 304 305
	winget)
		sudocmd winget source add "$repo"
		;;
306
	slackpkg)
307
		info "You need manually add repo to /etc/slackpkg/mirrors"
308 309
		;;
	*)
310
		fatal "Have no suitable command for $PMTYPE"
311 312 313 314
		;;
esac

}