epm-addrepo 5.07 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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
__epm_addrepo_rhel()
{
	local repo="$@"
	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"
		return 1
	fi
	case "$1" in
		epel)
			epm install epel-release
			return 1
			;;
	esac
	return 0
}

43
__epm_addrepo_altlinux()
44
{
45 46 47 48 49 50 51 52 53 54 55
	local repo="$@"
	case "$1" in
		etersoft)
			info "add Etersoft's addon repo"
			load_helper epm-query
			epm install --skip-installed apt-conf-etersoft-common apt-conf-etersoft-hold
			# TODO: ignore only error code 22 (skipped) || fatal
			local branch="$DISTRVERSION/branch"
			[ "$DISTRVERSION" = "Sisyphus" ] && branch="$DISTRVERSION"
			# FIXME
			[ -n "$DISTRVERSION" ] || fatal "Empty DISTRVERSION"
56
			# TODO: func?
57 58 59 60 61
			local arch=$(uname -m)
			[ "$arch" = "i686" ] && arch="i586"
			# 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
62
			echo "rpm [etersoft] $ETERSOFTPUBURL/Etersoft LINUX@Etersoft/$branch/$arch addon" | sudocmd tee -a /etc/apt/sources.list
63
			if [ "$arch" = "x86_64" ] ; then
64
				echo "rpm [etersoft] $ETERSOFTPUBURL/Etersoft LINUX@Etersoft/$branch/$arch-i586 addon" | sudocmd tee -a /etc/apt/sources.list
65
			fi
66
			echo "rpm [etersoft] $ETERSOFTPUBURL/Etersoft LINUX@Etersoft/$branch/noarch addon" | sudocmd tee -a /etc/apt/sources.list
67 68 69 70 71 72 73 74
			repo="$DISTRVERSION"
			return 0
			;;
		autoimports)
			[ -n "$DISTRVERSION" ] || fatal "Empty DISTRVERSION"
			repo="$repo.$(echo "$DISTRVERSION" | tr "[:upper:]" "[:lower:]")"
			;;
		archive)
75
			[ -n "$DISTRVERSION" ] || fatal "Empty DISTRVERSION"
76
			datestr="$2"
77
			echo "$datestr" | grep -Eq "^20[0-2][0-9]/[01][0-9]/[0-3][0-9]$" || fatal "use follow date format: 2017/12/31"
78 79 80 81
			# TODO: func?
			local arch=$(uname -m)
			[ "$arch" = "i686" ] && arch="i586"
			echo "" | sudocmd tee -a /etc/apt/sources.list
82 83 84
			local distrversion="$(echo "$DISTRVERSION" | tr "[:upper:]" "[:lower:]")"
			local rpmsign='[alt]'
			[ "$distrversion" != "sisyphus" ] && rpmsign="[$distrversion]"
85
			echo "rpm $rpmsign $ALTLINUXPUBURL archive/$distrversion/date/$datestr/$arch classic" | sudocmd tee -a /etc/apt/sources.list
86
			if [ "$arch" = "x86_64" ] ; then
87
				echo "rpm $rpmsign $ALTLINUXPUBURL archive/$distrversion/date/$datestr/$arch-i586 classic" | sudocmd tee -a /etc/apt/sources.list
88
			fi
89
			echo "rpm $rpmsign $ALTLINUXPUBURL archive/$distrversion/date/$datestr/noarch classic" | sudocmd tee -a /etc/apt/sources.list
90
			return 0
91 92
			;;
	esac
93

94
	assure_exists apt-repo
95

96
	if tasknumber "$repo" >/dev/null ; then
97
		sudocmd_foreach "apt-repo $dryrun add" $(tasknumber "$repo")
98 99 100 101
		return
	fi

	if [ -z "$repo" ] ; then
Vitaly Lipatov's avatar
Vitaly Lipatov committed
102
		info "Add branch repo. Use follow params:"
103
		sudocmd apt-repo $dryrun add branch
104 105
		echo "etersoft           - for LINUX@Etersoft repo"
		echo "archive 2018/02/09 - for archive from that date"
106 107
		return
	fi
108

109 110
	# TODO: add other mirror (mirror.yandex.ru)
	# TODO: apt-repo supports archive
111
	sudocmd apt-repo $dryrun add "$repo"
112

113
}
Vitaly Lipatov's avatar
Vitaly Lipatov committed
114

115 116
epm_addrepo()
{
117
local repo="$*"
118 119 120

case $DISTRNAME in
	ALTLinux)
121
		__epm_addrepo_altlinux $repo
122
		return
123
		;;
124 125 126
esac

case $PMTYPE in
127 128 129 130 131
	apt-dpkg)
		assure_exists apt-add-repository software-properties-common
		if echo "$repo" | grep -q "https://" ; then
			assure_exists apt-transport-https
		fi
Vitaly Lipatov's avatar
Vitaly Lipatov committed
132
		sudocmd apt-add-repository "$repo"
133 134 135
		info "Check file /etc/apt/sources.list if needed"
		;;
	aptitude-dpkg)
136
		info "You need manually add repo to /etc/apt/sources.list (TODO)"
137 138
		;;
	yum-rpm)
139
		assure_exists yum-utils
140
		__epm_addrepo_rhel "$repo" || return
141
		sudocmd yum-config-manager --add-repo "$repo"
142
		;;
143 144 145 146
	dnf-rpm)
		__epm_addrepo_rhel "$repo" || return
		sudocmd dnf config-manager --add-repo "$repo"
		;;
147
	urpm-rpm)
148
		sudocmd urpmi.addmedia "$repo"
149 150
		;;
	zypper-rpm)
151
		sudocmd zypper ar "$repo"
152 153
		;;
	emerge)
154
		sudocmd layman -a "$repo"
155 156
		;;
	pacman)
157
		info "You need manually add repo to /etc/pacman.conf"
158 159
		# Only for alone packages:
		#sudocmd repo-add $pkg_filenames
160
		;;
161
	npackd)
162
		sudocmd npackdcl add-repo --url="$repo"
163
		;;
164 165 166
	winget)
		sudocmd winget source add "$repo"
		;;
167
	slackpkg)
168
		info "You need manually add repo to /etc/slackpkg/mirrors"
169 170
		;;
	*)
171
		fatal "Have no suitable command for $PMTYPE"
172 173 174 175
		;;
esac

}