Commit 2eb41cbf authored by Jondy Zhao's avatar Jondy Zhao

refine script: slapos-cygwin-bootstrap.sh

parent feda5238
...@@ -8,6 +8,13 @@ ...@@ -8,6 +8,13 @@
<surname>Zhao</surname> <surname>Zhao</surname>
</author> </author>
<revhistory> <revhistory>
<revision>
<revnumber>0.6</revnumber>
<date>2013-09-04</date>
<authorinitials>Jondy Zhao - jondy.zhao@nexedi.com</authorinitials>
<revremark>Add chapter Inside SlapOS Cygwin Node. </revremark>
</revision>
<revision> <revision>
<revnumber>0.5</revnumber> <revnumber>0.5</revnumber>
<date>2013-08-29</date> <date>2013-08-29</date>
...@@ -433,7 +440,7 @@ Assum SourceDir in the section "Setup" is "D:\slapos", the builder will find "D: ...@@ -433,7 +440,7 @@ Assum SourceDir in the section "Setup" is "D:\slapos", the builder will find "D:
<para>This chapter describes how to run slapos slave node from sources in the windows.</para> <para>This chapter describes how to run slapos slave node from sources in the windows.</para>
<para>First Setting Up Cygwin follow the instructions in the above chapter <xref linkend="sec_setup_cygwin"/></para> <para>First Setting Up Cygwin follow the instructions in the above chapter <xref linkend="sec_setup_cygwin"/></para>
<para>Next register to slapos community to get client and computer certificate and key files, refer to <xref linkend="sec_configure_slapos"/>.</para> <para>Next register to slapos community to get client and computer certificate and key files, refer to <xref linkend="sec_configure_slapos"/>.</para>
<para>Then run slapos-cygwin-bootstrap.sh, got it from slapos.package.git/windows/scripts</para> <para>Then run slapos-cygwin-bootstrap.sh, slapos-configure.sh, slapos-node.sh in turn, got it from slapos.package.git/windows/scripts</para>
<para>If there are some errors when run both of scripts, fix them and run again, until no any error reported, and now you can run any slapos command in this terminal.</para> <para>If there are some errors when run both of scripts, fix them and run again, until no any error reported, and now you can run any slapos command in this terminal.</para>
</chapter> </chapter>
...@@ -505,8 +512,9 @@ Then upload the source packages dist/psutil-1.0.1.tar.gz to http://www.nexedi.or ...@@ -505,8 +512,9 @@ Then upload the source packages dist/psutil-1.0.1.tar.gz to http://www.nexedi.or
<listitem><para>Install cygwin</para></listitem> <listitem><para>Install cygwin</para></listitem>
<listitem><para>Prepare certificate, key, computer.key, computer.crt</para></listitem> <listitem><para>Prepare certificate, key, computer.key, computer.crt</para></listitem>
<listitem><para>Run slapos-cygwin-bootstrap.sh, got it from slapos.package.git/windows/scripts</para></listitem> <listitem><para>Run slapos-cygwin-bootstrap.sh, got it from slapos.package.git/windows/scripts</para></listitem>
<listitem><para>Run command slapos node software/release until instance created</para></listitem> <listitem><para>Run slapos-configure.sh, got it from slapos.package.git/windows/scripts</para></listitem>
<listitem><para>Run command slapos remove to destroy this instance</para></listitem> <listitem><para>Go to https://www.slapos.org, install test-agent in this node</para></listitem>
<listitem><para>Run command slapos-node.sh</para></listitem>
</itemizedlist> </itemizedlist>
</para> </para>
...@@ -516,6 +524,101 @@ Then upload the source packages dist/psutil-1.0.1.tar.gz to http://www.nexedi.or ...@@ -516,6 +524,101 @@ Then upload the source packages dist/psutil-1.0.1.tar.gz to http://www.nexedi.or
</section> </section>
</chapter> </chapter>
<chapter><title>Inside SlapOS Cygwin Node</title>
<para>This chapter descripts the internal of slapos cygwin node:
<itemizedlist>
<listitem><para>What we will do to create SlapOS node in the Cygwin</para></listitem>
<listitem><para>Use shell scripts to do these tasks</para></listitem>
</itemizedlist>
</para>
<section><title>What we will do to create SlapOS node in the Cygwin</title>
<para>In order to install SlapOS Node in the Cgywin, the tasks include:
<variablelist>
<varlistentry>
<term>Setup cygwin</term>
<listitem><para>See setup-cygwin.bat to know the detail</para></listitem>
</varlistentry>
<varlistentry>
<term>Patch cygwin</term>
<listitem><para>See function slapos-cygwin-bootstrap.sh!slapos_patch_cygwin</para></listitem>
</varlistentry>
<varlistentry>
<term>Create cygserver and syslog-ng service</term>
<listitem><para>The service names have a prefix so that we can install multi-nodes in one machine. Both of these services is running by local system account.</para></listitem>
</varlistentry>
<varlistentry>
<term>Install slapos-cygwin package</term>
<listitem><para>Extra scripts for slapos running in the cygwin, for examples, ipwin, regpwd, ip etc.</para></listitem>
</varlistentry>
<varlistentry>
<term>Create super user</term>
<listitem><para>The super user is used to start cron and re6stnet services, it's required in Windows 7 and later.</para></listitem>
</varlistentry>
<varlistentry>
<term>Create network interface for slapos</term>
<listitem><para>Slapos use a msloop insterface as its own interface, default name is 're6stnet-lo'. If there is more than one slapos node in the same machine, each node use a prefix.</para></listitem>
</varlistentry>
<varlistentry>
<term>Install re6stnet</term>
<listitem><para>We need re6stnet application except you specify an IPv6 address by manual way.</para></listitem>
</varlistentry>
<varlistentry>
<term>Run re6st-conf</term>
<listitem><para>By this way, we get our IPv6 address assigned by re6stnet network.</para></listitem>
</varlistentry>
<varlistentry>
<term>Install OpenVPN and Copy files to cygwin</term>
<listitem><para>It's required only no native IPv6</para></listitem>
</varlistentry>
<varlistentry>
<term>Build cygwin babeld</term>
<listitem><para>It's required only no native IPv6</para></listitem>
</varlistentry>
<varlistentry>
<term>Install re6stnet service</term>
<listitem><para>It's required only no native IPv6</para></listitem>
</varlistentry>
<varlistentry>
<term>Build SlapOS</term>
<listitem><para>In the Cygwin, we need apply 2 patches: slapos-core-format.patch, supervisor-cygwin.patch</para></listitem>
</varlistentry>
<varlistentry>
<term>Configure SlapOS Node</term>
<listitem><para></para></listitem>
</varlistentry>
<varlistentry>
<term>Run slapos format</term>
<listitem><para></para></listitem>
</varlistentry>
<varlistentry>
<term>Configure SlapOS Client</term>
<listitem><para>If we don't create instance in this SlapOS node, we need not configure slapos client.</para></listitem>
</varlistentry>
<varlistentry>
<term>Create Instance of Slap-Runner</term>
<listitem><para>After this software is releasesd, we need apply the patch 'slapos-cookbook-inotifyx.patch', otherwise it will not work in Cygwin now. </para></listitem>
</varlistentry>
<varlistentry>
<term>Create Instance of Test-Agent</term>
<listitem><para></para></listitem>
</varlistentry>
</variablelist>
Most of tasks list above section could be done by shell scripts, now we have the following scripts:
<itemizedlist>
<listitem><para>setup-cygwin.bat</para></listitem>
<listitem><para>slapos-cygwin-bootstrap.sh</para></listitem>
<listitem><para>slapos-configure.sh</para></listitem>
<listitem><para>slapos-node.sh</para></listitem>
<listitem><para>slapos-cleanup.sh</para></listitem>
<listitem><para>autorebase.bat</para></listitem>
</itemizedlist>
Except autorebase.bat, all of these scripts could be downloaded from <ulink url="http://git.erp5.org/gitweb/slapos.package.git/tree/refs/heads/cygwin:/windows/scripts?js=1"/>. You can read the source or run script with '-h' to know the usage of these scripts.
</para>
<para>The autorebase.bat located in the cygwin root path is generated by slapos-cygwin-bootstap.sh, and used to fix the remap problem. If cygwin reports remap error, you could run this script to fix the problem. Before run this script, you need close all the cygwin terminals at first, then double click autorebase.bat in the windows explorer.</para>
</section>
</chapter>
<appendix id="appendix_cygwin_packages"><title>Cygwin Required Packages List</title> <appendix id="appendix_cygwin_packages"><title>Cygwin Required Packages List</title>
<para>The following packages are requied by SlapOS Node <para>The following packages are requied by SlapOS Node
<itemizedlist> <itemizedlist>
......
#! /bin/bash #! /bin/bash
# #
function check_os_is_wow64() export PATH=/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin:$PATH
{ if ! source /usr/share/csih/cygwin-service-installation-helper.sh ; then
[[ $(uname) == CYGWIN_NT-*-WOW64 ]] echo "Error: Missing csih package."
} exit 1
readonly -f check_os_is_wow64 fi
# ======================================================================
# Functions
# ======================================================================
function show_usage() function show_usage()
{ {
echo "This script is used to build a bootstrap slapos in cywin." echo "This script is used to build a bootstrap slapos in cywin."
echo "" echo ""
echo "Usage:" echo "Usage:"
echo "" echo ""
echo " ./slapos-cygwin-bootstrap.sh" echo " ./slapos-cygwin-bootstrap.sh [--prefix=prefix] [-f | --force]"
echo ""
echo " --prefix=prefix The prefix is used by network connection name,"
echo " cygwin service name."
echo " --force"
echo " -f Force mode, everything will be reinstalled "
echo " even if it exits."
echo "" echo ""
echo "Before run this script, type the following command in the windows" echo "Before run this script, type the following command in the windows"
echo "command console to install cygwin:" echo "command console to install cygwin:"
echo "" echo ""
echo " setup_cygwin.bat C:\slapos-bootstrap network" echo " setup_cygwin.bat C:\slapos network"
echo "" echo ""
echo "Then sign up slapos.org, got the following certificate files:" echo "Then sign up slapos.org, got the following certificate files:"
echo "" echo ""
...@@ -28,59 +37,241 @@ function show_usage() ...@@ -28,59 +37,241 @@ function show_usage()
echo "" echo ""
echo "save them in your home path." echo "save them in your home path."
echo "" echo ""
echo "Register another computer for test node, save them in the root path"
echo ""
echo " test-computer.key"
echo " test-computer.crt"
echo ""
echo ""
} }
readonly -f show_usage readonly -f show_usage
export PATH=/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin:$PATH function check_os_is_wow64()
if ! source /usr/share/csih/cygwin-service-installation-helper.sh ; then {
echo "Error: Missing csih package." [[ $(uname) == CYGWIN_NT-*-WOW64 ]]
exit 1 }
fi readonly -f check_os_is_wow64
csih_inform "Starting bootstrap slapos node ..." function slapos_sanity_check()
echo "" {
csih_check_program_or_error /usr/bin/cygport cygport
csih_check_program_or_error /usr/bin/libtool libtool
# ====================================================================== _filename=$(cygpath -a -w $(cygpath -w /)\\..\\setup.exe)
# Constants [[ -f $(cygpath -u ${_filename}) ]] || csih_error "missing ${_filename}"
# ====================================================================== }
declare -r slapos_prefix=slapboot- readonly -f slapos_sanity_check
declare -r slapos_client_home=~/.slapos
declare -r client_configure_file=$slapos_client_home/slapos.cfg
declare -r client_certificate_file=$slapos_client_home/certificate
declare -r client_key_file=$slapos_client_home/key
declare -r node_certificate_file=/etc/opt/slapos/ssl/computer.crt
declare -r node_key_file=/etc/opt/slapos/ssl/computer.key
declare -r node_configure_file=/etc/opt/slapos/slapos.cfg
declare -r ipv4_local_network=10.202.29.0/24
declare -r ipv6_local_address=2001:67c:1254:e:32::1
declare -r slapos_administrator=${slapos_prefix:-slap}root
declare -r slapos_user_basename=${slapos_prefix:-slap}user
declare -r slapos_ifname=${slapos_prefix}re6stnet-lo
declare -r re6stnet_service_name=${slapos_prefix}re6stnet
declare -r cron_service_name=${slapos_prefix}cron
declare -r syslog_service_name=${slapos_prefix}syslog-ng
declare -r cygserver_service_name=${slapos_prefix}cygserver
declare -r slapos_installer_software=http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/heads/cygwin-share:/software/slapos-windows-installer/software.cfg function slapos_patch_cygwin()
declare -r cygwin_home=$(cygpath -a $(cygpath -w /)\\.. | sed -e "s%/$%%") {
csih_inform "Patching cygwin packages for building slapos"
# ----------------------------------------------------------- csih_inform "libtool patched"
# Local variable sed -i -e "s/4\.3\.4/4.5.3/g" /usr/bin/libtool
# -----------------------------------------------------------
declare _administrator=${slapos_administrator} csih_inform "/etc/passwd generated"
declare _password= [[ -f /etc/passwd ]] || mkpasswd > /etc/passwd
declare _computer_certificate=
declare _computer_key= csih_inform "/etc/group generated"
declare _client_certificate= [[ -f /etc/group ]] || mkgroup > /etc/group
declare _client_key=
declare _ipv4_local_network=${ipv4_local_network} _filename=/usr/bin/cygport
if [[ -f ${_filename} ]] ; then
csih_inform "Patching ${_filename} ..."
sed -i -e 's/D="${workdir}\/inst"/D="${CYGCONF_PREFIX-${workdir}\/inst}"/g' ${_filename} &&
csih_inform "OK"
else
csih_error "Missing cygport package, no ${_filename} found."
fi
_filename=/usr/share/cygport/cygclass/autotools.cygclass
if [[ -f ${_filename} ]] ; then
csih_inform "Patching ${_filename} ..."
sed -i -e 's/prefix=$(__host_prefix)/prefix=${CYGCONF_PREFIX-$(__host_prefix)}/g' ${_filename} &&
csih_inform "OK"
else
csih_error "Missing cygport package, no ${_filename} found."
fi
_filename=/usr/share/cygport/cygclass/cmake.cygclass
if [[ -f ${_filename} ]] ; then
csih_inform "Patching ${_filename} ..."
sed -i -e 's/-DCMAKE_INSTALL_PREFIX=$(__host_prefix)/-DCMAKE_INSTALL_PREFIX=${CYGCONF_PREFIX-$(__host_prefix)}/g' ${_filename} &&
csih_inform "OK"
else
csih_error "Missing cygport package, no ${_filename} found."
fi
# Change format of readme.txt
_filename=$(cygpath -u $(cygpath -m /)/../readme.txt)
if [[ -f ${_filename} ]] ; then
echo "Changing $(cygpath -w ${_filename}) as dos format ..."
unix2dos ${_filename} && echo OK.
fi
_filename=".minttyrc"
echo Checking ${_filename} ...
if [[ ! -f ${_filename} || "${_install_mode}" == "force" ]] ; then
cat <<EOF > ${_filename}
BoldAsFont=no
Font=Courier New
FontHeight=16
Scrollbar=none
EOF
echo "${_filename} has been generated."
else
echo OK.
fi
_filename="/cygtty.bat"
echo Checking ${_filename} ...
if [[ ! -x ${_filename} || "${_install_mode}" == "force" ]] ; then
cat <<EOF > ${_filename}
@echo off
${slapos_cygroot:0:2}
chdir ${slapos_cygroot}\\bin
start mintty.exe -i /Cygwin-Terminal.ico -
EOF
chmod +x ${_filename}
echo "${_filename} has been generated."
else
echo OK.
fi
_filename="/autorebase.bat"
echo Checking ${_filename} ...
if [[ ! -f ${_filename} || "${_install_mode}" == "force" ]] ; then
cat <<EOF > ${_filename}
@echo off
${slapos_cygroot:0:2}
CHDIR ${slapos_cygroot}
${slapos_cygroot}\bin\find /opt/slapos -name "*.dll" > ${slapos_cygroot}\myfile.list
IF EXIST ${slapos_cygroot}\opt\slapgrid. ${slapos_cygroot}\bin\find /opt/slapgrid -name "*.dll" >> ${slapos_cygroot}\myfile.list
IF EXIST ${slapos_cygroot}\srv\slapgrid. ${slapos_cygroot}\bin\find /srv/slapgrid -name "*.dll" >> ${slapos_cygroot}\myfile.list
NET STOP ${slapos_prefix}cron
NET STOP ${slapos_prefix}re6stnet
NET STOP ${slapos_prefix}syslog-ng
NET STOP ${slapos_prefix}cygserver
bin\bash --login -c "/opt/slapos/bin/slapos node stop all"
bin\bash --login -c "for pid in \$(ps | grep '/usr/bin/python2.7' | gawk '{print \$4}') ; do TASKKILL /F /T /PID \$pid ; done"
PATH .\bin;%PATH%
dash /bin/rebaseall -T /myfile.list -v
PAUSE ...
EXIT 0
EOF
chmod +x ${_filename}
echo "${_filename} has been generated."
else
echo OK.
fi
csih_inform "Patch cygwin packages for building slapos OK"
echo ""
}
readonly -f slapos_patch_cygwin
function install_slapos_cygwin_package()
{
for _cmdname in ip useradd usermod groupadd brctl tunctl ; do
[[ -f /usr/bin${_cmdname} && -z "${_install_mode}" ]] && continue
wget -c http://git.erp5.org/gitweb/slapos.package.git/blob_plain/heads/cygwin:/windows/scripts/${_cmdname} -O /usr/bin/${_cmdname} ||
csih_error "download ${_cmdname} failed"
csih_inform "download cygwin script ${_cmdname} OK"
chmod +x /usr/bin/${_cmdname} || csih_error "chmod /usr/bin/${_cmdname} failed"
done
for _cmdname in regpwd ; do
[[ -x /usr/bin${_cmdname} && -z "${_install_mode}" ]] && continue
wget -c http://dashingsoft.com/products/slapos/${_cmdname}.exe -O /usr/bin/${_cmdname}.exe ||
csih_error "download ${_filename} failed"
csih_inform "download ${_filename} OK"
chmod +x /usr/bin/${_cmdname}.exe || csih_error "chmod /usr/bin/${_cmdname}.exe failed"
fi
for _cmdname in ipwin ; do
[[ -x /usr/bin${_cmdname} && -z "${_install_mode}" ]] && continue
if check_os_is_wow64 ; then
_filename=${_cmdname}-x64.exe
else
_filename=${_cmdname}-x86.exe
fi
wget -c http://dashingsoft.com/products/slapos/${_filename} -O /usr/bin/${_cmdname}.exe ||
csih_error "download ${_filename} failed"
csih_inform "download ${_filename} OK"
chmod +x /usr/bin/${_cmdname}.exe || csih_error "chmod /usr/bin/${_cmdname}.exe failed"
fi
_path=/etc/slapos/scripts
csih_inform "create path: ${_path}"
mkdir -p ${_path}
for _name in slapos-include.sh slapos-cygwin-bootstrap.sh slapos-configure.sh slapos-cleanup.sh ; do
[[ -x ${_path}/${_name} && -z "${_install_mode}" ]] && continue
wget -c http://git.erp5.org/gitweb/slapos.package.git/blob_plain/heads/cygwin:/windows/scripts/${_name} -O ${_path}/${_name} ||
csih_error "download ${_name} failed"
csih_inform "download script ${_path}/${_name} OK"
done
# Set prefix for slapos
if [[ -n "${slapos_prefix}" ]] ; then
echo "Set slapos prefix as ${slapos_prefix}"
sed -i -e "s%slapos_prefix=.*\$%slapos_prefix=${slapos_prefix}%" ${_path|/slapos-include.sh
fi
}
readonly -f install_slapos_cygwin_package
function install_ipv6_protocol()
{
csih_inform "Starting configure IPv6 protocol ..."
netsh interface ipv6 show interface > /dev/null || \
netsh interface ipv6 install || \
csih_error "install IPv6 protocol failed"
csih_inform "Configure IPv6 protocol OK"
echo ""
}
readonly -f install_ipv6_protocol
function install_cygserver_service()
{
csih_inform "Starting configure cygwin services ..."
if ! cygrunsrv --query ${cygserver_service_name} > /dev/null 2>&1 ; then
csih_inform "run cygserver-config ..."
/usr/bin/cygserver-config --yes || \
csih_error "failed to run cygserver-config"
[[ ${cygserver_service_name} == cygserver ]] ||
cygrunsrv -I ${cygserver_service_name} -d "CYGWIN ${cygserver_service_name}" -p /usr/sbin/cygserver ||
csih_error "failed to install service ${cygserver_service_name}"
else
csih_inform "the cygserver service has been installed"
fi
}
readonly -f install_cygserver_service
function install_syslog_service()
{
if ! cygrunsrv --query ${syslog_service_name} > /dev/null 2>&1 ; then
csih_inform "run syslog-ng-config ..."
/usr/bin/syslog-ng-config --yes || \
csih_error "failed to run syslog-ng-config"
[[ ${syslog_service_name} == "syslog-ng" ]] ||
cygrunsrv -I ${syslog_service_name} -d "CYGWIN ${syslog_service_name}" -p /usr/sbin/syslog-ng -a "-F" ||
csih_error "failed to install service ${syslog_service_name}"
else
csih_inform "the syslog-ng service has been installed"
fi
}
readonly -f install_cygserver_service
# ----------------------------------------------------------- # -----------------------------------------------------------
# Command line options # Start script
# ----------------------------------------------------------- # -----------------------------------------------------------
csih_inform "Starting bootstrap slapos node ..."
echo ""
_prefix=
_install_mode=
while test $# -gt 0; do while test $# -gt 0; do
# Normalize the prefix. # Normalize the prefix.
case "$1" in case "$1" in
...@@ -89,33 +280,15 @@ while test $# -gt 0; do ...@@ -89,33 +280,15 @@ while test $# -gt 0; do
esac esac
case "$1" in case "$1" in
--password=*) --prefix=*)
_password=$optarg _prefix=$optarg
;;
-P)
_password=$2
shift
;;
-P)
_administrator=$2
shift
;;
--computer-certificate=*)
_computer_certificate=$optarg
;; ;;
--computer-key=*) -f | --force)
_computer_key=$optarg _install_mode=force
;; ;;
--client-certificate=*) -h | --help)
_client_certificate=$optarg show_usage
;; exit 0
--client-key=*)
_client_key=$optarg
;;
--ipv4-local-network=*)
[[ x$optarg == x*.*.*.*/* ]] ||
csih_error "invalid --ipv4-local-network=$optarg, no match x.x.x.x/x"
_ipv4_local_network=$optarg
;; ;;
*) *)
show_usage show_usage
...@@ -127,377 +300,43 @@ while test $# -gt 0; do ...@@ -127,377 +300,43 @@ while test $# -gt 0; do
shift shift
done done
# ----------------------------------------------------------- # ======================================================================
# Patch cygwin packages for building slapos # Constants: slapos bootstrap node use prefiix "slapboot-"
# ----------------------------------------------------------- # ======================================================================
csih_inform "Patching cygwin packages for building slapos" declare -r slapos_prefix=${_prefix}
declare -r cygserver_service_name=${slapos_prefix}cygserver
csih_check_program_or_error /usr/bin/cygport cygport declare -r syslog_service_name=${slapos_prefix}syslog-ng
csih_check_program_or_error /usr/bin/libtool libtool declare -r slapos_cygroot=$(cygpath -w /)
csih_inform "libtool patched"
sed -i -e "s/4\.3\.4/4.5.3/g" /usr/bin/libtool
csih_inform "/etc/passwd generated"
[[ -f /etc/passwd ]] || mkpasswd > /etc/passwd
csih_inform "/etc/group generated"
[[ -f /etc/group ]] || mkgroup > /etc/group
_filename=$(cygpath -a -w $(cygpath -w /)\\..\\setup.exe)
csih_inform "check ${_filename}"
[[ -f $(cygpath -u ${_filename}) ]] || csih_error "missing ${_filename}"
_filename=/usr/bin/cygport
if [[ -f ${_filename} ]] ; then
csih_inform "Patching ${_filename} ..."
sed -i -e 's/D="${workdir}\/inst"/D="${CYGCONF_PREFIX-${workdir}\/inst}"/g' ${_filename} &&
csih_inform "OK"
else
csih_error "Missing cygport package, no ${_filename} found."
fi
_filename=/usr/share/cygport/cygclass/autotools.cygclass
if [[ -f ${_filename} ]] ; then
csih_inform "Patching ${_filename} ..."
sed -i -e 's/prefix=$(__host_prefix)/prefix=${CYGCONF_PREFIX-$(__host_prefix)}/g' ${_filename} &&
csih_inform "OK"
else
csih_error "Missing cygport package, no ${_filename} found."
fi
_filename=/usr/share/cygport/cygclass/cmake.cygclass
if [[ -f ${_filename} ]] ; then
csih_inform "Patching ${_filename} ..."
sed -i -e 's/-DCMAKE_INSTALL_PREFIX=$(__host_prefix)/-DCMAKE_INSTALL_PREFIX=${CYGCONF_PREFIX-$(__host_prefix)}/g' ${_filename} &&
csih_inform "OK"
else
csih_error "Missing cygport package, no ${_filename} found."
fi
for _cmdname in ip useradd usermod groupadd brctl tunctl ; do
wget -c http://git.erp5.org/gitweb/slapos.package.git/blob_plain/heads/cygwin:/windows/scripts/${_cmdname} -O /usr/bin/${_cmdname} ||
csih_error "download ${_cmdname} failed"
csih_inform "download cygwin script ${_cmdname} OK"
chmod +x /usr/bin/${_cmdname} || csih_error "chmod /usr/bin/${_cmdname} failed"
done
if check_os_is_wow64 ; then
wget -c http://dashingsoft.com/products/slapos/ipwin-x64.exe -O /usr/bin/ipwin.exe ||
csih_error "download ipwin-x64.exe failed"
csih_inform "download ipwin-x64.exe OK"
else
wget -c http://dashingsoft.com/products/slapos/ipwin-x86.exe -O /usr/bin/ipwin.exe ||
csih_error "download ipwin-x86.exe failed"
csih_inform "download ipwin-x86.exe OK"
fi
chmod +x /usr/bin/ipwin.exe || csih_error "chmod /usr/bin/ipwin.exe failed"
csih_inform "Patch cygwin packages for building slapos OK"
echo ""
# -----------------------------------------------------------
# Install network interface used by slapos node
# -----------------------------------------------------------
csih_inform "Starting configure slapos network ..."
if ! netsh interface ipv6 show interface | grep -q "\\b${slapos_ifname}\\b" ; then
csih_inform "Installing network interface ${slapos_ifname} ..."
ipwin install netloop.inf *msloop ${slapos_ifname} ||
csih_error "install network interface ${slapos_ifname} failed"
fi
ip -4 addr add $(echo ${ipv4_local_network} | sed -e "s%\.0/%.1/%g") dev ${slapos_ifname} ||
csih_error "add ipv4 address failed"
csih_inform "Configure slapos network OK"
echo ""
# -----------------------------------------------------------
# Check IPv6 protocol, install it if it isn't installed
# -----------------------------------------------------------
csih_inform "Starting configure IPv6 protocol ..."
netsh interface ipv6 show interface > /dev/null || \
netsh interface ipv6 install || \
csih_error "install IPv6 protocol failed"
csih_inform "Configure IPv6 protocol OK"
echo ""
# -----------------------------------------------------------
# Run the buildout of slapos node
# -----------------------------------------------------------
csih_inform "Starting run buildout of slapos node ..."
csih_inform "mkdir /opt/slapos/log"
mkdir -p /opt/slapos/log
csih_inform "mkdir /opt/download-cache"
mkdir -p /opt/download-cache
[[ -f /opt/slapos/buildout.cfg ]] ||
(cd /opt/slapos && echo "[buildout]
extends = http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/heads/cygwin-share:/component/slapos/buildout.cfg
download-cache = /opt/download-cache
prefix = ${buildout:directory}
" > buildout.cfg) &&
csih_inform "buildout.cfg generated"
[[ -f /opt/slapos/bootstrap.py ]] ||
(cd /opt/slapos &&
python -S -c 'import urllib2;print urllib2.urlopen("http://git.erp5.org/gitweb/slapos.core.git/blob_plain/HEAD:/bootstrap.py").read()' > bootstrap.py ) ||
csih_error "download bootstrap.py failed"
csih_inform "download bootstrap.py OK"
[[ -f /opt/slapos/bin/buildout ]] ||
(cd /opt/slapos && python -S bootstrap.py) ||
csih_error "run bootstrap.py failed"
csih_inform "run bootstrap.py OK"
csih_inform "start bin/buildout"
(cd /opt/slapos ; bin/buildout -v -N) || csih_error "bin/buildout failed"
_filename=~/slapos-core-format.patch
wget -c http://git.erp5.org/gitweb/slapos.package.git/blob_plain/heads/cygwin:/windows/patches/$(basename ${_filename}) -O ${_filename} ||
csih_error "download ${_filename} failed"
csih_inform "download ${_filename} OK"
csih_inform "applay patch ${_filename}"
(cd $(ls -d /opt/slapos/eggs/slapos.core-*.egg/) &&
csih_inform "patch at $(pwd)" &&
patch -f --dry-run -p1 < ${_filename} > /dev/null &&
patch -p1 < ${_filename} &&
csih_inform "apply patch ${_filename} OK")
_filename=~/supervisor-cygwin.patch
wget -c http://git.erp5.org/gitweb/slapos.package.git/blob_plain/heads/cygwin:/windows/patches/$(basename ${_filename}) -O ${_filename} ||
csih_error "download ${_filename} failed"
csih_inform "download ${_filename} OK"
csih_inform "applay patch ${_filename}"
(cd $(ls -d /opt/slapos/eggs/supervisor-*.egg)/supervisor &&
csih_inform "patch at $(pwd)" &&
patch -f --dry-run -p1 < ${_filename} > /dev/null &&
patch -p1 < ${_filename} &&
csih_inform "apply patch ${_filename} OK")
csih_inform "Run buildout of slapos node OK"
echo ""
# ----------------------------------------------------------- # -----------------------------------------------------------
# Configure slapos node and client # Sanity Check
# ----------------------------------------------------------- # -----------------------------------------------------------
csih_inform "Starting configure slapos client and node ..." slapos_sanity_check
for _name in certificate key computer.key computer.crt ; do
[[ -f ~/${_name} ]] || csih_error "missing file ~/${_name}"
done
for _name in test-computer.key test-computer.crt ; do
[[ -f ${cygwin_home}/${_name} ]] || csih_error "missing file ${cygwin_home}/${_name}"
done
cp ~/certificate ${cygwin_home} && csih_inform "copy ~/certificate to ${cygwin_home}"
cp ~/key ${cygwin_home} && csih_inform "copy ~/key to ${cygwin_home}"
csih_inform "mkdir /etc/opt/slapos/ssl/partition_pki"
mkdir -p /etc/opt/slapos/ssl/partition_pki
csih_inform "mkdir ${slapos_client_home}"
mkdir -p ${slapos_client_home}
(cp ~/certificate ${client_certificate_file} &&
cp ~/key ${client_key_file} &&
cp ~/computer.crt ${node_certificate_file} &&
cp ~/computer.key ${node_key_file} &&
csih_inform "copy certificate/key files OK") ||
csih_error "copy certificate/key files failed"
computer_guid=$(grep "CN=COMP" ${node_certificate_file} | \
sed -e "s/^.*, CN=//g" | sed -e "s%/emailAddress.*\$%%g")
[[ "${computer_guid}" == COMP-+([0-9]) ]] ||
csih_error_multi "${computer_guid} is invalid computer guid." \
"It should like 'COMP-XXXX', edit ${node_certificate_file}" \
"to fix it."
csih_inform "computer reference id: ${computer_guid}"
interface_guid=$(ipwin guid *msloop ${slapos_ifname}) ||
csih_error "get guid of interface ${slapos_ifname} failed"
[[ "$interface_guid" == {*-*-*-*} ]] ||
csih_error "invalid interface guid ${interface_guid} specified."
csih_inform "the guid of interface ${slapos_ifname} is ${interface_guid}"
wget -c http://git.erp5.org/gitweb/slapos.core.git/blob_plain/HEAD:/slapos.cfg.example -O ${node_configure_file} ||
csih_error "download ${node_configure_file} failed"
csih_inform "download ${node_configure_file} OK"
wget -c http://git.erp5.org/gitweb/slapos.core.git/blob_plain/HEAD:/slapos-client.cfg.example -O ${client_configure_file} ||
csih_error "download ${node_configure_file} failed"
csih_inform "download ${node_configure_file} OK"
csih_inform "ipv4_local_network is ${ipv4_local_network}"
sed -i -e "s%^\\s*interface_name.*$%interface_name = ${interface_guid}%" \
-e "s%^#\?\\s*ipv6_interface.*$%# ipv6_interface =%g" \
-e "s%^ipv4_local_network.*$%ipv4_local_network = ${ipv4_local_network}%" \
-e "s%^computer_id.*$%computer_id = ${computer_guid}%" \
-e "s%^user_base_name =.*$%user_base_name = ${slapos_user_basename}%" \
${node_configure_file}
csih_inform "type ${node_configure_file}:"
csih_inform "************************************************************"
cat ${node_configure_file}
csih_inform "************************************************************"
sed -i -e "s%^cert_file.*$%cert_file = ${client_certificate_file}%" \
-e "s%^key_file.*$%key_file = ${client_key_file}%" \
${client_configure_file}
csih_inform "type ${client_configure_file}:"
csih_inform "************************************************************"
cat ${client_configure_file}
csih_inform "************************************************************"
csih_inform "Configure slapos client and node OK"
echo ""
# ----------------------------------------------------------- # -----------------------------------------------------------
# Format slapos node # Patch cygwin packages for building slapos
# ----------------------------------------------------------- # -----------------------------------------------------------
csih_inform "Formatting SlapOS Node ..." slapos_patch_cygwin
netsh interface ipv6 add addr ${slapos_ifname} ${ipv6_local_address}
/opt/slapos/bin/slapos node format -cv --now ||
csih_error "Run slapos node format failed. "
echo ""
# ----------------------------------------------------------- # -----------------------------------------------------------
# Check and configure cygwin environments # Install slapos cygwin package
# ----------------------------------------------------------- # -----------------------------------------------------------
csih_check_program_or_error /usr/bin/cygrunsrv cygserver install_slapos_cygwin_package
csih_check_program_or_error /usr/bin/syslog-ng-config syslog-ng
csih_check_program_or_error /usr/bin/openssl openssl
csih_check_program_or_error /usr/bin/ipwin slapos-patches
csih_check_program_or_error /usr/bin/slapos-cron-config slapos-patches
if [[ ! ":$PATH" == :/opt/slapos/bin: ]] ; then
for profile in ~/.bash_profile ~/.profile ; do
! grep -q "export PATH=/opt/slapos/bin:" $profile &&
csih_inform "add /opt/slapos/bin to PATH" &&
echo "export PATH=/opt/slapos/bin:\${PATH}" >> $profile
done
fi
_path=/etc/slapos/scripts
csih_inform "create path: ${_path}"
mkdir -p ${_path}
for _name in slapos-configure.sh slapos-include.sh post-install.sh slapos-cleanup.sh ; do
wget -c http://git.erp5.org/gitweb/slapos.package.git/blob_plain/heads/cygwin:/windows/scripts/${_name} -O ${_path}/${_name} ||
csih_error "download ${_name} failed"
csih_inform "download script ${_path}/${_name} OK"
done
# Set prefix for slapos
if [[ -n ${slapos_prefix} ]] ; then
echo "Set slapos prefix as ${slapos_prefix}"
sed -i -e "s%slapos_prefix=.*\$%slapos_prefix=${slapos_prefix}%" ${_path|/slapos-include.sh
fi
# ----------------------------------------------------------- # -----------------------------------------------------------
# Create account: slaproot # Check IPv6 protocol, install it if it isn't installed
# ----------------------------------------------------------- # -----------------------------------------------------------
# Start seclogon service in the Windows XP install_ipv6_protocol
if csih_is_xp ; then
csih_inform "set start property of seclogon to auto"
sc config seclogon start= auto ||
csih_warning "failed to set seclogon to auto start."
# In the later, it's RunAs service, and will start by default
fi
# echo Checking slapos account ${_administrator} ...
slapos_check_and_create_privileged_user ${_administrator} ${_password} ||
csih_error "failed to create account ${_administrator}."
# ----------------------------------------------------------- # -----------------------------------------------------------
# Configure cygwin services: cygserver syslog-ng # Configure cygwin services: cygserver syslog-ng
# ----------------------------------------------------------- # -----------------------------------------------------------
csih_inform "Starting configure cygwin services ..." install_cygserver_service
if ! cygrunsrv --query ${cygserver_service_name} > /dev/null 2>&1 ; then install_syslog_service
csih_inform "run cygserver-config ..."
/usr/bin/cygserver-config --yes || \
csih_error "failed to run cygserver-config"
[[ ${cygserver_service_name} == cygserver ]] ||
cygrunsrv -I ${cygserver_service_name} -d "CYGWIN ${cygserver_service_name}" -p /usr/sbin/cygserver ||
csih_error "failed to install service ${cygserver_service_name}"
else
csih_inform "the cygserver service has been installed"
fi
check_cygwin_service ${cygserver_service_name}
if ! cygrunsrv --query ${syslog_service_name} > /dev/null 2>&1 ; then
csih_inform "run syslog-ng-config ..."
/usr/bin/syslog-ng-config --yes || \
csih_error "failed to run syslog-ng-config"
[[ ${syslog_service_name} == "syslog-ng" ]] ||
cygrunsrv -I ${syslog_service_name} -d "CYGWIN ${syslog_service_name}" -p /usr/sbin/syslog-ng -a "-F" ||
csih_error "failed to install service ${syslog_service_name}"
else
csih_inform "the syslog-ng service has been installed"
fi
check_cygwin_service ${syslog_service_name}
# Use slapos-cron-config to configure slapos cron service.
if ! cygrunsrv --query ${cron_service_name} > /dev/null 2>&1 ; then
[[ -x ${slapos_cron_config} ]] ||
csih_error "Couldn't find slapos cron config script: ${slapos_cron_config}"
if [[ -z "${csih_PRIVILEGED_PASSWORD}" ]] ; then
slapos_request_password ${_administrator} "Install cron service need the password of ${_administrator}."
fi
csih_inform "run slapos-cron-config ..."
${slapos_cron_config} ${cron_service_name} ${_administrator} ${csih_PRIVILEGED_PASSWORD} ||
csih_error "Failed to run ${slapos_cron_config}"
else
csih_inform "the cron service has been installed"
fi
check_cygwin_service ${cron_service_name}
csih_inform "Configure cygwin services OK"
echo ""
# ----------------------------------------------------------- # -----------------------------------------------------------
# cron: Install cron service and create crontab # End script
# ----------------------------------------------------------- # -----------------------------------------------------------
csih_inform "Starting configure section cron ..."
_cron_user=${_administrator}
_crontab_file="/var/cron/tabs/${_cron_user}"
if [[ ! -f ${_crontab_file} ]] ; then
cat <<EOF > ${_crontab_file}
SHELL=/bin/bash
PATH=/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin
MAILTO=""
# Run "Installation/Destruction of Software Releases" and "Deploy/Start/Stop Partitions" once per minute
* * * * * /opt/slapos/bin/slapos node software --verbose --logfile=/opt/slapos/log/slapos-node-software.log > /dev/null 2>&1
* * * * * /opt/slapos/bin/slapos node instance --verbose --logfile=/opt/slapos/log/slapos-node-instance.log > /dev/null 2>&1
# Run "Destroy Partitions to be destroyed" once per hour
0 * * * * /opt/slapos/bin/slapos node report --maximal_delay=3600 --verbose --logfile=/opt/slapos/log/slapos-node-report.log > /dev/null 2>&1
# Run "Check/add IPs and so on" once per hour
0 * * * * /opt/slapos/bin/slapos node format >> /opt/slapos/log/slapos-node-format.log 2>&1
EOF
fi
csih_inform "change owner of ${_crontab_file} to ${_cron_user}"
chown ${_cron_user} ${_crontab_file}
csih_inform "change mode of ${_crontab_file} to 644"
chmod 644 ${_crontab_file}
ls -l ${_crontab_file}
csih_inform "begin of crontab of ${_administrator}:"
csih_inform "************************************************************"
cat ${_crontab_file} || csih_error "No crob tab found."
csih_inform "************************************************************"
csih_inform "end of crontab of ${_administrator}"
csih_inform "Configure section cron OK"
echo ""
echo "" echo ""
csih_inform "Configure slapos bootstrap node successfully." csih_inform "Configure slapos bootstrap node successfully."
echo "" echo ""
......
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