Commit aa14c55a authored by Jondy Zhao's avatar Jondy Zhao

Add subdirectory 'cygwin' in the component/slapos, push all the patches and...

Add subdirectory 'cygwin' in the component/slapos, push all the patches and scripts for cygwin here.
parent a0018c97
##############################################################################
#
# Copyright (c) 2010, 2011, 2012 Vifib SARL and Contributors.
# All Rights Reserved.
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly advised to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 3
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
# for debug installer
# trap "sleep 30" EXIT
function usage()
{
echo "Usage: configure.sh COMPUTER_ID [ KEY CERTIFICATE ]
For example:
$ /configure.sh COMP-161
$ /configure.sh COMP-161 ~/computer.key ~/computer.crt"
}
# return all the interface's GUID
function get_all_interface()
{
/opt/slapos/bin/py -c "from netifaces import interfaces
print '\n'.join(interfaces())"
}
# return GUID of physical netcard only
#
# Get the value of Characteristics of each interface,
#
# Characteristics & NCF_VIRTUAL == NCF_VIRTUAL
# Characteristics & NCF_PHYSICAL == NCF_PHYSICAL
#
function get_all_physical_netcard()
{
local -r NCF_VIRTUAL=1
local -r NCF_PHYSICAL=4
local -r NCF_HIDDEN=8
local -r NCF_HAS_UI=0x80
local -r NCF_EXPECTED=$((NCF_PHYSICAL | NCF_HAS_UI))
key='\HKLM\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}'
for subkey in $(regtool -q list "$key") ; do
local -i flags=$(regtool -q get "$key\\$subkey\Characteristics")
if (( (flags & NCF_EXPECTED) == NCF_EXPECTED )) ; then
echo $(regtool -q get "$key\\$subkey\NetCfgInstanceId")
fi
done
}
#
# DriverDesc == TAP-Win32 Adapter V9
#
function get_openvpn_tap_interface()
{
key='\HKLM\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}'
for subkey in $(regtool -q list "$key") ; do
desc=$(regtool -q get "$key\\$subkey\DriverDesc")
if [[ "$desc" == "TAP-Win32 Adapter V9" ]] ; then
echo $(regtool -q get "$key\\$subkey\NetCfgInstanceId")
break
fi
done
}
# get connection name by IF_GUID
function get_connection_name()
{
key='\HKLM\SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002bE10318}'
echo $(regtool -q get "$key\\$IF_GUID\Connection\Name")
}
# tell the ip version
#
# 0 None
# 1 ipv4
# 2 ipv6
# 3 mixed
#
function get_local_ip_version()
{
gateways=`ipconfig /all | grep "Gateway" | sed -e "s/^\\s\+Default Gateway[. :]\+//g"`
ipv4flag=$(echo $gateways | grep ".")
ipv6flag=$(echo $gateways | grep ":")
if [[ "$ipv4flag" != "" ]] ; then
local_ip_version=$((local_ip_version | 1))
fi
if [[ "$ipv6flag" != "" ]] ; then
local_ip_version=$((local_ip_version | 2))
fi
}
#
# Tell by getmac, if GUID can be found, it's ok, else disabled or not connected
function get_interface_state()
{
getmac /V /FO list | grep "${INTERFACENAME}"
return $?
}
# test code
# slist=$(get_all_physical_netcard)
# echo physical netcards: $slist
# for s in $slist ; do
# INTERFACE_NAME=$s
# echo conn name is $(get_connection_name)
# done
# get_local_ip_version
# echo version is $local_ip_version
# for s in $(get_all_interface) ; do
# INTERFACE_NAME=$s
# get_connection_name
# echo conn name is $(get_connection_name)
# done
# echo openvpn tap interface is $(get_openvpn_tap_interface)
# exit 0
#
# main entry, first initialize variable
#
WINSYS32HOME="$(/usr/bin/cygpath -S -w)"
CYGWINSYS32HOME="$(/usr/bin/cygpath -S)"
DESTKEYFILE=/etc/slapos/ssl/computer.key
DESTCERTFILE=/etc/slapos/ssl/computer.crt
IPV6=${CYGWINSYS32HOME}/ipv6.exe
NETSH=${CYGWINSYS32HOME}/netsh.exe
IPCONFIG=${CYGWINSYS32HOME}/ipconfig.exe
GETMAC=${CYGWINSYS32HOME}/getmac.exe
OPENVPNHOME=/opt/openvpn
SLAPOSCFG=/etc/slapos/slapos.cfg
declare -i local_ip_version=0
error_code=0
# remove startup item first.
RUNKEY='\HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run'
SLAPOSNODEINIT=SlapOSNodeInit
regtool -q unset "$RUNKEY\\$SLAPOSNODEINIT"
if (( $# != 1 && $# != 3 )) ; then
usage
exit 1
fi
which slapformat 2>/dev/null 1>/dev/null
if (( $? )) ; then
echo "Run this script must be in the SlapOS environments, do first:
\$ cd /opt/slapos
\$ source environment.sh"
cd /opt/slapos
source ./environment.sh
fi
COMPUTERID=$1
if [[ "$COMPUTERID" == "" ]] ; then
grep "^\\s\+computer_id\\s\+=\\s\+[-a-zA-Z0-9]\+" $SLAPOSCFG
if (( $? )) ; then
echo No computer id.
error_code=1
fi
elif [[ ${COMPUTERID:0:5} != "COMP-" ]] ; then
echo Invalide computer id \"$COMPUTERID\", it should be like \"COMP-XXX\"
error_code=1
fi
if [[ "$2" != "" ]] ; then
KEYFILE=$(cygpath -u "$2")
fi
if [[ "$3" != "" ]] ; then
CERTFILE=$(cygpath -u "$3")
fi
# check netsh
[ -f ${NETSH} ] || (echo "Error: unable to find command: netsh" && exit 1)
[ -f ${IPCONFIG} ] || (echo "Error: unable to find command: ipconfig" && exit 1)
[ -f ${GETMAC} ] || (echo "Error: unable to find command: getmac" && exit 1)
[ -f ${IPV6} ] || (echo "Error: unable to find command: ipv6" && exit 1)
# check ipv6
get_local_ip_version
if (( (local_ip_version & 2) == 0 )) ; then
echo "Install ipv6, maybe you need specify the location of windows setup pacakge ..."
netsh interface ipv6 install
fi
# get GUID of the first physics netcard
for IPINTERFACE in $(get_all_physical_netcard) ; do
break ;
done
# check to support native ipv6, if not, openvpn is necessary
IPV6INTERFACE=
declare -i openvpn_required=$((local_ip_version != 2))
if (( openvpn_required )) ; then
echo OpenVPN is required because of no native ipv6.
echo Check OpenVPN TAP Driver ...
getmac -v -Fo list | grep "TAP-Win32 Adapter V9" > /dev/null
if (( $? )) ; then
echo Install OpenVPN TAP driver as tap0901 ...
(cd ${OPENVPNHOME}/driver ; ./tapinstall.exe install OemWin2k.inf tap0901)
echo OpenVPN TAP driver Installed.
else
echo OpenVPN TAP Driver has been installed before.
fi
# echo Try to get OpenVPN TAP driver\'s connection name ...
# CONNAME=$(getmac -v -Fo list | grep -B1 "TAP-Win32 Adapter V9" | \
# sed -e "2d" | sed -e "s/Connection Name:\\s+//g")
# if [[ "${CONNAME}" == "" ]] ; then
# echo "Can't find connection name of TAP driver."
# exit 1
# fi
# echo TAP driver\'s connection name is "${CONNAME}"
echo Try to get OpenVPN TAP driver\'s GUID ...
# IPV6INTERFACE=$(ipv6 if | \
# grep -A1 "^Interface [0-9]+: Ethernet: ${CONNECTION}" | \
# sed -e "1d" | sed -e "s/\\s+Guid\\s+//g")
IPV6INTERFACE=$(get_openvpn_tap_interface)
if [[ "${IPV6INTERFACE}" == "" ]] ; then
echo "Can't get interface name of TAP driver."
exit 1
fi
echo Got it: ${IPV6INTERFACE}
fi
# check key, crt
if [[ -f "${KEYFILE}" && ! "${KEYFILE}" -ef ${DESTKEYFILE} ]] ; then
echo Copy ${KEYFILE} to ${DESTKEYFILE}
cp ${KEYFILE} ${DESTKEYFILE}
chmod 644 ${DESTKEYFILE}
fi
if [[ -f "${CERTFILE}" && ! "${CERTFILE}" -ef ${DESTCERTFILE} ]] ; then
echo Copy ${CERTFILE} to ${DESTCERTFILE}
cp ${CERTFILE} ${DESTCERTFILE}
chmod 644 ${DESTCERTFILE}
fi
[ -f ${DESTCERTFILE} ] || (echo "Error: unable to find $DESTCERTFILE file." && error_code=1)
[ -f ${DESTKEYFILE} ] || (echo "Error: unable to find $DESTKEYFILE file." && error_code=1)
# generate /etc/slapos/slapos.cfg
[ "${COMPUTERID}" == "" ] || \
sed -i "s/^\\s*computer_id.*$/computer_id = ${COMPUTERID}/g" ${SLAPOSCFG}
[ "${IPINTERFACE}" == "" ] || \
sed -i "s/^\\s*interface_name.*$/interface_name = ${IPINTERFACE}/g" ${SLAPOSCFG}
[ "${IPV6INTERFACE}" == "" ] || \
sed -i "s/^#\?\\s*ipv6_interface.*$/ipv6_interface = ${IPV6INTERFACE}/g" ${SLAPOSCFG}
echo Set slapos init script as Windows startup item.
regtool -q set "$RUNKEY\\$SLAPOSNODEINIT" "\"$(cygpath -w /usr/bin/sh)\" --login -i /slapnode-init.sh"
(( $? )) && echo Fail to set init script as startup item.
if (( error_code )) ; then
echo Fail to configure SlapOS node, you need run this scripts again after fix the problems.
else
echo Configure SlapOS node successfully.
fi
exit $error_code
--- gettext-tools/woe32dll/gettextlib-exports.c.orig 2012-02-09 20:18:39.108129400 -0800
+++ gettext-tools/woe32dll/gettextlib-exports.c 2012-02-09 20:19:17.197629400 -0800
@@ -18,9 +18,11 @@
#include "woe32dll/export.h"
VARIABLE(argmatch_die)
+#if 0
VARIABLE(error_message_count)
VARIABLE(error_one_per_line)
VARIABLE(error_print_progname)
+#endif
VARIABLE(error_with_progname)
VARIABLE(exit_failure)
VARIABLE(gl_array_list_implementation)
--- m4/woe32-dll.m4.bak 2010-06-06 05:49:58.000000000 -0700
+++ m4/woe32-dll.m4 1969-12-31 16:00:00.000000000 -0800
@@ -1,45 +0,0 @@
-# woe32-dll.m4 serial 2
-dnl Copyright (C) 2005-2006 Free Software Foundation, Inc.
-dnl This file is free software; the Free Software Foundation
-dnl gives unlimited permission to copy and/or distribute it,
-dnl with or without modifications, as long as this notice is preserved.
-
-dnl From Bruno Haible.
-
-# Add --disable-auto-import to the LDFLAGS if the linker supports it.
-# GNU ld has an --enable-auto-import option, and it is the default on Cygwin
-# since July 2005. But it has three fatal drawbacks:
-# - It produces executables and shared libraries with relocations in the
-# .text segment, defeating the principles of virtual memory.
-# - For some constructs such as
-# extern int var;
-# int * const b = &var;
-# it creates an executable that will give an error at runtime, rather
-# than either a compile-time or link-time error or a working executable.
-# (This is with both gcc and g++.) Whereas this code, not relying on
-# auto-import:
-# extern __declspec (dllimport) int var;
-# int * const b = &var;
-# gives a compile-time error with gcc and works with g++.
-# - It doesn't work in some cases (references to a member field of an
-# exported struct variable, or to a particular element of an exported
-# array variable), requiring code modifications. One platform
-# dictates code modifications on all platforms.
-AC_DEFUN([gl_WOE32_DLL],
-[
- AC_REQUIRE([AC_CANONICAL_HOST])
- case "$host_os" in
- mingw* | cygwin*)
- AC_MSG_CHECKING([for auto-import of symbols])
- AC_CACHE_VAL([gl_cv_ld_autoimport], [
- gl_save_LDFLAGS="$LDFLAGS"
- LDFLAGS="$LDFLAGS -Wl,--disable-auto-import"
- AC_TRY_LINK([], [], [gl_cv_ld_autoimport=yes], [gl_cv_ld_autoimport=no])
- LDFLAGS="$gl_save_LDFLAGS"])
- AC_MSG_RESULT([$gl_cv_ld_autoimport])
- if test $gl_cv_ld_autoimport = yes; then
- LDFLAGS="$LDFLAGS -Wl,--disable-auto-import"
- fi
- ;;
- esac
-])
--- ./gettext-runtime/configure.ac.bak 2012-02-09 22:05:07.737629400 -0800
+++ ./gettext-runtime/configure.ac 2012-02-09 22:05:20.077129400 -0800
@@ -64,7 +64,6 @@
dnl Check for build configuration.
-gl_WOE32_DLL
LT_INIT([win32-dll])
--- ./gettext-runtime/libasprintf/configure.ac.bak 2012-02-09 22:05:07.759629400 -0800
+++ ./gettext-runtime/libasprintf/configure.ac 2012-02-09 22:05:30.749629400 -0800
@@ -39,7 +39,6 @@
gl_EARLY
dnl Check for build configuration.
-gl_WOE32_DLL
LT_INIT([win32-dll])
case "$host_os" in
# On Cygwin, without -no-undefined, a warning is emitted and only a static
--- ./gettext-tools/configure.ac.bak 2012-02-09 22:05:07.782129400 -0800
+++ ./gettext-tools/configure.ac 2012-02-09 22:05:41.661629400 -0800
@@ -89,7 +89,6 @@
dnl Check for build configuration.
-gl_WOE32_DLL
LT_INIT([win32-dll])
--- glib/gstrfuncs.c~ 2011-09-10 22:57:34.802250000 +0800
+++ glib/gstrfuncs.c 2011-09-10 22:57:52.630375000 +0800
@@ -1424,7 +1424,7 @@ g_strsignal (gint signum)
const char *msg_locale;
#if defined(G_OS_BEOS) || defined(G_WITH_CYGWIN)
-extern const char *strsignal(int);
+extern char *strsignal(int);
#else
/* this is declared differently (const) in string.h on BeOS */
extern char *strsignal (int sig);
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2010, 2011, 2012 Vifib SARL and Contributors.
# All Rights Reserved.
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly advised to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 3
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
# Simulate the command groupadd to add a group on the Windows
#
ACTION=ADD
GROUP_NAME="$1"
NET LOCALGROUP ${GROUP_NAME} /${ACTION}
mkgroup > /etc/group
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2010, 2011, 2012 Vifib SARL and Contributors.
# All Rights Reserved.
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly advised to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 3
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
if [[ "$1" == "" ]]; then
exit 1
fi
GUID=$1
ipv6 if | grep -B1 "$GUID" | sed -e "2d" | sed -e "s/^Interface[0-9: ]\+\(Ethernet: \)\?//g"
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2010, 2011, 2012 Vifib SARL and Contributors.
# All Rights Reserved.
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly advised to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 3
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
# Simulate the command ip of Linux by netsh on the Windows.
#
# Usage: bash ip ...
#
#
# ip addr list INTERFACE_NAME
#
# => netsh interface ip show address [[name=]InterfaceName]
#
# ip link set INTERFACE_NAME up
#
# => netsh interface set interface [name = ] INTERFACE_NAME
# [ [admin = ] ENABLED|DISABLED
# [connect = ] CONNECTED|DISCONNECTED
# [newname = ] NewName ]
#
#
# ip addr add ADDRESS_STRING dev INTERFACE_NAME
#
# => netsh interface ip add address [name=]InterfaceName [addr=]IPAddress
# [mask=]SubnetMask [[gateway=] DefaultGateway [gwmetric=]GatewayMetric]
#
# ip addr del ADDRESS_STRING dev INTERFACE_NAME
#
# => netsh interface ip delete address [name=]InterfaceName [addr=] IPAddress
# [[gateway=]{DefaultGateway | all}]
#
function transfercommand()
{
IPCMD=`py -c "from netaddr.strategy import ipv4, ipv6
addr, prefix = '$ADDRESS_STRING'.split('/')
result = ''
if '.' in addr:
mask = ipv4.int_to_str(ipv4.prefix_to_netmask[int(prefix)])
if '$ACTION' == 'ADD':
if prefix == '32':
mask = '255.255.255.254'
result = 'netsh interface ip add address name=\"$INTERFACE_NAME\" addr=%s mask=%s' % (addr, mask)
elif '$ACTION' == 'DELETE':
result = 'netsh interface ip delete address name=\"$INTERFACE_NAME\" addr=%s' % addr
else:
mask = ipv6.int_to_str(ipv6.prefix_to_netmask[int(prefix)])
if '$ACTION' == 'ADD':
result = 'netsh interface ipv6 add address interface=\"$INTERFACE_NAME\" address=%s' % addr
elif '$ACTION' == 'DELETE':
result = 'netsh interface ipv6 delete address interface=\"$INTERFACE_NAME\" address=%s' % addr
print result"`
}
if [[ "$1" == "addr" ]]; then
if [[ "$2" == "list" ]]; then
INTERFACE_NAME=`guid2name $3`
# getmac /V /FO table /NH | grep "${INTERFACE_NAME}" | sed -e "s/Disable/Down/g" | sed -e "s/Enbale/Up/g"
# netsh interface ip show address name="${INTERFACE_NAME}"
ipconfig /all | gawk "BEGIN { ok = 0; flag = 0; }; /adapter $INTERFACE_NAME/ { ok = 1; }; /^\\s*\$/ { if (ok) flag += 1; if (flag == 2) { flag = 0; ok = 0; } }; { if (ok == 1) print \$0 }" | grep "IP Address"
netsh interface ipv6 show address interface="${INTERFACE_NAME}"
true
elif [[ "$2" == "add" ]]; then
ADDRESS_STRING="$3"
ACTION=ADD
INTERFACE_NAME=`guid2name $5`
transfercommand
$IPCMD
elif [[ "$2" == "del" ]]; then
ADDRESS_STRING="$3"
ACTION=DELETE
INTERFACE_NAME=`guid2name $5`
transfercommand
$IPCMD
fi
elif [[ "$1" == "link" ]]; then
INTERFACE_NAME=`guid2name $4`
netsh interface set interface "${INTERFACE_NAME}" enabled connected
fi
--- Python-2.7.3.org/Lib/plat-generic/regen~ 2011-09-10 22:39:45.536625000 +0800
+++ Python-2.7.3/Lib/plat-generic/regen 2011-09-10 22:36:43.302250000 +0800
@@ -1,3 +1,3 @@
#! /bin/sh
set -v
-python$EXE ../../Tools/scripts/h2py.py -i '(u_long)' /usr/include/netinet/in.h
+python$EXE -S ../../Tools/scripts/h2py.py -i '(u_long)' /usr/include/netinet/in.h
--- Python-2.7.3.org/Modules/_io/_iomodule.h 2012-11-04 23:59:16.140625000 +0800
+++ Python-2.7.3/Modules/_io/_iomodule.h 2012-11-04 23:59:49.109375000 +0800
@@ -72,7 +72,7 @@
PyObject *filename; /* Not used, but part of the IOError object */
Py_ssize_t written;
} PyBlockingIOErrorObject;
-PyAPI_DATA(PyObject *) PyExc_BlockingIOError;
+PyObject * PyExc_BlockingIOError;
/*
* Offset type for positioning.
--- Python-2.7.3.org/Include/py_curses.h 2009-09-06 16:23:05.000000000 -0500
+++ Python-2.7.3/Include/py_curses.h 2010-04-14 15:21:23.008971400 -0500
@@ -17,6 +17,13 @@
#define NCURSES_OPAQUE 0
#endif /* __APPLE__ */
+#ifdef __CYGWIN__
+/* the following define is necessary for Cygwin; without it, the
+ Cygwin-supplied ncurses.h sets NCURSES_OPAQUE to 1, and then Python
+ can't get at the WINDOW flags field. */
+#define NCURSES_INTERNALS
+#endif /* __CYGWIN__ */
+
#ifdef __FreeBSD__
/*
** On FreeBSD, [n]curses.h and stdlib.h/wchar.h use different guards
# Restart openvpn and slapos-node, this script will wait for ipv6 to
# be ready and run slapformat. After the first run of slapformat, the
# server on which slapformat was run and its partitions should appear
# on www.slapos.org.
# for debug installer
# trap "sleep 30" EXIT
function is_openvpn_disconnected()
{
getmac /V /FO list | grep "$IPV6INTERFACE" > /dev/null
# return $?
# 0 (false), connected
# 1 (true), disconnected or disabled
}
# get connection name by IF_GUID
function get_connection_name()
{
key='\HKLM\SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002bE10318}'
echo $(regtool -q get "$key\\$IPV6INTERFACE\Connection\Name")
}
#
# This script will be executed background.
#
SLAPOSCFG=/etc/slapos/slapos.cfg
OPENVPNHOME=/opt/openvpn
OPENVPNCFG=vifib.ovpn
LOGFILE=openvpn-vifib.log
# Startup openvpn if necessary
echo Check ipv6 interface
IPV6INTERFACE=$(grep "^\\s*ipv6_interface\\s*=\\s*[-{}0-9a-zA-Z]\+" $SLAPOSCFG | \
sed -e "s/\\s*ipv6_interface\\s*=\\s*//g"| sed -e "s/ //g")
echo ipv6 interface is $IPV6INTERFACE
if [[ "$IPV6INTERFACE" != "" ]] ; then
echo Check Vifib OpenVPN status ...
# if openvpn is not up, start it
is_openvpn_disconnected
if (( $? )) ; then
cd $OPENVPNHOME/config
./openvpn.exe --log "$LOGFILE" --dev-node $IPV6INTERFACE --config $OPENVPNCFG &
# make sure the last backgroud process is openvpn
ps -s -p "$i" | grep "config/openvpn" > /dev/null
(( $? )) || OPENVPN_PID=$!
fi
# waiting for openvpn up, no more than 3 minutes
for (( i = 1; i < 6; i += 1 )) ; do
is_openvpn_disconnected
(( $? )) || break
echo Vifib OpenVPN is down, re-try after 10 seconds \($i of 6\) ...
sleep 10
done
# last check
is_openvpn_disconnected
if (( $? )) ; then
if [[ "$OPENVPN_PID" != "" ]] ; then
echo Kill process of Vifib OpenVPN: $OPENVPN_PID
kill -9 $OPENVPN_PID
fi
echo Error: Vifib OpenVPN can not be up, check your network and try it later.
exit 1
fi
echo Vifib OpenVPN is up on \"$(get_connection_name)\"
echo Vifib OpenVPN Process Info:
ps -s -p ${OPENVPN_PID:-*}
[ "$OPENVPN_PID" == "" ] || disown
# kill -9 $OPENVPN_PID
fi
cd /opt/slapos
which slapformat 2>/dev/null 1>/dev/null
if (( $? )) ; then
source ./environment.sh
fi
# Run slapformat
echo Running slapformat to initialize slapos node ...
echo bin/slapformat -c --now $SLAPOSCFG
echo
# bin/slapformat -c --now $SLAPOSCFG
echo
echo Now slapformat finished.
--- slapos.core-0.33-py2.6.egg/slapos/format.py 2012-11-08 09:45:24.718750000 +0800
+++ slapos.core-0.33-py2.7.egg/slapos/format.py 2012-11-21 19:20:09.593750000 +0800
@@ -460,9 +460,9 @@
# This method shall check if all is correctly done
# This method shall not reset groups, just add them
try:
- grp.getgrnam(self.name)
+ grp.getgrnam('grp_' + self.name)
except KeyError:
- callAndRead(['groupadd', self.name])
+ callAndRead(['groupadd', 'grp_' + self.name])
user_parameter_list = ['-d', self.path, '-g', self.name, '-s',
'/bin/false']
@@ -637,6 +637,8 @@
except KeyError:
raise ValueError("%s must have at least one IPv6 address assigned" % \
interface_name)
+ for q in address_list:
+ q.setdefault('netmask', 'FFFF:FFFF:FFFF:FFFF::')
# XXX: Missing implementation of Unique Local IPv6 Unicast Addresses as
# defined in http://www.rfc-editor.org/rfc/rfc4193.txt
# XXX: XXX: XXX: IT IS DISALLOWED TO IMPLEMENT link-local addresses as
@@ -746,7 +748,7 @@
def addIPv4LocalAddress(self, addr=None):
"""Adds local IPv4 address in ipv4_local_network"""
- netmask = '255.255.255.255'
+ netmask = '255.255.255.254'
local_address_list = self.getIPv4LocalAddressList()
if addr is None:
return self._generateRandomIPv4Address(netmask)
@@ -1047,7 +1049,7 @@
except ValueError:
pass
except OSError:
- missing_binary_list.append(b)
+ missing_binary_list.append(b[0])
if missing_binary_list:
raise UsageError('Some required binaries are missing or not '
'functional: %s' % (','.join(missing_binary_list), ))
@@ -1142,7 +1144,7 @@
root_needed = False
# check root
- if root_needed and os.getuid() != 0:
+ if root_needed and os.getuid() != 500 if sys.platform in ['cygwin'] else 0:
message = "Root rights are needed"
self.logger.error(message)
raise UsageError(message)
@@ -1195,6 +1197,14 @@
real_callAndRead = callAndRead
usage = "usage: %s [options] CONFIGURATION_FILE" % sys.argv[0]
+ if sys.platform in ('cygwin',):
+ callAndRead = lambda args, flag=True : args.insert(0, '/bin/sh') \
+ or real_callAndRead(args, flag)
+ f = netifaces.ifaddresses
+ netifaces.ifaddresses = lambda s,f=f:reduce( \
+ lambda x,y:[x.__setitem__(k,v + x.get(k,[])) for k,v in y.iteritems()] and x, \
+ filter(None, [f(i) for i in netifaces.interfaces() if i.startswith(s)]),{})
+
# Parse arguments
options, configuration_file_path = Parser(usage=usage).check_args(args)
config = Config()
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2010, 2011, 2012 Vifib SARL and Contributors.
# All Rights Reserved.
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly advised to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 3
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
#
# Simulate the command useradd to add a user on the Cygwin
# useradd -d path -g init-group -s /bin/false -G group NAME
#
# -g, --gid GROUP
# The group name or number of the user's new initial login group. The group must exist.
#
# -G, --groups GROUP1[,GROUP2,...[,GROUPN]]]
# A list of supplementary groups which the user is also a member of.
# -s
# Shell used by user
#
ACTION=ADD
while getopts "Dd:g:G:p:s:r" opt ; do
case $opt in
d) USER_HOME=$OPTARG
;;
g,G) USER_GROUP=$OPTARG
;;
p) USER_PASSWORD=$OPTARG
;;
s) ;;
r) ;;
\?) echo Error when add user by cygwin
exit 1
;;
esac
done
shift $(($OPTIND - 1))
USER_NAME=$1
NET USER ${USER_NAME} ${USER_NAME} /${ACTION}
mkpasswd > /etc/passwd
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2010, 2011, 2012 Vifib SARL and Contributors.
# All Rights Reserved.
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly advised to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 3
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
#
# Simulate the command useradd to add a user on the Cygwin
# useradd -d path -g init-group -s /bin/false -G group NAME
#
# -g, --gid GROUP
# The group name or number of the user's new initial login group. The group must exist.
#
# -G, --groups GROUP1[,GROUP2,...[,GROUPN]]]
# A list of supplementary groups which the user is also a member of.
# -s
# Shell used by user
#
ACTION=ADD
while getopts "Dd:g:G:p:s:r" opt ; do
case $opt in
d) USER_HOME=$OPTARG
;;
g,G) USER_GROUP=$OPTARG
;;
p) USER_PASSWORD=$OPTARG
;;
s) ;;
r) ;;
\?) echo Error when add user by cygwin
exit 1
;;
esac
done
shift $(($OPTIND - 1))
USER_NAME=$1
# NET USER ${USER_NAME} ${USER_NAME} /${ACTION}
mkpasswd > /etc/passwd
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