-
Notifications
You must be signed in to change notification settings - Fork 10
/
place_files_onto_system.sh
executable file
·146 lines (108 loc) · 5.39 KB
/
place_files_onto_system.sh
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/bin/sh
# Author: stablestud <[email protected]>
# Repository: https://github.com/stablestud/adsorber
# License: MIT, https://opensource.org/licenses/MIT
##########[ Edit to fit your system ]###########################################
# Define where the executable 'adsorber(.sh)' file will be placed, it must be
# found when you type 'adsorber' into your console
readonly executable_path="/usr/local/bin/adsorber"
# Define where the other executables will be placed.
readonly library_dir_path="/usr/local/lib/adsorber/"
# Define the location of adsorbers shareable data (e.g. default config files...).
readonly shareable_dir_path="/usr/local/share/adsorber/"
# Define the location of the config files for adsorber.
readonly config_dir_path="/usr/local/etc/adsorber/"
# Define the location of the log file.
readonly log_file_path="/var/log/adsorber.log"
##########[ End of configuration ]##############################################
# Resolve script directory.
readonly script_dir_path="$(cd "$(dirname "${0}")" && pwd)"
printLocation()
{
echo "Going to place files to:"
echo " - main exectuable: ${executable_path}"
echo " - other executables: ${library_dir_path}"
echo " - configuration: ${config_dir_path}"
echo " - miscellaneous: ${shareable_dir_path}"
echo " - log files: ${log_file_path}"
return 0
}
printHelp()
{
printf "\\033[4;37minstall_to_system.sh\\033[0m:\\n\\n"
echo " Will place Adsorbers executables and other"
echo " files relevant to Adsorber into the system."
echo
printf "\\033[4;37mNote\\033[0m: Adsorbers own 'setup' command will not do the same action as\\n"
echo "this script, as it will only setup the scheduler and backup the original hosts file."
echo "You may want to run 'adsorber setup' afterwards"
echo
echo "Usage: ${0} [option]:"
echo
echo "Options:"
echo " -y, --yes automatically reply the confirmation prompt with yes"
echo " -h, --help show this help screen"
echo
printLocation
exit 0
}
prompt="${1}"
if [ "${prompt}" = "help" ] || [ "${prompt}" = "h" ] || [ "${prompt}" = "-h" ] || [ "${prompt}" = "--help" ]; then
printHelp
fi
printf "Adsorber will be placed into /usr/local/*, which is the default path for external scripts.\\n\\n"
if [ -z "${prompt}" ]; then
printf "Are you sure you want to place Adsorbers files onto the system? [(y)es/(N)o]: "
read -r prompt
fi
case "${prompt}" in
-[Yy] | --[Yy][Ee][Ss] | [Yy] | [Yy][Ee][Ss] )
echo
;;
* )
echo "Placing files onto the system has been cancelled."
exit 1
;;
esac
# Check if user is root, if not exit.
if [ "$(id -g)" -ne 0 ]; then
echo "You need to be root to place Adsorbers files onto the system." 1>&2
exit 126
fi
##[ Main exectuable ]###########################################################
echo "Placing main executable (src/bin/adsorber) to ${executable_path}"
mkdir -p "$(dirname ${executable_path})"
# Replacing the path to the libraries with the ones defined above.
sed "s|^readonly library_dir_path=.*$|readonly library_dir_path=\"${library_dir_path}\"|g" "${script_dir_path}/src/bin/adsorber" \
| sed "s|^readonly shareable_dir_path=.*$|readonly shareable_dir_path=\"${shareable_dir_path}\"|g" \
| sed "s|^readonly config_dir_path=.*$|readonly config_dir_path=\"${config_dir_path}\"|g" \
| sed "s|^readonly log_file_path=.*$|readonly log_file_path=\"${log_file_path}\"|g" \
> "${executable_path}"
chmod a+x "${executable_path}"
##[ Libraries ]#################################################################
echo "Placing other executables (src/lib/) to ${library_dir_path}"
mkdir -p "${library_dir_path}"
cp -r "${script_dir_path}/src/lib/." "${library_dir_path}"
##[ Shareables ]################################################################
echo "Placing miscellaneous (src/share/) to ${shareable_dir_path}"
mkdir -p "${shareable_dir_path}"
cp -r "${script_dir_path}/src/share/." "${shareable_dir_path}"
##[ Config files ]##############################################################
echo "Copying config files (src/share/default/) to ${config_dir_path}"
mkdir -p "${config_dir_path}"
cp "${script_dir_path}/src/share/default/default-adsorber.conf" "${config_dir_path}/adsorber.conf"
cp "${script_dir_path}/src/share/default/default-blacklist" "${config_dir_path}/blacklist"
cp "${script_dir_path}/src/share/default/default-whitelist" "${config_dir_path}/whitelist"
cp "${script_dir_path}/src/share/default/default-sources.list" "${config_dir_path}/sources.list"
echo
echo "Adsorber files have been successfully placed onto the system."
printf "\\033[1;37mTo start going (to setup the scheduler and to backup the hosts file) run 'adsorber setup'\\033[0m\\n"
## We don't run Adsorber after installation yet
#adsorber setup --noformatting \
# || {
# printf "\\n\033[0;93mAdsorber has been placed onto your system, however something went wrong at\\n"
# printf "running it.\\n"
# printf "If a proxy server is in use, please change the config file\\n"
# printf "(${config_dir_path}/adsorber.conf) to the appropriate proxy server.\\n\033[0m"
# echo "Run 'adsorber setup' to try again."
# }