build.sh 4.3 KB
Newer Older
R
Rongfeng Fu 已提交
1 2 3 4
#!/bin/bash

python_bin='python'
W_DIR=`pwd`
R
Rongfeng Fu 已提交
5
VERSION=${VERSION:-'1.3.3'}
R
Rongfeng Fu 已提交
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


function python_version()
{
    return `$python_bin -c 'import sys; print (sys.version_info.major)'`
}

function ispy3()
{
    python_version
    if [ $? != 3 ]; then
        echo 'need python3'
        exit 1
    fi
}

function ispy2()
{
    python_version
    if [ $? != 2 ]; then
        echo 'need python2'
        exit 1
    fi
}

function cd2workdir()
{
    cd $W_DIR
    DIR=`dirname $0`
    cd $DIR
}
    

function pacakge_executer27()
{
    ispy2
    cd2workdir
    rm -fr executer27
    mkdir -p ./executer27/{site-packages,bin}
    cd executer27
F
v1.5.0  
frf12 已提交
46
    pip install -r ../../executer27-requirements.txt --target=./site-packages -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com || exit 1
R
Rongfeng Fu 已提交
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
    pyinstaller -F ../../executer27.py
    if [ -e dist/executer27 ]; then
        cp dist/executer27 ./bin/executer
        rm -fr build dist executer27.spec
    else
        exit 1
    fi
}

function pacakge_obd()
{
    ispy3
    cd2workdir
    DIR=`pwd`
    RELEASE=${RELEASE:-'1'}
    export RELEASE=$RELEASE
R
Rongfeng Fu 已提交
63
    export VERSION=$VERSION
R
Rongfeng Fu 已提交
64 65 66 67
    pip install -r ../requirements3.txt
    rm -fr rpmbuild
    mkdir -p rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
    rpmbuild --define "_topdir $DIR/rpmbuild" -bb ob-deploy.spec
R
Rongfeng Fu 已提交
68
    rpms=`find rpmbuild/RPMS/ -name ob-deploy-\*` || exit 1
R
Rongfeng Fu 已提交
69 70 71 72 73 74
    for rpm in ${rpms[@]}; do
        cp $rpm ./
    done
    rm -fr rpmbuild
}

R
Rongfeng Fu 已提交
75 76 77 78 79 80 81 82 83
function package_web()
{
    cd2workdir
    DIR=`pwd`/../web
    cd $DIR
    yarn
    yarn build
}

R
Rongfeng Fu 已提交
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
function get_python()
{
    if [ `id -u` != 0 ] ; then
        echo "Please use root to run"
    fi

    obd_dir=`dirname $0`
    python_path=`which python`
    for bin in ${python_path[@]}; do
        if [ -e $bin ]; then
            python_bin=$bin
            break 1
        fi
    done

    if [ ${#python_path[*]} -gt 1 ]; then
        read -p "Enter python path [default $python_bin]:"
        if [ "x$REPLY" != "x" ]; then
            python_bin=$REPLY
        fi
    fi
}

function build()
{
    python_version
    if [ $? != 2 ]; then
        req_fn='requirements3'
    else
        req_fn='requirements'
    fi
    cd2workdir
    DIR=`pwd`
    cd ..
R
Rongfeng Fu 已提交
118 119 120 121 122 123 124
    if [ `git log |head -n1 | awk -F' ' '{print $2}'` ]; then
        CID=`git log |head -n1 | awk -F' ' '{print $2}'`
        BRANCH=`git rev-parse --abbrev-ref HEAD`
    else
        CID='UNKNOWN'
        BRANCH='UNKNOWN'
    fi
R
Rongfeng Fu 已提交
125
    DATE=`date '+%b %d %Y %H:%M:%S'`
R
Rongfeng Fu 已提交
126
    VERSION="$VERSION".`date +%s`
R
Rongfeng Fu 已提交
127 128 129 130 131
    BUILD_DIR="$DIR/.build"
    rm -fr $BUILD_DIR
    mkdir -p $BUILD_DIR/lib/site-packages
    mkdir -p $BUILD_DIR/mirror/remote
    wget https://mirrors.aliyun.com/oceanbase/OceanBase.repo -O $BUILD_DIR/mirror/remote/OceanBase.repo
R
Rongfeng Fu 已提交
132 133
    sed -i "s/<CID>/$CID/" const.py  && sed -i "s/<B_BRANCH>/$BRANCH/" const.py  && sed -i  "s/<B_TIME>/$DATE/" const.py  && sed -i "s/<DEBUG>/$OBD_DUBUG/" const.py && sed -i "s/<VERSION>/$VERSION/" const.py
    cp -f _cmd.py obd.py
F
v1.5.0  
frf12 已提交
134
    sed -i "s|<DOC_LINK>|$OBD_DOC_LINK|" _errno.py
135 136 137
    pip install -r $req_fn.txt || exit 1
    pip install -r plugins-$req_fn.txt --target=$BUILD_DIR/lib/site-packages || exit 1
    pyinstaller --hidden-import=decimal --hidden-import=configparser -F obd.py || exit 1
R
Rongfeng Fu 已提交
138 139
    rm -f obd.py obd.spec
    cp -r plugins $BUILD_DIR/plugins
R
Rongfeng Fu 已提交
140 141 142
    cp -r config_parser $BUILD_DIR/config_parser
    rm -fr $BUILD_DIR/plugins/oceanbase-ce
    rm -fr $BUILD_DIR/config_parser/oceanbase-ce
R
Rongfeng Fu 已提交
143 144 145 146
    rm -fr /usr/obd /usr/bin/obd
    cp ./dist/obd /usr/bin/obd 
    cp -fr ./profile/* /etc/profile.d/
    rm -fr dist
F
v1.5.0  
frf12 已提交
147 148
    cd $BUILD_DIR/plugins && ln -s oceanbase oceanbase-ce && cp -rf obproxy/3.1.0 obproxy-ce/ && cp -rf $DIR/plugins/obproxy-ce/* obproxy-ce/
    cd $BUILD_DIR/config_parser && ln -s oceanbase oceanbase-ce
R
Rongfeng Fu 已提交
149
    mv $BUILD_DIR /usr/obd
R
Rongfeng Fu 已提交
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
    chmod +x /usr/bin/obd
    chmod -R 755 /usr/obd/*
    chown -R root:root /usr/obd/*
    find /usr/obd -type f -exec chmod 644 {} \;
    echo -e 'Installation of obd finished successfully\nPlease source /etc/profile.d/obd.sh to enable it'
}

case "x$1" in
    xexecuter)
        pacakge_executer27
    ;;
    xrpm_obd)
        pacakge_obd
    ;;
    xrpm-all);&
	xrpm)
        pacakge_executer27
        $2
        pacakge_obd
    ;;
    xbuild_obd)
        build
    ;;
    xbuild)
        get_python
        pacakge_executer27
        $2
        get_python
        build
    ;;
R
Rongfeng Fu 已提交
180 181 182 183
    xweb)
        package_web
    ;;
esac