Commit f52dbd09 authored by Jondy Zhao's avatar Jondy Zhao

Refine build-slapos script

parent a102426b
#! /bin/bash
export PATH=/usr/local/bin:/usr/bin:$PATH
export PATH=/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin:$PATH
slapos_home=/opt/slapos
slapos_home=${1-/opt/slapos}
slapos_cache=/opt/download-cache
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
if [[ ! -d $slapos_home ]] ; then
echo "Make directory of slapos home: $slapos_home"
mkdir -p $slapos_home
fi
if [[ ! -d $slapos_cache ]] ; then
echo "Make directory of slapos cache: $slapos_cache"
mkdir -p $slapos_cache
fi
mkdir -p $slapos_home/log
mkdir -p $slapos_cache
cd $slapos_home
if [[ ! -f buildout.cfg ]] ; then
echo "Create $slapos_home/buildout.cfg"
echo "[buildout]
extends = http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/heads/cygwin-0:/component/slapos/buildout.cfg
download-cache = /opt/download-cache
prefix = ${buildout:directory}
" > buildout.cfg
if [[ -r $slapos_cfg ]] ; then
echo "Change $slapos_home/buildout.cfg with "
echo " extends = ${slapos_url}"
sed -i -e "s%^extends = .*$%extends = ${slapos_url}%g" $slapos_cfg
else
echo "Edit $slapos_home/buildout.cfg"
sed -i -e "s%^extends = .*$%extends = http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/heads/cygwin-0:/component/slapos/buildout.cfg%g" buildout.cfg
cat <<EOF > $slapos_cfg
[buildout]
extends = ${slapos_url}
download-cache = ${slapos_cache}
prefix = $${buildout:directory}
EOF
echo "$slapos_home/buildout.cfg created."
fi
if [[ ! -f bootstrap.py ]] ; then
echo "Download $slapos_home/bootstrap.py"
python -S -c 'import urllib2;print urllib2.urlopen("http://git.erp5.org/gitweb/slapos.core.git/blob_plain/HEAD:/bootstrap.py").read()' > bootstrap.py
python -S bootstrap.py
(($?)) && echo "SlapOS bootstrap failed." && exit 1
if [[ ! -f $slapos_bootstrap ]] ; then
python -S -c 'import urllib2;print urllib2.urlopen("http://git.erp5.org/gitweb/slapos.core.git/blob_plain/HEAD:/bootstrap.py").read()' > $slapos_bootstrap
echo "$slapos_bootstrap downloaded."
if (! cd $slapos_home ; python -S bootstrap.py) ; then
echo "SlapOS bootstrap failed."
exit 1
fi
fi
bin/buildout -v -N
(($?)) && echo "Buildout SlapOS failed." && exit 1
# cd $slapos_home
if (! cd $slapos_home ; $slapos_home/bin/buildout -v -N) ; then
echo "SlapOS buildout failed."
exit 1
fi
# apply patches
patch_file=/etc/slapos/patches/slapos-core-format.patch
if [[ -f $patch_file ]] ; then
echo "Apply patch: $patch_file"
for x in $(find $slapos_home/eggs -name slapos.core-*.egg ; do
echo Patching $x ...
cd $x
patch -f --dry-run -p1 < $patch_file > /dev/null && patch -p1 < $patch_file && echo Patch $x OK.
for filename in $patch_files ; do
if [[ -r $filename ]] ; then
echo "Apply patch: $filename"
for x in $(find $slapos_home/eggs -name slapos.core-*.egg) ; do
echo " at $x ..."
(cd $x ; patch -f --dry-run -p1 < $filename > /dev/null && \
patch -p1 < $filename && echo " OK.")
done
fi
fi
done
echo Build SlapOS successfully.
read -n 1 -p "Press any key to exit..."
read -n 1 -t 60 -p "Press any key to exit..."
exit 0
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment