forked from lunar-linux/lunar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugins.lunar
142 lines (129 loc) · 4.7 KB
/
plugins.lunar
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
#!/bin/bash
############################################################
# #
# plugins.lunar - Lunar plugin code #
# #
############################################################
# #
# Copyright 2005 by Auke Kok under GPLv2 #
# #
############################################################
#
# plugin handler return status convention:
#
# when a handler is called, it should use the following return codes
#
# 0 - OK AND HALT, do not process other plugins
# 1 - FAIL, stop executing plugins and report an error
# 2 - OK AND CONTINUE or CONTINUE, run other plugins
#
plugin_register() {
# first arg: plugin type
# second arg: function hook name
# Defined plugin types:
# 1 - SOURCE_DOWNLOAD download some source code
# 2 - SOURCE_NEEDREFRESH source exists but needs refresh
# 3 - SOURCE_VERIFY perform integrity verification on a file
# 4 - SOURCE_UNPACK unpack a certain file to $(PWD)
# 5 - MODULE_CHECK integrity checking on installed modules
# 6 - KERNEL_UPDATEBOOTLOADER automate bootloader maintenance
# 7 - BUILD_CONFIGURE called before running CONFIGURE
# 8 - BUILD_PRE_BUILD ,, ,, ,, PRE_BUILD
# 9 - BUILD_BUILD ,, ,, ,, BUILD
# 10 - BUILD_INSTALL ,, ,, ,, INSTALL
# 11 - BUILD_POST_BUILD ,, ,, ,, POST_BUILD
# 12 - BUILD_POST_INSTALL called after running POST_INSTALL
# 13 - BUILD_PRE_REMOVE called before running PRE_REMOVE
# 14 - BUILD_POST_REMOVE ,, ,, ,, POST_REMOVE
# 15 - OPTIMIZE_MENU Display optimization menu's
LUNAR_PLUGINS=(${LUNAR_PLUGINS[@]} "$1:$2")
((LUNAR_PLUGIN_COUNT++))
debug_msg "Registered plugin #$LUNAR_PLUGIN_COUNT, $1 -> $2()"
}
plugin_call() {
local REQUESTED_TYPE COUNT THIS_TYPE THIS_HANDLER RETVAL
debug_msg "plugin_call($@)"
# scan available plugins for plugin_type $1 and pass args to it
REQUESTED_TYPE=$1
shift
for ((COUNT=0; COUNT < $LUNAR_PLUGIN_COUNT; COUNT++)); do
THIS_TYPE=${LUNAR_PLUGINS[$COUNT]%%:*}
THIS_HANDLER=${LUNAR_PLUGINS[$COUNT]#*:}
if [ "$REQUESTED_TYPE" == "$THIS_TYPE" ]; then
# we have identified a valid plugin for this type
$THIS_HANDLER $@
RETVAL=$?
if [ $RETVAL -eq 2 ]; then
continue
else
debug_msg "plugin $THIS_HANDLER returned \"$RETVAL\""
return $RETVAL
fi
fi
done
debug_msg "Finished running all plugins for type \"$REQUESTED_TYPE\""
return 2
}
update_plugin() {
local SECTION PLUGIN
debug_msg "update_plugin($@)"
# update plugins of all modules or a specific one
#
# $1 - module name
# $2 - forced 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
# Force a reload in the parent lin process,
# this is required if a module dependency adds a plugin
if [ "$MAIN_PPID" != "$PPID" ]; then
case "$(ps -o comm= -p $PPID)" in
lin)
kill -USR1 $PPID
;;
esac
else
kill -USR1 $$
fi
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
reload_plugins
fi
fi
}
update_plugins() {
local MODULE
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
local baseplugin
pluginbase=${PLUGIN%/plugin.d/*}
update_plugin ${pluginbase##*/}
done
}
reload_plugins() {
local ITERATOR
debug_msg "reload_plugins($@, TRAP=$TRAP)"
verbose_msg "reload_plugins(TRAP=$TRAP)"
# Unload current plugins
unset LUNAR_PLUGINS
for ITERATOR in $PLUGIN_DIR/*.plugin; do
. $ITERATOR
done
}