~ubuntu-branches/ubuntu/saucy/prey/saucy

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/bin/bash
####################################################################
# Prey Core Module Functions - by Tomas Pollak (bootlog.org)
# URL: http://preyproject.com
# License: GPLv3
####################################################################

# mac/linux only. windows has another method of de/activating modules
is_module_active(){
	if [ -x "$modules_path/$1/core/run" ]; then
		echo 1
	else
		return 0
	fi
}

get_active_modules_from_filesystem(){
	for module_name in `find "$modules_path" -maxdepth 1 -mindepth 1 -type d -exec basename {} \;`
	do
		if [ `is_module_active "$module_name"` ]; then
			initialize_module $module_name
			active_modules="$active_modules $module_name"
		fi
	done
}

# gets the module name ($1) and optionally the upstream version ($2)
setup_module(){

	module_path="$modules_path/$1"
	upstream_version=$2

	# disable automatic updates
	if [ ! -d "$module_path" ]; then
		log " !! Module $1 not found!"
		return 1
	else
		return 0
	fi
}

initialize_module(){

	set_module_paths_for $1

	# if there's a language file, lets run it
	if [ -f "$module_path/lang/$lang" ]; then
	. "$module_path/lang/$lang"
	elif [ -f "$module_path/lang/en" ]; then
	. "$module_path/lang/en"
	fi

	# if there's a config file, lets run it as well
	if [ -f "$module_path/config" ]; then
		. "$module_path/config"
	fi

	# lets load the base functions for the module
	if [ -f "$module_path/core/functions" ]; then
		. "$module_path/core/functions"
	fi

	# and the OS-specific if there are
	if [ -f "$module_platform_path/functions" ]; then
		. "$module_platform_path/functions"
	fi

}

#unset_module_vars(){
#	unset current_module
#	unset module_path
#	unset module_platform_path
#}

set_module_paths_for(){
	module_path="$modules_path/$1"
	module_platform_path="$module_path/platform/$os"
}

run_active_modules() {

	if [[ -z $active_modules && "$post_method" != 'http' ]]; then
		get_active_modules_from_filesystem
	fi

	for current_module in $active_modules; do

		set_module_paths_for $current_module
		log "\n${bold} >> Running $current_module module!${bold_end}\n"

		# now, go!
		. "$module_path/core/run"

	done

}