Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plugins.lunar: Clean up the code a bit, simplify things. #116

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 33 additions & 22 deletions libs/plugins.lunar
Original file line number Diff line number Diff line change
Expand Up @@ -71,33 +71,43 @@ plugin_call() {


update_plugin() {
local SECTION PLUGIN
local MODULE SECTION PLUGIN UPDATE_COMMAND
debug_msg "update_plugin($@)"
# update plugins of all modules or a specific one
#
# $1 - module name
# $2 - forced removal of plugin
# $2 - forced installation/removal of plugin
#
# scan module for plugins, and add/delete them as needed
if SECTION=$(find_section $1); then
if [ -d $MOONBASE/$SECTION/$1/plugin.d ]; then
if [ "$2" == "install" ] ; then
for PLUGIN in $MOONBASE/$SECTION/$1/plugin.d/*.plugin; do
debug_msg "Installed \"$(basename $PLUGIN)\""
install -m644 $PLUGIN $PLUGIN_DIR/
done
elif [ "$2" == "remove" ] || ! module_installed $1 ; then
for PLUGIN in $MOONBASE/$SECTION/$1/plugin.d/*.plugin; do
debug_msg "Removed \"$(basename $PLUGIN)\""
rm -f $PLUGIN_DIR/$(basename $PLUGIN)
done
else
for PLUGIN in $MOONBASE/$SECTION/$1/plugin.d/*.plugin; do
debug_msg "Installed \"$(basename $PLUGIN)\""
install -m644 $PLUGIN $PLUGIN_DIR/
done
fi
MODULE=$1
UPDATE_COMMAND=$2

# if an explicit command isn't given, figure out automatically
# whether to install plugins (for installed modules) or clean up
# plugins (for removed modules)
if [[ -z "$UPDATE_COMMAND" ]]; then
if module_installed $MODULE; then
UPDATE_COMMAND=install
else
UPDATE_COMMAND=remove
fi
fi

if SECTION=$(find_section $MODULE); then
for PLUGIN in $MOONBASE/$SECTION/$1/plugin.d/*.plugin
Copy link
Member

@v4hn v4hn Apr 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will fail when there is no plugin.d folder. True, it should always be there, but I can imagine better error handling than running

install -m 644 a/b/c/d/plugin.d/*.plugin $PLUGIN_DIR (or worse: it's rm equivalent)

below.

do
case $UPDATE_COMMAND in
install)
debug_msg "Installed \"$(basename $PLUGIN)\""
install -m 644 $PLUGIN $PLUGIN_DIR
;;

remove)
debug_msg "Removed \"$(basename $PLUGIN)\""
rm -f $PLUGIN_DIR/$(basename $PLUGIN)
;;
esac
done
reload_plugins
fi
}
Expand All @@ -108,8 +118,9 @@ update_plugins() {
debug_msg "update_plugins($@)"
# find all plugins in moonbase and run update_plugin() on them
verbose_msg "Updating plugins"
find $MOONBASE -wholename "*/plugin.d/*.plugin" | while read PLUGIN ; do
update_plugin `basename $(echo $PLUGIN | sed 's/\/plugin.d\/.*//g')`
find $MOONBASE -wholename "*/plugin.d/*.plugin" | while read PLUGIN
do
update_plugin $(basename ${PLUGIN%/plugin.d/*})
done
}

Expand Down