build-slapos.sh 2.18 KB
Newer Older
1
#! /bin/bash
Jondy Zhao's avatar
Jondy Zhao committed
2
export PATH=/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin:$PATH
3

4 5 6 7 8 9 10
function show_error_exit()
{
    echo Error: ${1-Error: build slapos failed.}
    read -n 1 -p "Press any key to exit..."
    exit 1
}

Jondy Zhao's avatar
Jondy Zhao committed
11
slapos_home=${1-/opt/slapos}
Jondy Zhao's avatar
Jondy Zhao committed
12
slapos_cache=/opt/download-cache
Jondy Zhao's avatar
Jondy Zhao committed
13 14 15 16
slapos_url=http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/heads/cygwin-0:/component/slapos/buildout.cfg
slapos_cfg=$slapos_home/buildout.cfg
slapos_bootstrap=$slapos_home/bootstrap.py
patch_files=/etc/slapos/patches/slapos-core-format.patch
Jondy Zhao's avatar
Jondy Zhao committed
17

Jondy Zhao's avatar
Jondy Zhao committed
18 19
mkdir -p $slapos_home/log
mkdir -p $slapos_cache
20

21
echo "Checking $slapos_cfg ..."
Jondy Zhao's avatar
Jondy Zhao committed
22
if [[ -r $slapos_cfg ]] ; then
23
    echo "Change $slapos_cfg:"
Jondy Zhao's avatar
Jondy Zhao committed
24 25
    echo "  extends = ${slapos_url}"
    sed -i -e "s%^extends = .*$%extends = ${slapos_url}%g" $slapos_cfg
26
else
Jondy Zhao's avatar
Jondy Zhao committed
27 28 29 30 31 32
    cat <<EOF  > $slapos_cfg
[buildout]
extends = ${slapos_url}
download-cache = ${slapos_cache}
prefix = $${buildout:directory}
EOF
33
    echo "File $slapos_cfg has been generated."
34 35
fi

36
echo "Checking $slapos_bootstrap ..."
Jondy Zhao's avatar
Jondy Zhao committed
37
if [[ ! -f $slapos_bootstrap ]] ; then
38 39 40 41 42 43
    echo "Downloading $slapos_bootstrap ..."
    python -S -c 'import urllib2;print urllib2.urlopen("http://git.erp5.org/gitweb/slapos.core.git/blob_plain/HEAD:/bootstrap.py").read()' > $slapos_bootstrap ||
    show_error_exit "Error: download $slapos_bootstrap"
    echo "Downlaod $slapos_bootstrap OK."
else
    echo OK.
44 45
fi

46 47 48 49
if [[ ! -x $slapos_home/run/buildout ]] ; then
    echo "Bootstrap slapos ..."
    (cd $slapos_home ; python -S bootstrap.py) || show_error_exit "Error: slapos bootstrap failed."
    echo "Bootstrap slapos OK."
Jondy Zhao's avatar
Jondy Zhao committed
50
fi
51

52 53 54 55 56
echo
echo Start buildout of slapos ...
echo
(cd $slapos_home ; $slapos_home/bin/buildout -v -N) || show_error_exit "Error slapos buildout failed."

57
# apply patches
58 59 60 61 62 63 64
for _filename in $patch_files ; do
    if [[ -r ${_filename} ]] ; then
        echo "Apply patch: ${_filename}"
        for _path in $(find $slapos_home/eggs -name slapos.core-*.egg) ; do
            echo "  at ${_path} ..."
            (cd ${_path} ; patch -f --dry-run -p1 < ${_filename} > /dev/null &&
                patch -p1 < ${_filename} && echo "OK.")
Jondy Zhao's avatar
Jondy Zhao committed
65 66 67
        done
    fi
done
68

69 70 71
echo
echo Build slapos node successfully.
echo
Jondy Zhao's avatar
Jondy Zhao committed
72
read -n 1 -t 60 -p "Press any key to exit..."
73
exit 0