Optimize install function

This commit is contained in:
Teddysun 2014-06-16 21:58:21 +08:00
parent 28d1f84246
commit 263b13a19f
2 changed files with 42 additions and 40 deletions

View File

@ -101,8 +101,7 @@ function config_shadowsocks(){
if [ ! -d /etc/shadowsocks ];then if [ ! -d /etc/shadowsocks ];then
mkdir /etc/shadowsocks mkdir /etc/shadowsocks
fi fi
touch /etc/shadowsocks/config.json cat > /etc/shadowsocks/config.json<<-EOF
cat >>/etc/shadowsocks/config.json<<-EOF
{ {
"server":"${IP}", "server":"${IP}",
"server_port":8989, "server_port":8989,
@ -118,30 +117,32 @@ EOF
# Install # Install
function install(){ function install(){
# Build and Install shadowsocks-libev # Build and Install shadowsocks-libev
if [ ! -f /usr/local/bin/ss-server ];then if [ -s /usr/local/bin/ss-server ];then
echo "shadowsocks-libev has been installed!"
exit 0
else
./configure ./configure
make && make install make && make install
fi
# Run shadowsocks-libev
if [ -s /usr/local/bin/ss-server ]; then
# Add run on system start up
cat /etc/rc.local | grep 'ss-server' > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "nohup /usr/local/bin/ss-server -c /etc/shadowsocks/config.json > /dev/null 2>&1 &" >> /etc/rc.local
fi
# Run shadowsocks in the background
nohup /usr/local/bin/ss-server -c /etc/shadowsocks/config.json > /dev/null 2>&1 &
# Run success or not
ps -ef | grep -v grep | grep -v ps | grep -i '/usr/local/bin/ss-server' > /dev/null 2>&1
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
echo "Shadowsocks-libev start success!" # Add run on system start up
cat /etc/rc.local | grep 'ss-server' > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "nohup /usr/local/bin/ss-server -c /etc/shadowsocks/config.json > /dev/null 2>&1 &" >> /etc/rc.local
fi
# Run shadowsocks in the background
nohup /usr/local/bin/ss-server -c /etc/shadowsocks/config.json > /dev/null 2>&1 &
# Run success or not
ps -ef | grep -v grep | grep -v ps | grep -i '/usr/local/bin/ss-server' > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo "Shadowsocks-libev start success!"
else
echo "Shadowsocks-libev start failure!"
fi
else else
echo "Shadowsocks-libev start failure!" echo ""
echo "Shadowsocks-libev install failed! Please visit http://teddysun.com/358.html and contact."
exit 1
fi fi
else
echo ""
echo "Shadowsocks-libev install failed! Please visit http://teddysun.com/358.html and contact."
exit 1
fi fi
cd $cur_dir cd $cur_dir
# Delete shadowsocks-libev floder # Delete shadowsocks-libev floder

View File

@ -103,8 +103,7 @@ function config_shadowsocks(){
if [ ! -d /etc/shadowsocks ];then if [ ! -d /etc/shadowsocks ];then
mkdir /etc/shadowsocks mkdir /etc/shadowsocks
fi fi
touch /etc/shadowsocks/config.json cat > /etc/shadowsocks/config.json<<-EOF
cat >>/etc/shadowsocks/config.json<<-EOF
{ {
"server":"${IP}", "server":"${IP}",
"server_port":8989, "server_port":8989,
@ -134,28 +133,30 @@ function iptables_set(){
# Install # Install
function install(){ function install(){
# Build and Install shadowsocks-libev # Build and Install shadowsocks-libev
if [ ! -f /usr/local/bin/ss-server ];then if [ -s /usr/local/bin/ss-server ];then
echo "shadowsocks-libev has been installed!"
exit 0
else
./configure ./configure
make && make install make && make install
fi
# Run shadowsocks-libev
if [ -s /usr/local/bin/ss-server ]; then
cp -f $cur_dir/shadowsocks-libev-master/rpm/SOURCES/etc/init.d/shadowsocks /etc/init.d/
chmod +x /etc/init.d/shadowsocks
# Add run on system start up
chkconfig --add shadowsocks
chkconfig shadowsocks on
# Start shadowsocks
/etc/init.d/shadowsocks start
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
echo "Shadowsocks-libev start success!" cp -f $cur_dir/shadowsocks-libev-master/rpm/SOURCES/etc/init.d/shadowsocks /etc/init.d/
chmod +x /etc/init.d/shadowsocks
# Add run on system start up
chkconfig --add shadowsocks
chkconfig shadowsocks on
# Start shadowsocks
/etc/init.d/shadowsocks start
if [ $? -eq 0 ]; then
echo "Shadowsocks-libev start success!"
else
echo "Shadowsocks-libev start failure!"
fi
else else
echo "Shadowsocks-libev start failure!" echo ""
echo "Shadowsocks-libev install failed! Please visit http://teddysun.com/357.html and contact."
exit 1
fi fi
else
echo ""
echo "Shadowsocks-libev install failed! Please visit http://teddysun.com/357.html and contact."
exit 1
fi fi
cd $cur_dir cd $cur_dir
# Delete shadowsocks-libev floder # Delete shadowsocks-libev floder