Skip to content

Commit 43eea3e

Browse files
committed
optimize sed&&auto-start
1 parent fb7af64 commit 43eea3e

File tree

3 files changed

+28
-16
lines changed

3 files changed

+28
-16
lines changed

Centos/nginx_proxy.sh

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ make && make install
7979
cd /usr/src
8080
wget -N --no-check-certificate https://raw.githubusercontent.com/arnofeng/ngx_google_deployment/master/nginx.conf
8181
cp -r -f nginx.conf /etc/nginx/nginx.conf
82-
sed -i "s/g.adminhost.org/$DOMAIN1/" /etc/nginx/nginx.conf
83-
sed -i "s/x.adminhost.org/$DOMAIN2/" /etc/nginx/nginx.conf
82+
sed -i "s#g.adminhost.org#$DOMAIN1#g" /etc/nginx/nginx.conf
83+
sed -i "s#x.adminhost.org#$DOMAIN2#g" /etc/nginx/nginx.conf
8484
mkdir -p /etc/nginx/vhost
8585
mkdir -p /etc/nginx/cache/one
8686
mkdir -p /etc/nginx/cache/two
@@ -89,13 +89,19 @@ mkdir -p /etc/nginx/cache/three
8989
mkdir -p /var/www/google
9090
cd /var/www/google
9191
wget -N --no-check-certificate https://raw.githubusercontent.com/arnofeng/ngx_google_deployment/master/index.html
92-
sed -i "s/g.adminhost.org/$DOMAIN1/" /var/www/google/index.html
93-
sed -i "s/x.adminhost.org/$DOMAIN2/" /var/www/google/index.html
92+
sed -i "s#g.adminhost.org#$DOMAIN1#g" /var/www/google/index.html
93+
sed -i "s#x.adminhost.org#$DOMAIN2#g" /var/www/google/index.html
9494
#9.set auto-start for nginx
9595
cp -r -f /etc/rc.local /etc/rc.local_bak
96-
sed -i 's/\"exit 0\"/\#/' /etc/rc.local
97-
sed -i 's/\#exit 0/\#/' /etc/rc.local
98-
sed -i 's/exit 0/\/etc\/nginx\/sbin\/nginx \nexit 0/' /etc/rc.local
96+
AUTO='/etc/nginx/sbin/nginx'
97+
cat /etc/rc.local|grep 'exit 0'
98+
if [ $? -eq 0 ]; then
99+
sed -i 's/\"exit 0\"/\#/g' /etc/rc.local
100+
sed -i 's/\#exit 0/\#/g' /etc/rc.local
101+
sed -i "s#exit 0#$AUTO\nexit 0#" /etc/rc.local
102+
else
103+
echo "$AUTO">>/etc/rc.local
104+
fi
99105
#10.start nginx
100106
/etc/nginx/sbin/nginx
101107
if [ $? -eq 0 ]; then

Debian/nginx_proxy.sh

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ make && make install
7979
cd /usr/src
8080
wget -N --no-check-certificate https://raw.githubusercontent.com/arnofeng/ngx_google_deployment/master/nginx.conf
8181
cp -r -f nginx.conf /etc/nginx/nginx.conf
82-
sed -i "s/g.adminhost.org/$DOMAIN1/" /etc/nginx/nginx.conf
83-
sed -i "s/x.adminhost.org/$DOMAIN2/" /etc/nginx/nginx.conf
82+
sed -i "s#g.adminhost.org#$DOMAIN1#g" /etc/nginx/nginx.conf
83+
sed -i "s#x.adminhost.org#$DOMAIN2#g" /etc/nginx/nginx.conf
8484
mkdir -p /etc/nginx/vhost
8585
mkdir -p /etc/nginx/cache/one
8686
mkdir -p /etc/nginx/cache/two
@@ -89,13 +89,19 @@ mkdir -p /etc/nginx/cache/three
8989
mkdir -p /var/www/google
9090
cd /var/www/google
9191
wget -N --no-check-certificate https://raw.githubusercontent.com/arnofeng/ngx_google_deployment/master/index.html
92-
sed -i "s/g.adminhost.org/$DOMAIN1/" /var/www/google/index.html
93-
sed -i "s/x.adminhost.org/$DOMAIN2/" /var/www/google/index.html
92+
sed -i "s#g.adminhost.org#$DOMAIN1#g" /var/www/google/index.html
93+
sed -i "s#x.adminhost.org#$DOMAIN2#g" /var/www/google/index.html
9494
#9.set auto-start for nginx
9595
cp -r -f /etc/rc.local /etc/rc.local_bak
96-
sed -i 's/\"exit 0\"/\#/' /etc/rc.local
97-
sed -i 's/\#exit 0/\#/' /etc/rc.local
98-
sed -i 's/exit 0/\/etc\/nginx\/sbin\/nginx \nexit 0/' /etc/rc.local
96+
AUTO='/etc/nginx/sbin/nginx'
97+
cat /etc/rc.local|grep 'exit 0'
98+
if [ $? -eq 0 ]; then
99+
sed -i 's/\"exit 0\"/\#/g' /etc/rc.local
100+
sed -i 's/\#exit 0/\#/g' /etc/rc.local
101+
sed -i "s#exit 0#$AUTO\nexit 0#" /etc/rc.local
102+
else
103+
echo "$AUTO">>/etc/rc.local
104+
fi
99105
#10.start nginx
100106
/etc/nginx/sbin/nginx
101107
if [ $? -eq 0 ]; then

install.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ function update {
4747
mkdir -p /etc/nginx/vhost
4848
cd /usr/src
4949
wget -N --no-check-certificate https://raw.githubusercontent.com/arnofeng/ngx_google_deployment/master/nginx.conf
50-
sed -i "s/g.adminhost.org/$DOMAIN1/" /usr/src/nginx.conf
51-
sed -i "s/x.adminhost.org/$DOMAIN2/" /usr/src/nginx.conf
50+
sed -i "s#g.adminhost.org#$DOMAIN1#g" /usr/src/nginx.conf
51+
sed -i "s#x.adminhost.org#$DOMAIN2#g" /usr/src/nginx.conf
5252
cp -r -f /usr/src/nginx.conf /etc/nginx/nginx.conf
5353
/etc/nginx/sbin/nginx
5454
if [ $? -eq 0 ]; then

0 commit comments

Comments
 (0)