1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677
|
#!/bin/sh
: << =cut
=head1 Name
munin-get - a simple tool for managing plugins from remote repositories
=head1 Features
The small management tool "munin-get" supports the following actions:
=over
=item clone one or more git repositories containing munin plugins
=item multiple remote repositories can be used
=item list all found plugins (including change timestamp and description)
=item "install" a plugin (by default to: @@DBDIR@@/munin-get-plugins)
=item "enable" a plugin (create a symlink to @@CONFDIR@@/plugins/)
=item upgrade plugins (and review changes before)
=back
The primary purpose of this tool is the simplification of the process of using plugins from munin's
contrib repository.
=head1 Usage
All actions except "install", "enable" and "disable" can be run as a regular user. Please note
that the non-privileged commands use directories relative to $HOME by default (can be overridden).
Thus sudo or a similar tool should be used for gaining privileges. Of course, everything can also
be done as root.
The separate "install" step works around potential problems with systemd hardening flags or other
security policies, which may prevent files in /root/ or below /home/ from being accessed by
the "munin-node" service process.
=head1 Examples
=head2 Discover, inspect, install, enable and test a plugin
munin-get update
munin-get list
munin-get search throughput
munin-get doc contrib/traffic
munin-get install contrib/traffic
munin-get enable contrib/traffic
munin-run traffic
service munin-node restart # for systemd: systemctl restart munin-node
=head2 Review and apply changes from the upstream repository
munin-get update
munin-get list-upgradeable
munin-get diff-upgradeable
munin-get upgrade
=head2 Add custom 3rd party git repositories
munin-get add-repository foo http://example.org/repos/munin-plugins.git
munin-get add-repository bar http://example.org/repos/munin-stuff.git branch-tested plugins/
munin-get update
=head1 Internals
Repositories are cloned below ~/.cache/munin/munin-get/repositories (see REPOSITORY_CACHE_BASE_DIR).
Manual changes in the cloned repositories should be avoided.
The separate "install" and "enable" procedure is necessary due to possible process namespace /
hardening features enabled for "munin-node". Thus the target of the symlink is located in a path
that can be expected to be usable even for a restricted "munin-node" process.
Additionally the separate "install" location allows the manual review of upstream changes before
applying these locally.
=head1 Author
Lars Kruse <devel@sumpfralle.de>
=head1 License
GPLv3+
=cut
set -eu
# cache directory (can be removed without harm)
MUNIN_GET_CACHE_DIR=${MUNIN_GET_CACHE_DIR:-$HOME/.cache/munin/munin-get}
# configuration directory
MUNIN_GET_CONFIG_DIR=${MUNIN_GET_CONFIG_DIR:-$HOME/.local/share/munin/munin-get}
# location for mirrored munin plugin repositories
REPOSITORY_CACHE_BASE_DIR="$MUNIN_GET_CACHE_DIR/repositories"
# location for generated man pages
MANPAGE_CACHE_BASE_DIR="$MUNIN_GET_CACHE_DIR/manpages"
# location for assembled meta data
METADATA_CACHE_BASE_DIR="$MUNIN_GET_CACHE_DIR/metadata"
# location for configuration files describing the specified munin plugin repositories
REPOSITORY_CONFIG_DIR="$MUNIN_GET_CONFIG_DIR/repositories"
# default plugin repository (mainainted by the munin community)
DEFAULT_REPO_MUNIN_CONTRIB_CONFIG='{"remote_url": "https://github.com/munin-monitoring/contrib.git", "branch": "master", "plugins_dir": "plugins"}'
# location of "installed" munin plugins (i.e. available at an accesible location - but maybe not installed, yet)
PLUGINS_INSTALL_DIR=${PLUGINS_INSTALL_DIR:-@@DBDIR@@/munin-get-plugins}
# location of "enabled" munin plugins (munin-node uses this directory by default)
PLUGINS_ENABLE_DIR=${PLUGINS_ENABLE_DIR:-@@CONFDIR@@/plugins}
# emit an error message and exit with an error
error_die() {
local text="$1"
printf >&2 'ERROR: %s\n' "$text"
exit 1
}
# emit a warning message to stderr
log_warning() {
local text="$1"
printf >&2 'WARNING: %s\n' "$text"
}
log_info() {
local text="$1"
printf '%s\n' "$text"
}
check_missing_executable() {
local executable="$1"
local package="$2"
if ! command -v "$executable" >/dev/null; then
error_die "Failed to find executable '$executable'. Please install the package '$package'."
fi
}
check_dependencies() {
check_missing_executable git git
check_missing_executable jo jo
check_missing_executable jq jq
}
check_doc_dependencies() {
check_missing_executable man man
if ! perldoc -V >/dev/null 2>&1; then
error_die "Failed to run 'perldoc'. Please install the package 'perl-doc'."
fi
}
# check a name (e.g. for a repository) for invalid characters
verify_simple_name() {
local label_name="$1"
local text="$2"
echo "$text" | grep -q '^[[:alnum:]-]\+$' \
|| error_die "The '$label_name' parameter contains invalid characters. Only letters and numbers are allowed."
}
# create a minimized clone of a git repository
git_clone_minimal() {
# The minimal set would include "--depth=1" - but we need the revisions in order to determine
# the date of change for each plugin.
git clone --quiet --single-branch --no-tags "$@"
}
# write the output of a given command to a file
# The output is not written, if the command fails.
write_safely_to_file() {
local filename="$1"
local output
shift
if output="$("$@")"; then
if echo "$output" >"$filename.tmp"; then
mv "$filename.tmp" "$filename"
else
rm -f "$filename.tmp"
fi
return 0
else
return 1
fi
}
# Store the description of a plugin repository. The repository is not cloned in this step.
add_repository() {
local repo_name="$1"
local remote_url="$2"
local branch="$3"
local plugins_dir="${4:-}"
write_safely_to_file "$REPOSITORY_CONFIG_DIR/$repo_name.json" \
jo -p name="$repo_name" remote_url="$remote_url" branch="$branch" plugins_dir="$plugins_dir"
}
# Check wether a local git repository exists.
verify_repository() {
local repo_name="$1"
[ -d "$REPOSITORY_CACHE_BASE_DIR/$repo_name/.git" ] \
|| error_die "there is no git repository ('$repo_name') at its expected location ($REPOSITORY_CACHE_BASE_DIR/$repo_name). Maybe you want to run 'munin-get update'?"
}
# Test wether a local git repository exists. Create the repository based on the previously stored
# configuration, if the repository is not cloned, yet.
verify_or_create_repository() {
local repo_name="$1"
local remote_url target_dir branch
[ -d "$REPOSITORY_CACHE_BASE_DIR/$repo_name/.git" ] && return 0
if [ -n "$(get_repository_config_json "$repo_name")" ]; then
remote_url=$(get_repository_config_value "$repo_name" "remote_url")
branch=$(get_repository_config_value "$repo_name" "branch")
log_info "Cloning git repository ..."
create_repository "$remote_url" "$REPOSITORY_CACHE_BASE_DIR/$repo_name" "$branch"
else
error_die "Missing configuration for repository '$repo_name'"
fi
}
# Test whether a specific plugin exists as a file in a repository. No error messages are emitted.
exists_repository_plugin() {
local repo_name="$1"
local plugin_name="$2"
[ -f "$(get_repository_plugin_filename "$repo_name" "$plugin_name")" ]
}
# Carefully check the existence of a plugin in a repository. Failure messages are reported.
verify_repository_plugin() {
local repo_name="$1"
local plugin_name="$2"
local relative_plugin_filename absolute_plugin_filename
verify_repository "$repo_name"
relative_plugin_filename=$(get_plugin_metadata_value "$repo_name" "$plugin_name" "filename")
[ -z "$relative_plugin_filename" ] && error_die "Failed to determine filename of given plugin ($repo_name/$plugin_name). Maybe it does not exist?"
absolute_plugin_filename="$REPOSITORY_CACHE_BASE_DIR/$repo_name/$relative_plugin_filename"
[ -e "$absolute_plugin_filename" ] || error_die "Failed to find plugin file ($absolute_plugin_filename). Maybe the repository cache needs to be updated?"
}
# List the names of configured repositories.
get_repository_names() {
{
echo "contrib"
if [ -d "$REPOSITORY_CONFIG_DIR" ]; then
find "$REPOSITORY_CONFIG_DIR" -type d -mindepth 1 -maxdepth 1 -print0 \
| xargs --null --no-run-if-empty basename --multiple \
| grep -x '^[[:alnum:]-]\+$'
fi
} | sort | uniq
}
# Clone a git repository in the cache directory.
create_repository() {
local remote_url="$1"
local target_dir="$2"
local branch="$3"
if [ -n "$branch" ]; then
git_clone_minimal --branch="$branch" "$remote_url" "$target_dir"
else
git_clone_minimal "$remote_url" "$target_dir"
fi
}
# Retrieve the repository configuration as JSON.
get_repository_config_json() {
local repo_name="$1"
local filename="$REPOSITORY_CONFIG_DIR/$repo_name.json"
if [ -e "$filename" ]; then
cat "$filename"
elif [ "$repo_name" = "contrib" ]; then
echo "$DEFAULT_REPO_MUNIN_CONTRIB_CONFIG"
else
true
fi
}
# Retrieve a value from the configuration of a repository.
get_repository_config_value() {
local repo_name="$1"
local key="$2"
get_repository_config_json "$repo_name" | jq -r '.'"$key"'//""'
}
# Retrieve a value from the meta data of a plugin.
get_plugin_metadata_value() {
local repo_name="$1"
local plugin_name="$2"
local key="$3"
local metadata_filename="$METADATA_CACHE_BASE_DIR/$repo_name/$plugin_name.json"
[ -e "$metadata_filename" ] || return 0
jq -r '.'"$key"'//""' <"$metadata_filename"
}
# Retrive the full filename of a plugin in a mirrored repository.
get_repository_plugin_filename() {
local repo_name="$1"
local plugin_name="$2"
echo "$REPOSITORY_CACHE_BASE_DIR/$repo_name/$(get_plugin_metadata_value "$repo_name" "$plugin_name" "filename")"
}
# Synchronize the local plugin repository repository mirror with the upstream repository.
# Users are not supposed to interfere with these mirrored repositories.
update_repository() {
local repo_name="$1"
verify_or_create_repository "$repo_name"
cd "$REPOSITORY_CACHE_BASE_DIR/$repo_name"
log_info "Updating local git repository ..."
git pull --quiet --ff-only
log_info "Assembling meta data ..."
update_repository_metadata "$repo_name"
}
# Test wether a target file is older than its dependency.
compiled_file_needs_update() {
local source_file="$1"
local target_file="$2"
[ ! -e "$target_file" ] || [ -n "$(find "$source_file" -newer "$target_file")" ]
}
# Regenerate the manpage of a plugin via perldoc.
update_plugin_manpage() {
local plugin_filename="$1"
local manpage_filename="$2"
# TODO: set "date"
write_safely_to_file "$manpage_filename" \
perldoc -o nroff -w "center:Munin Plugin ($repo_name)" -T -F "$plugin_filename"
}
# Update the meta data of a plugin (e.g. tile, update timestamp and description).
update_plugin_metadata() {
local repo_name="$1"
local plugin_name="$2"
local relative_plugin_filename="$3"
local metadata_filename="$4"
local summary_cache_file="$5"
local change_time description summary
if compiled_file_needs_update "$relative_plugin_filename" "$metadata_filename"; then
cd "$REPOSITORY_CACHE_BASE_DIR/$repo_name"
change_time=$(git log -1 --format=%at "$relative_plugin_filename")
description=$(perldoc -o nroff -T -F "$relative_plugin_filename" | sed '/^\.Vb [12]/d' | grep -A 1 '^.SH "NAME"$' | tail -1 | sed 's/^\(\\& *\)\?[^ ]* \\- \+//' | sed 's/\\//g')
summary=$(printf '%s/%-30s %s %s\n' "$repo_name" "$plugin_name" "$(date +%Y-%m-%d --date="@$change_time")" "$description")
write_safely_to_file "$metadata_filename" \
jo -p -- "timestamp=$change_time" -s "description=$description" -s "summary=$summary" -s "filename=$relative_plugin_filename"
# update the entry in the summary cache file
[ -e "$summary_cache_file" ] || touch "$summary_cache_file"
sed -i "#^$repo_name/$plugin_name #d" "$summary_cache_file"
printf '%s\n' "$summary" >>"$summary_cache_file"
fi
}
# Update the meta data of a repository. This includes the plugin's meta data and generated man
# pages.
update_repository_metadata() {
local repo_name="$1"
local plugin_name relative_plugin_filename
mkdir -p "$MANPAGE_CACHE_BASE_DIR/$repo_name"
mkdir -p "$METADATA_CACHE_BASE_DIR/$repo_name"
list_repository_plugin_files "$repo_name" | while read -r relative_plugin_filename; do
plugin_name=$(basename "$relative_plugin_filename")
update_plugin_metadata "$repo_name" "$plugin_name" "$relative_plugin_filename" "$METADATA_CACHE_BASE_DIR/$repo_name/$plugin_name.json" "$METADATA_CACHE_BASE_DIR/$repo_name/_summary_cache.txt"
done
}
# Show the man page of a plugin (via "man").
show_plugin_manpage() {
local repo_name="$1"
local plugin_name="$2"
local manpage_filename="$MANPAGE_CACHE_BASE_DIR/$repo_name/$plugin_name"
local plugin_filename
plugin_filename=$(get_repository_plugin_filename "$repo_name" "$plugin_name")
if compiled_file_needs_update "$plugin_filename" "$manpage_filename"; then
log_info "Generating man page for $repo_name/$plugin_name ..."
update_plugin_manpage "$plugin_filename" "$manpage_filename" \
|| error_die "Failed to generate man page: $repo_name/$plugin_name"
fi
man --local-file "$manpage_filename"
}
# Execute a given action for one or multiple repositories. If no repositories are given, then the
# action is executed for all repositories. This function is useful for command line handling.
do_for_some_or_all_repositories() {
local action="$1"
local repo_name
shift
if [ $# -gt 0 ]; then
for repo_name in "$@"; do
verify_simple_name "name" "$repo_name"
"$action" "$repo_name"
done
else
get_repository_names | while read -r repo_name; do
"$action" "$repo_name"
done
fi
}
# List all plugin files found in a mirrored repository.
list_repository_plugin_files() {
local repo_name="$1"
local plugins_dir
verify_repository "$repo_name"
plugins_dir=$(get_repository_config_value "$repo_name" "plugins_dir")
[ -z "$plugins_dir" ] && plugins_dir="."
cd "$REPOSITORY_CACHE_BASE_DIR/$repo_name"
find "$plugins_dir" -type f -executable | sed 's#^\./##' | sort
}
# List all plugins in a repository. The output includes the last change timestamp and a plugin
# description.
list_repository_plugins() {
local repo_name="$1"
local relative_plugin_filename plugin_name summary_cache_filename
summary_cache_filename="$METADATA_CACHE_BASE_DIR/$repo_name/_summary_cache.txt"
if [ -e "$summary_cache_filename" ]; then
sort "$summary_cache_filename"
else
list_repository_plugin_files "$repo_name" | while read -r relative_plugin_filename; do
plugin_name=$(basename "$relative_plugin_filename")
summary=$(get_plugin_metadata_value "$repo_name" "$plugin_name" "summary")
echo "${summary:-$repo_name/$plugin_name}"
done
fi
}
# Split the input parameter into two tokens (separated by a slash). The two tokens are output in
# separate lines.
split_slashed_repo_plugin_name() {
local full_name="$1"
local repo_name plugin_name
echo "$full_name" | grep -q "/" || error_die "Invalid plugin name in repository ('$full_name'). Use REPOSITORY/PLUGIN instead."
repo_name=$(echo "$full_name" | cut -f 1 -d /)
plugin_name=$(echo "$full_name" | cut -f 2- -d /)
verify_simple_name "name" "$repo_name"
[ -n "$plugin_name" ] || error_die "Empty plugin name"
echo "$repo_name"
echo "$plugin_name"
}
ACTION=${1:-help}
[ $# -gt 0 ] && shift
case "$ACTION" in
add-repository)
[ $# -lt 2 ] && error_die "at least two parameters (name and remote_url) are required"
[ $# -gt 4 ] && error_die "not more than four parameters (name, remote_url, branch, base_dir) are allowed"
repo_name="$1"
remote_url="$2"
branch="${3:-}"
plugins_dir="${4:-.}"
check_dependencies
verify_simple_name "name" "$repo_name"
add_repository "$repo_name" "$remote_url" "$branch" "$plugins_dir"
;;
remove-repository)
[ $# -ne 1 ] && error_die "exactly one parameter (name) is required"
repo_name="$1"
check_dependencies
verify_simple_name "name" "$repo_name"
verify_repository "$repo_name"
rm -rf "${REPOSITORY_CACHE_BASE_DIR:?}/$repo_name"
rm -rf "${MANPAGE_CACHE_BASE_DIR:?}/$repo_name"
rm -rf "${METADATA_CACHE_BASE_DIR:?}/$repo_name"
rm -f "$REPOSITORY_CONFIG_DIR/$repo_name.json"
;;
update)
check_dependencies
do_for_some_or_all_repositories "update_repository" "$@"
;;
search)
[ $# -ne 1 ] && error_die "exactly one parameter (a regular expression) is required"
regex=$1
check_dependencies
get_repository_names | while read -r repo_name; do
plugins_dir=$(get_repository_config_value "$repo_name" "plugins_dir")
find "$REPOSITORY_CACHE_BASE_DIR/$repo_name/$plugins_dir" -type f -executable -print0 \
| xargs --null -r grep --files-with-matches "$regex" \
| xargs -r basename --multiple | sed "s#^#$repo_name #"
done | sort | while read -r repo_name plugin_name; do
summary=$(get_plugin_metadata_value "$repo_name" "$plugin_name" "summary")
printf '%s\n' "$summary"
done
;;
list-repositories)
check_dependencies
get_repository_names
;;
list)
check_dependencies
do_for_some_or_all_repositories "list_repository_plugins" "$@"
;;
list-installed)
check_dependencies
get_repository_names | while read -r repo_name; do
[ -d "$PLUGINS_INSTALL_DIR/$repo_name" ] || continue
find "$PLUGINS_INSTALL_DIR/$repo_name" -type f -executable -print0 \
| xargs -r -0 -n 100 basename --multiple \
| sed "s#^#$repo_name/#"
done
;;
list-enabled)
check_dependencies
[ -d "$PLUGINS_ENABLE_DIR" ] || exit 0
find "$PLUGINS_ENABLE_DIR" -type l | while read -r plugin_symlink; do
target=$(readlink --canonicalize-missing "$plugin_symlink")
repo_plugin_path=${target#${PLUGINS_INSTALL_DIR%/}/}
[ "$repo_plugin_path" = "$target" ] && continue
parsed=$(split_slashed_repo_plugin_name "$repo_plugin_path")
repo_name=$(echo "$parsed" | sed -n 1p)
plugin_name=$(echo "$parsed" | sed -n 2p)
exists_repository_plugin "$repo_name" "$plugin_name" || continue
echo "$repo_name/$plugin_name"
done
;;
list-upgradeable|diff-upgradeable)
check_dependencies
"$0" list-installed | while read -r repo_plugin_path; do
parsed=$(split_slashed_repo_plugin_name "$repo_plugin_path")
repo_name=$(echo "$parsed" | sed -n 1p)
plugin_name=$(echo "$parsed" | sed -n 2p)
plugin_filename=$(get_repository_plugin_filename "$repo_name" "$plugin_name")
install_target_filename="$PLUGINS_INSTALL_DIR/$repo_name/$plugin_name"
if [ ! -e "$plugin_filename" ]; then
log_warning "Missing plugin file in repository cache ($plugin_filename)"
continue
fi
if [ ! -e "$install_target_filename" ]; then
log_warning "Missing installed plugin file ($install_target_filename)"
continue
fi
case "$ACTION" in
list-upgradeable)
cmp --silent "$plugin_filename" "$install_target_filename" || echo "$repo_name/$plugin_name"
;;
diff-upgradeable)
diff -ruN "$install_target_filename" "$plugin_filename"
;;
*)
;;
esac
done
;;
doc|install|upgrade|uninstall|enable|disable)
# the special action "upgrade" may be used without parameters
if [ "$ACTION" = "upgrade" ] && [ $# -eq 0 ]; then
"$0" list-upgradeable | while read -r repository_plugin; do
"$0" upgrade "$repository_plugin"
done
exit 0
fi
[ $# -ne 1 ] && error_die "exactly one parameter (plugin name in repository) is required"
repo_plugin_path="$1"
check_dependencies
parsed=$(split_slashed_repo_plugin_name "$repo_plugin_path")
repo_name=$(echo "$parsed" | sed -n 1p)
plugin_name=$(echo "$parsed" | sed -n 2p)
verify_repository_plugin "$repo_name" "$plugin_name"
source_filename=$(get_repository_plugin_filename "$repo_name" "$plugin_name")
install_target_filename="$PLUGINS_INSTALL_DIR/$repo_name/$plugin_name"
enabled_symlink="$PLUGINS_ENABLE_DIR/$plugin_name"
not_installed_message="Plugin is not installed ($install_target_filename)."
not_installed_message_with_hint="$not_installed_message Run '$(basename "$0") install $repo_plugin_path' before."
not_enabled_message="Plugin is not enabled ($enabled_symlink)."
case "$ACTION" in
doc)
check_doc_dependencies
show_plugin_manpage "$repo_name" "$plugin_name"
;;
install)
if [ -e "$install_target_filename" ]; then
log_warning "Plugin is already installed ($install_target_filename)"
else
mkdir -p "$PLUGINS_INSTALL_DIR/$repo_name"
cp "$source_filename" "$install_target_filename"
fi
;;
uninstall)
if [ -e "$enabled_symlink" ]; then
error_die "Refusing to uninstall plugin, while it is enabled ($enabled_symlink)"
elif [ -e "$install_target_filename" ]; then
rm "$install_target_filename"
else
log_warning "$not_installed_message"
fi
;;
upgrade)
if [ -e "$install_target_filename" ]; then
cp "$source_filename" "$install_target_filename"
else
error_die "$not_installed_message_with_hint"
fi
;;
enable)
if [ -e "$enabled_symlink" ]; then
log_warning "Plugin is already enabled ($enabled_symlink)"
else
[ -e "$install_target_filename" ] || error_die "$not_installed_message_with_hint"
ln -s "$install_target_filename" "$enabled_symlink"
fi
;;
disable)
if [ -e "$enabled_symlink" ]; then
rm "$enabled_symlink"
else
log_warning "$not_enabled_message"
fi
;;
*)
error_die "Internal error - unexpected action: $ACTION"
;;
esac
;;
clean)
rm -rf "${REPOSITORY_CACHE_BASE_DIR:?}"
rm -rf "${MANPAGE_CACHE_BASE_DIR:?}"
rm -rf "${METADATA_CACHE_BASE_DIR:?}"
;;
help|--help)
echo "Syntax: $(basename "$0") ACTION [ARGS [..]]"
echo " add-repository NAME REMOTE_URL [BRANCH [PLUGINS_DIR]]"
echo " remove-repository NAME"
echo " list-repositories"
echo " list-upgradeable"
echo " diff-upgradeable"
echo " update [REPOSITORY [..]]"
echo " list [REPOSITORY [..]]"
echo " search REGULAR_EXPRESSION"
echo " doc REPOSITORY/PLUGIN_NAME"
echo " install REPOSITORY/PLUGIN_NAME"
echo " uninstall REPOSITORY/PLUGIN_NAME"
echo " upgrade [REPOSITORY/PLUGIN_NAME]"
echo " enable REPOSITORY/PLUGIN_NAME"
echo " disable REPOSITORY/PLUGIN_NAME"
echo " clean"
echo " help"
echo
;;
*)
"$0" help >&2
exit 1
;;
esac
|