#!/bin/sh
#
# CloudShark Plugin for WireShark
# Simple Unix installer
# Contact support@cloudshark.org
#
# Developed by QA Cafe 2012
#

echo "Starting installation of CloudShark plugin for WireShark"

# -- check for curl
CURL=`which curl`
if [ $? -ne 0 -o ! -x "$CURL" ]; then
   echo
   echo "ERROR: Can not find curl on your system. The CloudShark plugin"
   echo "requires curl. Please install curl first, then run this installer"
   echo "again."
   echo
   exit 1
fi

# -- install into users Wireshark plugins directory
DEST=~/.wireshark/plugins/cloudshark
echo
echo "Plugin will be installed into $DEST"

# -- passing 'devel' argument will install plugin using symlinks
# -- rather than copying files
DEVEL=0
if [ $# -eq 1 -a "$1" = "devel" ]; then
    DEVEL=1
    echo "Installing plugin files using symlinks to $(pwd)"
fi

# -- make the required directories
mkdir -p "$DEST"
mkdir -p "$DEST/tmp"

# -- copy the plugin files, default CA bundle, and the readme file
for file in cloudshark.lua json.lua version.lua curl-ca-bundle.crt CLOUDSHARK_README.txt
do
    if [ $DEVEL -eq 0 ]; then
        cp "$file" "$DEST"
    else
        ln -s "$(pwd)/$file" "$DEST/$file"
    fi
done

# -- copy the default configuration if it does not exist
if [ ! -e "$DEST/cloudshark_init.lua" ]
then
    echo "Installing default plugin configuration file."
    cp cloudshark_init.default "$DEST/cloudshark_init.lua"
else
    echo "Detected existing configuration file, skipping config file."
fi


echo "The CloudShark Plugin for Wireshark is now installed."
echo "Please restart Wireshark."
echo ""
echo "Visit http://appliance.cloudshark.org for additional help"
echo ""

