-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathinstall.sh
executable file
·140 lines (126 loc) · 5.01 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
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
#!/bin/bash
# user can config the following configs, then package.
INSTALL=/usr/local/sfu
##################################################################################
##################################################################################
##################################################################################
# discover the current work dir, the log and access.
echo "argv[0]=$0"
if [[ ! -f $0 ]]; then
echo "directly execute the scripts on shell.";
work_dir=`pwd`
else
echo "execute scripts in file: $0";
work_dir=`dirname $0`; work_dir=`(cd ${work_dir} && pwd)`
echo "work_dir: ${work_dir}";
fi
product_dir=$work_dir
log="${work_dir}/logs/package.`date +%s`.log" && . ${product_dir}/scripts/_log.sh && check_log
ret=$?; if [[ $ret -ne 0 ]]; then exit $ret; fi
# check lsb_release
ok_msg "check tools"
lsb_release -v >/dev/null 2>&1; ret=$?
if [[ $ret -ne 0 ]]; then failed_msg "no lsb_release, install: yum install -y redhat-lsb"; exit $ret; fi
# user must stop service first.
ok_msg "check previous install"
if [[ -f /etc/init.d/sfu ]]; then
/etc/init.d/sfu status >/dev/null 2>&1
ret=$?; if [[ 0 -eq ${ret} ]]; then
failed_msg "you must stop the service first: sudo /etc/init.d/sfu stop";
exit 1;
fi
fi
ok_msg "previous install checked"
# backup old sfu
ok_msg "backup old sfu"
install_root=$INSTALL
install_bin=$install_root/bin/sfu
if [[ -d $install_root ]]; then
version="unknown"
if [[ -f $install_bin ]]; then
version=`$install_bin -v 2>/dev/stdout 1>/dev/null`
fi
backup_dir=${install_root}.`date "+%Y-%m-%d_%H-%M-%S"`.v-$version
ok_msg "backup installed dir, version=$version"
ok_msg " to=$backup_dir"
mv $install_root $backup_dir >>$log 2>&1
ret=$?; if [[ 0 -ne ${ret} ]]; then failed_msg "backup installed dir failed"; exit $ret; fi
ok_msg "backup installed dir success"
fi
ok_msg "old sfu backuped"
# prepare files.
ok_msg "prepare files"
(
sed -i "s|^ROOT=.*|ROOT=\"${INSTALL}\"|g" $work_dir/etc/init.d/sfu
) >> $log 2>&1
ret=$?; if [[ 0 -ne ${ret} ]]; then failed_msg "prepare files failed"; exit $ret; fi
ok_msg "prepare files success"
# copy core files
ok_msg "copy core components"
(
mkdir -p $install_root
cp -r $work_dir/conf $install_root &&
cp -r $work_dir/etc $install_root &&
cp -r $work_dir/usr $install_root &&
cp -r $work_dir/bin $install_root
) >>$log 2>&1
ret=$?; if [[ 0 -ne ${ret} ]]; then failed_msg "copy core components failed"; exit $ret; fi
ok_msg "copy core components success"
# install init.d scripts
ok_msg "install init.d scripts"
(
rm -rf /etc/init.d/sfu &&
ln -sf $install_root/etc/init.d/sfu /etc/init.d/sfu
) >>$log 2>&1
ret=$?; if [[ 0 -ne ${ret} ]]; then failed_msg "install init.d scripts failed"; exit $ret; fi
ok_msg "install init.d scripts success"
# For systemctl
if [[ -d /usr/lib/systemd/system ]]; then
ok_msg "install sfu.service for systemctl"
(
cp -f $install_root/usr/lib/systemd/system/sfu.service /usr/lib/systemd/system/sfu.service &&
systemctl daemon-reload
) >>$log 2>&1
ret=$?; if [[ 0 -ne ${ret} ]]; then failed_msg "install sfu.service for systemctl failed"; exit $ret; fi
ok_msg "install sfu.service for systemctl success"
fi
# install system service
lsb_release --id|grep "CentOS" >/dev/null 2>&1; os_id_centos=$?
lsb_release --id|grep "Ubuntu" >/dev/null 2>&1; os_id_ubuntu=$?
lsb_release --id|grep "Debian" >/dev/null 2>&1; os_id_debian=$?
lsb_release --id|grep "Raspbian" >/dev/null 2>&1; os_id_rasabian=$?
if [[ 0 -eq $os_id_centos ]]; then
ok_msg "install system service for CentOS"
if [[ -d /usr/lib/systemd/system ]]; then
systemctl enable sfu
else
/sbin/chkconfig --add sfu && /sbin/chkconfig sfu on
fi
ret=$?; if [[ 0 -ne ${ret} ]]; then failed_msg "install system service failed"; exit $ret; fi
ok_msg "install system service success"
elif [[ 0 -eq $os_id_ubuntu ]]; then
ok_msg "install system service for Ubuntu"
update-rc.d sfu defaults
ret=$?; if [[ 0 -ne ${ret} ]]; then failed_msg "install system service failed"; exit $ret; fi
ok_msg "install system service success"
elif [[ 0 -eq $os_id_debian ]]; then
ok_msg "install system service for Debian"
update-rc.d sfu defaults
ret=$?; if [[ 0 -ne ${ret} ]]; then failed_msg "install system service failed"; exit $ret; fi
ok_msg "install system service success"
elif [[ 0 -eq $os_id_rasabian ]]; then
ok_msg "install system service for RaspberryPi"
update-rc.d sfu defaults
ret=$?; if [[ 0 -ne ${ret} ]]; then failed_msg "install system service failed"; exit $ret; fi
ok_msg "install system service success"
else
warn_msg "ignore and donot install system service for `lsb_release --id|awk '{print $3}'`."
fi
echo ""
echo "see: https://github.com/X-Leia/SFU.git"
echo "install success, you can start SFU on CentOS6:"
echo -e "${GREEN} sudo /etc/init.d/sfu start${BLACK}"
echo "or CentOS7:"
echo -e "${GREEN} sudo systemctl start sfu${BLACK}"
echo "sfu root is ${INSTALL}"
exit 0