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,403 +37,219 @@ function show_usage() ...@@ -28,403 +37,219 @@ 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 ..."
echo ""
# ======================================================================
# Constants
# ======================================================================
declare -r slapos_prefix=slapboot-
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
declare -r cygwin_home=$(cygpath -a $(cygpath -w /)\\.. | sed -e "s%/$%%")
# -----------------------------------------------------------
# Local variable
# -----------------------------------------------------------
declare _administrator=${slapos_administrator}
declare _password=
declare _computer_certificate=
declare _computer_key=
declare _client_certificate=
declare _client_key=
declare _ipv4_local_network=${ipv4_local_network}
# -----------------------------------------------------------
# Command line options
# -----------------------------------------------------------
while test $# -gt 0; do
# Normalize the prefix.
case "$1" in
-*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
*) optarg= ;;
esac
case "$1" in
--password=*)
_password=$optarg
;;
-P)
_password=$2
shift
;;
-P)
_administrator=$2
shift
;;
--computer-certificate=*)
_computer_certificate=$optarg
;;
--computer-key=*)
_computer_key=$optarg
;;
--client-certificate=*)
_client_certificate=$optarg
;;
--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
exit 1
;;
esac
# Next please.
shift
done
# ----------------------------------------------------------- function slapos_sanity_check()
# Patch cygwin packages for building slapos {
# ----------------------------------------------------------- csih_check_program_or_error /usr/bin/cygport cygport
csih_inform "Patching cygwin packages for building slapos" csih_check_program_or_error /usr/bin/libtool libtool
csih_check_program_or_error /usr/bin/cygport cygport _filename=$(cygpath -a -w $(cygpath -w /)\\..\\setup.exe)
csih_check_program_or_error /usr/bin/libtool libtool [[ -f $(cygpath -u ${_filename}) ]] || csih_error "missing ${_filename}"
}
readonly -f slapos_sanity_check
csih_inform "libtool patched" function slapos_patch_cygwin()
sed -i -e "s/4\.3\.4/4.5.3/g" /usr/bin/libtool {
csih_inform "Patching cygwin packages for building slapos"
csih_inform "/etc/passwd generated" csih_inform "libtool patched"
[[ -f /etc/passwd ]] || mkpasswd > /etc/passwd sed -i -e "s/4\.3\.4/4.5.3/g" /usr/bin/libtool
csih_inform "/etc/group generated" csih_inform "/etc/passwd generated"
[[ -f /etc/group ]] || mkgroup > /etc/group [[ -f /etc/passwd ]] || mkpasswd > /etc/passwd
_filename=$(cygpath -a -w $(cygpath -w /)\\..\\setup.exe) csih_inform "/etc/group generated"
csih_inform "check ${_filename}" [[ -f /etc/group ]] || mkgroup > /etc/group
[[ -f $(cygpath -u ${_filename}) ]] || csih_error "missing ${_filename}"
_filename=/usr/bin/cygport _filename=/usr/bin/cygport
if [[ -f ${_filename} ]] ; then if [[ -f ${_filename} ]] ; then
csih_inform "Patching ${_filename} ..." csih_inform "Patching ${_filename} ..."
sed -i -e 's/D="${workdir}\/inst"/D="${CYGCONF_PREFIX-${workdir}\/inst}"/g' ${_filename} && sed -i -e 's/D="${workdir}\/inst"/D="${CYGCONF_PREFIX-${workdir}\/inst}"/g' ${_filename} &&
csih_inform "OK" csih_inform "OK"
else else
csih_error "Missing cygport package, no ${_filename} found." csih_error "Missing cygport package, no ${_filename} found."
fi fi
_filename=/usr/share/cygport/cygclass/autotools.cygclass _filename=/usr/share/cygport/cygclass/autotools.cygclass
if [[ -f ${_filename} ]] ; then if [[ -f ${_filename} ]] ; then
csih_inform "Patching ${_filename} ..." csih_inform "Patching ${_filename} ..."
sed -i -e 's/prefix=$(__host_prefix)/prefix=${CYGCONF_PREFIX-$(__host_prefix)}/g' ${_filename} && sed -i -e 's/prefix=$(__host_prefix)/prefix=${CYGCONF_PREFIX-$(__host_prefix)}/g' ${_filename} &&
csih_inform "OK" csih_inform "OK"
else else
csih_error "Missing cygport package, no ${_filename} found." csih_error "Missing cygport package, no ${_filename} found."
fi fi
_filename=/usr/share/cygport/cygclass/cmake.cygclass _filename=/usr/share/cygport/cygclass/cmake.cygclass
if [[ -f ${_filename} ]] ; then if [[ -f ${_filename} ]] ; then
csih_inform "Patching ${_filename} ..." csih_inform "Patching ${_filename} ..."
sed -i -e 's/-DCMAKE_INSTALL_PREFIX=$(__host_prefix)/-DCMAKE_INSTALL_PREFIX=${CYGCONF_PREFIX-$(__host_prefix)}/g' ${_filename} && sed -i -e 's/-DCMAKE_INSTALL_PREFIX=$(__host_prefix)/-DCMAKE_INSTALL_PREFIX=${CYGCONF_PREFIX-$(__host_prefix)}/g' ${_filename} &&
csih_inform "OK" csih_inform "OK"
else else
csih_error "Missing cygport package, no ${_filename} found." csih_error "Missing cygport package, no ${_filename} found."
fi 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" # Change format of readme.txt
echo "" _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"
# Check IPv6 protocol, install it if it isn't installed echo Checking ${_filename} ...
# ----------------------------------------------------------- if [[ ! -f ${_filename} || "${_install_mode}" == "force" ]] ; then
csih_inform "Starting configure IPv6 protocol ..." cat <<EOF > ${_filename}
netsh interface ipv6 show interface > /dev/null || \ BoldAsFont=no
netsh interface ipv6 install || \ Font=Courier New
csih_error "install IPv6 protocol failed" FontHeight=16
Scrollbar=none
EOF
echo "${_filename} has been generated."
else
echo OK.
fi
csih_inform "Configure IPv6 protocol OK" _filename="/cygtty.bat"
echo "" echo Checking ${_filename} ...
if [[ ! -x ${_filename} || "${_install_mode}" == "force" ]] ; then
cat <<EOF > ${_filename}
@echo off
# ----------------------------------------------------------- ${slapos_cygroot:0:2}
# Run the buildout of slapos node chdir ${slapos_cygroot}\\bin
# -----------------------------------------------------------
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 ""
# ----------------------------------------------------------- start mintty.exe -i /Cygwin-Terminal.ico -
# Configure slapos node and client EOF
# ----------------------------------------------------------- chmod +x ${_filename}
csih_inform "Starting configure slapos client and node ..." echo "${_filename} has been generated."
else
echo OK.
fi
for _name in certificate key computer.key computer.crt ; do _filename="/autorebase.bat"
[[ -f ~/${_name} ]] || csih_error "missing file ~/${_name}" echo Checking ${_filename} ...
done if [[ ! -f ${_filename} || "${_install_mode}" == "force" ]] ; then
for _name in test-computer.key test-computer.crt ; do cat <<EOF > ${_filename}
[[ -f ${cygwin_home}/${_name} ]] || csih_error "missing file ${cygwin_home}/${_name}" @echo off
done ${slapos_cygroot:0:2}
cp ~/certificate ${cygwin_home} && csih_inform "copy ~/certificate to ${cygwin_home}" CHDIR ${slapos_cygroot}
cp ~/key ${cygwin_home} && csih_inform "copy ~/key to ${cygwin_home}" ${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
csih_inform "mkdir /etc/opt/slapos/ssl/partition_pki" IF EXIST ${slapos_cygroot}\srv\slapgrid. ${slapos_cygroot}\bin\find /srv/slapgrid -name "*.dll" >> ${slapos_cygroot}\myfile.list
mkdir -p /etc/opt/slapos/ssl/partition_pki NET STOP ${slapos_prefix}cron
csih_inform "mkdir ${slapos_client_home}" NET STOP ${slapos_prefix}re6stnet
mkdir -p ${slapos_client_home} NET STOP ${slapos_prefix}syslog-ng
NET STOP ${slapos_prefix}cygserver
(cp ~/certificate ${client_certificate_file} && bin\bash --login -c "/opt/slapos/bin/slapos node stop all"
cp ~/key ${client_key_file} && bin\bash --login -c "for pid in \$(ps | grep '/usr/bin/python2.7' | gawk '{print \$4}') ; do TASKKILL /F /T /PID \$pid ; done"
cp ~/computer.crt ${node_certificate_file} && PATH .\bin;%PATH%
cp ~/computer.key ${node_key_file} && dash /bin/rebaseall -T /myfile.list -v
csih_inform "copy certificate/key files OK") || PAUSE ...
csih_error "copy certificate/key files failed" EXIT 0
EOF
computer_guid=$(grep "CN=COMP" ${node_certificate_file} | \ chmod +x ${_filename}
sed -e "s/^.*, CN=//g" | sed -e "s%/emailAddress.*\$%%g") echo "${_filename} has been generated."
[[ "${computer_guid}" == COMP-+([0-9]) ]] || else
csih_error_multi "${computer_guid} is invalid computer guid." \ echo OK.
"It should like 'COMP-XXXX', edit ${node_certificate_file}" \ fi
"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 ""
# ----------------------------------------------------------- csih_inform "Patch cygwin packages for building slapos OK"
# Format slapos node echo ""
# ----------------------------------------------------------- }
csih_inform "Formatting SlapOS Node ..." readonly -f slapos_patch_cygwin
netsh interface ipv6 add addr ${slapos_ifname} ${ipv6_local_address} function install_slapos_cygwin_package()
/opt/slapos/bin/slapos node format -cv --now || {
csih_error "Run slapos node format failed. " 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
echo "" 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
# Check and configure cygwin environments [[ -x /usr/bin${_cmdname} && -z "${_install_mode}" ]] && continue
# ----------------------------------------------------------- if check_os_is_wow64 ; then
csih_check_program_or_error /usr/bin/cygrunsrv cygserver _filename=${_cmdname}-x64.exe
csih_check_program_or_error /usr/bin/syslog-ng-config syslog-ng else
csih_check_program_or_error /usr/bin/openssl openssl _filename=${_cmdname}-x86.exe
csih_check_program_or_error /usr/bin/ipwin slapos-patches fi
csih_check_program_or_error /usr/bin/slapos-cron-config slapos-patches wget -c http://dashingsoft.com/products/slapos/${_filename} -O /usr/bin/${_cmdname}.exe ||
csih_error "download ${_filename} failed"
if [[ ! ":$PATH" == :/opt/slapos/bin: ]] ; then csih_inform "download ${_filename} OK"
for profile in ~/.bash_profile ~/.profile ; do chmod +x /usr/bin/${_cmdname}.exe || csih_error "chmod /usr/bin/${_cmdname}.exe failed"
! grep -q "export PATH=/opt/slapos/bin:" $profile && fi
csih_inform "add /opt/slapos/bin to PATH" &&
echo "export PATH=/opt/slapos/bin:\${PATH}" >> $profile
done
fi
_path=/etc/slapos/scripts _path=/etc/slapos/scripts
csih_inform "create path: ${_path}" csih_inform "create path: ${_path}"
mkdir -p ${_path} mkdir -p ${_path}
for _name in slapos-configure.sh slapos-include.sh post-install.sh slapos-cleanup.sh ; do 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} || 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_error "download ${_name} failed"
csih_inform "download script ${_path}/${_name} OK" csih_inform "download script ${_path}/${_name} OK"
done done
# Set prefix for slapos # Set prefix for slapos
if [[ -n ${slapos_prefix} ]] ; then if [[ -n "${slapos_prefix}" ]] ; then
echo "Set slapos prefix as ${slapos_prefix}" echo "Set slapos prefix as ${slapos_prefix}"
sed -i -e "s%slapos_prefix=.*\$%slapos_prefix=${slapos_prefix}%" ${_path|/slapos-include.sh sed -i -e "s%slapos_prefix=.*\$%slapos_prefix=${slapos_prefix}%" ${_path|/slapos-include.sh
fi fi
}
readonly -f install_slapos_cygwin_package
# ----------------------------------------------------------- function install_ipv6_protocol()
# Create account: slaproot {
# ----------------------------------------------------------- csih_inform "Starting configure IPv6 protocol ..."
# Start seclogon service in the Windows XP netsh interface ipv6 show interface > /dev/null || \
if csih_is_xp ; then netsh interface ipv6 install || \
csih_inform "set start property of seclogon to auto" csih_error "install IPv6 protocol failed"
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} ... csih_inform "Configure IPv6 protocol OK"
slapos_check_and_create_privileged_user ${_administrator} ${_password} || echo ""
csih_error "failed to create account ${_administrator}." }
readonly -f install_ipv6_protocol
# ----------------------------------------------------------- function install_cygserver_service()
# Configure cygwin services: cygserver syslog-ng {
# ----------------------------------------------------------- csih_inform "Starting configure cygwin services ..."
csih_inform "Starting configure cygwin services ..." if ! cygrunsrv --query ${cygserver_service_name} > /dev/null 2>&1 ; then
if ! cygrunsrv --query ${cygserver_service_name} > /dev/null 2>&1 ; then
csih_inform "run cygserver-config ..." csih_inform "run cygserver-config ..."
/usr/bin/cygserver-config --yes || \ /usr/bin/cygserver-config --yes || \
csih_error "failed to run cygserver-config" csih_error "failed to run cygserver-config"
[[ ${cygserver_service_name} == cygserver ]] || [[ ${cygserver_service_name} == cygserver ]] ||
cygrunsrv -I ${cygserver_service_name} -d "CYGWIN ${cygserver_service_name}" -p /usr/sbin/cygserver || cygrunsrv -I ${cygserver_service_name} -d "CYGWIN ${cygserver_service_name}" -p /usr/sbin/cygserver ||
csih_error "failed to install service ${cygserver_service_name}" csih_error "failed to install service ${cygserver_service_name}"
else else
csih_inform "the cygserver service has been installed" csih_inform "the cygserver service has been installed"
fi fi
check_cygwin_service ${cygserver_service_name} }
readonly -f install_cygserver_service
if ! cygrunsrv --query ${syslog_service_name} > /dev/null 2>&1 ; then function install_syslog_service()
{
if ! cygrunsrv --query ${syslog_service_name} > /dev/null 2>&1 ; then
csih_inform "run syslog-ng-config ..." csih_inform "run syslog-ng-config ..."
/usr/bin/syslog-ng-config --yes || \ /usr/bin/syslog-ng-config --yes || \
csih_error "failed to run syslog-ng-config" csih_error "failed to run syslog-ng-config"
...@@ -432,72 +257,86 @@ if ! cygrunsrv --query ${syslog_service_name} > /dev/null 2>&1 ; then ...@@ -432,72 +257,86 @@ if ! cygrunsrv --query ${syslog_service_name} > /dev/null 2>&1 ; then
cygrunsrv -I ${syslog_service_name} -d "CYGWIN ${syslog_service_name}" -p /usr/sbin/syslog-ng -a "-F" || 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}" csih_error "failed to install service ${syslog_service_name}"
else else
csih_inform "the syslog-ng service has been installed" 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 fi
}
csih_inform "run slapos-cron-config ..." readonly -f install_cygserver_service
${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 # Start script
# ----------------------------------------------------------- # -----------------------------------------------------------
csih_inform "Starting configure section cron ..." csih_inform "Starting bootstrap slapos node ..."
echo ""
_cron_user=${_administrator} _prefix=
_crontab_file="/var/cron/tabs/${_cron_user}" _install_mode=
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 while test $# -gt 0; do
* * * * * /opt/slapos/bin/slapos node software --verbose --logfile=/opt/slapos/log/slapos-node-software.log > /dev/null 2>&1 # Normalize the prefix.
* * * * * /opt/slapos/bin/slapos node instance --verbose --logfile=/opt/slapos/log/slapos-node-instance.log > /dev/null 2>&1 case "$1" in
-*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
*) optarg= ;;
esac
# Run "Destroy Partitions to be destroyed" once per hour case "$1" in
0 * * * * /opt/slapos/bin/slapos node report --maximal_delay=3600 --verbose --logfile=/opt/slapos/log/slapos-node-report.log > /dev/null 2>&1 --prefix=*)
_prefix=$optarg
;;
-f | --force)
_install_mode=force
;;
-h | --help)
show_usage
exit 0
;;
*)
show_usage
exit 1
;;
esac
# Run "Check/add IPs and so on" once per hour # Next please.
0 * * * * /opt/slapos/bin/slapos node format >> /opt/slapos/log/slapos-node-format.log 2>&1 shift
EOF done
fi
csih_inform "change owner of ${_crontab_file} to ${_cron_user}" # ======================================================================
chown ${_cron_user} ${_crontab_file} # Constants: slapos bootstrap node use prefiix "slapboot-"
# ======================================================================
declare -r slapos_prefix=${_prefix}
declare -r cygserver_service_name=${slapos_prefix}cygserver
declare -r syslog_service_name=${slapos_prefix}syslog-ng
declare -r slapos_cygroot=$(cygpath -w /)
# -----------------------------------------------------------
# Sanity Check
# -----------------------------------------------------------
slapos_sanity_check
# -----------------------------------------------------------
# Patch cygwin packages for building slapos
# -----------------------------------------------------------
slapos_patch_cygwin
csih_inform "change mode of ${_crontab_file} to 644" # -----------------------------------------------------------
chmod 644 ${_crontab_file} # Install slapos cygwin package
ls -l ${_crontab_file} # -----------------------------------------------------------
install_slapos_cygwin_package
csih_inform "begin of crontab of ${_administrator}:" # -----------------------------------------------------------
csih_inform "************************************************************" # Check IPv6 protocol, install it if it isn't installed
cat ${_crontab_file} || csih_error "No crob tab found." # -----------------------------------------------------------
csih_inform "************************************************************" install_ipv6_protocol
csih_inform "end of crontab of ${_administrator}"
csih_inform "Configure section cron OK" # -----------------------------------------------------------
echo "" # Configure cygwin services: cygserver syslog-ng
# -----------------------------------------------------------
install_cygserver_service
install_syslog_service
# -----------------------------------------------------------
# End script
# -----------------------------------------------------------
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