Commit 3ba4a851 authored by Jondy Zhao's avatar Jondy Zhao

Fix issues for node config

parent 32de5cf4
......@@ -24,13 +24,13 @@ Source: "cygwin-packages\*"; DestDir: "{app}\cygwin-packages"; Flags: recursesub
Source: "publish\buildout\slapos\*"; DestDir: "{app}\cygwin\opt\slapos"; Flags: recursesubdirs;
Source: "opt\git\slapos.core\slapos.cfg.example"; DestDir: "{app}\cygwin\etc\slapos";
Source: "opt\git\slapos.core\slapos-client.cfg.example"; DestDir: "{app}\cygwin\etc\slapos";
Source: "opt\downloads\pyOpenSSL-0.13.tar.gz"; DestDir: "{app}\cygwin"; DestName: "pyOpenSSL.tar.gz"; Flags: deleteafterinstall;
Source: "opt\git\re6stnet\dist\re6stnet-0.1.tar.gz"; DestDir: "{app}\cygwin"; DestName: "re6stnet-0.1.tar.gz"; Flags: deleteafterinstall;
Source: "opt\downloads\miniupnpc-1.8.tar.gz"; DestDir: "{app}\cygwin"; DestName: "miniupnpc.tar.gz"; Flags: deleteafterinstall;
Source: "opt\git\slapos\component\cygwin\slapos-core.patch"; DestDir: "{app}\cygwin\etc\slapos\patches";
Source: "opt\git\slapos\component\cygwin\slapos-cookbook-inotifyx.patch"; DestDir: "{app}\cygwin\etc\slapos\patches";
Source: "opt\git\re6stnet\dist\re6stnet-0.1.tar.gz"; DestDir: "{app}\cygwin"; DestName: "re6stnet-0.1.tar.gz"; Flags: deleteafterinstall;
Source: "opt\downloads\miniupnpc-1.8.tar.gz"; DestDir: "{app}\cygwin"; DestName: "miniupnpc.tar.gz"; Flags: deleteafterinstall;
Source: "opt\git\qooxdoo\application\playground\build\*"; DestDir: "{app}\cygwin\etc\slapos\desktop"; Flags: recursesubdirs;
Source: "opt\git\qooxdoo\application\showcase\build\*"; DestDir: "{app}\cygwin\etc\slapos\node"; Flags: recursesubdirs;
......
......@@ -32,7 +32,7 @@ if [[ -f "$1" ]] ; then
elif [[ ! -f $client_certificate_file ]] ; then
read -p "Where is certificate file: " certificate_file
[[ ! -f "$certificate_file" ]] && \
echo "Certificate file %s doesn't exists." && exit 1
echo "Certificate file $certificate_file doesn't exists." && exit 1
echo "Copy certificate from $certificate_file to $client_certificate_file"
cp $certificate_file $client_certificate_file
fi
......@@ -43,18 +43,18 @@ if [[ -f "$2" ]] ; then
elif [[ ! -f $client_key_file ]] ; then
read -p "Where is key file: " key_file
[[ ! -f "$key_file" ]] && \
echo "Key file %s doesn't exists." && exit 1
echo "Key file $key_file doesn't exists." && exit 1
echo "Copy key from $key_file to $client_key_file"
cp $key_file $client_key_file
fi
if [[ ! -f $client_configure_file ]] ; then
[[ -f $template_configure_file ]] || \
(cd /etc/slapos; wget -O slapos.cfg http://git.erp5.org/gitweb/slapos.core.git/blob_plain/HEAD:/slapos-client.cfg.example) || \
(cd /etc/slapos; wget http://git.erp5.org/gitweb/slapos.core.git/blob_plain/HEAD:/slapos-client.cfg.example) || \
(echo "Download slapos-client.cfg.example failed."; exit 1)
cp $template_configure_file $client_configure_file
fi
sed -i -e "s/^cert_file.*$/cert_file = $client_certificate_file/" \
-e "s/^key_file.*$/key_file = $client_key_file/" \
sed -i -e "s%^cert_file.*$%cert_file = $client_certificate_file%" \
-e "s%^key_file.*$%key_file = $client_key_file%" \
$client_configure_file
......@@ -38,12 +38,12 @@ function get_all_connections()
#
function get_new_connection()
{
original_connections="$* X"
original_connections=" $* "
current_connections=$(get_all_connections)
for name in $current_connections ; do
[[ "$original_connections" == ".* $name .*" ]] && \
echo ${name//%/ /} && return 0
[[ ! "$original_connections" == *[\ ]$name[\ ]* ]] && \
echo ${name//%/ } && return 0
done
}
......@@ -54,12 +54,12 @@ function reset_connection()
{
ifname=${1-re6stnet-lo}
for addr in $(netsh interface ipv6 show address $ifname level=normal | \
grep "^Manual" \
grep "^Manual" | \
sed -e "s/^\(\w\+\s\+\)\{4\}//") ; do
netsh interface ipv6 del address $ifname $addr
done
for addr in $(netsh interface ip show address $ifname | \
grep "IP Address:" \
grep "IP Address:" | \
sed -e "s/IP Address://") ; do
netsh interface del address $ifname $addr
done
......@@ -76,24 +76,34 @@ function connection2guid()
sed -e "s/^GUID\s*:\s*//"
}
# Remove startup item first.
node_certificate_file=/etc/opt/slapos/ssl/certificate
node_key_file=/etc/opt/slapos/ssl/key
node_config_file=/etc/opt/slapos/slapos.cfg
node_template_file=/etc/slapos/slapos.cfg.example
run_key='\HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run'
slapos_run_entry=SlapOS-Node
slapos_ifname=re6stnet-lo
# Remove startup item first.
regtool -q unset "$run_key\\$slapos_run_entry"
#
# Add msloop network adapter, ane name it as "re6stnet-lo"
#
original_connections=$(get_all_connections)
if [[ ! "$original_connections X" == ".*\bre6stnet-lo\b.*X" ; then
echo Checking slapos network adapter: $slapos_ifname ...
original_connections=$(echo $(get_all_connections))
if [[ ! " $original_connections " == *[\ ]$slapos_ifname[\ ]* ]] ; then
echo Installing slapos network adapter ...
devcon install $WINDIR\\inf\\netloop.inf *MSLOOP
connection_name=$(get_new_connection $original_connections)
[[ "X$connection_name" == "X" ]] && \
echo "Add msloop network adapter failed." && \
exit 1
netsh interface set interface "$connection_name" newname=re6stnet-lo
echo
netsh interface set interface name="$connection_name" newname="$slapos_ifname"
fi
reset_connection re6stnet-lo
reset_connection $slapos_ifname
echo SlapOS network adapter OK.
#
# Generate Node Configure file
......@@ -106,7 +116,9 @@ echo
echo Refer to http://community.slapos.org/wiki/osoe-Lecture.SlapOS.Extended/developer-Installing.SlapOS.Slave.Node.Source
echo
if [[ "X$1" == "XCOMP-[0-9]+" ]] ; then
mkdir -p /etc/opt/slapos/ssl/partition_pki
if [[ "$1" == COMP-+([0-9]) ]] ; then
computer_id=$1
else
[[ "X$1" == "X" ]] || echo "Invalid computer id: $1"
......@@ -114,29 +126,27 @@ else
echo Please input computer id you have registered, it looks like COMP-XXXX
read -p "computer id: " computer_id
fi
[[ "X$computer_id" == "XCOMP-[0-9]+" ]] || \
[[ "$computer_id" == COMP-+([0-9]) ]] || \
(echo "Invalid computer id specified."; exit 1)
node_certificate_file=/etc/opt/slapos/ssl/certificate
if [[ -f "$2" ]] ; then
echo "Copy certificate from $2 to $node_certificate_file"
cp $2 $node_certificate_file
elif [[ ! -f $node_certificate_file ]] ; then
read -p "Where is certificate file: " certificate_file
[[ ! -f "$certificate_file" ]] && \
echo "Certificate file %s doesn't exists." && exit 1
echo "Certificate file $certificate_file doesn't exists." && exit 1
echo "Copy certificate from $certificate_file to $node_certificate_file"
cp $certificate_file $node_certificate_file
fi
node_key_file=/etc/opt/slapos/ssl/key
if [[ -f "$3" ]] ; then
echo "Copy key from $3 to $node_key_file"
cp $3 $node_key_file
elif [[ ! -f $node_key_file ]] ; then
read -p "Where is key file: " key_file
[[ ! -f "$key_file" ]] && \
echo "Key file %s doesn't exists." && exit 1
echo "Key file $key_file doesn't exists." && exit 1
echo "Copy key from $key_file to $node_key_file"
cp $key_file $node_key_file
fi
......@@ -145,28 +155,25 @@ fi
ipv4_local_network=10.201.67.0/8
# Add ipv4 address
ip -4 addr $ipv4_local_network dev re6stnet-lo
ip -4 addr add $ipv4_local_network dev $slapos_ifname
# Create node configure file, replace interface_name with guid of
# re6stnet-lo
mkdir -p /etc/opt/slapos/ssl/partition_pki
nodecfgfile=/etc/opt/slapos/slapos.cfg
if [[ ! -f $nodecfgfile ]] ; then
[[ -f /etc/slapos/slapos.cfg.example ]] || \
(cd /etc/slapos; wget -O slapos.cfg http://git.erp5.org/gitweb/slapos.core.git/blob_plain/HEAD:/slapos.cfg.example) || \
if [[ ! -f $node_config_file ]] ; then
[[ -f $node_template_file ]] || \
(cd /etc/slapos; wget http://git.erp5.org/gitweb/slapos.core.git/blob_plain/HEAD:/slapos.cfg.example) || \
(echo "Download slapos.cfg.example failed."; exit 1)
cp /etc/slapos/slapos.cfg.example $nodecfgfile
cp $node_template_file $node_config_file
fi
interface_guid=$(connection2guid re6stnet-lo)
interface_guid=$(connection2guid $slapos_ifname)
# generate /etc/slapos/slapos.cfg
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_id/" \
$nodecfgfile
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_id%" \
$node_config_file
#
# Re6stnet
......@@ -177,22 +184,40 @@ netsh interface ipv6 show interface > /dev/null || netsh interface ipv6 install
# miniupnpc is required by re6stnet
if [[ ! -f /opt/miniupnpc ]] ; then
cd /opt
if [[ -f /miniupnpc.tar.gz ]] ; then
tar xzf miniupnpc.tar.gz
mv $(ls miniupnpc-*) miniupnpc
echo "Installing miniupnpc ..."
cd /opt
tar xzf /miniupnpc.tar.gz --no-same-owner
mv $(ls -d miniupnpc-*) miniupnpc
cd miniupnpc
make
python setup.py install || echo "Install miniupnpc failed."
else
echo "No miniupnpc source package found."
fi
fi
# pyOpenSSL is required by re6stnet
if [[ ! -f /opt/pyOpenSSL ]] ; then
if [[ -f /pyOpenSSL.tar.gz ]] ; then
echo "Installing pyOpenSSL ..."
cd /opt
tar xzf /pyOpenSSL.tar.gz --no-same-owner
mv $(ls -d pyOpenSSL-*) pyOpenSSL
cd pyOpenSSL
python setup.py install || echo "Install pyOpenSSL failed."
fi
fi
# Install re6stnet
if [[ ! -f /opt/re6stnet ]] ; then
echo "Installing re6stnet ..."
cd /opt
if [[ -f /re6stnet.tar.gz ]] ; then
tar xzf re6stnet.tar.gz
mv $(ls re6stnet-*) re6stnet
tar xzf /re6stnet.tar.gz --no-same-owner
mv $(ls -d re6stnet-*) re6stnet
else
echo "Clone re6stnet from http://git.erp5.org/repos/re6stnet.git"
git clone -b cygwin -n http://git.erp5.org/repos/re6stnet.git
fi
cd re6stnet
......@@ -209,15 +234,17 @@ fi
#
# Add run item when windows startup
#
init_script_name=/etc/slapos/scripts/init-salpos-node
echo "Add ${init_script_name}.sh as Windows startup item."
if [[ ! -f ${init_script_name}.bat ]] ; then
cat <<EOF > ${init_script_name}.bat
\"$(cygpath -w /usr/bin/sh)\" --login -i ${init_script_name}.sh
EXIT 0
EOF
fi
init_script=/etc/slapos/scripts/init-slapos-node
echo "Add ${init_script}.sh as Windows startup item."
# if [[ ! -f ${init_script}.bat ]] ; then
# cat <<EOF > ${init_script}.bat
# "$(cygpath -w /usr/bin/bash)" --login -i ${init_script}.sh
# EXIT 0
# EOF
# fi
regtool -q set "$run_key\\$slapos_run_entry" \
"START \"$(cygpath -w ${init_script_name}.bat)" || \
"\"$(cygpath -w /usr/bin/bash)\" --login -i ${init_script}.sh" || \
echo "Add startup item failed."
exit 0
......@@ -22,12 +22,12 @@ Name: "{app}\cygwin\etc\slapos\patches"
Name: "{app}\cygwin\etc\slapos\images"
[Files]
Source: "opt\git\slapos\component\cygwin\slapos-core.patch"; DestDir: "{app}\cygwin\etc\slapos\patches";
Source: "opt\git\slapos\component\cygwin\slapos-cookbook-inotifyx.patch"; DestDir: "{app}\cygwin\etc\slapos\patches";
Source: "opt\git\re6stnet\dist\re6stnet-0.1.tar.gz"; DestDir: "{app}\cygwin"; DestName: "re6stnet-0.1.tar.gz"; Flags: deleteafterinstall;
Source: "opt\downloads\miniupnpc-1.8.tar.gz"; DestDir: "{app}\cygwin"; DestName: "miniupnpc.tar.gz"; Flags: deleteafterinstall;
Source: "opt\git\slapos\component\cygwin\slapos-core.patch"; DestDir: "{app}\cygwin\etc\slapos\patches";
Source: "opt\git\slapos\component\cygwin\slapos-cookbook-inotifyx.patch"; DestDir: "{app}\cygwin\etc\slapos\patches";
Source: "opt\git\qooxdoo\application\playground\build\*"; DestDir: "{app}\cygwin\etc\slapos\desktop"; Flags: recursesubdirs;
Source: "opt\git\qooxdoo\application\showcase\build\*"; DestDir: "{app}\cygwin\etc\slapos\node"; Flags: recursesubdirs;
......
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