Commit 387b771a authored by Jondy Zhao's avatar Jondy Zhao

add function get_free_local_ipv4_network

slapos-configure support --ipv4-local-network
refine slapos-windows-wrapper.bat
parent 4e5d2985
......@@ -300,7 +300,6 @@ _installer_name=slapos-windows-all-in-one
_output_dir=$(cygpath -a -w $(cygpath -w /)\\.. | sed -e 's%\\%\\\\%g')
_source_dir=$(cygpath -a -w $(cygpath -w /)\\.. | sed -e 's%\\%\\\\%g')
_srcfile=/opt/git/slapos.package/windows/scripts/slapos-all-in-one.iss
_install_path=$(cygpath -w /slapos-node | sed -e 's%\\%\\\\%g')
csih_inform "Starting generate Windows installer ..."
......@@ -309,8 +308,7 @@ csih_inform "copy ${_srcfile} to ${_issfile}"
cp ${_srcfile} ${_issfile} || csih_error "copy failed"
csih_inform "patch ${_issfile} ..."
sed -i -e "s%^DefaultDirName=.*%DefaultDirName=${_install_path}%" \
-e "s%^OutputBaseFilename=.*%OutputBaseFilename=${_installer_name}%" \
sed -i -e "s%^OutputBaseFilename=.*%OutputBaseFilename=${_installer_name}%" \
-e "s%^OutputDir=.*%OutputDir=${_output_dir}%" \
-e "s%^SourceDir=.*%SourceDir=${_source_dir}%" \
-e "s%/etc/slapos/scripts/post-install.sh%/etc/slapos/scripts/post-install.sh slaptest-%" \
......
......@@ -37,6 +37,7 @@ function show_usage()
echo " --computer-key=FILENAME"
echo " --client-certificate=FILENAME"
echo " --client-key=FILENAME"
echo " --ipv4-local-network=x.x.x.x/n"
echo ""
echo " The action option:"
echo ""
......@@ -71,6 +72,7 @@ declare _computer_certificate=
declare _computer_key=
declare _client_certificate=
declare _client_key=
declare _ipv4_local_network=${ipv4_local_network}
# -----------------------------------------------------------
# Command line options
......@@ -106,6 +108,11 @@ while test $# -gt 0; do
--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
......@@ -243,7 +250,7 @@ if ! netsh interface ipv6 show interface | grep -q "\\b${slapos_ifname}\\b" ; th
ipwin install $WINDIR\\inf\\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} ||
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"
......@@ -330,7 +337,7 @@ csih_error "Invalid computer id '$computer_guid' specified."
csih_inform "Computer configuration information:"
csih_inform " interface name: ${slapos_ifname}"
csih_inform " GUID: ${interface_guid}"
csih_inform " ipv4_local_network: ${ipv4_local_network}"
csih_inform " ipv4_local_network: ${_ipv4_local_network}"
csih_inform " computer_id: ${computer_guid}"
csih_inform " user_base_name: ${slapos_user_basename}"
csih_inform
......@@ -339,10 +346,10 @@ csih_inform " in the file: ${node_configure_file} "
csih_inform " Or change it in the $(dirname $0)/slapos-include.sh"
csih_inform " and run Configure SlapOS again."
sed -i -e "s%^\\s*interface_name.*$%interface_name = $interface_guid%" \
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%^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}
......
......@@ -177,6 +177,40 @@ function reset_slapos_connection()
netsh interface ip set address $ifname source=dhcp
} # === reset_slapos_connection() === #
# ======================================================================
# Routine: get_free_local_ipv4_network
# Get a free local ipv4 network in 10.x.x.0/24, return 10.x.x
# ======================================================================
function get_free_local_ipv4_network()
{
local addr=${1}
local -i i=10
local -i seg1=
local -i seg2=
[[ -n "${addr}" ]] &&
[[ ${addr} == 10.*.* ]] &&
! IPCONFIG /ALL | grep -q ${addr} &&
echo ${addr} &&
return 0
while (( i )) ; do
let seg1=($(date +%N) % 255) 2>&1 > /dev/null
let seg2=($(date +%N) % 255) 2>&1 > /dev/null
addr=${seg1}.${seg2}
! IPCONFIG /ALL | grep -q ${addr} &&
echo ${addr} &&
return 0
let i--
done
# No found
return 1
} # === get_free_local_ipv4_network() === #
readonly -f get_free_local_ipv4_network
# ======================================================================
# Routine: show_error_exit
# Show error message and wait for user to press any key to exit
......
......@@ -11,16 +11,6 @@ CMD.EXE /C %CYGWINROOT%\bin\bash --login %*
SET RETVALUE=%ERRORLEVEL%
GOTO END
:SLAPOS_BUILD_INSTALLER
CMD.EXE /C %CYGWINROOT%\bin\bash --login /slapos-build-installer
SET RETVALUE=%ERRORLEVEL%
GOTO END
:SLAPOS_CONFIGURE
CMD.EXE /C %CYGWINROOT%\bin\bash --login /etc/slapos/scripts/slapos-configure.sh --password=%2 --client-certificate=/certificate --client-key=/key --computer-certificate=/computer.crt --computer-key=/computer.key
SET RETVALUE=%ERRORLEVEL%
GOTO END
:END
ENDLOCAL
EXIT %RETVALUE%
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