add plugin system

Support plugins in /usr/share/pkg/plugins/

  • if plugin not executable, skip it
  • to enable: chmod +x <plugin.sh>
  • to disable: chmod -x <plugin.sh>
  • or, enable/disable plugins:
    • pkg plugin enable <plugin-name>
    • pkg plugin disable <plugin-name>
  • execute them at these times:
	init/*.sh				# run once before any opts/params processed
	pre_cmd/*.sh			# run before each given command 
	post_cmd/*.sh			# run after each given command 
	pre_install/*.sh		# run before pkg install
	post_install/*.sh		# run after pkg install
	pre_uninstall/*.sh		# run before pkg uninstall
	post_uninstall/*.sh		# run after pkg uninstall
	pre_package/*.sh		# run before converting dir to pkg
	post_package/*.sh		# run after converting dir to pkg
	exit/*.sh				# run once, just before exit
  • pre_cmd, post_cmd: run immediately before/immediately after the given pkg cmd
    • NOTE: if you give multiple packages to an option, the pre_cmd/post_cmd hooks will execute for each package given example:
	# will execute appropriate hooks for each package
	`pkg -i vlc geany mtpaint`
  • example func to execute plugin:
run_plugins(){ # $1 must be valid hook
			
	local hooks='init|pre_cmd|post_cmd|pre_install|post_install|pre_uninstall|post_uninstall'

	if [ ! grep -q -E $1 "$hooks" ];then
		return 1
	fi
			
	if [ ! -d /usr/share/pkg/plugins/$hook/ ];then
		return 1
	fi

	cd /usr/share/pkg/plugins/$hook

	for plugin in *.sh
	do
		[ -x $plugin ] || continue
		$plugin
	done
			
	cd -
        return 0
}
Edited by sc0ttj