forked from juli3nk/csf-pre_post_sh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·73 lines (56 loc) · 1.59 KB
/
install.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
#!/bin/bash
CSF_BIN_PATH="/usr/local/csf/bin"
CSFPRESH_SCRIPT="${CSF_BIN_PATH}/csfpre.sh"
CSFPOSTSH_SCRIPT="${CSF_BIN_PATH}/csfpost.sh"
CSFPRED_PATH="/usr/local/include/csf/pre.d"
CSFPOSTD_PATH="/usr/local/include/csf/post.d"
function copy_script {
local csf_script=$1
local csf_dst_path=$2
if [ -f ${csf_dst_path} ]; then
md5_0=`md5sum ${csf_script} | awk '{ print $1 }'`
md5_1=`md5sum ${csf_dst_path} | awk '{ print $1 }'`
if [ ${md5_0} == ${md5_1} ]; then
echo "The script ${csf_script} already exists and is up to date"
exit 0
else
ok=0
while [ ${ok} -eq 0 ]; do
clear
echo "** Warning! **"
echo "A different version of the script ${csf_script} is already present"
echo "Do you want to replace it (y/n)?"
read answer
if [ ${answer} == "y" -o ${answer} == "n" ]; then
ok=1
fi
done
if [ ${answer} == "n" ]; then
exit 1
fi
fi
fi
cp -f ${csf_script} ${csf_dst_path}
chown root:root ${csf_dst_path}
chmod 700 ${csf_dst_path}
}
# Verify /bin/bash is linked to /bin/sh
shell="bash"
sh_shell=`ls -l /bin/sh | awk '{ print $NF }'`
if [ ${sh_shell} != ${shell} -a ${sh_shell} != "/bin/${shell}" ]; then
echo "** Critical! **"
echo "/bin/sh is not linked to /bin/${shell}. Yours is ${sh_shell}."
echo "Only /bin/${shell} is supported"
exit 1
fi
# Create directories needed for custom csf{pre,post}
if [ ! -d ${CSFPRED_PATH} ]; then
mkdir -p ${CSFPRED_PATH}
fi
if [ ! -d ${CSFPOSTD_PATH} ]; then
mkdir -p ${CSFPOSTD_PATH}
fi
# Copy scripts
copy_script "csfpre.sh" ${CSFPRESH_SCRIPT}
copy_script "csfpost.sh" ${CSFPOSTSH_SCRIPT}
exit 0