Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 160 lines (134 sloc) 3.982 kb
5c8b1cc Tomás Pollak Ordered the directories for platfomrms, needed for updater
tomas authored
1 #!/bin/bash
2 ####################################################################
3 # Prey Core Setup Routine - by Tomas Pollak (bootlog.org)
4 # URL: http://preyproject.com
5 # License: GPLv3
6 ####################################################################
7
ca53d2c Tomás Pollak Traps for handling INT, better cleanup strategy
tomas authored
8 trap "" INT TERM
ce2e35c Tomás Pollak Cleanup as requested, not with trap
tomas authored
9 # trap cleanup EXIT
ca53d2c Tomás Pollak Traps for handling INT, better cleanup strategy
tomas authored
10
11 cleanup(){
cd1d9b2 Tomás Pollak Better key/val handling in XML
tomas authored
12 log " -- Cleaning up!\n"
ca53d2c Tomás Pollak Traps for handling INT, better cleanup strategy
tomas authored
13 delete_tmpdir
14 }
15
070c400 Tomás Pollak error_exit function to handle better ungraceful exits
tomas authored
16 error_exit(){
17 log " !! $1"
f4375af Tomás Pollak Added exceptions_host for notify_exception function.
tomas authored
18 notify_exception "${1}" "error_exit"
070c400 Tomás Pollak error_exit function to handle better ungraceful exits
tomas authored
19 cleanup
20 exit 1
21 }
22
3c2bdcf Tomás Pollak Fixed on demand pipe for Windows and Mac. Added help message
tomas authored
23 show_usage(){
7e1584a Tomás Pollak Help output format
tomas authored
24 echo -e "Usage: `basename $0` [options]\n"
3c2bdcf Tomás Pollak Fixed on demand pipe for Windows and Mac. Added help message
tomas authored
25 echo -e "Options:"
26 echo -e " -c | --check\t\tCheck mode. Checks if configuration is correctly set up."
27 echo -e " -l | --log\t\tLog output to ${base_path}/prey.log (default in Windows)."
28 echo -e " -s | --silent\t\tDon't log any output."
30fda43 Tomás Pollak Help message output
tomas authored
29 echo -e " -t | --test\t\tTest mode. Runs Prey without sending any data."
30 echo -e " -v | --version\tDisplay version."
7e1584a Tomás Pollak Help output format
tomas authored
31 echo -e "\nFor more information and customization options, please check http://preyproject.com.\n"
3c2bdcf Tomás Pollak Fixed on demand pipe for Windows and Mac. Added help message
tomas authored
32 }
33
410fb83 Tomás Pollak Added SMTP verification. MD5sum Mac updater bug fixed (issue #84). Bette...
tomas authored
34 show_version(){
35 echo "Prey ${version}"
36 }
37
265b15b Tomás Pollak Added check mode for verifying keys
tomas authored
38 # step throught the params and check
39 until [ -z "$1" ]; do
3c2bdcf Tomás Pollak Fixed on demand pipe for Windows and Mac. Added help message
tomas authored
40 case "$1" in
41 -t | --test )
42 echo -e "\n -- TEST MODE ON."
43 trap - INT # set off trap
44 test_mode=1
2e3516f Tomás Pollak core/setup: make sure we only shift if an argument was passed to --test
tomas authored
45 # the following lets us include stuff for specific tests
46 # e.g. ./prey.sh --test reports
786cc05 Tomás Pollak Removed --immediate check option. Simpler (better) way of checking wheth...
tomas authored
47 if [ -z $(find_in $2 '-') ]; then
2e3516f Tomás Pollak core/setup: make sure we only shift if an argument was passed to --test
tomas authored
48 . $base_path/test/include "$2" 2> /dev/null
49 shift
50 fi
3c2bdcf Tomás Pollak Fixed on demand pipe for Windows and Mac. Added help message
tomas authored
51 ;;
52 -c | --check )
53 echo -e "\n -- CHECK MODE ON."
54 check_mode=1
55 ;;
56 -l | --log )
57 logfile="$base_path/prey.log"
58 echo -n "" > "$logfile" # empty the logfile first
59 log_output=">> \"$logfile\""
60 ;;
61 -s | --silent )
62 log_output="&> /dev/null"
63 ;;
410fb83 Tomás Pollak Added SMTP verification. MD5sum Mac updater bug fixed (issue #84). Bette...
tomas authored
64 -v | --version )
65 show_version && exit
66 ;;
3c2bdcf Tomás Pollak Fixed on demand pipe for Windows and Mac. Added help message
tomas authored
67 -h | --help | * )
68 show_usage && exit
69 esac
5df9725 Tomás Pollak Cosmetic changes. Better checksum management for updater
tomas authored
70 shift
265b15b Tomás Pollak Added check mode for verifying keys
tomas authored
71 done
fa1766a Tomás Pollak Added settings file for each platform. Less is more
tomas authored
72
73 get_os(){
786cc05 Tomás Pollak Removed --immediate check option. Simpler (better) way of checking wheth...
tomas authored
74 os=$(lowercase $(uname))
fa1766a Tomás Pollak Added settings file for each platform. Less is more
tomas authored
75
76 if [ "$os" == "windowsnt" ]; then
77 os=windows
78 else # linux/mac stuff
af35cbb Tomás Pollak stat /dev/console works in Mac but not in Linux
tomas authored
79 [ "$os" == "darwin" ] && os=mac
744779d Tomás Pollak Added constants for root, system, programs, users and home path
tomas authored
80 readonly root_path='/'
d24abe4 Tomás Pollak Removed a few backticks. Modules URL not readonly var.
tomas authored
81 readonly home_path=$(eval echo ~)
2a383af Tomás Pollak Linux wifi device getter. On Demand pinging. Disable colors when running...
tomas authored
82 [ -t 1 ] && set_colors # only set color if running from terminal (not Cron)
bcbce5d Tomás Pollak Moving parts for consistency.
tomas authored
83 fi
fdb179f Tomás Pollak Really fixed setup routine
tomas authored
84
85 readonly os
86 readonly platform_path="$base_path/platform/$os"
4b06d4b Tomás Pollak Correct way of detecting modules, Mac OS's find doesnt support -printf
tomas authored
87 PATH=$PATH:$platform_path/bin
fa1766a Tomás Pollak Added settings file for each platform. Less is more
tomas authored
88 }
89
f9228be Tomás Pollak Dont delete an installed module unless we know that the unzip was succes...
tomas authored
90 # here we put the vars that are shared by two os, but a third one has
91 # different values
fa1766a Tomás Pollak Added settings file for each platform. Less is more
tomas authored
92 set_vars(){
1cfff09 Tomás Pollak core/setup: Only set tmpbase is not already set.
tomas authored
93 [ -z "$tmpbase" ] && tmpbase="/tmp"
fa1766a Tomás Pollak Added settings file for each platform. Less is more
tomas authored
94 line_breaker="\n"
91ddc10 Tomás Pollak Clean BASH_VERSION before putting it in curl's User-Agent.
tomas authored
95 local bash_ver=$(echo $BASH_VERSION | sed "s/[^0-9\.]//g")
96 user_agent="-A Prey/$version ($(capitalize $os) $os_version, Bash $bash_ver)"
103cb45 Tomás Pollak Dumb mistake
tomas authored
97 processes='ps ax'
fa1766a Tomás Pollak Added settings file for each platform. Less is more
tomas authored
98 }
99
8b46847 Tomás Pollak Using aliases for commands, makes more sense
tomas authored
100 set_aliases(){
155b6b0 Tomás Pollak Better way of handling colors in output
tomas authored
101 shopt -s expand_aliases
f3ab36d Tomás Pollak Curl options on config. Making sure we set the real path on crontab
tomas authored
102 alias getter="curl $curl_options -s \"$user_agent\""
8b46847 Tomás Pollak Using aliases for commands, makes more sense
tomas authored
103 alias mailsender="sendEmail"
104 }
105
fa1766a Tomás Pollak Added settings file for each platform. Less is more
tomas authored
106 set_constants(){
8987c78 Tomás Pollak Make the mem setting of vars actually work
tomas authored
107 readonly lang
fa2fbe8 Tomás Pollak Fix set_key_value function. Make sure query_string is generated correctl...
tomas authored
108 readonly start_time=$(date +"%F %T")
1e860b0 Tomás Pollak Fixed test mode check
tomas authored
109
aa66078 Tomás Pollak Added default.config. Evenually we will remove config from the repo itse...
tomas authored
110 readonly config_file="$base_path/config"
fbb05a1 Tomás Pollak Jobs are now actions. Offline mode support. Actions are run even if the ...
tomas authored
111 readonly tmpdir="$tmpbase/p${RANDOM}"
eb0a08f Tomás Pollak Offline actions are back
tomas authored
112 readonly last_response="$tmpbase/prey-last-response.xml"
2a383af Tomás Pollak Linux wifi device getter. On Demand pinging. Disable colors when running...
tomas authored
113 readonly on_demand_pipefile="$tmpbase/prey-on-demand.pipe"
fa1766a Tomás Pollak Added settings file for each platform. Less is more
tomas authored
114 readonly logged_user
115
67d9a34 Tomás Pollak Updated URLs in core/setup. Use HTTPS endpoint to Control Panel.
tomas authored
116 readonly control_panel_url="https://control.preyproject.com" 2> /dev/null
f4375af Tomás Pollak Added exceptions_host for notify_exception function.
tomas authored
117 readonly exceptions_host="https://exceptions.preyproject.com"
7b61ab5 Carlos Yaconi H. Moved modules' URL from Github (deprecated) to S3.
cyaconi authored
118 modules_url="https://prey-bash-client-modules.s3.amazonaws.com" 2> /dev/null
b900c0d Tomás Pollak Typo.
tomas authored
119 updates_url="https://s3.amazonaws.com/prey-releases/bash-client/patches" 2> /dev/null
fa1766a Tomás Pollak Added settings file for each platform. Less is more
tomas authored
120 }
121
155b6b0 Tomás Pollak Better way of handling colors in output
tomas authored
122 set_colors(){
5df9725 Tomás Pollak Cosmetic changes. Better checksum management for updater
tomas authored
123 cyan='\E[36m'
124 green='\E[32m'
125 red='\E[31m'
126 color_end='\E[0m'
127 bold='\033[1m'
128 bold_end='\033[0m'
155b6b0 Tomás Pollak Better way of handling colors in output
tomas authored
129 }
130
616c917 Tomás Pollak Added on-demand pushlike logic
tomas authored
131 check_on_demand_status(){
de94df4 Tomás Pollak Using PID as method of verifying if On Demand is still active
tomas authored
132
c0b1679 Tomás Pollak Using AES encryption for responses. Make sure On Demand is connected (an...
tomas authored
133 # we check if the pipe has been used to send pings in the last ten minutes
134 # if not, then we assume the connection has been cut off
b82a802 Tomás Pollak Removed --on-demand argument in favor of --(i)mmediate. Make sure On Dem...
tomas authored
135 # if the file doesn't exist, simply return
136
137 if [ ! -f "$on_demand_pipefile" ]; then
138
139 return 1
140
141 elif test $(find "$on_demand_pipefile" -mmin +10); then
de94df4 Tomás Pollak Using PID as method of verifying if On Demand is still active
tomas authored
142
6117eea Tomás Pollak Small improvements to On-demand check
tomas authored
143 echo " -- On Demand connection seems to have ended. Cleaning up and resetting..."
144 . "$base_path/core/on_demand"
c0b1679 Tomás Pollak Using AES encryption for responses. Make sure On Demand is connected (an...
tomas authored
145
6117eea Tomás Pollak Small improvements to On-demand check
tomas authored
146 [ -n "`is_process_running 'openssl'`" ] && kill_process 'openssl'
147 on_demand_cleanup
148 sleep 3 # just to make sure changes are reflected as they should
c0b1679 Tomás Pollak Using AES encryption for responses. Make sure On Demand is connected (an...
tomas authored
149
616c917 Tomás Pollak Added on-demand pushlike logic
tomas authored
150 fi
c0b1679 Tomás Pollak Using AES encryption for responses. Make sure On Demand is connected (an...
tomas authored
151
616c917 Tomás Pollak Added on-demand pushlike logic
tomas authored
152 }
153
fa1766a Tomás Pollak Added settings file for each platform. Less is more
tomas authored
154 get_os
c154e8b Tomás Pollak Include os and bash version in HTTP user agent.
tomas authored
155 . "$platform_path/settings"
fa1766a Tomás Pollak Added settings file for each platform. Less is more
tomas authored
156 set_vars
e8e8116 Tomás Pollak Better check mode. Now also check if the installation is fine.
tomas authored
157 set_aliases
fa1766a Tomás Pollak Added settings file for each platform. Less is more
tomas authored
158 set_constants
786cc05 Tomás Pollak Removed --immediate check option. Simpler (better) way of checking wheth...
tomas authored
159 check_on_demand_status
Something went wrong with that request. Please try again.