Rework of functions

pull/1/head
Lukas Macura 2016-03-30 16:09:02 +02:00
parent bffda469c8
commit 5a811dedf6
6 changed files with 381 additions and 190 deletions

View File

@ -1,8 +1,28 @@
# Zabbix Agent Framework
This tool is used to maintain external zabbix checks in *one place*. There are lot of places where it is possible to download many external checks.
But there is problem with installation, update and centralised management. This tool should do all of this in easy steps. Today is is in devel stage and not everything works.
I will try to make it working :)
But there is problem with installation, update and centralised management. This tool should do all of this in easy steps. In future it can be *starting point* to
install and configure zabbix agent on systems with one step. Primary goal is not to make all plugins available here but to be able to use any plugin and decentralized development.
If you are maintainer of some external check, it is enough to create zaf file in your repo and use zaf installer everywhere.
## Features
* Minimal dependencies. At this time, only sh, sed, awk and curl
* Minimal runtime version to fit on different systems (openwrt, debian, ubuntu, ...)
* Modular. Zaf module can be maintained externaly from this framework
* Sharing code. Many zabbix external checks share common shell functions.
* Zabbix discovery simplification. Creating zabbix item for discovery is not so easy in shell based system and result is not nice. But you can use framework function to do so.
* OS packaging support.
## Installing Zaf
You need to be root and you must have curl installed on your system. Depending on your system, github certificates may not be available so you have to use *-k* option for curl (insecure). Default installation type is silent. So there will be no questions and everything will be autodetected. This command should be used on most systems:
```
curl https://raw.githubusercontent.com/limosek/zaf/master/install.sh | sh
```
but in openwrt, you should use this:
```
curl -k https://raw.githubusercontent.com/limosek/zaf/master/install.sh | sh
```
## Example
Best way how to explain everything is example. Supposing we are working on debian-like system.

View File

@ -2,15 +2,27 @@
if ! [ "$(basename $0)" = "install.sh" ]; then
# We are runing from stdin
url="https://raw.githubusercontent.com/limosek/zaf/master/"
if ! which curl >/dev/null;
then
echo "Curl not found. Cannot continue. Please install it."
exit 2
fi
echo "Installing from url $url..." >&2
[ -z "$*" ] && silent=silent
set -e
mkdir -p /tmp/zaf-installer \
&& cd /tmp/zaf-installer \
&& curl -f -k -s -L -o - https://raw.githubusercontent.com/limosek/zaf/master/install.sh >install.sh \
&& (for i in lib/zaf.lib.sh lib/os.lib.sh lib/ctrl.lib.sh install.sh ; do curl -f -k -s -L -o - "$url/$i") >install.sh \
&& chmod +x install.sh \
&& exec ./install.sh defconf
&& exec ./install.sh $silent "$@"
exit
fi
ZAF_CFG_FILE=/etc/zaf.conf
. $(dirname $0)/lib/zaf.lib.sh
. $(dirname $0)/lib/os.lib.sh
. $(dirname $0)/lib/ctrl.lib.sh
zaf_msg() {
[ "$ZAF_DEBUG" = "1" ] && echo $@
@ -44,13 +56,14 @@ zaf_get_option(){
else
zaf_msg "Got $2 <$1> from USER: $opt"
fi
eval "$1='$opt'"
eval "$1='$opt'"
}
# Sets option to zaf.conf
# $1 option name
# $2 option value
zaf_set_option(){
local description
if ! grep -q "^$1=" ${ZAF_CFG_FILE}; then
echo "$1='$2'" >>${ZAF_CFG_FILE}
zaf_msg "Saving $1 to $2 in ${ZAF_CFG_FILE}" >&2
@ -77,25 +90,45 @@ zaf_install_exe(){
chmod +x "$2"
}
zaf_detect_pkg() {
if which dpkg >/dev/null; then
ZAF_PKG="dpkg"
ZAF_CURL_INSECURE=0
return
fi
if which opkg >/dev/null; then
ZAF_PKG="opkg"
ZAF_AGENT_RESTART="/etc/init.d/zabbix_agentd restart"
ZAF_AGENT_CONFIGD="/var/run/zabbix_agentd.conf.d/"
ZAF_AGENT_CONFIG="/etc/zabbix_agentd.conf"
ZAF_CURL_INSECURE=1
return
fi
if which rpm >/dev/null; then
ZAF_PKG="rpm"
ZAF_CURL_INSECURE=0
return
# Automaticaly install agent if supported
zaf_install_agent() {
case $ZAF_OS in
Debian)
curl "http://repo.zabbix.com/zabbix/3.0/debian/pool/main/z/zabbix-release/zabbix-release_3.0-1+${ZAF_CODENAME}_all.deb" >"/tmp/zaf-installer/zabbix-release_3.0-1+${ZAF_CODENAME}_all.deb" \
&& dpkg -i "/tmp/zaf-installer/zabbix-release_3.0-1+${ZAF_CODENAME}_all.deb" \
&& apt-get update \
&& apt-get install $ZAF_AGENT_PKG
;;
esac
}
# Set config option in zabbix agent
# $1 option
# $2 value
zaf_agent_set_option() {
local option="$1"
local value="$2"
if grep ^$option\= $ZAF_AGENT_CONFIG; then
echo "Moving option $option to zaf config part."
sed -i "s/$option=/#$option=/" $ZAF_AGENT_CONFIG
fi
echo "$option=$value" >> "$ZAF_AGENT_CONFIGD/zaf_options.conf"
}
# Automaticaly configure agent if supported
# Parameters are in format zabbixconfvar=value
zaf_configure_agent() {
local pair
local option
local value
touch "$ZAF_AGENT_CONFIGD/zaf_options.conf"
for pair in "$@"; do
echo $pair | grep -q '^Z\_' || continue
option=$(echo $pair|cut -d '=' -f 1|cut -d '_' -f 2)
value=$(echo $pair|cut -d '=' -f 2-)
zaf_agent_set_option "$option" "$value"
done
}
zaf_no_perms(){
@ -105,8 +138,19 @@ zaf_no_perms(){
zaf_configure(){
[ "$1" = "user" ] && ZAF_DEBUG=1
zaf_detect_pkg ZAF_PKG "Packaging system to use" "$(zaf_detect_pkg)" "$1"
[ "$1" = "interactive" ] && ZAF_DEBUG=1
zaf_detect_system
zaf_get_option ZAF_PKG "Packaging system to use" "$ZAF_PKG" "$1"
zaf_get_option ZAF_OS "Operating system to use" "$ZAF_OS" "$1"
zaf_get_option ZAF_OS_CODENAME "Operating system codename" "$ZAF_OS_CODENAME" "$1"
zaf_get_option ZAF_AGENT_PKG "Zabbix agent package" "$ZAF_AGENT_PKG" "$1"
if [ -n "$ZAF_AGENT_PKG" ]; then
if ! zaf_check_deps "$ZAF_AGENT_PKG"; then
if [ "$1" = "silent" ]; then
zaf_install_agent
fi
fi
fi
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_LIB_DIR "Libraries directory" "/usr/lib/zaf" "$1"
@ -134,6 +178,9 @@ zaf_configure(){
fi
zaf_set_option ZAF_PKG "${ZAF_PKG}"
zaf_set_option ZAF_OS "${ZAF_OS}"
zaf_set_option ZAF_OS_CODENAME "${ZAF_OS_CODENAME}"
zaf_set_option ZAF_AGENT_PKG "${ZAF_AGENT_PKG}"
zaf_set_option ZAF_GIT "${ZAF_GIT}"
zaf_set_option ZAF_CURL_INSECURE "${ZAF_CURL_INSECURE}"
zaf_set_option ZAF_TMP_BASE "$ZAF_TMP_BASE"
@ -154,16 +201,13 @@ fi
ZAF_TMP_DIR="${ZAF_TMP_BASE}-${USER}-$$"
case $1 in
reconf)
zaf_configure user
interactive)
zaf_configure interactive
$0 install
;;
defconf)
silent)
zaf_configure silent
$0 install
;;
*)
zaf_configure
zaf_configure_agent "$@"
rm -rif ${ZAF_TMP_DIR}
mkdir -p ${ZAF_TMP_DIR}
mkdir -p ${ZAF_LIB_DIR}
@ -175,7 +219,7 @@ defconf)
mkdir -p ${ZAF_PLUGINS_DIR}
zaf_install_exe $(zaf_getrest zaf) /usr/bin/zaf
/usr/bin/zaf install zaf
if ! /usr/bin/zaf check-agent-config; then
if ! zaf_check_agent_config; then
echo "Something is wrong with zabbix agent config."
echo "Ensure that zabbix_agentd reads ${ZAF_AGENT_CONFIG}"
echo "and there is Include=${ZAF_AGENT_CONFIGD} directive inside."
@ -185,6 +229,16 @@ defconf)
rm -rif ${ZAF_TMP_DIR}
echo "Install OK. Use 'zaf' without parameters to continue."
;;
*)
echo
echo "Please specify how to install."
echo "ZAF_CONFIG_OPTION=value [...] install.sh {silent|interactive} Z_option=value [...]"
echo "Example 1 (default install): install.sh silent"
echo 'Example 2 (preconfigure agent options): install.sh silent Z_Server=zabbix.server Z_ServerActive=zabbix.server Z_Hostname=$(hostname)'
echo "Example 3 (preconfigure zaf packaging system to use): ZAF_PKG=dpkg install.sh silent"
echo "Example 4 (interactive): install.sh interactive"
echo
exit 1
esac

112
lib/ctrl.lib.sh Normal file
View File

@ -0,0 +1,112 @@
# Control file related functions
# Check plugin url
# $1 plugin uri
# $2 local file to fetch
zaf_plugin_fetch_control() {
[ -z "$1" ] && return -1
local name=$(basename "$1")
zaf_fetch_url "$1/control.zaf" >"$2"
}
# Get block from stdin
# $1 option
# $2 name
zaf_ctrl_get_items() {
grep '^Item ' | cut -d ' ' -f 2 | cut -d ':' -f 1 | tr '\r\n' ' '
}
# Get item body from stdin
# $1 itemname
zaf_ctrl_get_item_block() {
grep -v '^#' | awk '/^Item '$1'/ { i=0;
while (i==0) {
getline;
if (/^\/Item/) exit;
print $0;
}}'
}
# Get global plugin block body from stdin
# $1 itemname
zaf_ctrl_get_global_block() {
grep -v '^#' | awk '{ i=0;
while (i==0) {
getline;
if (/^Item /) exit;
print $0;
}}'
}
# Get item multiline option
# $1 optionname
zaf_block_get_moption() {
awk '/^'$1'::$/ { i=0;
while (i==0) {
getline;
if (/^::$/) exit;
print $0;
}}'
}
# Get item singleline option
# $1 optionname
zaf_block_get_option() {
grep "^$1:" | cut -d ' ' -f 2- | tr -d '\r\n'
}
zaf_ctrl_check_deps() {
local deps
deps=$(zaf_ctrl_get_global_block <$1 | zaf_block_get_option "Depends-${ZAF_PKG}" )
zaf_check_deps $deps
deps=$(zaf_ctrl_get_global_block <$1 | zaf_block_get_option "Depends-bin" )
for cmd in $deps; do
if ! which $cmd >/dev/null; then
echo "Missing binary dependency $cmd. Please install it first."
return 1
fi
done
}
# Install binaries from control
# $1 control
# $2 plugindir
zaf_ctrl_install() {
local binaries
local pdir
local script
local cmd
pdir="$2"
binaries=$(zaf_ctrl_get_global_block <$1 | zaf_block_get_option "Install-bin" | zaf_far '{PLUGINDIR}' "$plugindir" )
for b in $binaries; do
zaf_fetch_url "$url/$b" >"$pdir/$b"
chmod +x "$pdir/$b"
done
script=$(zaf_ctrl_get_global_block <$1 | zaf_block_get_moption "Install-script" | zaf_far '{PLUGINDIR}' "$plugindir" )
[ -n "$script" ] && eval $script
cmd=$(zaf_ctrl_get_global_block <$1 | zaf_block_get_option "Install-cmd" | zaf_far '{PLUGINDIR}' "$plugindir" )
[ -n "$cmd" ] && $cmd
}
# Generates zabbix cfg from control file
# $1 control
# $2 pluginname
zaf_ctrl_generate_cfg() {
local items
local cmd
local ilock
items=$(zaf_ctrl_get_items <"$1")
for i in $items; do
block=$(zaf_ctrl_get_item_block <$1 $i)
ilock=$(echo $i | tr -d '[]*&;:')
cmd=$(zaf_block_get_option <$1 "Cmd")
[ -n "$cmd" ] && { echo "UserParameter=$2.${i},$cmd"; continue; }
cmd=$(zaf_block_get_option <$1 "Function")
[ -n "$cmd" ] && { echo "UserParameter=$2.${i},${ZAF_LIB_DIR}/preload.sh $cmd"; continue; }
cmd=$(zaf_block_get_moption <$1 "Script")
[ -n "$cmd" ] && { zaf_block_get_moption <$1 "Script" >${ZAF_PLUGIN_DIR}/$2/$ilock.sh; echo "UserParameter=$2.${i},${ZAF_PLUGIN_DIR}/$ilock.sh"; continue; }
done
}

74
lib/os.lib.sh Normal file
View File

@ -0,0 +1,74 @@
# Os related functions
zaf_detect_system() {
if which dpkg >/dev/null; then
ZAF_PKG="dpkg"
ZAF_OS=$(lsb_release -is)
ZAF_OS_CODENAME=$(lsb_release -cs)
ZAF_CURL_INSECURE=0
ZAF_AGENT_PKG="zabbix-agent"
return
else if which rpm >/dev/null; then
ZAF_PKG="rpm"
ZAF_OS=$(lsb_release -is)
ZAF_OS_CODENAME=$(lsb_release -cs)
ZAF_CURL_INSECURE=0
ZAF_AGENT_PKG="zabbix-agent"
return
else if which opkg >/dev/null; then
ZAF_PKG="opkg"
. /etc/openwrt_release
ZAF_OS="$DISTRIB_ID"
ZAF_OS_CODENAME="$DISTRIB_CODENAME"
ZAF_AGENT_RESTART="/etc/init.d/zabbix_agentd restart"
ZAF_AGENT_CONFIGD="/var/run/zabbix_agentd.conf.d/"
ZAF_AGENT_CONFIG="/etc/zabbix_agentd.conf"
ZAF_AGENT_PKG="zabbix-agentd"
ZAF_CURL_INSECURE=1
return
else
ZAF_PKG="unknown"
ZAF_OS="unknown"
ZAF_OS_CODENAME="unknown"
ZAF_AGENT_PKG=""
fi
fi
fi
}
# Check if dpkg dependency is met
# $* - packages
zaf_check_deps_dpkg() {
dpkg-query -f '${Package}\n' -W $* >/dev/null
}
# Check if dpkg dependency is met
# $* - packages
zaf_check_deps_rpm() {
rpm --quiet -qi $*
}
# Check if dpkg dependency is met
# $* - packages
zaf_check_deps_opkg() {
local p
for p in $*; do
opkg info $p | grep -q 'Package:' || { echo "Missing package $p" >&2; return 1; }
done
}
# Check dependency based on system
zaf_check_deps() {
case $ZAF_PKG in
dpkg) zaf_check_deps_dpkg $*
;;
opkg) zaf_check_deps_opkg $*
;;
rpm) zaf_check_deps_rpm $*
;;
*) return
;;
esac
}

View File

@ -1,14 +1,4 @@
############################################ Init part
# Get all config variables and initialise TMP
! [ -f /etc/zaf.conf ] && { echo "Config file /etc/zaf.conf does not exists! Exiting."; exit 2; }
. /etc/zaf.conf
. ${ZAF_LIB_DIR}/jshn.sh
ZAF_TMP_DIR="${ZAF_TMP_BASE}-${USER}-$$"
trap "rm -rif ${ZAF_TMP_DIR}" EXIT
! [ -d "${ZAF_TMP_DIR}" ] && mkdir "${ZAF_TMP_DIR}"
############################################ Common routines
zaf_msg() {
@ -32,7 +22,7 @@ zaf_fetch_url() {
http|https|ftp|file)
[ "${ZAF_CURL_INSECURE}" = "1" ] && insecure="-k"
zaf_msg curl $insecure -f -s -L -o - "$1"
curl $insecure -f -s -L -o - "$1";
curl $insecure -f -s -L -o - "$1"
;;
esac
}
@ -113,81 +103,13 @@ zaf_update_repo() {
[ -n "${ZAF_PLUGINS_REPO}" ] && cd ${ZAF_REPO_DIR} && git pull
}
# Check plugin url
# $1 plugin uri
# $2 local file to fetch
zaf_plugin_fetch_control() {
[ -z "$1" ] && return -1
local name=$(basename "$1")
zaf_fetch_url "$1/control" >"$2"
}
# Get option from control file
# $1 control file
# $2 option
zaf_ctrl_get_option() {
awk 'BEGIN { FS=": "; }; /^'$2': / { printf $2$3$4$5"\n"; }' <$1
}
# Get description from control file
# $1 control file
# $2 option
zaf_ctrl_get_description() {
awk \
"/^$2/"' { i=1;
while (1) {
getline; if (substr($0,0,1) != " ") exit;
printf $0"\n";
}
}' <$1
}
zaf_ctrl_binary_deps() {
local deps
deps=$(zaf_ctrl_get_option "$1" Binary-Depends)
for cmd in $deps; do
if ! which $cmd >/dev/null; then
echo "Missing binary dependency $cmd. Please install it first."
exit 5
fi
done
}
zaf_ctrl_install_bin() {
local binaries
local pdir
binaries=$(zaf_ctrl_get_option "$1" Install-bin)
pdir="${ZAF_PLUGINS_DIR}/${2}/"
for b in $binaries; do
zaf_fetch_url "$url/$b" >"$pdir/$b"
chmod +x "$pdir/$b"
done
}
# Generates zabbix cfg from control file
# $1 control
# $2 pluginname
zaf_ctrl_generate_cfg() {
local items
local cmd
local ilock
items=$(zaf_ctrl_get_option "$1" Item)
for i in $items; do
ilock=$(echo $i | tr -d '[]*&;:')
cmd=$(zaf_ctrl_get_option "$1" "Item-cmd-$i")
echo "UserParameter=$2.${i},$cmd"
done
}
# Install plugin.
# Parameter is url, directory or plugin name (will be searched in default plugin dir)
zaf_install_plugin() {
# Construct url from plugin name
# It can be http[s]://url
# /path (from file)
# name (to try from repo)
zaf_get_plugin_url() {
local url
local control
local plugin
local plugindir
if echo "$1" | grep -q '/'; then
url="$1" # plugin with path - installing from directory
else
@ -201,51 +123,73 @@ zaf_install_plugin() {
fi
fi
fi
plugin="plug$$"
rm -rf ${ZAF_TMP_DIR}/${plugin}
control=${ZAF_TMP_DIR}/${plugin}/control
mkdir -p "${ZAF_TMP_DIR}/${plugin}"
echo $url
}
# $1 - control
# $2 - if nonempty, show informarions instead of setting env
zaf_plugin_info() {
local control="$1"
plugin=$(zaf_ctrl_get_global_block <"${control}" | zaf_block_get_option Plugin)
pdescription=$(zaf_ctrl_get_global_block <"${control}" | zaf_block_get_moption Description)
pmaintainer=$(zaf_ctrl_get_global_block <"${control}" | zaf_block_get_option Maintainer)
pversion=$(zaf_ctrl_get_global_block <"${control}" | zaf_block_get_option Version)
purl=$(zaf_ctrl_get_global_block <"${control}" | zaf_block_get_option Url)
phome=$(zaf_ctrl_get_global_block <"${control}" | zaf_block_get_option Home)
pitems=$(zaf_ctrl_get_items <"${control}")
[ -z "$2" ] && return
echo
echo -n "Plugin $plugin "; [ -n "$version" ] && echo -n "version ${pversion}"; echo ":"
echo "$pdescription"; echo
[ -n "$pmaintainer" ] && echo "Maintainer: $pmaintainer"
[ -n "$purl" ] && echo "Url: $purl"
[ -n "$phome" ] && echo "Home: $phome"
echo
echo "Items: $pitems"
echo
}
# Prepare plugin into tmp dir
# $1 is url, directory or plugin name (will be searched in default plugin dir).
# $2 is directory to prepare.
zaf_prepare_plugin() {
url=$(zaf_get_plugin_url "$1")
plugindir="$2"
control=${plugindir}/control.zaf
echo "Fetching control file from $url ..."
if zaf_plugin_fetch_control "$url" "${control}"; then
plugin=$(zaf_ctrl_get_option "${control}" Plugin)
if [ -n "$plugin" ]; then
echo Installing plugin $plugin from $url...
plugindir="${ZAF_PLUGINS_DIR}/${plugin}"
zaf_ctrl_binary_deps "${control}"
mkdir -p $plugindir
zaf_ctrl_install_bin "${control}" "${plugin}"
zaf_ctrl_generate_cfg "${control}" "${plugin}" | \
zaf_plugin_info "${control}"
zaf_ctrl_check_deps "${control}"
else
echo "Cannot fetch control file!"
return 1
fi
}
zaf_install_plugin() {
mkdir "${ZAF_TMP_DIR}/plugin"
if zaf_prepare_plugin "$1" "${ZAF_TMP_DIR}/plugin"; then
plugindir="${ZAF_PLUGINS_DIR}"/$plugin
echo $plugindir;exit;
if zaf_prepare_plugin "$1" $plugindir; then
zaf_ctrl_check_deps "${control}"
zaf_ctrl_install "${control}" "${plugin}"
zaf_ctrl_generate_cfg "${control}" "${plugin}"
exit;
#| \
zaf_far '{PLUGINDIR}' "$plugindir" | \
zaf_far '{ZAFLIB}' ". ${ZAF_LIB_DIR}/zaf.lib.sh; . " | \
zaf_far '{ZAFFUNC}' ". ${ZAF_LIB_DIR}/zaf.lib.sh; " | \
zaf_far '{ZAFLIBDIR}' "${ZAF_LIB_DIR}" | \
zaf_far '{ZAFLOCK}' "${ZAF_LIB_DIR}/zaflock '$plugin' " \
>${ZAF_AGENT_CONFIGD}/zaf_${plugin}.conf
zaf_restart_agent
cp $control "$plugindir"/
zaf_fetch_url $url/template.xml >"$plugindir"/template.xml
>$plugindir/zabbix.conf
else
echo "Bad control file $control ($url)!"
cat $control
exit 4
fi
else
echo "Cannot fetch control file!"
exit 4
fi
}
# Show installed plugins (human readable)
# $1 - plugin
zaf_show_installed_plugins() {
local cfile
local plugin
cd ${ZAF_PLUGINS_DIR}; ls --hide '.' -1 | while read plugin; do
cfile=${ZAF_PLUGINS_DIR}/$plugin/control
echo Plugin $plugin:
zaf_ctrl_get_description $cfile Plugin:
echo " Homepage:" $(zaf_ctrl_get_option $cfile Web)
echo " Maintainer:" $(zaf_ctrl_get_option $cfile Maintainer)
echo
done
}
# List installed plugins
@ -256,41 +200,6 @@ zaf_list_plugins() {
cd ${ZAF_PLUGINS_DIR}; ls -1
}
zaf_show_plugin() {
local items
local plugindir
local cfile
local tst
if [ -z "$1" ]; then
echo "Missing plugin name";
exit 1
fi
[ -n "$2" ] && tst=1
plugindir="${ZAF_PLUGINS_DIR}/$1"
cfile="$plugindir/control"
if [ -d "$plugindir" ] ; then
echo "Plugin $1:"
zaf_ctrl_get_description "$cfile" "Plugin:"
echo " Homepage:" $(zaf_ctrl_get_option $cfile Web)
echo " Maintainer:" $(zaf_ctrl_get_option $cfile Maintainer)
items=$(zaf_list_plugin_items $1)
echo " Supported items:"
for i in $items; do
if [ -n "$tst" ]; then
echo -n " "; ${ZAF_AGENT_BIN} -t "$1.$i"
else
echo -n " $1.$i: "
fi
echo
zaf_ctrl_get_description "$cfile" "Item: $i";
echo
done
else
echo "Plugin $1 not installed"
fi
}
zaf_discovery_plugins() {
zaf_list_plugins | zaf_discovery '{#PLUGIN}'
}

28
zaf
View File

@ -7,7 +7,19 @@ else
exit 2
fi
[ -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}"
# Devel version
if [ -f $(dirname $0)/lib/zaf.lib.sh ]; then
ZAF_LIB_DIR=$(realpath $(dirname $0)/lib)
fi
. ${ZAF_LIB_DIR}/zaf.lib.sh
. ${ZAF_LIB_DIR}/os.lib.sh
. ${ZAF_LIB_DIR}/ctrl.lib.sh
case $1 in
@ -44,7 +56,11 @@ test-items)
;;
install)
zaf_install_plugin "$2"
shift;
[ -z "$@" ] && echo "$0 install plugin [plugin]..."
for p in $@; do
zaf_install_plugin "$p"
done
;;
remove)
@ -52,12 +68,17 @@ remove)
;;
self-upgrade)
curl -s https://raw.githubusercontent.com/limosek/zaf/master/install.sh | sh
rm -rf /tmp/zaf-installer && mkdir /tmp/zaf-installer
if zaf_fetch_url https://raw.githubusercontent.com/limosek/zaf/master/install.sh >/tmp/zaf-installer/install.sh; then
cd /tmp/zaf-installer && ./install.sh
else
echo "Cannot fetch uri https://raw.githubusercontent.com/limosek/zaf/master/install.sh!";
fi
;;
self-remove)
if [ "$2" = "force" ]; then
rm -rf /etc/zaf.conf ${ZAF_PLUGINS_DIR} ${ZAF_REPO_DIR} ${ZAF_LIB_DIR} /usr/bin/zaf ${ZAF_AGENT_CONFIGD}/zap_*
rm -rf /etc/zaf.conf ${ZAF_PLUGINS_DIR} ${ZAF_REPO_DIR} ${ZAF_LIB_DIR} /usr/bin/zaf ${ZAF_AGENT_CONFIGD}/zaf_*
else
echo "This will remove zaf from this computer and erase all configuration."
echo "To continue, please do $0 self-remove force"
@ -73,6 +94,7 @@ self-remove)
echo "$0 install plugin To install plugin"
echo "$0 remove plugin To remove plugin"
echo "$0 self-upgrade To self-upgrade zaf"
echo "$0 self-remove To self-remove zaf and its config"
;;
esac