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

175 lines
4.0 KiB
Plaintext
Raw Normal View History

2016-03-23 14:37:51 +01:00
#!/bin/sh
ZAF_CFG_FILE="/etc/zaf.conf"
if [ -f $ZAF_CFG_FILE ]; then
. $ZAF_CFG_FILE
2016-03-24 15:46:42 +01:00
else
echo "Missing config file $ZAF_CFG_FILE! Exiting."
2016-03-24 15:46:42 +01:00
exit 2
2016-03-23 14:37:51 +01:00
fi
2016-03-30 16:09:02 +02:00
[ -z "$ZAF_TMP_BASE" ] && ZAF_TMP_BASE=/tmp/zaf
2016-04-01 12:20:23 +02:00
ZAF_TMP_DIR="${ZAF_TMP_BASE}-${USER}"
2016-03-30 16:09:02 +02:00
trap "rm -rif ${ZAF_TMP_DIR}" EXIT
! [ -d "${ZAF_TMP_DIR}" ] && mkdir "${ZAF_TMP_DIR}"
2016-04-01 12:20:23 +02:00
[ -z "$ZAF_DEBUG" ] && ZAF_DEBUG=1
2016-03-30 16:09:02 +02:00
2016-04-01 15:51:45 +02:00
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
2016-03-23 14:37:51 +01:00
. ${ZAF_LIB_DIR}/zaf.lib.sh
2016-03-30 16:09:02 +02:00
. ${ZAF_LIB_DIR}/os.lib.sh
. ${ZAF_LIB_DIR}/ctrl.lib.sh
[ -f ${ZAF_LIB_DIR}/zaf.${ZAF_OS}.sh ] && . ${ZAF_LIB_DIR}/zaf.${ZAF_OS}.sh
2016-04-01 15:51:45 +02:00
fi
2016-03-23 14:37:51 +01:00
case $1 in
2016-03-23 17:25:18 +01:00
check-agent-config)
zaf_check_agent_config
;;
2016-03-23 14:37:51 +01:00
update)
2016-04-04 16:08:07 +02:00
zaf_wrn "Updating repository ${ZAF_PLUGINS_GITURL}..."
2016-03-23 14:37:51 +01:00
zaf_update_repo
;;
2016-03-24 15:46:42 +01:00
show)
if [ -z "$2" ]; then
2016-04-01 12:20:23 +02:00
zaf_list_plugins | while read plugin; do
zaf_plugin_info $ZAF_PLUGINS_DIR/$plugin/control.zaf
done
else
if zaf_list_plugins | grep -q "^$2"; then
zaf_plugin_info $ZAF_PLUGINS_DIR/$2/control.zaf
else
2016-04-01 15:51:45 +02:00
if echo $2 |grep -q ^http; then
zaf_prepare_plugin "$2" "$ZAF_TMP_DIR/plugin"
zaf_plugin_info "$ZAF_TMP_DIR/plugin/control.zaf"
else
zaf_err "Plugin $2 not installed."
fi
2016-04-01 12:20:23 +02:00
fi
2016-03-24 15:46:42 +01:00
fi
;;
2016-04-01 15:51:45 +02:00
plugins)
2016-03-24 15:46:42 +01:00
zaf_list_plugins
2016-03-23 14:37:51 +01:00
;;
2016-04-01 15:51:45 +02:00
items)
2016-03-24 15:46:42 +01:00
if [ -z "$2" ]; then
zaf_list_items
else
zaf_list_plugin_items "$2"
fi
;;
2016-04-01 15:51:45 +02:00
test)
2016-04-04 14:49:38 +02:00
if echo $2|grep -q '\.'; then
zaf_test_item "$2"
exit
fi
2016-04-01 15:51:45 +02:00
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
2016-03-23 17:25:18 +01:00
;;
2016-03-23 14:37:51 +01:00
install)
2016-03-30 16:09:02 +02:00
shift;
2016-04-04 14:00:44 +02:00
[ -z "$1" ] && echo "$0 install plugin [plugin]..."
2016-03-30 16:09:02 +02:00
for p in $@; do
2016-04-01 12:20:23 +02:00
if zaf_is_plugin "$p"; then
zaf_wrn "Plugin $p already installed. Skipping installation."
continue
fi
2016-03-30 16:09:02 +02:00
zaf_install_plugin "$p"
2016-04-01 12:20:23 +02:00
installed=1
2016-03-30 16:09:02 +02:00
done
2016-04-01 12:20:23 +02:00
[ -n "$installed" ] && zaf_is_root && zaf_restart_agent
;;
reinstall)
shift;
2016-04-04 14:00:44 +02:00
[ -z "$1" ] && echo "$0 reinstall plugin [plugin]..."
2016-04-01 12:20:23 +02:00
for p in $@; do
if zaf_is_plugin "$p"; then
2016-04-01 15:51:45 +02:00
zaf_remove_plugin "$(basename $p)"
2016-04-01 12:20:23 +02:00
reinstalled=1
fi
zaf_install_plugin "$p"
reinstalled=1
done
[ -n "$reinstalled" ] && zaf_is_root && zaf_restart_agent
2016-03-23 14:37:51 +01:00
;;
2016-03-23 17:25:18 +01:00
remove)
2016-04-01 12:20:23 +02:00
shift;
2016-04-04 14:00:44 +02:00
[ -z "$1" ] && echo "$0 remove plugin [plugin]..."
2016-04-01 12:20:23 +02:00
for p in $@; do
if zaf_is_plugin "$p"; then
zaf_remove_plugin "$p"
removed=1
fi
done
[ -n "$removed" ] && zaf_is_root && zaf_restart_agent
2016-03-23 17:25:18 +01:00
;;
2016-03-24 15:46:42 +01:00
self-upgrade)
2016-03-30 16:09:02 +02:00
rm -rf /tmp/zaf-installer && mkdir /tmp/zaf-installer
2016-04-04 15:10:38 +02:00
if ! which curl >/dev/null;
then
zaf_err "Curl not found. Cannot continue. Please install it."
2016-03-30 16:09:02 +02:00
fi
2016-04-04 15:10:38 +02:00
[ -z "$2" ] && auto=auto
set -e
mkdir -p /tmp/zaf-installer \
&& cd /tmp/zaf-installer \
&& (for i in lib/zaf.lib.sh lib/os.lib.sh lib/ctrl.lib.sh install.sh ; do echo curl -f -k -s -L -o - "$ZAF_URL/$i" >&2; curl -f -k -s -L -o - "$ZAF_URL/$i"; done) >install.sh \
&& chmod +x install.sh \
&& exec ./install.sh $auto "$@"
exit
2016-03-24 15:46:42 +01:00
;;
2016-03-24 20:37:03 +01:00
self-remove)
2016-04-01 15:51:45 +02:00
. /etc/zaf.conf
if [ "$2" = "force" ]; then
rm -rf /etc/zaf.conf ${ZAF_PLUGINS_DIR} ${ZAF_REPO_DIR} ${ZAF_LIB_DIR} \
${ZAF_BIN_DIR}/zaf ${ZAF_AGENT_CONFIGD}/zaf_*
2016-03-24 20:37:03 +01:00
else
echo "This will remove zaf from this computer and erase all configuration."
2016-04-01 15:51:45 +02:00
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
2016-03-24 20:37:03 +01:00
echo "To continue, please do $0 self-remove force"
fi
;;
2016-03-24 15:46:42 +01:00
2016-03-23 14:37:51 +01:00
*)
2016-04-04 14:00:44 +02:00
echo "$0 Version ${ZAF_VERSION}. Please use some of this commands:"
2016-03-24 15:46:42 +01:00
echo "$0 update To update repo"
2016-04-01 15:51:45 +02:00
echo "$0 plugins To list installed plugins"
2016-03-24 15:46:42 +01:00
echo "$0 show [plugin] To show installed plugins or plugin info"
2016-04-01 15:51:45 +02:00
echo "$0 items [plugin] To list all suported items [for plugin]"
2016-04-04 14:49:38 +02:00
echo "$0 test [plugin[.item]] To test all suported items [for plugin]"
2016-03-24 15:46:42 +01:00
echo "$0 install plugin To install plugin"
echo "$0 remove plugin To remove plugin"
echo "$0 self-upgrade To self-upgrade zaf"
2016-03-30 16:09:02 +02:00
echo "$0 self-remove To self-remove zaf and its config"
2016-03-23 14:37:51 +01:00
;;
2016-03-23 17:25:18 +01:00
2016-03-23 14:37:51 +01:00
esac