1
0
mirror of https://github.com/limosek/zaf.git synced 2024-11-22 02:19:06 +01:00

Reworked interface

This commit is contained in:
Lukas Macura 2016-04-01 15:51:45 +02:00
parent d0a3244f79
commit 99bd255e3f
6 changed files with 147 additions and 65 deletions

View File

@ -144,12 +144,18 @@ zaf_configure(){
fi fi
fi fi
fi fi
if which git >/dev/null; then
ZAF_GIT=1
else
ZAF_GIT=""
fi
zaf_get_option ZAF_CURL_INSECURE "Insecure curl (accept all certificates)" "1" "$1" zaf_get_option ZAF_CURL_INSECURE "Insecure curl (accept all certificates)" "1" "$1"
zaf_get_option ZAF_TMP_BASE "Tmp directory prefix (\$USER will be added)" "/tmp/zaf" "$1" zaf_get_option ZAF_TMP_BASE "Tmp directory prefix (\$USER will be added)" "/tmp/zaf" "$1"
zaf_get_option ZAF_LIB_DIR "Libraries directory" "/usr/lib/zaf" "$1" zaf_get_option ZAF_LIB_DIR "Libraries directory" "/usr/lib/zaf" "$1"
zaf_get_option ZAF_BIN_DIR "Directory to put binaries" "/usr/bin" "$1" zaf_get_option ZAF_BIN_DIR "Directory to put binaries" "/usr/bin" "$1"
zaf_get_option ZAF_PLUGINS_DIR "Plugins directory" "${ZAF_LIB_DIR}/plugins" "$1" zaf_get_option ZAF_PLUGINS_DIR "Plugins directory" "${ZAF_LIB_DIR}/plugins" "$1"
zaf_get_option ZAF_PLUGINS_REPO "Plugins reposiory" "https://github.com/limosek/zaf-plugins.git" "$1" [ "${ZAF_GIT}" -eq 1 ] && zaf_get_option ZAF_PLUGINS_GITURL "Git plugins repository" "https://github.com/limosek/zaf-plugins.git" "$1"
zaf_get_option ZAF_PLUGINS_URL "Plugins http[s] repository" "https://raw.githubusercontent.com/limosek/zaf-plugins/master/" "$1"
zaf_get_option ZAF_REPO_DIR "Plugins directory" "${ZAF_LIB_DIR}/repo" "$1" zaf_get_option ZAF_REPO_DIR "Plugins directory" "${ZAF_LIB_DIR}/repo" "$1"
zaf_get_option ZAF_AGENT_CONFIG "Zabbix agent config" "/etc/zabbix/zabbix_agentd.conf" "$1" zaf_get_option ZAF_AGENT_CONFIG "Zabbix agent config" "/etc/zabbix/zabbix_agentd.conf" "$1"
! [ -d "${ZAF_AGENT_CONFIGD}" ] && [ -d "/etc/zabbix/zabbix_agentd.d" ] && ZAF_AGENT_CONFIGD="/etc/zabbix/zabbix_agentd.d" ! [ -d "${ZAF_AGENT_CONFIGD}" ] && [ -d "/etc/zabbix/zabbix_agentd.d" ] && ZAF_AGENT_CONFIGD="/etc/zabbix/zabbix_agentd.d"
@ -160,11 +166,6 @@ zaf_configure(){
if zaf_is_root && ! which $ZAF_AGENT_BIN >/dev/null; then if zaf_is_root && ! which $ZAF_AGENT_BIN >/dev/null; then
zaf_err "Zabbix agent not installed? Use ZAF_ZABBIX_AGENT_BIN env variable to specify location. Exiting." zaf_err "Zabbix agent not installed? Use ZAF_ZABBIX_AGENT_BIN env variable to specify location. Exiting."
fi fi
if which git >/dev/null; then
ZAF_GIT=1
else
ZAF_GIT=""
fi
[ -n "$INSTALL_PREFIX" ] && zaf_install_dir "/etc" [ -n "$INSTALL_PREFIX" ] && zaf_install_dir "/etc"
if ! [ -f "${ZAF_CFG_FILE}" ]; then if ! [ -f "${ZAF_CFG_FILE}" ]; then
@ -181,7 +182,8 @@ zaf_configure(){
zaf_set_option ZAF_LIB_DIR "$ZAF_LIB_DIR" zaf_set_option ZAF_LIB_DIR "$ZAF_LIB_DIR"
zaf_set_option ZAF_BIN_DIR "$ZAF_BIN_DIR" zaf_set_option ZAF_BIN_DIR "$ZAF_BIN_DIR"
zaf_set_option ZAF_PLUGINS_DIR "$ZAF_PLUGINS_DIR" zaf_set_option ZAF_PLUGINS_DIR "$ZAF_PLUGINS_DIR"
zaf_set_option ZAF_PLUGINS_REPO "$ZAF_PLUGINS_REPO" zaf_set_option ZAF_PLUGINS_URL "$ZAF_PLUGINS_URL"
[ "${ZAF_GIT}" -eq 1 ] && zaf_set_option ZAF_PLUGINS_GITURL "$ZAF_PLUGINS_GITURL"
zaf_set_option ZAF_REPO_DIR "$ZAF_REPO_DIR" zaf_set_option ZAF_REPO_DIR "$ZAF_REPO_DIR"
zaf_set_option ZAF_AGENT_CONFIG "$ZAF_AGENT_CONFIG" zaf_set_option ZAF_AGENT_CONFIG "$ZAF_AGENT_CONFIG"
zaf_set_option ZAF_AGENT_CONFIGD "$ZAF_AGENT_CONFIGD" zaf_set_option ZAF_AGENT_CONFIGD "$ZAF_AGENT_CONFIGD"
@ -241,7 +243,8 @@ install)
zaf_install_bin $(zaf_getrest zaf) ${ZAF_BIN_DIR} zaf_install_bin $(zaf_getrest zaf) ${ZAF_BIN_DIR}
export INSTALL_PREFIX ZAF_CFG_FILE export INSTALL_PREFIX ZAF_CFG_FILE
if zaf_is_root; then if zaf_is_root; then
${INSTALL_PREFIX}/${ZAF_BIN_DIR}/zaf install zaf || zaf_err "Error installing zaf plugin." [ "${ZAF_GIT}" -eq 1 ] && ${INSTALL_PREFIX}/${ZAF_BIN_DIR}/zaf update
${INSTALL_PREFIX}/${ZAF_BIN_DIR}/zaf reinstall zaf || zaf_err "Error installing zaf plugin."
if zaf_is_root && ! zaf_check_agent_config; then if zaf_is_root && ! zaf_check_agent_config; then
echo "Something is wrong with zabbix agent config." echo "Something is wrong with zabbix agent config."
echo "Ensure that zabbix_agentd reads ${ZAF_AGENT_CONFIG}" echo "Ensure that zabbix_agentd reads ${ZAF_AGENT_CONFIG}"

View File

@ -1,8 +1,6 @@
# Control file related functions # Control file related functions
# Get block from stdin # Get item list from control on stdin
# $1 option
# $2 name
zaf_ctrl_get_items() { zaf_ctrl_get_items() {
grep '^Item ' | cut -d ' ' -f 2 | cut -d ':' -f 1 | tr '\r\n' ' ' grep '^Item ' | cut -d ' ' -f 2 | cut -d ':' -f 1 | tr '\r\n' ' '
} }
@ -57,14 +55,16 @@ zaf_block_get_option() {
# $1 - control file # $1 - control file
# $2 - option name # $2 - option name
zaf_ctrl_get_global_option() { zaf_ctrl_get_global_option() {
zaf_ctrl_get_global_block <$1 | zaf_block_get_moption "$2" || zaf_ctrl_get_global_block <$1 | zaf_block_get_option "$2" zaf_ctrl_get_global_block <$1 | zaf_block_get_moption "$2" \
|| zaf_ctrl_get_global_block <$1 | zaf_block_get_option "$2"
} }
# Get item specific option (single or multiline) # Get item specific option (single or multiline)
# $1 - control file # $1 - control file
# $2 - item name # $2 - item name
# $3 - option name # $3 - option name
zaf_ctrl_get_item_option() { zaf_ctrl_get_item_option() {
zaf_ctrl_get_item_block <$1 "$2" | zaf_block_get_moption "$3" || zaf_ctrl_get_item_block <$1 "$2" | zaf_block_get_option "$3" zaf_ctrl_get_item_block <$1 "$2" | zaf_block_get_moption "$3" \
|| zaf_ctrl_get_item_block <$1 "$2" | zaf_block_get_option "$3"
} }
# Check dependencies based on control file # Check dependencies based on control file
@ -82,24 +82,24 @@ zaf_ctrl_check_deps() {
} }
# Install binaries from control # Install binaries from control
# $1 control # $1 pluginurl
# $2 plugindir # $2 control
# $3 plugindir
zaf_ctrl_install() { zaf_ctrl_install() {
local binaries local binaries
local pdir local pdir
local script local script
local cmd local cmd
pdir="$2" pdir="$3"
export ZAF_PLUGIN_DIR="$pdir" binaries=$(zaf_ctrl_get_global_block <$2 | zaf_block_get_option "Install-bin")
binaries=$(zaf_ctrl_get_global_block <$1 | zaf_block_get_option "Install-bin")
for b in $binaries; do for b in $binaries; do
zaf_fetch_url "$url/$b" >"${ZAF_TMP_DIR}/$b" zaf_fetch_url "$1/$b" >"${ZAF_TMP_DIR}/$b"
zaf_install_bin "${ZAF_TMP_DIR}/$b" "$pdir" zaf_install_bin "${ZAF_TMP_DIR}/$b" "$pdir"
done done
script=$(zaf_ctrl_get_global_block <$1 | zaf_block_get_moption "Install-script") script=$(zaf_ctrl_get_global_block <$2 | zaf_block_get_moption "Install-script")
[ -n "$script" ] && eval "$script" [ -n "$script" ] && eval "$script"
cmd=$(zaf_ctrl_get_global_block <$1 | zaf_block_get_option "Install-cmd") cmd=$(zaf_ctrl_get_global_block <$2 | zaf_block_get_option "Install-cmd")
[ -n "$cmd" ] && $cmd [ -n "$cmd" ] && $cmd
} }
@ -109,33 +109,41 @@ zaf_ctrl_install() {
zaf_ctrl_generate_cfg() { zaf_ctrl_generate_cfg() {
local items local items
local cmd local cmd
local iscript
local ikey local ikey
local lock local lock
items=$(zaf_ctrl_get_items <"$1") items=$(zaf_ctrl_get_items <"$1")
for i in $items; do for i in $items; do
ikey=$(echo $i | tr -d '[]*&;:') iscript=$(echo $i | tr -d '[]*&;:')
params=$(zaf_ctrl_get_item_option $1 $i "Parameters")
if [ -n "$params" ]; then
ikey="$2.$i[*]"
else
ikey="$2.$i"
fi
lock=$(zaf_ctrl_get_item_option $1 $i "Lock") lock=$(zaf_ctrl_get_item_option $1 $i "Lock")
if [ -n "$lock" ]; then if [ -n "$lock" ]; then
lock="${ZAF_LIB_DIR}/zaflock $lock " lock="${ZAF_LIB_DIR}/zaflock $lock "
fi fi
cmd=$(zaf_ctrl_get_item_option $1 $i "Cmd") cmd=$(zaf_ctrl_get_item_option $1 $i "Cmd")
if [ -n "$cmd" ]; then if [ -n "$cmd" ]; then
echo "UserParameter=$2.${i},$lock$cmd"; echo "UserParameter=$ikey,${ZAF_LIB_DIR}/preload.sh $lock$cmd";
continue continue
fi fi
cmd=$(zaf_ctrl_get_item_option $1 $i "Function") cmd=$(zaf_ctrl_get_item_option $1 $i "Function")
if [ -n "$cmd" ]; then if [ -n "$cmd" ]; then
echo "UserParameter=$2.${i},${ZAF_LIB_DIR}/preload.sh $lock$cmd"; echo "UserParameter=$ikey,${ZAF_LIB_DIR}/preload.sh $lock$cmd";
continue; continue;
fi fi
cmd=$(zaf_ctrl_get_item_option $1 $i "Script") cmd=$(zaf_ctrl_get_item_option $1 $i "Script")
if [ -n "$cmd" ]; then if [ -n "$cmd" ]; then
zaf_ctrl_get_item_option $1 $i "Script" >${ZAF_TMP_DIR}/${ikey}.sh; zaf_ctrl_get_item_option $1 $i "Script" >${ZAF_TMP_DIR}/${iscript}.sh;
zaf_install_bin ${ZAF_TMP_DIR}/${ikey}.sh ${ZAF_PLUGINS_DIR}/$2/ zaf_install_bin ${ZAF_TMP_DIR}/${ikey}.sh ${ZAF_PLUGINS_DIR}/$2/
echo "UserParameter=$2.${i},${ZAF_LIB_DIR}/preload.sh $lock${ZAF_PLUGINS_DIR}/$2/${ikey}.sh"; echo "UserParameter=$ikey,${ZAF_LIB_DIR}/preload.sh $lock${ZAF_PLUGINS_DIR}/$2/${iscript}.sh";
continue; continue;
fi fi
zaf_err "Item $i declared in control file but has no Cmd, Function or Script!"
done done
} }

View File

@ -68,24 +68,34 @@ zaf_is_root(){
# $2 - directory # $2 - directory
zaf_install(){ zaf_install(){
zaf_dbg "Install file $1 to $INSTALL_PREFIX/$2/$(basename $1)" zaf_dbg "Install file $1 to $INSTALL_PREFIX/$2/$(basename $1)"
cp "$1" "$INSTALL_PREFIX/$2/$(basename $1)" $ZAF_DO cp "$1" "$INSTALL_PREFIX/$2/$(basename $1)"
} }
# $1 - src file # $1 - src file
# $2 - directory # $2 - directory
zaf_install_bin(){ zaf_install_bin(){
zaf_dbg "Install binary $1 to $INSTALL_PREFIX/$2/$(basename $1)" zaf_dbg "Install binary $1 to $INSTALL_PREFIX/$2/$(basename $1)"
cp "$1" "$INSTALL_PREFIX/$2/$(basename $1)" $ZAF_DO cp "$1" "$INSTALL_PREFIX/$2/$(basename $1)"
chmod +x "$INSTALL_PREFIX/$2/$(basename $1)" $ZAF_DO chmod +x "$INSTALL_PREFIX/$2/$(basename $1)"
} }
# $1 - directory # $1 - directory
zaf_install_dir(){ zaf_install_dir(){
zaf_dbg "Install directory $1 to $INSTALL_PREFIX/$1" zaf_dbg "Install directory $1 to $INSTALL_PREFIX/$1"
mkdir -p "$INSTALL_PREFIX/$1" $ZAF_DO mkdir -p "$INSTALL_PREFIX/$1"
} }
# $1 - file # $1 - file
zaf_touch(){ zaf_touch(){
zaf_dbg "Touch $INSTALL_PREFIX/$1" zaf_dbg "Touch $INSTALL_PREFIX/$1"
touch "$INSTALL_PREFIX/$1" $ZAF_DO touch "$INSTALL_PREFIX/$1"
}
# $1 - directory
zaf_uninstall(){
if [ -n "$INSTALL_PREFIX" ]; then
zaf_dbg "Removing $INSTALL_PREFIX/$1"
$ZAF_DO rm -rf "$INSTALL_PREFIX/$1"
else
zaf_dbg "Removing $1"
$ZAF_DO rm -rf "$1"
fi
} }
# Automaticaly install agent on debian # Automaticaly install agent on debian

View File

@ -1,7 +1,20 @@
#!/bin/sh #!/bin/sh
. /etc/zaf.conf . /etc/zaf.conf
[ -z "$ZAF_TMP_BASE" ] && ZAF_TMP_BASE=/tmp/zaf
ZAF_TMP_DIR="${ZAF_TMP_BASE}-${USER}"
trap "rm -rif ${ZAF_TMP_DIR}" EXIT
! [ -d "${ZAF_TMP_DIR}" ] && mkdir "${ZAF_TMP_DIR}"
[ -z "$ZAF_DEBUG" ] && ZAF_DEBUG=1
. ${ZAF_LIB_DIR}/zaf.lib.sh . ${ZAF_LIB_DIR}/zaf.lib.sh
. ${ZAF_LIB_DIR}/ctrl.lib.sh
. ${ZAF_LIB_DIR}/os.lib.sh
export ZAF_LIB_DIR
export ZAF_TMP_DIR
export ZAF_PLUGINS_DIR
[ -n "$*" ] && $@ [ -n "$*" ] && $@

View File

@ -1,4 +1,8 @@
# Hardcoded variables
ZAF_VERSION="trunk"
ZAF_URL="https://raw.githubusercontent.com/limosek/zaf/master/"
############################################ Common routines ############################################ Common routines
zaf_msg() { zaf_msg() {
@ -16,6 +20,10 @@ zaf_err() {
exit 1 exit 1
} }
zaf_version(){
echo $ZAF_VERSION
}
# Fetch url to stdout # Fetch url to stdout
# $1 url # $1 url
# It supports real file, file:// and other schemes known by curl # It supports real file, file:// and other schemes known by curl
@ -73,7 +81,7 @@ zaf_discovery_add_row(){
shift;shift shift;shift
echo " {" echo " {"
while [ -n "$1" ]; do while [ -n "$1" ]; do
echo -n ' "{#'$1'}":"'$2'" ' echo -n ' "'$1'":"'$2'" '
shift;shift shift;shift
if [ -n "$1" ]; then if [ -n "$1" ]; then
echo "," echo ","
@ -135,8 +143,12 @@ zaf_check_agent_config() {
# Update repo # Update repo
zaf_update_repo() { zaf_update_repo() {
[ "$ZAF_GIT" != 1 ] && { zaf_err "Git is not installed. Exiting."; } [ "$ZAF_GIT" != 1 ] && { zaf_err "Git is not installed. Exiting."; }
! [ -d ${ZAF_REPO_DIR} ] && git clone "${ZAF_PLUGINS_REPO}" "${ZAF_REPO_DIR}" if [ -z "${ZAF_PLUGINS_GITURL}" ] || [ -z "${ZAF_REPO_DIR}" ]; then
[ -n "${ZAF_PLUGINS_REPO}" ] && cd ${ZAF_REPO_DIR} && git pull zaf_err "This system is not configured for git repository."
else
[ ! -d "${ZAF_REPO_DIR}" ] && git clone "${ZAF_PLUGINS_GITURL}" "${ZAF_REPO_DIR}"
(cd ${ZAF_REPO_DIR} && git pull)
fi
} }
# Construct url from plugin name # Construct url from plugin name
@ -154,7 +166,7 @@ zaf_get_plugin_url() {
if [ -d "${ZAF_REPO_DIR}/$1" ]; then if [ -d "${ZAF_REPO_DIR}/$1" ]; then
url="${ZAF_REPO_DIR}/$1" url="${ZAF_REPO_DIR}/$1"
else else
url="${ZAF_PLUGINS_REPO}/$1"; url="${ZAF_PLUGINS_URL}/$1";
fi fi
fi fi
fi fi
@ -206,8 +218,9 @@ zaf_install_plugin() {
if zaf_prepare_plugin "$1" $plugindir; then if zaf_prepare_plugin "$1" $plugindir; then
[ "$ZAF_DEBUG" -gt 0 ] && zaf_plugin_info "${control}" [ "$ZAF_DEBUG" -gt 0 ] && zaf_plugin_info "${control}"
zaf_ctrl_check_deps "${control}" zaf_ctrl_check_deps "${control}"
zaf_ctrl_install "${control}" "${plugin}" zaf_ctrl_install "$1" "${control}" "${plugindir}"
zaf_ctrl_generate_cfg "${control}" "${plugin}" >${ZAF_AGENT_CONFIGD}/zaf_${plugin}.conf zaf_ctrl_generate_cfg "${control}" "${plugin}" \
| zaf_far '{PLUGINDIR}' "${plugindir}" >${ZAF_AGENT_CONFIGD}/zaf_${plugin}.conf
zaf_dbg "Generated ${ZAF_AGENT_CONFIGD}/zaf_${plugin}.conf" zaf_dbg "Generated ${ZAF_AGENT_CONFIGD}/zaf_${plugin}.conf"
else else
zaf_err "Cannot install plugin $plugin to $plugindir!" zaf_err "Cannot install plugin $plugin to $plugindir!"
@ -228,7 +241,6 @@ zaf_list_plugins() {
} }
zaf_is_plugin() { zaf_is_plugin() {
[ -d "$1" ] && [ -f "$1/control.zaf" ] && return
[ -d "$ZAF_PLUGINS_DIR/$1" ] && [ -f "$ZAF_PLUGINS_DIR/$1/control.zaf" ] && return [ -d "$ZAF_PLUGINS_DIR/$1" ] && [ -f "$ZAF_PLUGINS_DIR/$1/control.zaf" ] && return
false false
} }
@ -252,25 +264,39 @@ zaf_plugin_version() {
} }
zaf_list_plugin_items() { zaf_list_plugin_items() {
if [ -z "$1" ]; then local items
echo "Missing plugin name"; local i
exit 1 local p
local key
if ! zaf_is_plugin "$1"; then
zaf_err "Missing plugin name or plugin $1 unknown. ";
fi fi
plugindir="${ZAF_PLUGINS_DIR}/$1" plugindir="${ZAF_PLUGINS_DIR}/$1"
cfile="$plugindir/control" cfile="$plugindir/control.zaf"
if [ -d "$plugindir" ] ; then items=$(zaf_ctrl_get_items <$cfile)
zaf_ctrl_get_option "$cfile" Item for i in $items; do
p=$(zaf_ctrl_get_item_option $cfile $i "Parameters")
if [ -n "$p" ]; then
key="$1.$i[]"
else else
echo "Plugin $1 not installed" key="$1.$i"
fi fi
echo -n "$key "
done
echo
} }
zaf_list_items() { zaf_list_items() {
for p in $(zaf_list_plugins); do for p in $(zaf_list_plugins); do
zaf_list_plugin_items $p echo $p: $(zaf_list_plugin_items $p)
done done
} }
zaf_test_item() {
$ZAF_AGENT_BIN -t "$1"
}
zaf_remove_plugin() { zaf_remove_plugin() {
! [ -d ${ZAF_PLUGINS_DIR}/$1 ] && { zaf_err "Plugin $1 not installed!"; } ! [ -d ${ZAF_PLUGINS_DIR}/$1 ] && { zaf_err "Plugin $1 not installed!"; }
zaf_wrn "Removing plugin $1" zaf_wrn "Removing plugin $1"

50
zaf
View File

@ -1,9 +1,5 @@
#!/bin/sh #!/bin/sh
# Hardcoded variables
ZAF_VERSION="trunk"
ZAF_URL="https://raw.githubusercontent.com/limosek/zaf/master/"
ZAF_CFG_FILE="/etc/zaf.conf" ZAF_CFG_FILE="/etc/zaf.conf"
if [ -f $ZAF_CFG_FILE ]; then if [ -f $ZAF_CFG_FILE ]; then
. $ZAF_CFG_FILE . $ZAF_CFG_FILE
@ -11,7 +7,6 @@ else
echo "Missing config file $ZAF_CFG_FILE! Exiting." echo "Missing config file $ZAF_CFG_FILE! Exiting."
exit 2 exit 2
fi fi
[ -d $(dirname $0)/.git ] && ZAF_LIB_DIR=$(dirname $0)/lib
[ -z "$ZAF_TMP_BASE" ] && ZAF_TMP_BASE=/tmp/zaf [ -z "$ZAF_TMP_BASE" ] && ZAF_TMP_BASE=/tmp/zaf
ZAF_TMP_DIR="${ZAF_TMP_BASE}-${USER}" ZAF_TMP_DIR="${ZAF_TMP_BASE}-${USER}"
@ -19,10 +14,17 @@ trap "rm -rif ${ZAF_TMP_DIR}" EXIT
! [ -d "${ZAF_TMP_DIR}" ] && mkdir "${ZAF_TMP_DIR}" ! [ -d "${ZAF_TMP_DIR}" ] && mkdir "${ZAF_TMP_DIR}"
[ -z "$ZAF_DEBUG" ] && ZAF_DEBUG=1 [ -z "$ZAF_DEBUG" ] && ZAF_DEBUG=1
if [ -f ./lib/zaf.lib.sh ]; then
. ./lib/zaf.lib.sh
. ./lib/os.lib.sh
. ./lib/ctrl.lib.sh
[ -f ./lib/zaf.${ZAF_OS}.sh ] && . ./lib/zaf.${ZAF_OS}.sh
else
. ${ZAF_LIB_DIR}/zaf.lib.sh . ${ZAF_LIB_DIR}/zaf.lib.sh
. ${ZAF_LIB_DIR}/os.lib.sh . ${ZAF_LIB_DIR}/os.lib.sh
. ${ZAF_LIB_DIR}/ctrl.lib.sh . ${ZAF_LIB_DIR}/ctrl.lib.sh
[ -f ${ZAF_LIB_DIR}/zaf.${ZAF_OS}.sh ] && . ${ZAF_LIB_DIR}/zaf.${ZAF_OS}.sh [ -f ${ZAF_LIB_DIR}/zaf.${ZAF_OS}.sh ] && . ${ZAF_LIB_DIR}/zaf.${ZAF_OS}.sh
fi
case $1 in case $1 in
@ -43,17 +45,21 @@ show)
if zaf_list_plugins | grep -q "^$2"; then if zaf_list_plugins | grep -q "^$2"; then
zaf_plugin_info $ZAF_PLUGINS_DIR/$2/control.zaf zaf_plugin_info $ZAF_PLUGINS_DIR/$2/control.zaf
else else
if echo $2 |grep -q ^http; then
zaf_prepare_plugin "$2" "$ZAF_TMP_DIR/plugin" zaf_prepare_plugin "$2" "$ZAF_TMP_DIR/plugin"
zaf_plugin_info "$ZAF_TMP_DIR/plugin/control.zaf" zaf_plugin_info "$ZAF_TMP_DIR/plugin/control.zaf"
else
zaf_err "Plugin $2 not installed."
fi
fi fi
fi fi
;; ;;
list) plugins)
zaf_list_plugins zaf_list_plugins
;; ;;
list-items) items)
if [ -z "$2" ]; then if [ -z "$2" ]; then
zaf_list_items zaf_list_items
else else
@ -61,8 +67,18 @@ list-items)
fi fi
;; ;;
test-items) test)
zaf_show_plugin "$2" tst if [ -n "$2" ]; then
shift
plugins="$@"
else
plugins="$(zaf_list_plugins)"
fi
for p in $plugins; do
for i in $(zaf_list_plugin_items $p); do
echo $i: $(zaf_test_item $i)
done
done
;; ;;
install) install)
@ -84,7 +100,7 @@ reinstall)
[ -z "$@" ] && echo "$0 reinstall plugin [plugin]..." [ -z "$@" ] && echo "$0 reinstall plugin [plugin]..."
for p in $@; do for p in $@; do
if zaf_is_plugin "$p"; then if zaf_is_plugin "$p"; then
zaf_remove_plugin "$p" zaf_remove_plugin "$(basename $p)"
reinstalled=1 reinstalled=1
fi fi
zaf_install_plugin "$p" zaf_install_plugin "$p"
@ -115,20 +131,26 @@ self-upgrade)
;; ;;
self-remove) self-remove)
. /etc/zaf.conf
if [ "$2" = "force" ]; then if [ "$2" = "force" ]; then
rm -rf /etc/zaf.conf ${ZAF_PLUGINS_DIR} ${ZAF_REPO_DIR} ${ZAF_LIB_DIR} /usr/bin/zaf ${ZAF_AGENT_CONFIGD}/zaf_* rm -rf /etc/zaf.conf ${ZAF_PLUGINS_DIR} ${ZAF_REPO_DIR} ${ZAF_LIB_DIR} \
${ZAF_BIN_DIR}/zaf ${ZAF_AGENT_CONFIGD}/zaf_*
else else
echo "This will remove zaf from this computer and erase all configuration." echo "This will remove zaf from this computer and erase all configuration."
echo "This command will be executed:"
echo "rm -rf /etc/zaf.conf ${ZAF_PLUGINS_DIR} ${ZAF_REPO_DIR} ${ZAF_LIB_DIR} \
${ZAF_BIN_DIR}/zaf ${ZAF_AGENT_CONFIGD}/zaf_*"
echo
echo "To continue, please do $0 self-remove force" echo "To continue, please do $0 self-remove force"
fi fi
;; ;;
*) *)
echo "$0 update To update repo" echo "$0 update To update repo"
echo "$0 list To list installed plugins" echo "$0 plugins To list installed plugins"
echo "$0 show [plugin] To show installed plugins or plugin info" echo "$0 show [plugin] To show installed plugins or plugin info"
echo "$0 list-items [plugin] To list all suported items [for plugin]" echo "$0 items [plugin] To list all suported items [for plugin]"
echo "$0 test-items plugin To test all suported items for plugin" echo "$0 test [plugin] To test all suported items [for plugin]"
echo "$0 install plugin To install plugin" echo "$0 install plugin To install plugin"
echo "$0 remove plugin To remove plugin" echo "$0 remove plugin To remove plugin"
echo "$0 self-upgrade To self-upgrade zaf" echo "$0 self-upgrade To self-upgrade zaf"