Commit 44a4afcf authored by Vitaly Lipatov's avatar Vitaly Lipatov

epm addrepo: add --disabled and --name options

parent 406a8b4e
...@@ -366,7 +366,7 @@ check_command() ...@@ -366,7 +366,7 @@ check_command()
epm_cmd=update epm_cmd=update
direct_args=1 direct_args=1
;; ;;
addrepo|ar|--add-repo) # HELPCMD: add package repo (etersoft, autoimports, archive 2017/01/31); run with param to get list addrepo|ar|--add-repo) # HELPCMD: add package repo (etersoft, autoimports, --disabled); run with param to get list
epm_cmd=addrepo epm_cmd=addrepo
direct_args=1 direct_args=1
;; ;;
......
...@@ -218,8 +218,9 @@ epm repo add - add branch repo. Use follow params: ...@@ -218,8 +218,9 @@ epm repo add - add branch repo. Use follow params:
Examples: Examples:
# epm repo add yandex # epm repo add yandex
# epm repo add "rpm http://somesite/pub/product x86_64 addon # epm repo add "rpm http://somesite/pub/product x86_64 addon"
# epm repo add /var/ftp/pub/altlinux/p10 # epm repo add /var/ftp/pub/altlinux/p10
# epm repo add --name myrepo "rpm https://example.com x86_64 main"
' '
return return
...@@ -560,10 +561,126 @@ __epm_addrepo_deb() ...@@ -560,10 +561,126 @@ __epm_addrepo_deb()
} }
epm_addrepo_help()
{
message 'epm addrepo - add package repository
Usage: epm addrepo [options] <repo>
Options:'
get_help HELPOPT $SHAREDIR/epm-addrepo
message '
Examples:
epm repo add yandex
epm repo add "rpm http://somesite/pub/product x86_64 addon"
epm repo add --name akvis "rpm https://akvis-alt.sfo2.cdn.digitaloceanspaces.com x86_64 akvis"
epm repo add --disabled --name angie "rpm [angie] https://download.angie.software/angie/altlinux/11/ x86_64 main"
With --name, the repo is stored in sources.list.d/<name>.list.
With --disabled, the repo line is commented out.
Use repo/package install syntax to install from named repos:
epm install akvis/alivecolors
epm install angie/angie
'
}
# Extract repo name from repo string for use as filename
# Priority: --name parameter, [name] in repo string, last component
__get_repo_filename()
{
local repo="$*"
# Try to extract [name] from repo string: "rpm [name] URL arch comp"
local bracket_name="$(echo "$repo" | sed -n 's/.*\[\([^]]*\)\].*/\1/p')"
if [ -n "$bracket_name" ] ; then
echo "$bracket_name"
return
fi
# Use last component: "rpm URL arch component" -> "component"
local last="$(echo "$repo" | sed -e 's/[[:space:]]*$//' | awk '{print $NF}')"
# For deb repos: "deb URL suite component" -> last word
if [ -n "$last" ] && [ "$last" != "rpm" ] && [ "$last" != "deb" ] ; then
echo "$last"
return
fi
# Fallback: extract domain from URL
echo "$repo" | grep -o 'https\?://[^/[:space:]]*' | head -1 | sed -e 's|.*://||' -e 's|\..*||'
}
epm_addrepo() epm_addrepo()
{ {
local disabled=
local repo_name=
# Parse options
while true ; do
case "$1" in
-h|--help) # HELPOPT: print this help
epm_addrepo_help
return
;;
--disabled) # HELPOPT: add repo as disabled (commented out) in sources.list.d
disabled=1
shift
;;
--name) # HELPOPT: save repo to sources.list.d/<name>.list (enables repo/package install syntax)
shift
repo_name="$1"
shift
;;
--name=*) # HELPOPT: save repo to sources.list.d/<name>.list (--name=reponame)
repo_name="$(echo "$1" | sed -e 's|--name=||')"
shift
;;
*)
break
;;
esac
done
local repo="$*" local repo="$*"
# Handle --name: write repo to sources.list.d/<name>.list
if [ -n "$repo_name" ] ; then
if [ -z "$repo" ] ; then
fatal '--name requires a repo string'
fi
case $PMTYPE in
apt-rpm|apt-dpkg)
;;
*)
fatal '--name is only supported for apt-based systems'
;;
esac
local file="$APT_SOURCES_LIST_D/$repo_name.list"
local line="$repo"
[ -n "$disabled" ] && line="# $repo"
# check for duplicate (both enabled and disabled forms)
if [ -s "$file" ] && grep -q -F "$repo" "$file" ; then
info "Repo '$repo_name' already contains this source"
return
fi
# also check if repo already exists in other sources (including disabled)
if epm --quiet repo list --all "$repo" >/dev/null 2>&1 ; then
info "Repo is already in the sources list"
return
fi
if [ -n "$dryrun" ] ; then
echo "$line -> $file"
return
fi
__add_line_to_file "$file" "$line"
[ -n "$disabled" ] && info "Added disabled repo to $file" || info "Added repo to $file"
return
fi
# Handle copr/owner/project syntax for Fedora/RHEL # Handle copr/owner/project syntax for Fedora/RHEL
case "$1" in case "$1" in
copr/*) copr/*)
......
...@@ -127,7 +127,7 @@ epm_repo() ...@@ -127,7 +127,7 @@ epm_repo()
load_helper epm-reposave load_helper epm-reposave
epm_repostatus "$@" epm_repostatus "$@"
;; ;;
add) # HELPCMD: add package repo (etersoft, autoimports, archive 2017/01/31); run with param to get list add) # HELPCMD: add package repo (etersoft, autoimports, --disabled); run with param to get list
load_helper epm-addrepo load_helper epm-addrepo
epm_addrepo "$@" epm_addrepo "$@"
;; ;;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment