Commit a102426b authored by Jondy Zhao's avatar Jondy Zhao

Refine slapos configure scripts

parent 33654f24
...@@ -44,23 +44,24 @@ Source: "opt\images\manager.ico"; DestDir: "{app}\cygwin\etc\slapos\images"; ...@@ -44,23 +44,24 @@ Source: "opt\images\manager.ico"; DestDir: "{app}\cygwin\etc\slapos\images";
Source: "setup.exe"; DestDir: "{app}"; Source: "setup.exe"; DestDir: "{app}";
Source: "opt\git\slapos.package\windows\scripts\setup-cygwin.bat"; DestDir: "{app}"; Source: "opt\git\slapos.package\windows\scripts\setup-cygwin.bat"; DestDir: "{app}";
Source: "opt\git\slapos.package\windows\scripts\ip"; DestDir: "{app}\cygwin\bin"; Permissions: readexec; Source: "opt\git\slapos.package\windows\scripts\ip"; DestDir: "{app}\cygwin\bin";
Source: "opt\git\slapos.package\windows\scripts\useradd"; DestDir: "{app}\cygwin\bin"; Permissions: readexec; Source: "opt\git\slapos.package\windows\scripts\useradd"; DestDir: "{app}\cygwin\bin";
Source: "opt\git\slapos.package\windows\scripts\usermod"; DestDir: "{app}\cygwin\bin"; Permissions: readexec; Source: "opt\git\slapos.package\windows\scripts\usermod"; DestDir: "{app}\cygwin\bin";
Source: "opt\git\slapos.package\windows\scripts\groupadd"; DestDir: "{app}\cygwin\bin"; Permissions: readexec; Source: "opt\git\slapos.package\windows\scripts\groupadd"; DestDir: "{app}\cygwin\bin";
Source: "opt\git\slapos.package\windows\scripts\brctl"; DestDir: "{app}\cygwin\bin"; Permissions: readexec; Source: "opt\git\slapos.package\windows\scripts\brctl"; DestDir: "{app}\cygwin\bin";
Source: "opt\git\slapos.package\windows\scripts\tunctl"; DestDir: "{app}\cygwin\bin"; Permissions: readexec; Source: "opt\git\slapos.package\windows\scripts\tunctl"; DestDir: "{app}\cygwin\bin";
Source: "opt\git\slapos.package\windows\scripts\cyg_wscript"; DestDir: "{app}\cygwin\usr\local\bin"; Permissions: readexec; Source: "opt\git\slapos.package\windows\scripts\cyg_wscript"; DestDir: "{app}\cygwin\usr\local\bin";
Source: "opt\git\slapos.package\windows\babeld\babeld.exe"; DestDir: "{app}\cygwin\bin"; Permissions: readexec; Source: "opt\git\slapos.package\windows\babeld\babeld.exe"; DestDir: "{app}\cygwin\bin";
Source: "opt\git\slapos.package\windows\openvpn\src\openvpn\.libs\openvpn.exe"; DestDir: "{app}\cygwin\bin"; Permissions: readexec; Source: "opt\git\slapos.package\windows\openvpn\src\openvpn\.libs\openvpn.exe"; DestDir: "{app}\cygwin\bin";
Source: "opt\openvpn\bin\*.exe"; DestDir: "{app}\cygwin\bin"; Permissions: readexec; Source: "opt\openvpn\bin\*.exe"; DestDir: "{app}\cygwin\bin";
Source: "opt\openvpn\bin\*.dll"; DestDir: "{app}\cygwin\bin"; Permissions: readexec; Source: "opt\openvpn\bin\*.dll"; DestDir: "{app}\cygwin\bin";
Source: "opt\openvpn\bin\addtap.bat"; DestDir: "{app}\cygwin\bin"; Source: "opt\openvpn\bin\addtap.bat"; DestDir: "{app}\cygwin\bin";
Source: "opt\openvpn\bin\deltapall.bat"; DestDir: "{app}\cygwin\bin"; Source: "opt\openvpn\bin\deltapall.bat"; DestDir: "{app}\cygwin\bin";
Source: "opt\openvpn\driver\*"; DestDir: "{app}\cygwin\etc\slapos\driver"; Source: "opt\openvpn\driver\*"; DestDir: "{app}\cygwin\etc\slapos\driver";
Source: "opt\git\slapos.package\windows\scripts\slapos-include.sh"; DestDir: "{app}\cygwin\etc\slapos\scripts";
Source: "opt\git\slapos.package\windows\scripts\slapos-node.sh"; DestDir: "{app}\cygwin\etc\slapos\scripts"; Source: "opt\git\slapos.package\windows\scripts\slapos-node.sh"; DestDir: "{app}\cygwin\etc\slapos\scripts";
Source: "opt\git\slapos.package\windows\scripts\post-install.sh"; DestDir: "{app}\cygwin\etc\slapos\scripts"; Source: "opt\git\slapos.package\windows\scripts\post-install.sh"; DestDir: "{app}\cygwin\etc\slapos\scripts";
Source: "opt\git\slapos.package\windows\scripts\build-slapos.sh"; DestDir: "{app}\cygwin\etc\slapos\scripts"; Source: "opt\git\slapos.package\windows\scripts\build-slapos.sh"; DestDir: "{app}\cygwin\etc\slapos\scripts";
......
...@@ -8,13 +8,13 @@ ...@@ -8,13 +8,13 @@
# #
# * Install msloop network adapter, named to re6stnet-lo # * Install msloop network adapter, named to re6stnet-lo
# #
# * ipv6: Ipv6 configure # * Check IPv6 protocol and install it if require
# #
# * re6stnet: Install re6stnet and register to nexedi re6stnet if it hasn't # * Configure and start cygwin service: cygserver, syslog-ng, sshd
# #
# * node: Create node configure file by parameters ca/key # * config: Create node and client configure file by parameters ca/key
# #
# * client: Create client configure file by parameters ca/key # * re6stnet: Install re6stnet and register to nexedi re6stnet if required
# #
# * cron: create cron configure file # * cron: create cron configure file
# #
...@@ -22,230 +22,58 @@ ...@@ -22,230 +22,58 @@
# #
# Usage: # Usage:
# #
# ./slapos-configure # ./slapos-configure [--install | --query | --overwrite | --uninstall]
# [ * | re6stnet | taps | config | cron | startup | runner]
# #
export PATH=/usr/local/bin:/usr/bin:$PATH # The action option:
# ======================================================================
# Routine: get_system_and_admins_gids
# Get the ADMINs ids from /etc/group and /etc/passwd
# ======================================================================
get_system_and_admins_ids() {
ret=0
for fname in /etc/passwd /etc/group; do
if ls -ld "${fname}" | grep -Eq '^-r..r..r..'; then
true
else
echo "The file $fname is not readable by all."
echo "Please run 'chmod +r $fname'."
echo
ret=1
fi
done
[ ! -r /etc/passwd -o ! -r /etc/group ] && return 1;
ADMINSGID=$(sed -ne '/^[^:]*:S-1-5-32-544:.*:/{s/[^:]*:[^:]*:\([0-9]*\):.*$/\1/p;q}' /etc/group)
SYSTEMGID=$(sed -ne '/^[^:]*:S-1-5-18:.*:/{s/[^:]*:[^:]*:\([0-9]*\):.*$/\1/p;q}' /etc/group)
if [ -z "$ADMINSGID" -o -z "$SYSTEMGID" ]; then
echo "It appears that you do not have correct entries for the"
echo "ADMINISTRATORS and/or SYSTEM sids in /etc/group."
echo
echo "Use the 'mkgroup' utility to generate them"
echo " mkgroup -l > /etc/group"
warning_for_etc_file group
ret=1;
fi
ADMINSUID=$(sed -ne '/^[^:]*:[^:]*:[0-9]*:[0-9]*:[^:]*,S-1-5-32-544:.*:/{s/[^:]*:[^:]*:\([0-9]*\):.*$/\1/p;q}' /etc/passwd)
SYSTEMUID=$(sed -ne '/^[^:]*:[^:]*:[0-9]*:[0-9]*:[^:]*,S-1-5-18:.*:/{s/[^:]*:[^:]*:\([0-9]*\):.*$/\1/p;q}' /etc/passwd)
if [ -z "$ADMINSUID" -o -z "$SYSTEMUID" ]; then
echo "It appears that you do not have correct entries for the"
echo "ADMINISTRATORS and/or SYSTEM sids in /etc/passwd."
echo
echo "Use the 'mkpasswd' utility to generate it"
echo " mkpasswd -l > /etc/passwd."
warning_for_etc_file passwd
ret=1;
fi
return "${ret}"
} # === get_system_and_admins_ids() === #
#-------------------------------------------------
# Common functions
#-------------------------------------------------
# #
# Return connection name by line, and replace space with '%' # --install Install only when the item hasn't been installed
# --query Interactive to install all the item
# --overwite Overwrite the item even it has been installed
# --uninstall Remove the configure item
# #
function get_all_connections() # Default is --install
{
netsh interface ipv6 show interface | \
grep "^[ 0-9]\+ " | \
sed -e "s/^[ 0-9]\+[a-zA-Z]\+//" -e "s/^\s*//" -e "s/ /%/g"
}
# #
# Check all the connection names, and compare the original connection # The configure item option:
# list, return the new connection name
# #
# If nothing found, return empty # * All the configure item
# If more than one, return the first one # re6stnet Install re6stent and dependencies
# taps Install OpenVPN Tap-Windows Driver for re6stnet
# config Generate slapos node and client configure files
# cron Generate cron file and start cron job
# startup Run slapos-configure.sh on windows startup
# runner Install web runner for this node
# #
function get_new_connection() source $(dirname $0)/slapos-include.sh
{ check_administrator_right
original_connections=" $* "
current_connections=$(get_all_connections)
for name in $current_connections ; do
[[ ! "$original_connections" == *[\ ]$name[\ ]* ]] && \
echo ${name//%/ } && return 0
done
}
# if [[ ! ":$PATH" == :/opt/slapos/bin: ]] ; then
# Remove all ipv4/ipv6 addresses in the connection re6stnet-lo for profile in ~/.bash_profile ~/.profile ; do
# grep -q "export PATH=/opt/slapos/bin:" $profile || \
function reset_connection() echo "export PATH=/opt/slapos/bin:$$PATH" >> $profile
{
ifname=${1-re6stnet-lo}
for addr in $(netsh interface ipv6 show address $ifname level=normal | \
grep "^Manual" | \
sed -e "s/^\(\w\+\s\+\)\{4\}//") ; do
netsh interface ipv6 del address $ifname $addr
done done
netsh interface ip set address $ifname source=dhcp fi
# for addr in $(netsh interface ip show address $ifname | \
# grep "IP Address:" | \
# sed -e "s/IP Address://") ; do
# netsh interface del address $ifname $addr
# done
}
#
# Transfer connection name to GUID
#
function connection2guid()
{
ifname=${1-re6stnet-lo}
#
# This command doesn't work in the Windows 7, Window 8, maybe
# Vista. Because no guid information in these platforms.
#
# netsh interface ipv6 show interface $ifname | \
# grep "^GUID\s*:" | \
# sed -e "s/^GUID\s*:\s*//"
#
# So we use getmac to repleace it:
getmac /fo list /v | grep -A3 "^Connection Name: *$ifname\$" \
| grep "^Transport Name:" | sed -e "s/^.*Tcpip_//g"
}
#
# Show error message and waiting for user to press any key quit
#
function show_error_exit()
{
msg=${1-Failed to configure Slapos Node in this computer.}
echo $msg
read -n 1 -p "Press any key to exit..."
exit 1
}
function check_service_state()
{
service_name=$1
service_state=$(cygrunsrv --query $service_name | sed -n -e 's/^Current State[ :]*//p')
echo Cygwin $service_name service state: $service_state
if [[ ! x$service_state == "xRunning" ]] ; then
echo Starting $service_name service ...
net start $service_name || show_error_exit "Failed to start $service_name service"
echo Start $service_name service OK.
else
echo Cygwin $service_name service is running.
fi
}
#
# Check ipv6 connection by default ipv6 route
#
function check_ipv6_connection()
{
netsh interface ipv6 show route | grep -q " ::/0 "
}
#
# Query the parameter, usage:
#
# query_parameter ACTUAL EXCPETED MESSAGE
#
function query_parameter()
{
if [[ X$1 == X || $1 == "*" || $1 == "all" ]] ; then
return 1
fi
if [[ $1 == "?" || $1 == "query" ]] ; then
read -n 1 -p $3 user_ack
if [[ X$user_ack == X[Yy] ]] ; then
return 1
else
return 0
fi
fi
if [[ $1 == $2 ]] ; then
return 1
fi
return 0
}
#-------------------------------------------------
# Check adminsitrator rights
#-------------------------------------------------
get_system_and_admins_ids || show_error_exit "Failed to get uids of system and amdinistrator account."
id | grep -q "$ADMINSUID(Administrators)" || show_error_exit "Error: Administrator right required to run this script."
for myprofile in ~/.bash_profile ~/.profile ; do # cygrunsrv
grep -q "export CYGWIN=server" $myprofile || echo "export CYGWIN=server" >> $myprofile # devcon
grep -q "export PATH=/opt/slapos/bin:" $myprofile || echo "export PATH=/opt/slapos/bin:$$PATH" >> $myprofile # openssl
done # export WINDIR
#------------------------------------------------- # -----------------------------------------------------------
# Constants
#-------------------------------------------------
slapos_client_home=~/.slapos
client_configure_file=$slapos_client_home/slapos.cfg
client_certificate_file=$slapos_client_home/certificate
client_key_file=$slapos_client_home/key
client_template_file=/etc/slapos/slapos-client.cfg.example
url_client_template_file=http://git.erp5.org/gitweb/slapos.core.git/blob_plain/HEAD:/slapos-client.cfg.example
node_certificate_file=/etc/opt/slapos/ssl/computer.crt
node_key_file=/etc/opt/slapos/ssl/computer.key
node_config_file=/etc/opt/slapos/slapos.cfg
node_template_file=/etc/slapos/slapos.cfg.example
url_node_template_file=http://git.erp5.org/gitweb/slapos.core.git/blob_plain/HEAD:/slapos.cfg.example
slapos_ifname=re6stnet-lo
# Hope it will not confilct with original network in the local machine
ipv4_local_network=10.201.67.0/24
slapos_runner_file=/etc/slapos/scripts/slap-runner.html
slaprunner_cfg=http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/heads/cygwin-0:/software/slaprunner/software.cfg
netdrive_reporter_cfg=http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/heads/cygwin-0:/software/netdrive-reporter/software.cfg
wordpress_cfg=http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/heads/cygwin:/software/wordpress/software.cfg
#-------------------------------------------------
# Create paths # Create paths
#------------------------------------------------- # -----------------------------------------------------------
mkdir -p /etc/opt/slapos/ssl/partition_pki mkdir -p /etc/opt/slapos/ssl/partition_pki
mkdir -p $slapos_client_home mkdir -p $slapos_client_home
mkdir -p /opt/slapos/log
mkdir -p /etc/slapos/scripts
mkdir -p /etc/re6stnet
#------------------------------------------------- # -----------------------------------------------------------
# Configure cygwin server services # Configure cygwin services: cygserver syslog-ng sshd
#------------------------------------------------- # -----------------------------------------------------------
echo
echo Checking cygserver service ... echo Starting configure cygwin services ...
echo
cygrunsrv --query cygserver > /dev/null 2>&1 cygrunsrv --query cygserver > /dev/null 2>&1
if (( $? )) ; then if (( $? )) ; then
echo Run cygserver-config ... echo Run cygserver-config ...
...@@ -266,15 +94,16 @@ else ...@@ -266,15 +94,16 @@ else
echo The syslog-ng service has been installed. echo The syslog-ng service has been installed.
fi fi
check_service_state syslog-ng check_service_state syslog-ng
echo
echo Configure cygwin services OK.
echo
#------------------------------------------------- # -----------------------------------------------------------
# Configure slapos network # Install network connection used by slapos node
#------------------------------------------------- # -----------------------------------------------------------
echo
# echo Starting configure slapos network ...
# Add msloop network adapter, ane name it as "re6stnet-lo" echo
#
echo Checking slapos network adapter: $slapos_ifname ...
original_connections=$(echo $(get_all_connections)) original_connections=$(echo $(get_all_connections))
if [[ ! " $original_connections " == *[\ ]$slapos_ifname[\ ]* ]] ; then if [[ ! " $original_connections " == *[\ ]$slapos_ifname[\ ]* ]] ; then
echo Installing slapos network adapter ... echo Installing slapos network adapter ...
...@@ -283,174 +112,145 @@ if [[ ! " $original_connections " == *[\ ]$slapos_ifname[\ ]* ]] ; then ...@@ -283,174 +112,145 @@ if [[ ! " $original_connections " == *[\ ]$slapos_ifname[\ ]* ]] ; then
[[ "X$connection_name" == "X" ]] && \ [[ "X$connection_name" == "X" ]] && \
show_error_exit "Add msloop network adapter failed." show_error_exit "Add msloop network adapter failed."
echo echo
netsh interface set interface name="$connection_name" newname="$slapos_ifname" netsh interface set interface name="$connection_name" newname="$slapos_ifname" || \
show_error_exit "Failed to rename connection to $slapos_ifname."
interface_guid=$(connection2guid $slapos_ifname) || \
show_error_exit "Failed to get guid of interface: $slapos_ifname."
fi fi
#ip -4 addr add $ipv4_local_network dev $slapos_ifname #ip -4 addr add $ipv4_local_network dev $slapos_ifname
# reset_connection $slapos_ifname # reset_connection $slapos_ifname
echo SlapOS network adapter OK. echo " Slapos ipv4_local_network is $ipv4_local_network"
echo Slapos ipv4_local_network is $ipv4_local_network echo " If it confilcts with your local network, change it in the file:"
echo " $(dirname $0)/slapos-include.sh"
echo
echo Configure slapos network OK.
echo
# -----------------------------------------------------------
# Check IPv6 protocol, install it if it isn't installed
# -----------------------------------------------------------
echo
echo Starting configure IPv6 protocol ...
echo
netsh interface ipv6 show interface > /dev/null || \
netsh interface ipv6 install || \
show_error_exit "Failed to install IPv6 protocol."
echo
echo Configure IPv6 protocol OK.
echo
#------------------------------------------------- # -----------------------------------------------------------
# Generate slapos node configure file # config: Generate slapos node and client configure file
#------------------------------------------------- # -----------------------------------------------------------
echo
echo Starting configure section config ...
echo
[[ -r $node_template_file && -r $client_template_file ]] || \
create_template_configure_file || \
show_error_exit "Failed to create template configure file."
echo Checking computer certificate file ...
if [[ ! -f $node_certificate_file ]] ; then if [[ ! -f $node_certificate_file ]] ; then
read -p "Where is computer certificate file (/computer.crt): " certificate_file read -p "Where is computer certificate file (/computer.crt): " filename
[[ X$certificate_file == X ]] && certificate_file=/computer.crt [[ -z $filenname ]] && filename="/computer.crt"
[[ ! -f "$certificate_file" ]] && \ [[ ! -r "$filename" ]] && \
show_error_exit "Certificate file $certificate_file doesn't exists." show_error_exit "Computer certificate file $filename doesn't exists."
echo "Copy certificate from $certificate_file to $node_certificate_file" echo "Copy certificate from $filename to $node_certificate_file"
certificate_file=$(cygpath -u $certificate_file) filename=$(cygpath -u $filename)
cp $certificate_file $node_certificate_file cp $filename $node_certificate_file
else else
echo Found computer certificate file: $node_certificate_file echo "Found computer certificate file: $node_certificate_file"
fi fi
openssl x509 -noout -in $node_certificate_file || \ openssl x509 -noout -in $node_certificate_file || \
show_error_exit "Invalid computer certificate: $node_certificate_file." show_error_exit "Invalid computer certificate: $node_certificate_file."
echo Check computer certificate OK.
echo Checking computer guid ...
computer_id=$(grep CN=COMP $node_certificate_file | sed -e "s/^.*, CN=//g" | sed -e "s%/emailAddress.*\$%%g")
[[ "$computer_id" == COMP-+([0-9]) ]] || \
show_error_exit "Invalid computer id specified."
echo Computer GUID is: $computer_id
echo Checking computer key file ...
if [[ ! -f $node_key_file ]] ; then if [[ ! -f $node_key_file ]] ; then
read -p "Where is computer key file (/computer.key): " key_file read -p "Where is computer key file (/computer.key): " filename
[[ X$key_file == X ]] && key_file=/computer.key [[ -z $filename ]] && filename="/computer.key"
[[ ! -f "$key_file" ]] && \ [[ ! -f "$filename" ]] && \
show_error_exit "Key file $key_file doesn't exists." show_error_exit "Key file $filename doesn't exists."
echo "Copy key from $key_file to $node_key_file" echo "Copy key from $filename to $node_key_file"
key_file=$(cygpath -u $key_file) filename=$(cygpath -u $filename)
cp $key_file $node_key_file cp $filename $node_key_file
else else
echo Found computer key file: $node_key_file echo "Found computer key file: $node_key_file"
fi fi
openssl rsa -noout -in $node_key_file -check || \ openssl rsa -noout -in $node_key_file -check || \
show_error_exit "Invalid computer key: $node_key_file." show_error_exit "Invalid node key: $node_key_file."
echo Check computer key OK.
# Create node configure file, replace interface_name with guid of
# re6stnet-lo
echo Checking computer configure file ...
if [[ ! -f $node_config_file ]] ; then if [[ ! -f $node_config_file ]] ; then
[[ -f $node_template_file ]] || \
(cd /etc/slapos; wget $url_node_template_file -O $node_template_file) || \
show_error_exit "Download slapos.cfg.example failed."
echo "Copy computer configure file from $node_template_file to $node_config_file" echo "Copy computer configure file from $node_template_file to $node_config_file"
cp $node_template_file $node_config_file cp $node_template_file $node_config_file
fi fi
interface_guid=$(connection2guid $slapos_ifname) || \ [[ -z $interface_guid ]] && \
interface_guid=$(sed -n -e "s/^\\sinterface_name\\s*=\\s*//p" $node_config_file)
[[ -z $interface_guid ]] && \
interface_guid=$(connection2guid $slapos_ifname)
[[ -z $interface_guid ]] && \
show_error_exit "Failed to get guid of interface: $slapos_ifname." show_error_exit "Failed to get guid of interface: $slapos_ifname."
computer_guid=$(grep "CN=COMP" $node_certificate_file | \
sed -e "s/^.*, CN=//g" | sed -e "s%/emailAddress.*\$%%g")
[[ "$computer_guid" == COMP-+([0-9]) ]] || \
show_error_exit "Invalid computer id '$computer_guid' specified."
echo "Computer configuration information:" echo "Computer configuration information:"
echo " interface name: $slapos_ifname" echo " interface name: $slapos_ifname"
echo " GUID: $interface_guid" echo " GUID: $interface_guid"
echo " ipv4_local_network: $ipv4_local_network" echo " ipv4_local_network: $ipv4_local_network"
echo " computer_id: $computer_id" echo " computer_id: $computer_guid"
# generate /etc/slapos/slapos.cfg
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%^#\?\\s*ipv6_interface.*$%# ipv6_interface =%g" \
-e "s%^ipv4_local_network.*$%ipv4_local_network = $ipv4_local_network%" \ -e "s%^ipv4_local_network.*$%ipv4_local_network = $ipv4_local_network%" \
-e "s%^computer_id.*$%computer_id = $computer_id%" \ -e "s%^computer_id.*$%computer_id = $computer_guid%" \
$node_config_file $node_config_file
echo Check computer configure file OK.
#-------------------------------------------------
# Generate slapos client configure file
#-------------------------------------------------
echo Checking client certificate file ...
if [[ ! -f $client_certificate_file ]] ; then if [[ ! -f $client_certificate_file ]] ; then
read -p "Where is client certificate file (/certificate): " certificate_file read -p "Where is client certificate file (/certificate): " filename
[[ X$certificate_file == X ]] && certificate_file=/certificate [[ -z $filename ]] && certificate_file="/certificate"
[[ ! -f "$certificate_file" ]] && \ [[ ! -f "$filename" ]] && \
show_error_exit "Certificate file $certificate_file doesn't exists." show_error_exit "Client certificate file $filename doesn't exists."
echo "Copy client certificate from $certificate_file to $client_certificate_file" echo "Copy client certificate from $filename to $client_certificate_file"
certificate_file=$(cygpath -u $certificate_file) certificate_file=$(cygpath -u $filename)
cp $certificate_file $client_certificate_file cp $filename $client_certificate_file
fi fi
openssl x509 -noout -in $client_certificate_file || \ openssl x509 -noout -in $client_certificate_file || \
show_error_exit "Invalid client certificate: $client_certificate_file." show_error_exit "Invalid client certificate: $client_certificate_file."
echo Check client certificate Ok.
echo Checking client key file ...
if [[ ! -f $client_key_file ]] ; then if [[ ! -f $client_key_file ]] ; then
read -p "Where is client key file (/key): " key_file read -p "Where is client key file (/key): " filename
[[ X$key_file == X ]] && key_file=/key [[ -z $filename ]] && key_file="/key"
[[ ! -f "$key_file" ]] && \ [[ ! -f "$filename" ]] && \
show_error_exit "Key file $key_file doesn't exists." show_error_exit "Key file $filename doesn't exists."
echo "Copy client key from $key_file to $client_key_file" echo "Copy client key from $filename to $client_key_file"
key_file=$(cygpath -u $key_file) key_file=$(cygpath -u $filename)
cp $key_file $client_key_file cp $filename $client_key_file
fi fi
openssl rsa -noout -in $client_key_file -check || \ openssl rsa -noout -in $client_key_file -check || \
show_error_exit "Invalid client key: $client_key_file." show_error_exit "Invalid client key: $client_key_file."
echo Checking computer key OK.
echo Checking client configure file ...
if [[ ! -f $client_configure_file ]] ; then if [[ ! -f $client_configure_file ]] ; then
cat <<EOF > $client_configure_file echo "Copy client configure file from $client_template_file to $client_config_file"
[slapos] cp $client_template_file $client_config_file
master_url = https://slap.vifib.com/
[slapconsole]
# Put here retrieved certificate from SlapOS Master.
# Beware: put certificate from YOUR account, not the one from your node.
# You (as identified person from SlapOS Master) will request an instance, node your node.
# Conclusion: node certificate != person certificate.
cert_file = certificate file location coming from your slapos master account
key_file = key file location coming from your slapos master account
# Below are softwares maintained by slapos.org and contributors
alias =
apache_frontend http://git.erp5.org/gitweb/slapos.git/blob_plain/HEAD:/software/apache-frontend/software.cfg
dokuwiki http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/tags/slapos-0.158:/software/dokuwiki/software.cfg
drupal http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/tags/slapos-0.151:/software/erp5/software.cfg
erp5 http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/tags/slapos-0.143:/software/erp5/software.cfg
erp5_branch http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/heads/erp5:/software/erp5/software.cfg
fengoffice http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/tags/slapos-0.158:/software/fengoffice/software.cfg
kumofs http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/tags/slapos-0.141:/software/kumofs/software.cfg
kvm http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/tags/slapos-0.156:/software/kvm/software.cfg
maarch http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/tags/slapos-0.159:/software/maarch/software.cfg
mariadb http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/tags/slapos-0.152:/software/mariadb/software.cfg
memcached http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/tags/slapos-0.82:/software/memcached/software.cfg
mysql http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/tags/slapos-0.65:/software/mysql-5.1/software.cfg
opengoo http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/tags/slapos-0.158:/software/opengoo/software.cfg
postgresql http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/tags/slapos-0.157:/software/postgres/software.cfg
slaposwebrunner http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/heads/cygwin-0:/software/slaprunner/software.cfg
slaposwebrunner_lite http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/heads/cygwin-0:/software/slaprunner-lite/software.cfg
wordpress http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/heads/cygwin:/software/wordpress/software.cfg
xwiki http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/tags/slapos-0.46:/software/xwiki/software.cfg
zabbixagent http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/tags/slapos-0.162:/software/zabbix-agent/software.cfg
netdrive_reporter http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/heads/cygwin-0:/software/netdrive-reporter/software.cfg
demoapp http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/heads/cygwin-0:/software/demoapp/software.cfg
EOF
echo "Client configure file $client_config_file created."
fi fi
echo Client configuration information: echo "Client configuration information:"
echo client certificate file: $client_certificate_file echo " client certificate file: $client_certificate_file"
echo client key file: $client_key_file echo " client key file: $client_key_file"
echo
sed -i -e "s%^cert_file.*$%cert_file = $client_certificate_file%" \ sed -i -e "s%^cert_file.*$%cert_file = $client_certificate_file%" \
-e "s%^key_file.*$%key_file = $client_key_file%" \ -e "s%^key_file.*$%key_file = $client_key_file%" \
$client_configure_file $client_configure_file
echo Check client configure file OK. echo
echo Configure section config OK.
#------------------------------------------------- echo
# Re6stnet
#-------------------------------------------------
# Check ipv6, install it if it isn't installed. # -----------------------------------------------------------
echo Checking ipv6 protocol ... # re6stnet: Install required packages and register to nexedi
netsh interface ipv6 show interface > /dev/null || netsh interface ipv6 install || \ # -----------------------------------------------------------
show_error_exit "Failed to install ipv6 protocol." echo
echo IPv6 protocol has been installed. echo Starting configure section re6stnet ...
echo
# miniupnpc is required by re6stnet
echo Checking miniupnpc ... echo Checking miniupnpc ...
if [[ ! -d /opt/miniupnpc ]] ; then if [[ ! -d /opt/miniupnpc ]] ; then
[[ -f /miniupnpc.tar.gz ]] || show_error_exit "No package found: /miniupnpc.tar.gz" [[ -f /miniupnpc.tar.gz ]] || show_error_exit "No package found: /miniupnpc.tar.gz"
...@@ -466,7 +266,6 @@ else ...@@ -466,7 +266,6 @@ else
echo Check miniupnpc OK. echo Check miniupnpc OK.
fi fi
# pyOpenSSL is required by re6stnet
echo Checking pyOpenSSL ... echo Checking pyOpenSSL ...
if [[ ! -d /opt/pyOpenSSL ]] ; then if [[ ! -d /opt/pyOpenSSL ]] ; then
[[ -f /pyOpenSSL.tar.gz ]] || show_error_exit "No package found: /pyOpenSSL.tar.gz" [[ -f /pyOpenSSL.tar.gz ]] || show_error_exit "No package found: /pyOpenSSL.tar.gz"
...@@ -481,7 +280,6 @@ else ...@@ -481,7 +280,6 @@ else
echo Check pyOpenSSL OK. echo Check pyOpenSSL OK.
fi fi
# Install re6stnet
echo Checking re6stnet ... echo Checking re6stnet ...
if [[ ! -d /opt/re6stnet ]] ; then if [[ ! -d /opt/re6stnet ]] ; then
echo "Installing re6stnet ..." echo "Installing re6stnet ..."
...@@ -491,7 +289,7 @@ if [[ ! -d /opt/re6stnet ]] ; then ...@@ -491,7 +289,7 @@ if [[ ! -d /opt/re6stnet ]] ; then
mv $(ls -d re6stnet-*) re6stnet mv $(ls -d re6stnet-*) re6stnet
else else
echo "Clone re6stnet from http://git.erp5.org/repos/re6stnet.git" echo "Clone re6stnet from http://git.erp5.org/repos/re6stnet.git"
git clone -b cygwin http://git.erp5.org/repos/re6stnet.git git clone -b cygwin http://git.erp5.org/repos/re6stnet.git
fi fi
cd re6stnet cd re6stnet
python setup.py install || show_error_exit "Failed to install re6stnet." python setup.py install || show_error_exit "Failed to install re6stnet."
...@@ -500,64 +298,83 @@ else ...@@ -500,64 +298,83 @@ else
echo Check re6stnet OK. echo Check re6stnet OK.
fi fi
echo Checking re6stent configuration ... echo Checking re6stnet configuration ...
mkdir -p /etc/re6stnet if [[ ! -r $re6stnet_configure_file ]] ; then
cd /etc/re6stnet echo "Registering to http://re6stnet.nexedi.com ..."
if [[ ! -f re6stnet.conf ]] ; then cd $(dirname $re6stnet_configure_file)
echo Register to http://re6stnet.nexedi.com ...
# Your subnet: 2001:67c:1254:e:19::/80 (CN=917529/32) # Your subnet: 2001:67c:1254:e:19::/80 (CN=917529/32)
mysubnet=$(re6st-conf --registry http://re6stnet.nexedi.com/ --anonymous | grep "^Your subnet:") \ subnet=$(re6st-conf --registry http://re6stnet.nexedi.com/ --anonymous | \
|| show_error_exit "Register to nexedi re6stnet failed" grep "^Your subnet:") || \
echo Register OK. show_error_exit "Register to nexedi re6stnet failed"
echo [[ -r re6stnet.conf ]] || \
echo $mysubnet show_error_exit "No $re6stnet_configure_file found."
echo echo Register re6stnet OK.
echo Write subnet information to re6stnet.conf
echo "# $mysubnet" >> re6stnet.conf echo "Write information to re6stnet.conf:"
echo Write "table 0" to re6stnet.conf echo " # $subnet"
echo "table 0" >> re6stnet.conf echo " table 0"
echo "ovpnlog" >> re6stnet.conf echo " ovpnlog"
echo "interface $slapos_ifname" >> re6stnet.conf echo " main-interface $slapos_ifname"
echo "main-interface $slapos_ifname" >> re6stnet.conf echo " interface $slapos_ifname"
echo "log $(cygpath -m /var/log/re6stnet)" echo " log $(cygpath -m /var/log/re6stnet)"
echo -e "# $subnet\ntable 0\novpnlog" \
"\nmain-interface $slapos_ifname\ninterface $slapos_ifname" \
"\nlog $(cygpath -m /var/log/re6stnet)" \
>> $re6stnet_configure_file
fi
# Run re6stnet if no native ipv6
if check_re6stnet_needed ; then
check_re6stnet_configure || exit 1
if [[ ! -r ${re6stnet_cgywin_script} ]] ; then
cat <<EOF > /${re6stnet_cgywin_script}
$(cygpath -w /bin/bash.exe) --login -c 'python %*'
EOF
chmod +x ${re6stnet_cgywin_script}
fi
if ! cygrunsrv --query $re6stnet_service_name >/dev/null 2>&1 ; then
cygrunsrv -I $re6stnet_service_name -c $(dirname $re6stnet_configure_file) \
-p $(which re6stnet) -a "@re6stnet.conf" -d "CYGWIN re6stnet" || \
show_error_exit "Failed to install cygwin service $re6stnet_service_name."
fi
check_cygwin_service $re6stnet_service_name || exit 1
echo "You can check log files in the /var/log/re6stnet/*.log"
else
echo "Native IPv6 found, no re6stnet required."
fi fi
[[ ! -f re6stnet.conf ]] && \
show_error_exit "Failed to register to nexedi re6stnet: no /etc/re6stnet/re6stnet.conf found."
grep -q "^table 0" re6stnet.conf || \
show_error_exit "Error: no parameter 'table 0' found in the /etc/re6stnet/re6stnet.conf"
grep -q "^# Your subnet: " re6stnet.conf || \
show_error_exit "Error: no subnet found in the /etc/re6stnet/re6stnet.conf"
echo Check re6stnet configuration OK.
echo
#------------------------------------------------- echo
# Create openvpn tap-windows drivers used by re6stnet echo Configure section re6stnet OK.
#------------------------------------------------- echo
# -----------------------------------------------------------
# taps: Install openvpn tap-windows drivers used by re6stnet
# -----------------------------------------------------------
#
# Adding tap-windows driver will break others, so we add all drivers # Adding tap-windows driver will break others, so we add all drivers
# here. Get re6stnet client count, then remove extra drivers and add # here. Get re6stnet client count, then remove extra drivers and add
# required drivers. # required drivers.
#
echo echo
echo Installing OpenVPN Tap-Windows Driver ... echo Starting configure section taps ...
echo echo
original_connections=$(echo $(get_all_connections)) original_connections=$(echo $(get_all_connections))
client_count=$(sed -n -e "s/^client-count *//p" /etc/re6stnet/re6stnet.conf) client_count=$(sed -n -e "s/^client-count *//p" $re6stnet_configure_file)
[[ -z $client_count ]] && client_count=10 [[ -z $client_count ]] && client_count=10
echo Re6stnet client count = $client_count echo " Client count: $client_count"
re6stnet_name_list="re6stnet-tcp re6stnet-udp" re6stnet_name_list="re6stnet-tcp re6stnet-udp"
for (( i=1; i<=client_count; i=i+1 )) ; do for (( i=1; i<=client_count; i=i+1 )) ; do
re6stnet_name_list="$re6stnet_name_list re6stnet$i" re6stnet_name_list="$re6stnet_name_list re6stnet$i"
done done
for re6stnet_ifname in $re6stnet_name_list ; do for name in $re6stnet_name_list ; do
echo Checking interface $re6stnet_ifname ... echo "Checking interface $name ..."
if [[ ! " $original_connections " == *[\ ]$re6stnet_ifname[\ ]* ]] ; then if [[ ! " $original_connections " == *[\ ]$name[\ ]* ]] ; then
echo Installing interface $re6stnet_ifname ... echo "Installing interface $name ..."
ip vpntap add dev $re6stnet_ifname || show_error_exit "Failed to install openvpn tap-windows driver." ip vpntap add dev $name || \
echo Interface $re6stnet_ifname installed. show_error_exit "Failed to install OpenVPN Tap-Windows Driver."
echo "Interface $name installed."
else else
echo $re6stnet_ifname has been installed. echo "$name has been installed."
fi fi
done done
# #
...@@ -565,96 +382,56 @@ done ...@@ -565,96 +382,56 @@ done
# #
# ip vpntap del dev re6stnet-x # ip vpntap del dev re6stnet-x
# #
echo
echo Configure section taps OK.
echo
#------------------------------------------------- # -----------------------------------------------------------
# IPv6 Connection # runner: Create instance of slap web runner
#------------------------------------------------- # -----------------------------------------------------------
echo "Checking native IPv6 ..." echo
check_ipv6_connection echo Starting configure section runner ...
# Run re6stnet if no native ipv6 echo
if (( $? )) ; then slaprunner_title="SlapOS-Node-Runner-In-$computer_guid"
re6stnet_script=/etc/re6stnet/ovpn-cygwin.bat feature_code="#-*- SlapOS Web Runner JavaScript Boot Code -*-#"
service_name=slapos-re6stnet if ! grep -q -F "$feature_code" $slapos_runner_file ; then
echo Installing SlapOS Web Runner ...
echo No native IPv6.
echo Check re6stnet network ... if [[ -r $re6stnet_configure_file ]] ; then
which re6stnet > /dev/null 2>&1 || show_error_exit "Error: no re6stnet installed, please run Configure SlapOS first." re6stnet_ipv6=$(grep "Your subnet" $re6stnet_configure_file| \
sed -e "s/^.*subnet: //g" -e "s/\/80 (CN.*\$/1/g")
if [[ ! -f ${re6stnet_script} ]] ; then if [[ ! -z $re6stnet_ipv6 ]] ; then
cat <<EOF > /${re6stnet_script} echo "Re6stnet address in this computer: $re6stnet_ipv6"
$(cygpath -w /bin/bash.exe) --login -c 'python %*' netsh interface ipv6 show addr $slapos_ifname level=normal | \
EOF grep -q $re6stnet_ipv6 || \
fi netsh interface ipv6 add addr $slapos_ifname $re6stnet_ipv6
chmod +x ${re6stnet_script} fi
# re6st-conf --registry http://re6stnet.nexedi.com/ --is-needed
cygrunsrv --query $service_name >/dev/null 2>&1
if (( $? )) ; then
[[ -d /var/log/re6stnet ]] || mkdir -p /var/log/re6stnet
echo "Install slapos-re6stnet service ..."
cygrunsrv -I $service_name -c /etc/re6stnet -p $(which re6stnet) -a "@re6stnet.conf" || \
show_error_exit "Failed to install $service_name service."
echo "Cygwin $service_name service installed."
# echo "Waiting re6stent network work ..."
# while true ; do
# check_ipv6_connection && break
# done
fi
service_state=$(cygrunsrv --query $service_name | sed -n -e 's/^Current State[ :]*//p')
if [[ ! x$service_state == "xRunning" ]] ; then
echo "Starting $service_name service ..."
cygrunsrv --start $service_name || show_error_exit "Failed to start $service_name service."
service_state=$(cygrunsrv --query $service_name | sed -n -e 's/^Current State[ :]*//p')
fi fi
[[ x$service_state == "xRunning" ]] || show_error_exit "Failed to start $service_name service."
echo Cygwin $service_name service is running. /opt/slapos/bin/slapos node format -cv --now || \
echo "You can check log files in the /var/log/re6stnet/*.log"
echo
echo "re6stnet network OK."
else
echo "Native IPv6 Found."
fi
#-------------------------------------------------
# Create instance of Web Runner
#-------------------------------------------------
slaprunner_title="SlapOS-Node-Runner-In-$computer_id"
grep -q "window.location.href" $slapos_runner_file
if (( $? )) ; then
echo
echo Installing Web Runner ...
echo
re6stnet_ipv6=$(cat /etc/re6stnet/re6stnet.conf | grep "Your subnet" | \
sed -e "s/^.*subnet: //g" -e "s/\/80 (CN.*\$/1/g")
echo "Re6stnet address in this computer: $re6stnet_ipv6"
netsh interface ipv6 show addr $slapos_ifname level=normal | grep -q $re6stnet_ipv6 || \
netsh interface ipv6 add addr $slapos_ifname $re6stnet_ipv6
echo Run slapformat ...
/opt/slapos/bin/slapos node format -cv --now ||
show_error_exit "Failed to run slapos format." show_error_exit "Failed to run slapos format."
echo
echo "Supply $slaprunner_cfg in the computer $computer_id" echo "Supply $slaprunner_cfg in the computer $computer_guid"
/opt/slapos/bin/slapos supply $slaprunner_cfg $computer_id /opt/slapos/bin/slapos supply $slaprunner_cfg $computer_guid
echo "Request an instance $slaprunner_title ..." echo "Request an instance $slaprunner_title ..."
patch_file=/etc/slapos/patches/slapos-cookbook-inotifyx.patch patch_file=/etc/slapos/patches/slapos-cookbook-inotifyx.patch
while true ; do while true ; do
/opt/slapos/bin/slapos node software --verbose /opt/slapos/bin/slapos node software --verbose
# Apply patches to slapos.cookbook for inotifix # Apply patches to slapos.cookbook for inotifix
if [[ -f $patch_file ]] ; then if [[ -r $patch_file ]] ; then
for x in $(find /opt/slapgrid/ -name slapos.cookbook-*.egg) ; do for x in $(find /opt/slapgrid/ -name slapos.cookbook-*.egg) ; do
echo Apply patch $patch_file at $x echo Apply patch $patch_file at $x
cd $x cd $x
patch -f --dry-run -p1 < $patch_file > /dev/null && patch -p1 < $patch_file patch -f --dry-run -p1 < $patch_file > /dev/null && \
patch -p1 < $patch_file
done done
fi fi
/opt/slapos/bin/slapos node instance --verbose /opt/slapos/bin/slapos node instance --verbose
/opt/slapos/bin/slapos node report --verbose /opt/slapos/bin/slapos node report --verbose
/opt/slapos/bin/slapos request $client_config_file $slaprunner_title $slaprunner_cfg --node computer_guid=$computer_id && break /opt/slapos/bin/slapos request $client_config_file $slaprunner_title \
sleep 5 $slaprunner_cfg --node computer_guid=$computer_guid && break
sleep 3
done done
# Connection parameters of instance are: # Connection parameters of instance are:
# {'backend_url': 'http://[2001:67c:1254:45::c5d5]:50000', # {'backend_url': 'http://[2001:67c:1254:45::c5d5]:50000',
...@@ -662,10 +439,12 @@ if (( $? )) ; then ...@@ -662,10 +439,12 @@ if (( $? )) ; then
# 'password_recovery_code': 'e2d01c14', # 'password_recovery_code': 'e2d01c14',
# 'ssh_command': 'ssh 2001:67c:1254:45::c5d5 -p 2222', # 'ssh_command': 'ssh 2001:67c:1254:45::c5d5 -p 2222',
# 'url': 'http://softinst39090.host.vifib.net/'} # 'url': 'http://softinst39090.host.vifib.net/'}
slaprunner_url=$(/opt/slapos/bin/slapos request $client_config_file $slaprunner_title $slaprunner_cfg --node computer_guid=$computer_id | \ slaprunner_url=$(/opt/slapos/bin/slapos request $client_config_file \
$slaprunner_title $slaprunner_cfg --node computer_guid=$computer_guid | \
grep backend_url | sed -e "s/^.*': '//g" -e "s/',.*$//g") grep backend_url | sed -e "s/^.*': '//g" -e "s/',.*$//g")
echo Got node runner url: $slaprunner_url echo "SlapOS Web Runner URL: $slaprunner_url"
[[ -z $slaprunner_url ]] && show_error_exit "Failed to create instance of SlapOS Web Runner." [[ -z $slaprunner_url ]] && \
show_error_exit "Failed to create instance of SlapOS Web Runner."
cat <<EOF > $slapos_runner_file cat <<EOF > $slapos_runner_file
<html> <html>
...@@ -679,69 +458,79 @@ function openwin() { ...@@ -679,69 +458,79 @@ function openwin() {
</script> </script>
</head> </head>
<body onload="openwin()"/> <body onload="openwin()"/>
<!-- $feature_code -->
</html> </html>
EOF EOF
echo Generate file: $slapos_runner_file echo SlapOS Web Runner boot file $slapos_runner_file generated.
echo echo
echo Install Web Runner OK. echo Install Web Runner OK.
echo echo
fi fi
echo
echo Configure section runner OK.
echo
#------------------------------------------------- # -----------------------------------------------------------
# Configure crontab # tab: Install cron service and create crontab
#------------------------------------------------- # -----------------------------------------------------------
crontab_file=/var/cron/tabs/$(whoami) echo
if [[ ! -f $crontab_file ]] ; then echo Starting configure section cron ...
echo
crontab_file="/var/cron/tabs/${USER}"
if [[ ! -r $crontab_file ]] ; then
cat <<EOF > $crontab_file cat <<EOF > $crontab_file
SHELL=/bin/bash SHELL=/bin/bash
PATH=/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin PATH=/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin
MAILTO="" MAILTO=""
# Run "Installation/Destruction of Software Releases" and "Deploy/Start/Stop Partitions" once per minute # Run "Installation/Destruction of Software Releases" and "Deploy/Start/Stop Partitions" once per minute
* * * * * Administrator /opt/slapos/bin/slapos node software --verbose --logfile=/opt/slapos/log/slapos-node-software.log > /dev/null 2>&1 * * * * * ${USER} /opt/slapos/bin/slapos node software --verbose --logfile=/opt/slapos/log/slapos-node-software.log > /dev/null 2>&1
* * * * * Administrator /opt/slapos/bin/slapos node instance --verbose --logfile=/opt/slapos/log/slapos-node-instance.log > /dev/null 2>&1 * * * * * ${USER} /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 # Run "Destroy Partitions to be destroyed" once per hour
0 * * * * Administrator /opt/slapos/bin/slapos node report --maximal_delay=3600 --verbose --logfile=/opt/slapos/log/slapos-node-report.log > /dev/null 2>&1 0 * * * * ${USER} /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 # Run "Check/add IPs and so on" once per hour
0 * * * * Administrator /opt/slapos/bin/slapos node format >> /opt/slapos/log/slapos-node-format.log 2>&1 0 * * * * ${USER} /opt/slapos/bin/slapos node format >> /opt/slapos/log/slapos-node-format.log 2>&1
# Make sure we have only good network routes if we use VPN
# * * * * * root if [ -f /etc/opt/slapos/openvpn-needed ]; then ifconfig tapVPN | grep "Scope:Global" > /dev/null ;if [ $? = 0 ]; then ROUTES=$(ip -6 r l | grep default | awk '{print $5}'); for GW in $ROUTES ; do if [ ! $GW = tapVPN ]; then /sbin/ip -6 route del default dev $GW > /dev/null 2>&1;fi ;done ;fi ;fi
EOF EOF
echo Cron file $crontab_file created.
fi fi
echo
echo Checking cron job ... echo
ps -ef | grep -q "/usr/sbin/cron" cat $crontab_file || show_error_exit "No crob tab found."
if (( $? )) ; then echo
echo
if ps -ef | grep -q "/usr/sbin/cron" ; then
echo "The cron job is running."
else
echo Starting cron job ... echo Starting cron job ...
/usr/sbin/cron & /usr/sbin/cron &
(( $? )) && show_error_exit "Failed to run cron-config" (( $? )) && show_error_exit "Failed to start cron job."
disown -h disown -h
echo The cron job started. echo "The cron job started."
else
echo The cron job is running.
fi fi
echo
echo Configure section cron OK.
echo
# -----------------------------------------------------------
#------------------------------------------------- # startup: Start slapos-configure when windows startup
# Add slapos-configure to windows startup item # -----------------------------------------------------------
#------------------------------------------------- echo
slapos_run_key='\HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run' echo Starting configure section startup ...
slapos_run_entry=slapos-configure echo
slapos_run_script=/etc/slapos/scripts/slapos-configure.sh slapos_run_script=$(cygpath -a $0)
echo Checking startup item ...
regtool -q get "$slapos_run_key\\$slapos_run_entry" || \ regtool -q get "$slapos_run_key\\$slapos_run_entry" || \
regtool -q set "$slapos_run_key\\$slapos_run_entry" \ regtool -q set "$slapos_run_key\\$slapos_run_entry" \
"\"$(cygpath -w /usr/bin/bash)\" --login -i $slapos_run_script" || \ "\"$(cygpath -w /usr/bin/bash)\" --login -i $slapos_run_script" || \
show_error_exit "Failed to add slapos-configure.sh as windows startup item." show_error_exit "Failed to add slapos-configure.sh as windows startup item."
echo Startup item "$slapos_run_key\\$slapos_run_entry": $(regtool get "$slapos_run_key\\$slapos_run_entry") echo "Windows startup item:"
echo " $slapos_run_key\\$slapos_run_entry = " \
$(regtool get "$slapos_run_key\\$slapos_run_entry")
echo
echo Configure section startup OK.
echo echo
echo SlapOS Node configure successfully. echo Configure SlapOS successfully.
read -n 1 -t 60 -p "Press any key to exit..." read -n 1 -t 60 -p "Press any key to exit..."
exit 0 exit 0
#! /bin/bash
#
export PATH=/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin:$PATH
# ======================================================================
# Constants
# ======================================================================
slapos_client_home=~/.slapos
client_configure_file=$slapos_client_home/slapos.cfg
client_certificate_file=$slapos_client_home/certificate
client_key_file=$slapos_client_home/key
client_template_file=/etc/slapos/slapos-client.cfg.example
node_certificate_file=/etc/opt/slapos/ssl/computer.crt
node_key_file=/etc/opt/slapos/ssl/computer.key
node_config_file=/etc/opt/slapos/slapos.cfg
node_template_file=/etc/slapos/slapos.cfg.example
slapos_ifname=re6stnet-lo
# Change it if it confilcts with your local network
ipv4_local_network=10.201.67.0/24
re6stnet_configure_file=/etc/re6stnet/re6stnet.conf
re6stnet_cygwin_script=/etc/re6stnet/ovpn-cygwin.bat
re6stnet_service_name=slapos-re6stnet
slaprunner_startup_file=/etc/slapos/scripts/slap-runner.html
slapos_run_key='\HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run'
slapos_run_entry=slapos-configure
# ======================================================================
# Routine: get_system_and_admins_gids
# Get the ADMINs ids from /etc/group and /etc/passwd
# ======================================================================
function get_system_and_admins_ids() {
ret=0
for fname in /etc/passwd /etc/group; do
if ls -ld "${fname}" | grep -Eq '^-r..r..r..'; then
true
else
echo "The file $fname is not readable by all."
echo "Please run 'chmod +r $fname'."
echo
ret=1
fi
done
[ ! -r /etc/passwd -o ! -r /etc/group ] && return 1;
ADMINSGID=$(sed -ne '/^[^:]*:S-1-5-32-544:.*:/{s/[^:]*:[^:]*:\([0-9]*\):.*$/\1/p;q}' /etc/group)
SYSTEMGID=$(sed -ne '/^[^:]*:S-1-5-18:.*:/{s/[^:]*:[^:]*:\([0-9]*\):.*$/\1/p;q}' /etc/group)
if [ -z "$ADMINSGID" -o -z "$SYSTEMGID" ]; then
echo "It appears that you do not have correct entries for the"
echo "ADMINISTRATORS and/or SYSTEM sids in /etc/group."
echo
echo "Use the 'mkgroup' utility to generate them"
echo " mkgroup -l > /etc/group"
warning_for_etc_file group
ret=1;
fi
ADMINSUID=$(sed -ne '/^[^:]*:[^:]*:[0-9]*:[0-9]*:[^:]*,S-1-5-32-544:.*:/{s/[^:]*:[^:]*:\([0-9]*\):.*$/\1/p;q}' /etc/passwd)
SYSTEMUID=$(sed -ne '/^[^:]*:[^:]*:[0-9]*:[0-9]*:[^:]*,S-1-5-18:.*:/{s/[^:]*:[^:]*:\([0-9]*\):.*$/\1/p;q}' /etc/passwd)
if [ -z "$ADMINSUID" -o -z "$SYSTEMUID" ]; then
echo "It appears that you do not have correct entries for the"
echo "ADMINISTRATORS and/or SYSTEM sids in /etc/passwd."
echo
echo "Use the 'mkpasswd' utility to generate it"
echo " mkpasswd -l > /etc/passwd."
warning_for_etc_file passwd
ret=1;
fi
return "${ret}"
} # === get_system_and_admins_ids() === #
# ======================================================================
# Routine: check_administrator_right
# Check script run as Administrator or not
# ======================================================================
function check_administrator_right()
{
get_system_and_admins_ids || exit 1
groups=" $(id -G) "
if [[ ! $groups == *\ $ADMINGUID\ * ]] ; then
echo
echo "You haven't right to run this script $0. "
echo "Please login as Administrator to run it, or right-click this script and"
echo "then click Run as administrator."
echo
exit 1
fi
} # === check_administrator_right() === #
# ======================================================================
# Routine: check_administrator_right
# Check cygwin service is install or not, running state, and run by
# which account
# ======================================================================
function check_cygwin_service()
{
ret=0
name=$1
echo Checking cygwin service $name ...
if [ ! -e /usr/bin/cygrunsrv.exe ]; then
echo "Error: Download the cygrunsrv package to start the $name daemon as a service."
exit 1
fi
if [[ ! cygrunsrv --query $name > /dev/null 2>&1 ]] ; then
echo "Error: No cygwin service $name installed, please run Configure SlapOS to install it."
return 1
fi
account="$(cygrunsrv -VQ $name | sed -n -e 's/^Account[ :]*//p')"
state=$(cygrunsrv --query $name | sed -n -e 's/^Current State[ :]*//p')
[[ "$state" == "Running" ]] || cygrunsrv --start $name
state=$(cygrunsrv --query $name | sed -n -e 's/^Current State[ :]*//p')
cygrunsrv --query --verbose $name
echo Check cygwin service $name OVER.
[[ "$state" == "Running" ]] || ret=1
return "${ret}"
} # === check_cygwin_service() === #
# ======================================================================
# Routine: check_network_configure
# Check slapos network configure
# ======================================================================
function check_network_configure()
{
echo Checking slapos network ...
original_connections=$(echo $(get_all_connections))
if [[ ! " $original_connections " == *[\ ]$slapos_ifname[\ ]* ]] ; then
echo "Error: No connection name $slapos_ifname found, please "
echo "run Configure SlapOS to install it."
return 1
fi
echo Check slapos network Over.
} # === check_network_configure() === #
# ======================================================================
# Routine: check_node_configure
# Check slapos node configure
# ======================================================================
function check_node_configure()
{
echo Checking slapos node configure ...
[[ ! -r $node_certificate_file ]] && \
( echo "Computer certificate file $node_certificate_file" ;
echo "doesn't exists, or you haven't right to visit." ) && \
return 1
openssl x509 -noout -in $node_certificate_file || return 1
openssl rsa -noout -in $node_key_file -check || return 1
computer_guid=$(grep "CN=COMP" $node_certificate_file | \
sed -e "s/^.*, CN=//g" | sed -e "s%/emailAddress.*\$%%g")
[[ ! "$computer_guid" == COMP-+([0-9]) ]] && \
( echo "Invalid computer id '$computer_guid' specified." ;
echo "It should look like 'COMP-XXXX'" ) && \
return 1
echo Check slapos node configure Over.
} # === check_node_configure() === #
# ======================================================================
# Routine: check_client_configure
# Check slapos client configure
# ======================================================================
function check_client_configure()
{
echo Checking slapos client confiure ...
echo Check slapos client configure Over.
} # === check_client_configure() === #
# ======================================================================
# Routine: check_cron_configure
# Check slapos cron configure
# ======================================================================
function check_cron_configure()
{
echo Checking slapos cron confiure ...
echo Check slapos cron configure Over.
} # === check_cron_configure() === #
# ======================================================================
# Routine: check_re6stnet_configure
# Check slapos re6stnet configure
# ======================================================================
function check_re6stnet_configure()
{
echo Checking slapos re6stnet confiure ...
! which re6stnet > /dev/null 2>&1 && \
echo "No re6stnet installed, please run Configure SlapOS first." && \
return 1
echo Check slapos re6stnet configure Over.
} # === check_re6stnet_configure() === #
# ======================================================================
# Routine: check_re6stnet_needed
# Check re6stnet required or not
# ======================================================================
function check_re6stnet_needed()
{
# This doesn't work in the cygwin now, need hack ip script
# re6st-conf --registry http://re6stnet.nexedi.com/ --is-needed
netsh interface ipv6 show route | grep -q " ::/0 "
return ! $?
} # === check_re6stnet_needed() === #
# ======================================================================
# Routine: get_all_connections
# Return all connection names line by line, and replace space with '%'
# ======================================================================
function get_all_connections()
{
netsh interface ipv6 show interface | \
grep "^[ 0-9]\+ " | \
sed -e "s/^[ 0-9]\+[a-zA-Z]\+//" -e "s/^\s*//" -e "s/ /%/g"
} # === get_all_connections() === #
# ======================================================================
# Routine: get_new_connection
# Check all the connection names, and compare the original connection
# list, return the new connection name
#
# Note: If nothing found, return empty
# If more than one, return the first one
# ======================================================================
function get_new_connection()
{
original_connections=" $* "
current_connections=$(get_all_connections)
for name in $current_connections ; do
[[ ! "$original_connections" == *[\ ]$name[\ ]* ]] && \
echo ${name//%/ } && return 0
done
} # === get_new_connections() === #
# ======================================================================
# Routine: reset_slapos_connection
# Remove all ipv4/ipv6 addresses in the connection re6stnet-lo
# ======================================================================
function reset_slapos_connection()
{
ifname=${1-re6stnet-lo}
for addr in $(netsh interface ipv6 show address $ifname level=normal | \
grep "^Manual" | \
sed -e "s/^\(\w\+\s\+\)\{4\}//") ; do
netsh interface ipv6 del address $ifname $addr
done
netsh interface ip set address $ifname source=dhcp
# for addr in $(netsh interface ip show address $ifname | \
# grep "IP Address:" | \
# sed -e "s/IP Address://") ; do
# netsh interface del address $ifname $addr
# done
} # === reset_slapos_connection() === #
# ======================================================================
# Routine: connection2guid
# Transfer connection name to GUID
# ======================================================================
function connection2guid()
{
ifname=${1-re6stnet-lo}
#
# This command doesn't work in the Windows 7, Window 8, maybe
# Vista. Because no guid information in these platforms.
#
# netsh interface ipv6 show interface $ifname | \
# grep "^GUID\s*:" | \
# sed -e "s/^GUID\s*:\s*//"
#
# So we use getmac to repleace it:
getmac /fo list /v | grep -A3 "^Connection Name: *$ifname\$" \
| grep "^Transport Name:" | sed -e "s/^.*Tcpip_//g"
} # === connection2guid() === #
# ======================================================================
# Routine: show_error_exit
# Show error message and wait for user to press any key to exit
# ======================================================================
function show_error_exit()
{
echo ${1-Error: run Configure Slapos failed.}
read -n 1 -p "Press any key to exit..."
exit 1
} # === show_error_exit() === #
# ======================================================================
# Routine: start_cygwin_service
# Start cygwin service if required
# ======================================================================
function start_cygwin_service()
{
name=$1
state=$(cygrunsrv --query $name | sed -n -e 's/^Current State[ :]*//p')
[[ "$state" == "Running" ]] || net start $name
state=$(cygrunsrv --query $name | sed -n -e 's/^Current State[ :]*//p')
[[ "$state" == "Running" ]] || return 1
} # === start_cygwin_service() === #
#
# Query the parameter, usage:
#
# query_parameter ACTUAL EXCPETED MESSAGE
#
function query_parameter()
{
if [[ X$1 == X || $1 == "*" || $1 == "all" ]] ; then
return 1
fi
if [[ $1 == "?" || $1 == "query" ]] ; then
read -n 1 -p $3 user_ack
if [[ X$user_ack == X[Yy] ]] ; then
return 1
else
return 0
fi
fi
if [[ $1 == $2 ]] ; then
return 1
fi
return 0
}
# ======================================================================
# Routine: create_template_configure_file
# Generate the template file for node and client
# ======================================================================
function create_template_configure_file()
{
cat <<EOF > $client_template_file
[slapos]
master_url = https://slap.vifib.com/
[slapconsole]
# Put here retrieved certificate from SlapOS Master.
# Beware: put certificate from YOUR account, not the one from your node.
# You (as identified person from SlapOS Master) will request an instance, node your node.
# Conclusion: node certificate != person certificate.
cert_file = certificate file location coming from your slapos master account
key_file = key file location coming from your slapos master account
# Below are softwares maintained by slapos.org and contributors
alias =
apache_frontend http://git.erp5.org/gitweb/slapos.git/blob_plain/HEAD:/software/apache-frontend/software.cfg
dokuwiki http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/tags/slapos-0.158:/software/dokuwiki/software.cfg
drupal http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/tags/slapos-0.151:/software/erp5/software.cfg
erp5 http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/tags/slapos-0.143:/software/erp5/software.cfg
erp5_branch http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/heads/erp5:/software/erp5/software.cfg
fengoffice http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/tags/slapos-0.158:/software/fengoffice/software.cfg
kumofs http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/tags/slapos-0.141:/software/kumofs/software.cfg
kvm http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/tags/slapos-0.156:/software/kvm/software.cfg
maarch http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/tags/slapos-0.159:/software/maarch/software.cfg
mariadb http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/tags/slapos-0.152:/software/mariadb/software.cfg
memcached http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/tags/slapos-0.82:/software/memcached/software.cfg
mysql http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/tags/slapos-0.65:/software/mysql-5.1/software.cfg
opengoo http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/tags/slapos-0.158:/software/opengoo/software.cfg
postgresql http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/tags/slapos-0.157:/software/postgres/software.cfg
slaposwebrunner http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/heads/cygwin-0:/software/slaprunner/software.cfg
slaposwebrunner_lite http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/heads/cygwin-0:/software/slaprunner-lite/software.cfg
wordpress http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/heads/cygwin:/software/wordpress/software.cfg
xwiki http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/tags/slapos-0.46:/software/xwiki/software.cfg
zabbixagent http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/tags/slapos-0.162:/software/zabbix-agent/software.cfg
netdrive_reporter http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/heads/cygwin-0:/software/netdrive-reporter/software.cfg
demoapp http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/heads/cygwin-0:/software/demoapp/software.cfg
EOF
cat <<EOF > $node_template_file
[slapos]
# Replace computer_id by the unique identifier of your computer on vifib.net,
# starting by COMP-
computer_id = COMP-12345
master_url = https://slap.vifib.com/
key_file = /etc/opt/slapos/ssl/computer.key
cert_file = /etc/opt/slapos/ssl/computer.crt
certificate_repository_path = /etc/opt/slapos/ssl/partition_pki
software_root = /opt/slapgrid
instance_root = /srv/slapgrid
[slapformat]
# Replace by your network interface like eth0, eth1, slapbr0...
interface_name = interfacename
# Change "create_tap" into "true" if you need to host KVM services
create_tap = false
partition_amount = 10
computer_xml = /opt/slapos/slapos.xml
log_file = /opt/slapos/log/slapos-node-format.log
partition_base_name = slappart
user_base_name = slapuser
tap_base_name = slaptap
# You can choose any other local network which does not conflict with your
# current machine configuration
ipv4_local_network = 10.0.0.0/16
# Comment this if you are using native IPv6 and don't want to use SlapOS tunnel
ipv6_interface = tapVPN
[networkcache]
# Define options for binary cache, used to download already compiled software.
download-binary-cache-url = http://www.shacache.org/shacache
download-cache-url = https://www.shacache.org/shacache
download-binary-dir-url = http://www.shacache.org/shadir
# Configuration to Upload Configuration for Binary cache
#upload-binary-dir-url = https://www.shacache.org/shadir
#upload-binary-cache-url = https://www.shacache.org/shacache
#signature_private_key_file = /etc/opt/slapos/shacache/signature.key
#signature_certificate_file = /etc/opt/slapos/shacache/signature.cert
#upload-cache-url = https://www.shacache.org/shacache
#shacache-cert-file = /etc/opt/slapos/shacache/shacache.cert
#shacache-key-file = /etc/opt/slapos/shacache/shacache.key
#upload-binary-dir-url = https://www.shacache.org/shadir
#upload-binary-cache-url = https://www.shacache.org/shacache
#upload-dir-url = https://www.shacache.org/shadir
#shadir-cert-file = /etc/opt/slapos/shacache/shacache.cert
#shadir-key-file = /etc/opt/slapos/shacache/shacache.key
# List of signatures of uploaders we trust:
# Romain Courteaud
# Sebastien Robin
# Kazuhiko Shiozaki
# Cedric de Saint Martin
# Yingjie Xu
# Gabriel Monnerat
# Łukasz Nowak
# Test Agent Signature
signature-certificate-list =
-----BEGIN CERTIFICATE-----
MIIB4DCCAUkCADANBgkqhkiG9w0BAQsFADA5MQswCQYDVQQGEwJGUjEZMBcGA1UE
CBMQRGVmYXVsdCBQcm92aW5jZTEPMA0GA1UEChMGTmV4ZWRpMB4XDTExMDkxNTA5
MDAwMloXDTEyMDkxNTA5MDAwMlowOTELMAkGA1UEBhMCRlIxGTAXBgNVBAgTEERl
ZmF1bHQgUHJvdmluY2UxDzANBgNVBAoTBk5leGVkaTCBnzANBgkqhkiG9w0BAQEF
AAOBjQAwgYkCgYEApYZv6OstoqNzxG1KI6iE5U4Ts2Xx9lgLeUGAMyfJLyMmRLhw
boKOyJ9Xke4dncoBAyNPokUR6iWOcnPHtMvNOsBFZ2f7VA28em3+E1JRYdeNUEtX
Z0s3HjcouaNAnPfjFTXHYj4um1wOw2cURSPuU5dpzKBbV+/QCb5DLheynisCAwEA
ATANBgkqhkiG9w0BAQsFAAOBgQBCZLbTVdrw3RZlVVMFezSHrhBYKAukTwZrNmJX
mHqi2tN8tNo6FX+wmxUUAf3e8R2Ymbdbn2bfbPpcKQ2fG7PuKGvhwMG3BlF9paEC
q7jdfWO18Zp/BG7tagz0jmmC4y/8akzHsVlruo2+2du2freE8dK746uoMlXlP93g
QUUGLQ==
-----END CERTIFICATE-----
-----BEGIN CERTIFICATE-----
MIIB8jCCAVugAwIBAgIJAPu2zchZ2BxoMA0GCSqGS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-----
-----BEGIN CERTIFICATE-----
MIIB9jCCAV+gAwIBAgIJAKRvzcy7OH0UMA0GCSqGSIb3DQEBBQUAMBMxETAPBgNV
BAMMCENPTVAtNzcyMCAXDTEyMDgxMDE1NDI1MVoYDzIxMTIwNzE3MTU0MjUxWjAT
MREwDwYDVQQDDAhDT01QLTc3MjCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA
o7aipd6MbnuGDeR1UJUjuMLQUariAyQ2l2ZDS6TfOwjHiPw/mhzkielgk73kqN7A
sUREx41eTcYCXzTq3WP3xCLE4LxLg1eIhd4nwNHj8H18xR9aP0AGjo4UFl5BOMa1
mwoyBt3VtfGtUmb8whpeJgHhqrPPxLoON+i6fIbXDaUCAwEAAaNQME4wHQYDVR0O
BBYEFEfjy3OopT2lOksKmKBNHTJE2hFlMB8GA1UdIwQYMBaAFEfjy3OopT2lOksK
mKBNHTJE2hFlMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEFBQADgYEAaNRx6YN2
M/p3R8/xS6zvH1EqJ3FFD7XeAQ52WuQnKSREzuw0dsw12ClxjcHiQEFioyTiTtjs
5pW18Ry5Ie7iFK4cQMerZwWPxBodEbAteYlRsI6kePV7Gf735Y1RpuN8qZ2sYL6e
x2IMeSwJ82BpdEI5niXxB+iT0HxhmR+XaMI=
-----END CERTIFICATE-----
# List of URL(s) which shouldn't be downloaded from binary cache.
# Any URL beginning by a blacklisted URL will be blacklisted as well.
download-from-binary-cache-url-blacklist =
http://git.erp5.org/gitweb/slapos.git/blob_plain/HEAD
http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/heads
/
# List of URL(s) which shouldn't be uploaded into binary cache.
# Any URL beginning by a blacklisted URL will be blacklisted as well.
upload-to-binary-cache-url-blacklist =
http://git.erp5.org/gitweb/slapos.git/blob_plain/HEAD
http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/heads
/
EOF
} # === create_template_configure_file() === #
#! /bin/bash #! /bin/bash
export PATH=/usr/local/bin:/usr/bin:$PATH source $(dirname $0)/slapos-include.sh
check_administrator_right
# ======================================================================
# Routine: get_system_and_admins_gids # -----------------------------------------------------------
# Get the ADMINs ids from /etc/group and /etc/passwd # Check all the configure files
# ====================================================================== # -----------------------------------------------------------
get_system_and_admins_ids() { check_network_configure || exit 1
ret=0 check_node_configure || exit 1
for fname in /etc/passwd /etc/group; do check_client_configure || exit 1
if ls -ld "${fname}" | grep -Eq '^-r..r..r..'; then check_cron_configure
true check_re6stnet_configure
else
echo "The file $fname is not readable by all." # -----------------------------------------------------------
echo "Please run 'chmod +r $fname'." # Check cygwin services used by slapos
echo # -----------------------------------------------------------
ret=1 check_cygwin_service cygserver || exit 1
fi check_cygwin_service syslog-ng || exit 1
done check_cygwin_service sshd
check_cygwin_service cron
[ ! -r /etc/passwd -o ! -r /etc/group ] && return 1; check_re6stnet_needed && check_cygwin_service re6stnet
ADMINSGID=$(sed -ne '/^[^:]*:S-1-5-32-544:.*:/{s/[^:]*:[^:]*:\([0-9]*\):.*$/\1/p;q}' /etc/group) # -----------------------------------------------------------
SYSTEMGID=$(sed -ne '/^[^:]*:S-1-5-18:.*:/{s/[^:]*:[^:]*:\([0-9]*\):.*$/\1/p;q}' /etc/group) # Format slapos node
if [ -z "$ADMINSGID" -o -z "$SYSTEMGID" ]; then # -----------------------------------------------------------
echo "It appears that you do not have correct entries for the"
echo "ADMINISTRATORS and/or SYSTEM sids in /etc/group."
echo
echo "Use the 'mkgroup' utility to generate them"
echo " mkgroup -l > /etc/group"
warning_for_etc_file group
ret=1;
fi
ADMINSUID=$(sed -ne '/^[^:]*:[^:]*:[0-9]*:[0-9]*:[^:]*,S-1-5-32-544:.*:/{s/[^:]*:[^:]*:\([0-9]*\):.*$/\1/p;q}' /etc/passwd)
SYSTEMUID=$(sed -ne '/^[^:]*:[^:]*:[0-9]*:[0-9]*:[^:]*,S-1-5-18:.*:/{s/[^:]*:[^:]*:\([0-9]*\):.*$/\1/p;q}' /etc/passwd)
if [ -z "$ADMINSUID" -o -z "$SYSTEMUID" ]; then
echo "It appears that you do not have correct entries for the"
echo "ADMINISTRATORS and/or SYSTEM sids in /etc/passwd."
echo
echo "Use the 'mkpasswd' utility to generate it"
echo " mkpasswd -l > /etc/passwd."
warning_for_etc_file passwd
ret=1;
fi
return "${ret}"
} # === get_system_and_admins_ids() === #
#
# Check ipv6 connection by default ipv6 route
#
function check_ipv6_connection()
{
netsh interface ipv6 show route | grep -q " ::/0 "
}
#
# Check cygwin service
#
function check_cygwin_service()
{
service_name=$1
echo Checking $1 service ...
if [ ! -e /usr/bin/cygrunsrv.exe ]; then
show_error_exit "No cygserver found, please install the cygrunsrv package first."
fi
service_account="$(cygrunsrv -VQ $service_name | sed -n -e 's/^Account[ :]*//p')" || \
show_error_exit "No $1 service install, please run Configure SlapOS to install it."
service_state=$(cygrunsrv --query $service_name | sed -n -e 's/^Current State[ :]*//p')
if [[ ! x$service_state == "xRunning" ]] ; then
echo "Cygwin service $1 currnt state is $service_state, try to use"
echo " cygrunsrv --start $1 to start this service"
cygrunsrv --start $1 || show_error_exit "Failed to start service $1"
echo Cygwin $1 service is running.
fi
echo Check $1 service OVER.
}
#
# Show error message and waiting for user to press any key quit
#
function show_error_exit()
{
msg=${1-Failed to configure Slapos Node in this computer.}
echo $msg
read -n 1 -p "Press any key to exit..."
exit 1
}
#-------------------------------------------------
# Check adminsitrator rights
#-------------------------------------------------
get_system_and_admins_ids || show_error_exit "Failed to get uids of system and amdinistrator account."
id | grep -q "$ADMINSUID(Administrators)" || show_error_exit "Error: Administrator right required to run this script."
#-------------------------------------------------
# Constants
#-------------------------------------------------
slapos_ifname=re6stnet-lo
#-------------------------------------------------
# Check cygserver, syslog-ng
#-------------------------------------------------
check_cygwin_service cygserver
check_cygwin_service syslog-ng
#-------------------------------------------------
# IPv6 Connection
#-------------------------------------------------
echo "Checking native IPv6 ..."
check_ipv6_connection
# Run re6stnet if no native ipv6
if (( $? )) ; then
echo "No native IPv6."
echo Check re6stnet network ...
which re6stnet > /dev/null 2>&1 || show_error_exit "Error: no re6stnet installed, please run Configure SlapOS first."
service_name=slapos-re6stnet
# re6st-conf --registry http://re6stnet.nexedi.com/ --is-needed
cygrunsrv --query $service_name >/dev/null 2>&1
if (( $? )) ; then
[[ -d /var/log/re6stnet ]] || mkdir -p /var/log/re6stnet
echo "Install slapos-re6stnet service ..."
cygrunsrv -I $service_name -c /etc/re6stnet -p $(which re6stnet) -a "@re6stnet.conf" || \
show_error_exit "Failed to install $service_name service."
echo "Cygwin $service_name service installed."
# echo "Waiting re6stent network work ..."
# while true ; do
# check_ipv6_connection && break
# done
fi
service_state=$(cygrunsrv --query $service_name | sed -n -e 's/^Current State[ :]*//p')
if [[ ! x$service_state == "xRunning" ]] ; then
echo "Starting $service_name service ..."
cygrunsrv --start $service_name || show_error_exit "Failed to start $service_name service."
service_state=$(cygrunsrv --query $service_name | sed -n -e 's/^Current State[ :]*//p')
fi
[[ x$service_state == "xRunning" ]] || show_error_exit "Failed to start $service_name service."
echo Cygwin $service_name service is running.
echo "You can check log files in the /var/log/re6stnet/*.log"
echo
echo "re6stnet network OK."
else
echo "Native IPv6 Found."
fi
#-------------------------------------------------
# Format slapos node, need root right
#-------------------------------------------------
[[ -f /etc/opt/slapos/slapos.cfg ]] || \
show_error_exit "Error: no node configure file found, please run Configure SlapOS first."
echo "Formating SlapOS Node ..." echo "Formating SlapOS Node ..."
/opt/slapos/bin/slapos node format -cv --now || \ /opt/slapos/bin/slapos node format -cv --now || exit 1
show_error_exit "Failed to run slapos format."
#------------------------------------------------- # -----------------------------------------------------------
# Release software # Release software
#------------------------------------------------- # -----------------------------------------------------------
echo "Releasing software ..." echo "Releasing software ..."
/opt/slapos/bin/slapos node software --verbose /opt/slapos/bin/slapos node software --verbose
#------------------------------------------------- # -----------------------------------------------------------
# Instance software # Instance software
#------------------------------------------------- # -----------------------------------------------------------
echo "Creating instance ..." echo "Creating instance ..."
/opt/slapos/bin/slapos node instance --verbose /opt/slapos/bin/slapos node instance --verbose
#------------------------------------------------- # -----------------------------------------------------------
# Send report # Send report
#------------------------------------------------- # -----------------------------------------------------------
echo "Sending report ..." echo "Sending report ..."
/opt/slapos/bin/slapos node report --verbose /opt/slapos/bin/slapos node report --verbose
......
...@@ -55,6 +55,7 @@ Source: "opt\openvpn\bin\addtap.bat"; DestDir: "{app}\cygwin\bin"; ...@@ -55,6 +55,7 @@ Source: "opt\openvpn\bin\addtap.bat"; DestDir: "{app}\cygwin\bin";
Source: "opt\openvpn\bin\deltapall.bat"; DestDir: "{app}\cygwin\bin"; Source: "opt\openvpn\bin\deltapall.bat"; DestDir: "{app}\cygwin\bin";
Source: "opt\openvpn\driver\*"; DestDir: "{app}\cygwin\etc\slapos\driver"; Source: "opt\openvpn\driver\*"; DestDir: "{app}\cygwin\etc\slapos\driver";
Source: "opt\git\slapos.package\windows\scripts\slapos-include.sh"; DestDir: "{app}\cygwin\etc\slapos\scripts";
Source: "opt\git\slapos.package\windows\scripts\slapos-node.sh"; DestDir: "{app}\cygwin\etc\slapos\scripts"; Source: "opt\git\slapos.package\windows\scripts\slapos-node.sh"; DestDir: "{app}\cygwin\etc\slapos\scripts";
Source: "opt\git\slapos.package\windows\scripts\post-install.sh"; DestDir: "{app}\cygwin\etc\slapos\scripts"; Source: "opt\git\slapos.package\windows\scripts\post-install.sh"; DestDir: "{app}\cygwin\etc\slapos\scripts";
Source: "opt\git\slapos.package\windows\scripts\build-slapos.sh"; DestDir: "{app}\cygwin\etc\slapos\scripts"; Source: "opt\git\slapos.package\windows\scripts\build-slapos.sh"; DestDir: "{app}\cygwin\etc\slapos\scripts";
......
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