Commit b74eb518 authored by Jondy Zhao's avatar Jondy Zhao

Add +x rights to the customized scripts

Change startup item name from SlapOS-Node to slapos-configure
Check Administrator right before run configure scripts
Add alias of software to client configure file
Run re6stnet as cygwin service on demand
parent f27041e1
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 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.
#
##############################################################################
import argparse
from datetime import datetime, date
from lxml import etree
import netuse
import os.path
import slapos.slap.slap
import sqlite3
import sys
from time import sleep
def parseArgumentTuple():
parser = argparse.ArgumentParser()
parser.add_argument("--master-url",
help="The master server URL. Mandatory.",
required=True)
parser.add_argument("--computer-id",
help="The computer id defined in the server.",
required=True)
parser.add_argument("--cert-file",
help="Path to computer certificate file.",
default="/etc/slapos/ssl/computer.crt")
parser.add_argument("--key-file",
help="Path to computer key file.",
default="/etc/slapos/ssl/computer.key")
parser.add_argument("--report-interval",
help="Interval in seconds to send report to master.",
default=300.0)
parser.add_argument("--report-path",
help="Where to save TioXML report.",
required=True)
parser.add_argument("--data-file",
help="File used to save report data.",
default="net_drive_usage_report.data")
parser.add_argument("--server-name",
help="Interval in seconds to send report to master.",
default="")
option = parser.parse_args()
# Build option_dict
option_dict = {}
for argument_key, argument_value in vars(option).iteritems():
option_dict.update({argument_key: argument_value})
return option_dict
class NetDriveUsageReporter(object):
def __init__(self, option_dict):
for option, value in option_dict.items():
setattr(self, option, value)
self._slap_computer = None
self._domain_name = None
self._domain_account = None
self._config_id = None
self._report_date = None
self.report_interval = float(self.report_interval)
self.initializeDatabase(self.data_file)
def initializeConnection(self):
connection_dict = {}
connection_dict['key_file'] = self.key_file
connection_dict['cert_file'] = self.cert_file
slap = slapos.slap.slap()
slap.initializeConnection(self.master_url,
**connection_dict)
self._slap_computer = slap.registerComputer(self.computer_id)
def initializeConfigData(self):
user_info = netuse.userInfo()
self._domain_account = "%s\\%s" % user_info[1:3]
q = self._db.execute
s = "SELECT _rowid_, report_date FROM config " \
"WHERE domain_account=? and computer_id=?"
for r in q(s, (self._domain_account, self.computer_id)):
self._config_id, self._report_date = r
else:
q("INSERT OR REPLACE INTO config"
"(domain_account, computer_id, report_date)"
" VALUES (?,?,?)",
(self._domain_account, self.computer_id, date.today().isoformat()))
for r in q(s, (self._domain_account, self.computer_id)):
self._config_id, self._report_date = r
def run(self):
self.initializeConfigData()
self.sendAllReport()
self.initializeConnection()
last_timestamp = datetime.now()
try:
while True:
current_timestamp = datetime.now()
d = current_timestamp - last_timestamp
if d.seconds < self.report_interval:
sleep(self.report_interval)
continue
self.insertUsageReport(last_timestamp.isoformat(), d.seconds)
self.sendReport()
last_timestamp = current_timestamp
except KeyboardInterrupt:
pass
finally:
self._db.close()
def insertUsageReport(self, start, duration):
q = self._db.execute
for r in netuse.usageReport(self.server_name):
q( "INSERT INTO net_drive_usage "
"(config_id, drive_letter, remote_folder, "
" start, duration, usage_bytes )"
" VALUES (?, ?, ?, ?, ?, ?)",
(self._config_id, r[0], r[1], start, duration, r[3] - r[2]))
def sendAllReport(self):
"""Called at startup of this application, send all report
in the config table."""
q = self._db.execute
for r in q("SELECT _rowid_, domain_account, computer_id, report_date "
"FROM config "
"WHERE report_date < date('now')"):
self._postData(self.generateDailyReport(*r))
q("UPDATE config SET report_date = date('now') "
"WHERE report_date < date('now')")
def sendReport(self):
# If report_date is not today, then
# Generate xml data from local table by report_date
# Send xml data to master node
# Change report_date to today
# (Optional) Move all the reported data to histroy table
today = date.today().isoformat()
if self._report_date < today:
self._postData(self.generateDailyReport(self._config_id,
self.computer_id,
self._domain_account,
self._report_date))
self._db.execute("UPDATE config SET report_date=? where _rowid_=?",
(today, self._config_id))
def _postData(self, report):
"""Send a marshalled dictionary of the net drive usage record
serialized via_getDict.
"""
if report is not None:
name = "netdrive-report-%s.xml" % datetime.now().isoformat()
etree.ElementTree(report).write(
os.path.join(self.report_path, name),
xml_declaration=True
)
def initializeDatabase(self, db_path):
self._db = sqlite3.connect(db_path, isolation_level=None)
q = self._db.execute
q("""CREATE TABLE IF NOT EXISTS config (
domain_account TEXT PRIMARY KEY,
computer_id TEXT NOT NULL,
report_date TEXT NOT NULL,
remark TEXT)""")
q("""CREATE TABLE IF NOT EXISTS net_drive_usage (
config_id INTEGER REFERENCES config ( _rowid_ ),
drive_letter TEXT NOT NULL,
remote_folder TEXT NOT NULL,
start TEXT DEFAULT CURRENT_TIMESTAMP,
duration FLOAT NOT NULL,
usage_bytes INTEGER,
remark TEXT)""")
q("""CREATE TABLE IF NOT EXISTS net_drive_usage_history (
config_id INTEGER REFERENCES config ( _rowid_ ),
drive_letter TEXT NOT NULL,
remote_folder TEXT NOT NULL,
start TEXT NOT NULL,
duration FLOAT NOT NULL,
usage_bytes INTEGER,
remark TEXT)""")
def generateDailyReport(self, config_id, computer_id, domain_account,
report_date, remove=True):
q = self._db.execute
report = etree.Element("consumption")
for r in q("SELECT remote_folder, duration, usage_bytes FROM net_drive_usage "
"WHERE config_id=? AND strftime('%Y-%m-%d', start)=?",
(config_id, report_date)):
movement = etree.Element('movement')
element = etree.Element("resource")
element.text = r[0]
movement.append(element)
element = etree.Element("title")
element.text = 'NetDrive Usage %s' % report_date
movement.append(element)
element = etree.Element("reference")
element.text = domain_account
movement.append(element)
element = etree.Element("reference")
element.text = report_date
movement.append(element)
element = etree.Element("quantity")
element.text = str(r[1] * r[2])
movement.append(element)
element = etree.Element("price")
element.text = '0.0'
movement.append(element)
element = etree.Element("VAT")
movement.append(element)
element = etree.Element("category")
element.text = "NetDrive"
movement.append(element)
report.append(movement)
if remove:
q("INSERT INTO net_drive_usage_history "
"SELECT * FROM net_drive_usage "
"WHERE config_id=? AND strftime('%Y-%m-%d', start)=?",
(config_id, report_date))
q("DELETE FROM net_drive_usage "
"WHERE config_id=? AND strftime('%Y-%m-%d', start)=?",
(config_id, report_date))
return report
def main():
reporter = NetDriveUsageReporter(parseArgumentTuple())
reporter.run()
if __name__ == '__main__':
main()
...@@ -102,6 +102,9 @@ done ...@@ -102,6 +102,9 @@ done
# Backup slap-runner.html # Backup slap-runner.html
cp /etc/slapos/scripts/slap-runner.html{,.orig} cp /etc/slapos/scripts/slap-runner.html{,.orig}
# Add right to scripts
chmod +x /usr/local/bin/*
echo Run post-install script successfully. echo Run post-install script 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
......
...@@ -35,7 +35,7 @@ done ...@@ -35,7 +35,7 @@ done
# Remove slapos-configure from windows startup item # Remove slapos-configure from windows startup item
# #
slapos_run_key='\HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run' slapos_run_key='\HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run'
slapos_run_entry=SlapOS-Node slapos_run_entry=slapos-configure
echo Removing startup item "$slapos_run_key\\$slapos_run_entry" echo Removing startup item "$slapos_run_key\\$slapos_run_entry"
regtool -q unset "$slapos_run_key\\$slapos_run_entry" regtool -q unset "$slapos_run_key\\$slapos_run_entry"
......
...@@ -26,9 +26,50 @@ ...@@ -26,9 +26,50 @@
# #
export PATH=/usr/local/bin:/usr/bin:$PATH export PATH=/usr/local/bin:/usr/bin:$PATH
for myprofile in ~/.bash_profile ~/.profile ; do # ======================================================================
grep -q "export CYGWIN=server" $myprofile || echo "export CYGWIN=server" >> $myprofile # Routine: get_system_and_admins_gids
done # 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 # Common functions
...@@ -157,6 +198,17 @@ function query_parameter() ...@@ -157,6 +198,17 @@ function query_parameter()
return 0 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
grep -q "export CYGWIN=server" $myprofile || echo "export CYGWIN=server" >> $myprofile
grep -q "export PATH=/opt/slapos/bin:" $myprofile || echo "export PATH=/opt/slapos/bin:$$PATH" >> $myprofile
done
#------------------------------------------------- #-------------------------------------------------
# Constants # Constants
#------------------------------------------------- #-------------------------------------------------
...@@ -178,7 +230,9 @@ slapos_ifname=re6stnet-lo ...@@ -178,7 +230,9 @@ slapos_ifname=re6stnet-lo
ipv4_local_network=10.201.67.0/24 ipv4_local_network=10.201.67.0/24
slapos_runner_file=/etc/slapos/scripts/slap-runner.html 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' 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
...@@ -351,11 +405,42 @@ echo Checking computer key OK. ...@@ -351,11 +405,42 @@ echo Checking computer key OK.
echo Checking client configure file ... echo Checking client configure file ...
if [[ ! -f $client_configure_file ]] ; then if [[ ! -f $client_configure_file ]] ; then
[[ -f $client_template_file ]] || \ cat <<EOF > $client_configure_file
(cd /etc/slapos; wget $url_client_template_file -O $client_template_file) || \ [slapos]
show_error_exit "Download slapos-client.cfg.example failed." master_url = https://slap.vifib.com/
echo "Copy client configure file from $client_template_file to $client_config_file"
cp $client_template_file $client_configure_file [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:
...@@ -443,11 +528,14 @@ if [[ ! -f re6stnet.conf ]] ; then ...@@ -443,11 +528,14 @@ if [[ ! -f re6stnet.conf ]] ; then
echo "# $mysubnet" >> re6stnet.conf echo "# $mysubnet" >> re6stnet.conf
echo Write "table 0" to re6stnet.conf echo Write "table 0" to re6stnet.conf
echo "table 0" >> re6stnet.conf echo "table 0" >> re6stnet.conf
echo "ovpnlog" >> re6stnet.conf
echo "interface $slapos_ifname" >> re6stnet.conf
echo "main-interface $slapos_ifname" >> re6stnet.conf
fi fi
[[ ! -f re6stnet.conf ]] && \ [[ ! -f re6stnet.conf ]] && \
show_error_exit "Failed to register to nexedi re6stnet: no /etc/re6stnet/re6stnet.conf found." show_error_exit "Failed to register to nexedi re6stnet: no /etc/re6stnet/re6stnet.conf found."
grep -q "^table " re6stnet.conf || \ grep -q "^table 0" re6stnet.conf || \
show_error_exit "Error: no parameter 'table 0' found in the /etc/re6stnet/re6stnet.conf" show_error_exit "Error: no parameter 'table 0' found in the /etc/re6stnet/re6stnet.conf"
grep -q "^# Your subnet: " re6stnet.conf || \ grep -q "^# Your subnet: " re6stnet.conf || \
show_error_exit "Error: no subnet found in the /etc/re6stnet/re6stnet.conf" show_error_exit "Error: no subnet found in the /etc/re6stnet/re6stnet.conf"
...@@ -489,6 +577,45 @@ done ...@@ -489,6 +577,45 @@ done
# ip vpntap del dev re6stnet-x # ip vpntap del dev re6stnet-x
# #
#-------------------------------------------------
# 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" -u Administrator|| \
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
#------------------------------------------------- #-------------------------------------------------
# Create instance of Web Runner # Create instance of Web Runner
#------------------------------------------------- #-------------------------------------------------
...@@ -592,7 +719,7 @@ fi ...@@ -592,7 +719,7 @@ fi
# Add slapos-configure to windows startup item # Add slapos-configure to windows startup item
#------------------------------------------------- #-------------------------------------------------
slapos_run_key='\HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run' slapos_run_key='\HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run'
slapos_run_entry=SlapOS-Node slapos_run_entry=slapos-configure
slapos_run_script=/etc/slapos/scripts/slapos-configure.sh slapos_run_script=/etc/slapos/scripts/slapos-configure.sh
echo Checking startup item ... echo Checking startup item ...
regtool -q get "$slapos_run_key\\$slapos_run_entry" || \ regtool -q get "$slapos_run_key\\$slapos_run_entry" || \
......
#! /bin/bash #! /bin/bash
export PATH=/usr/local/bin:/usr/bin:$PATH export PATH=/usr/local/bin:/usr/bin:$PATH
# ======================================================================
# 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() === #
# #
# Check ipv6 connection by default ipv6 route # Check ipv6 connection by default ipv6 route
# #
...@@ -45,6 +90,12 @@ function show_error_exit() ...@@ -45,6 +90,12 @@ function show_error_exit()
exit 1 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 # Constants
#------------------------------------------------- #-------------------------------------------------
...@@ -66,25 +117,30 @@ if (( $? )) ; then ...@@ -66,25 +117,30 @@ if (( $? )) ; then
echo "No native IPv6." echo "No native IPv6."
echo Check re6stnet network ... echo Check re6stnet network ...
which re6stnet > /dev/null 2>&1 || show_error_exit "Error: no re6stnet installed, please run Configure SlapOS first." 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 # re6st-conf --registry http://re6stnet.nexedi.com/ --is-needed
# Check if babeld is running, so we guess whether re6stnet is running or not cygrunsrv --query $service_name >/dev/null 2>&1
ps -ef | grep -q /usr/local/bin/babeld
if (( $? )) ; then if (( $? )) ; then
echo "Start re6stnet ..."
# It need root rights to install tap-driver
cd /etc/re6stnet
[[ -d /var/log/re6stnet ]] || mkdir -p /var/log/re6stnet [[ -d /var/log/re6stnet ]] || mkdir -p /var/log/re6stnet
re6stnet @re6stnet.conf --ovpnlog -I $slapos_ifname -i $slapos_ifname >> /var/log/re6stnet/slapos-node.log 2>&1 & echo "Install slapos-re6stnet service ..."
disown -h cygrunsrv -I $service_name -c /etc/re6stnet -p $(which re6stnet) -a "@re6stnet.conf" -u Administrator|| \
echo $! > /var/run/slapos-node-re6stnet.pid show_error_exit "Failed to install $service_name service."
echo "Start re6stent (pid=$!) in the background OK." echo "Cygwin $service_name service installed."
echo "You can check log files in the /var/log/re6stnet/."
echo
# echo "Waiting re6stent network work ..." # echo "Waiting re6stent network work ..."
# while true ; do # while true ; do
# check_ipv6_connection && break # check_ipv6_connection && break
# done # done
fi 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." echo "re6stnet network OK."
else else
echo "Native IPv6 Found." echo "Native IPv6 Found."
......
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