|
#!/bin/zsh |
|
|
|
if [[ -z $1 ]]; then |
|
echo "Auto Build Script by geta6" |
|
echo "" |
|
echo "Usage: build [command] [branch]" |
|
echo "" |
|
echo "command:" |
|
echo " test # exit with no configure" |
|
echo " configure # configure only" |
|
echo " make # make only" |
|
echo " install # install" |
|
echo "" |
|
echo "branch:" |
|
echo " if detected branch param, do not use version detector" |
|
echo "" |
|
exit 0 |
|
fi |
|
|
|
echo "" |
|
|
|
NG() { |
|
echo "\x1b[31m$1\n" |
|
exit 1 |
|
} |
|
OK() { |
|
echo "\x1b[36m$1\n" |
|
exit 0 |
|
} |
|
|
|
[[ ! $1 =~ '(test|configure|make|install)' ]] && NG 'invalid command.' |
|
|
|
while : ; do |
|
[[ -d '.git' ]] && ROOT=`pwd` && break; cd .. |
|
[[ `pwd` = '/' ]] && NG "'.git' NOT found." |
|
done |
|
|
|
while read l |
|
do |
|
[[ $l =~ '\[remote \"origin\"\]' ]] && REPO='find' |
|
if [[ $REPO = 'find' && $l =~ 'url = ' ]]; then |
|
REPO=`echo $l | sed -e 's/^.*url = //g'` |
|
NAME=`echo $REPO | sed -e 's/^.*\/\(.*\?\)\.git/\1/g'` |
|
break |
|
fi |
|
done < $ROOT/.git/config |
|
|
|
[[ ! $NAME =~ '(node|nginx)' ]] && NG 'invalid repo.' |
|
|
|
git checkout master > /dev/null 2>&1 |
|
git pull origin master > /dev/null 2>&1 |
|
|
|
if [[ -z $2 ]]; then |
|
TAGS=`git tag | sed -e '/^[^v]/d'` |
|
V1=0 |
|
V2=0 |
|
V3=0 |
|
echo $TAGS | while read t; do [[ $V1 < $(( T1=`echo $t | cut -c2- | cut -d'.' -f1` )) ]] && V1=$T1; done |
|
echo $TAGS | grep -E "^v$V1" | while read t; do [[ $V2 -lt $(( T2=`echo $t | cut -d'.' -f2` )) ]] && V2=$T2; done |
|
V2=$(( $V2 - $V2 % 2 )) |
|
echo $TAGS | grep -E "^v$V1\.$V2" | while read t; do [[ $V3 -lt $(( T3=`echo $t | cut -c2- | cut -d'.' -f3` )) ]] && V3=$T3; done |
|
VERSION="v$V1.$V2.$V3" |
|
else |
|
VERSION=$2 |
|
fi |
|
|
|
git checkout $VERSION > /dev/null 2>&1 |
|
|
|
echo "Repo $REPO" |
|
echo "Root $ROOT" |
|
echo "Name $NAME" |
|
echo "Branch $VERSION" |
|
echo "-----" |
|
|
|
|
|
[[ 'test' = $1 ]] && OK 'test done.' |
|
|
|
case $NAME in |
|
nginx) |
|
[[ ! -d modules ]] && mkdir modules |
|
if [[ ! -d modules/ngx_pagespeed ]]; then |
|
git clone https://github.com/pagespeed/ngx_pagespeed modules/ngx_pagespeed |
|
cd "$ROOT/modules/ngx_pagespeed" |
|
git checkout release-1.6.29.3-beta |
|
wget https://dl.google.com/dl/page-speed/psol/1.6.29.3.tar.gz |
|
tar -xzvf 1.6.29.3.tar.gz && rm 1.6.29.3.tar.gz |
|
cd "$ROOT" |
|
fi |
|
./configure \ |
|
--user=nginx \ |
|
--group=nginx \ |
|
--prefix=/usr \ |
|
--http-log-path=/var/log/nginx/access.log \ |
|
--error-log-path=/var/log/nginx/errors.log \ |
|
--conf-path=/etc/nginx/nginx.conf \ |
|
--http-proxy-temp-path=/var/lib/nginx/tmp/proxy \ |
|
--http-client-body-temp-path=/var/lib/nginx/tmp/client_body \ |
|
--http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi \ |
|
--pid-path=/run/nginx.pid \ |
|
--lock-path=/var/lock/subsys/nginx \ |
|
--with-http_ssl_module \ |
|
--with-http_dav_module \ |
|
--with-http_spdy_module \ |
|
--with-http_sub_module \ |
|
--with-http_xslt_module \ |
|
--with-http_realip_module \ |
|
--with-http_degradation_module \ |
|
--with-http_gzip_static_module \ |
|
--with-http_image_filter_module \ |
|
--with-http_secure_link_module \ |
|
--with-http_addition_module \ |
|
--with-mail \ |
|
--with-mail_ssl_module \ |
|
--without-http_scgi_module \ |
|
--without-http_uwsgi_module \ |
|
--add-module=modules/ngx_pagespeed |
|
[[ 'configure' = $1 ]] && OK 'configure done' |
|
[[ ! -d /var/lib/nginx/tmp ]] && mkdir -p /var/lib/nginx/tmp |
|
[[ ! -d /var/lib/nginx/tmp ]] && mkdir -p /var/lib/nginx/tmp |
|
make |
|
[[ 'make' = $1 ]] && OK 'make done' |
|
if [[ 'install' = $1 ]]; then |
|
killall nginx && make install && nginx |
|
fi |
|
;; |
|
|
|
node) |
|
./configure --prefix=/usr/local |
|
[[ 'configure' = $1 ]] && OK 'configure done' |
|
make |
|
[[ 'make' = $1 ]] && OK 'make done' |
|
if [[ 'install' = $1 ]]; then |
|
make install |
|
fi |
|
;; |
|
|
|
esac |