Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

133 lines (116 sloc) 3.183 kb
#!/bin/bash
####################################################################
# Prey Core Setup Routine - by Tomas Pollak (bootlog.org)
# URL: http://preyproject.com
# License: GPLv3
####################################################################
trap "" INT TERM
# trap cleanup EXIT
cleanup(){
log " -- Cleaning up!\n"
delete_tmpdir
}
show_usage(){
echo "Prey ${version} ( http://preyproject.com )"
echo -e "\nUsage: `basename $0` [options]"
echo -e "Options:"
echo -e " -t | --test\t\tTest mode. Runs Prey without sending any data."
echo -e " -c | --check\t\tCheck mode. Checks if configuration is correctly set up."
echo -e " -l | --log\t\tLog output to ${base_path}/prey.log (default in Windows)."
echo -e " -s | --silent\t\tDon't log any output."
echo -e " -o | --on-demand\tRuns Prey without checking if on-demand mode is active.\n"
}
# step throught the params and check
until [ -z "$1" ]; do
case "$1" in
-t | --test )
echo -e "\n -- TEST MODE ON."
trap - INT # set off trap
test_mode=1
. $base_path/test/include "$2" 2> /dev/null
shift
;;
-c | --check )
echo -e "\n -- CHECK MODE ON."
check_mode=1
;;
-o | --on-demand )
echo -e "\n -- ON-DEMAND MODE ON."
on_demand_call=1
;;
-l | --log )
logfile="$base_path/prey.log"
echo -n "" > "$logfile" # empty the logfile first
log_output=">> \"$logfile\""
;;
-s | --silent )
log_output="&> /dev/null"
;;
-h | --help | * )
show_usage && exit
esac
shift
done
get_os(){
os=`lowercase \`uname\``
if [ "$os" == "windowsnt" ]; then
os=windows
else # linux/mac stuff
if [ "$os" == "darwin" ]; then
os=mac
fi
readonly logged_user=`who | cut -d' ' -f1 | sort -u | tail -1`
readonly root_path='/'
readonly home_path=`eval echo ~`
set_colors
fi
readonly os
readonly platform_path="$base_path/platform/$os"
PATH=$PATH:$platform_path/bin
}
# here we put the vars that are shared by two os, but a third one has
# different values
set_vars(){
tmpbase="/tmp"
line_breaker="\n"
user_agent="-A Prey/$version ($os)"
processes='ps ax'
}
set_aliases(){
shopt -s expand_aliases
alias getter="curl $curl_options -s \"$user_agent\""
alias mailsender="sendEmail"
}
set_constants(){
readonly lang
readonly start_time=`date +"%F %T"`
readonly config_file="$base_path/config"
readonly tmpdir="$tmpbase/p${RANDOM}"
readonly last_response="$tmpbase/prey-last-response.xml"
readonly on_demand_pipe="$tmpbase/prey-on-demand.pipe"
readonly logged_user
readonly control_panel_url="http://control.preyproject.com" 2> /dev/null
readonly updates_url="http://cloud.github.com/downloads/tomas/prey" 2> /dev/null
readonly modules_url=$control_panel_url 2> /dev/null
}
set_colors(){
cyan='\E[36m'
green='\E[32m'
red='\E[31m'
color_end='\E[0m'
bold='\033[1m'
bold_end='\033[0m'
}
check_on_demand_status(){
# if this is a regular call (from cron) let's check if we should run or not
if [[ -z "$on_demand_call" && -f "$on_demand_pipe" ]]; then
echo -e " -- Prey on-demand mode is active. Back to sleep...\n"
exit 0
fi
}
get_os
set_vars
set_aliases
. "$platform_path/settings"
set_constants
check_on_demand_status
Jump to Line
Something went wrong with that request. Please try again.