Commit 36ac3ca0 authored by Jondy Zhao's avatar Jondy Zhao

add slapos prefix for slapos windows node

so that it could run multi-instances in one machine
parent 699b5f33
......@@ -2,7 +2,7 @@
#
# When cygwin is installed, then call this script by Administrator:
#
# /bin/bash/ --login -i init-cygwin.sh
# /bin/bash/ --login -i post-install.sh PREFIX
#
# It will do:
#
......@@ -14,28 +14,33 @@
#
# * Change readme.txt to dos format
#
# * Set prefix for this slapos node
#
function show_error_exit()
{
echo Error: ${1-Run post-install script failed.}
read -n 1 -p "Press any key to exit..."
exit 1
}
readonly -f show_error_exit
declare -r cyghome=$(cygpath -w /)
declare -r password_filename=/etc/passwd
declare -r slapos_prefix=$1
echo Checking /etc/passwd ...
if [[ ! -f ${password_filename} ]] ; then
mkpasswd -l > ${password_filename} || show_error_exit "Error: mkpasswd failed"
echo File /etc/passwd has been generated.
_filename=/etc/passwd
echo "Checking ${_filename} ..."
if [[ ! -f ${_filename} ]] ; then
mkpasswd -l > ${_filename} || show_error_exit "Error: mkpasswd failed"
echo "${_filename} has been generated."
else
echo OK.
fi
echo Checking /etc/group ...
if [[ ! -f /etc/group ]] ; then
mkgroup -l > /etc/group || show_error_exit "Error: mkgroup failed"
echo File /etc/group has been generated.
_filename=/etc/group
echo "Checking ${_filename} ..."
if [[ ! -f ${_filename} ]] ; then
mkgroup -l > ${_filename} || show_error_exit "Error: mkgroup failed"
echo "${_filename} has been generated."
else
echo OK.
fi
......@@ -51,9 +56,8 @@ fi
# fi
# fi
echo Checking Windows OEM Codepage ...
_charset=$(ipwin codepage) || _charset=""
echo Windows OEM Codepage is ${_charset}
echo "Windows OEM Codepage is ${_charset}"
_filename=".minttyrc"
echo Checking ${_filename} ...
......@@ -66,7 +70,7 @@ Scrollbar=none
Locale=C
Charset=${_charset}
EOF
echo File ${_filename} has been generated.
echo "${_filename} has been generated."
else
echo OK.
fi
......@@ -83,7 +87,7 @@ chdir ${cyghome}\\bin
start mintty.exe -i /Cygwin-Terminal.ico -
EOF
chmod +x ${_filename}
echo File ${_filename} has been generated.
echo "${_filename} has been generated."
else
echo OK.
fi
......@@ -108,7 +112,7 @@ path .\bin;%path%
dash /bin/rebaseall -T /myfile.list -v
EOF
chmod +x ${_filename}
echo File ${_filename} has been generated.
echo "${_filename} has been generated."
else
echo OK.
fi
......@@ -116,60 +120,58 @@ fi
# Change format of readme.txt
_filename=$(cygpath -u $(cygpath -m /)/../readme.txt)
if [[ -f ${_filename} ]] ; then
echo Changing $(cygpath -w ${_filename}) as dos format ...
echo "Changing $(cygpath -w ${_filename}) as dos format ..."
unix2dos ${_filename} && echo OK.
fi
# Remove cygwin services to be sure these services will be configured
# in this cygwin enviroments when there are many cygwin instances
# installed in this computer.
for name in $(cygrunsrv --list) ; do
echo Removing $name service
cygrunsrv -R $name || show_error_exit
echo OK.
done
# Backup slap-runner.html
_filename=/etc/slapos/scripts/slap-runner.html
if [[ -r ${_filename} ]] ; then
echo Backuping ${_filename} as ${_filename}.orig
echo "Backuping ${_filename} as ${_filename}.orig"
cp ${_filename}{,.orig} && echo OK.
else
echo Warning: Missing ${_filename}
echo "Warning: missing ${_filename}"
fi
# Unzip slapos.tar.gz
_filename=/opt/downloads/slapos.tar.gz
if [[ -r ${_filename} ]] ; then
echo Extracting ${_filename} ...
echo "Extracting ${_filename} ..."
(cd /opt ; tar xzf ${_filename} --no-same-owner) || show_error_exit
echo OK.
elif [[ ! -d /opt/slapos ]] ; then
echo Warning: Missing ${_filename}
echo "Warning: missing ${_filename}"
fi
# Patch cygport, so that we can specify package prefix by ourself.
_filename=/usr/bin/cygport
if [[ -f ${_filename} ]] ; then
echo Patching ${_filename} ...
echo "Patching ${_filename} ..."
sed -i -e 's/D="${workdir}\/inst"/D="${CYGCONF_PREFIX-${workdir}\/inst}"/g' ${_filename} &&
echo OK.
fi
_filename=/usr/share/cygport/cygclass/autotools.cygclass
if [[ -f ${_filename} ]] ; then
echo Patching ${_filename} ...
echo "Patching ${_filename} ..."
sed -i -e 's/prefix=$(__host_prefix)/prefix=${CYGCONF_PREFIX-$(__host_prefix)}/g' ${_filename} &&
echo OK.
fi
_filename=/usr/share/cygport/cygclass/cmake.cygclass
if [[ -f ${_filename} ]] ; then
echo Patching ${_filename} ...
echo "Patching ${_filename} ..."
sed -i -e 's/-DCMAKE_INSTALL_PREFIX=$(__host_prefix)/-DCMAKE_INSTALL_PREFIX=${CYGCONF_PREFIX-$(__host_prefix)}/g' ${_filename} &&
echo OK.
fi
# Set prefix for slapos
if [[ -n ${slapos_prefix} ]] ; then
echo "Set slapos prefix as ${slapos_prefix}"
sed -i -e "s%slapos_prefix=.*\$%slapos_prefix=${slapos_prefix}" \
/etc/slapos/scripts/pre-uninstall.sh /etc/slapos/scripts/slapos-include.sh
fi
echo
echo Run post-install.sh script successfully.
echo "Run post-install.sh script successfully."
echo
read -n 1 -t 60 -p "Press any key to exit..."
exit 0
......@@ -15,18 +15,46 @@
#
# * Remove instance root /srv/slapgrid
#
# Required:
# grep gawk TASKKILL
#
export PATH=/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin:$PATH
function slapos_kill_process()
{
name=$1
echo "Try to kill all $name ..."
for pid in $(ps | grep "$name" | gawk '{print $4}') ; do
echo "Kill pid $pid"
TASKKILL /F /T /PID $pid
done
}
read -f slapos_kill_process
#
# Declare variables
#
declare -r slapos_prefix=
declare -r slapos_administrator=${slapos_prefix:slap}root
declare -r slapos_user_basename=${slapos_prefix:slap}user
declare -r slapos_ifname=${slapos_prefix}re6stnet-lo
declare -r re6stnet_service_name=${slapos_prefix}re6stnet
declare -r cron_service_name=${slapos_prefix}cron
declare -r ssh_service_name=${slapos_prefix}ssh
declare -r syslog_service_name=${slapos_prefix}syslog-ng
declare -r cygserver_service_name=${slapos_prefix}cygserver
#
# Remove services installed by cygwin,
#
echo Try to stop re6stnet service ...
if ! net stop re6stnet ; then
echo Try to kill openvpn process ...
ps -ef | grep -q "/usr/bin/openvpn" && TASKKILL /IM openvpn.exe /F && echo OK.
fi
for name in $(cygrunsrv --list) ; do
echo Removing cygservice $name
echo "Try to stop service ${re6stnet_service_name} ..."
net stop ${re6stnet_service_name} ||
slapos_kill_process /usr/bin/openvpn
for name in ${re6stnet_service_name} ${cron_service_name} \
${ssh_service_name} ${syslog_service_name} \
${cygserver_service_name} ; do
echo "Removing ervice $name"
cygrunsrv -R $name && echo OK.
done
......@@ -34,35 +62,27 @@ done
# Stop slapos
#
if [[ -x /opt/slapos/bin/slapos ]] ; then
echo Stoping slapos node ...
echo "Stoping slapos node ..."
/opt/slapos/bin/slapos node stop all && echo OK.
fi
echo Try to kill python2.7 process ...
ps -ef | grep -q "/usr/bin/python2.7" && TASKKILL /IM python2.7.exe /F && echo OK.
slapos_kill_process /usr/bin/python2.7
#
# Remove virtual netcard installed by re6stnet
# Remove virtual netcard installed by slapos
#
for ifname in $(netsh interface ipv6 show interface | gawk '{ print $5 }') ; do
if [[ "$ifname" == "re6stnet-lo" ]] ; then
echo Removing network connection: $ifname
ipwin remove *msloop re6stnet-lo && echo OK.
elif [[ "$ifname" == re6stnet* ]] ; then
echo Removing network connection: $ifname
ipwin remove tap0901 $ifname && echo OK.
fi
done
echo "Removing network connection ${slapos_ifname}"
ipwin remove *msloop ${slapos_ifname} && echo OK.
#
# Remove users installed by slapos node
# Remove users installed by slapos
#
for name in $(net user) ; do
if [[ "x$name" == x\*slapuser* ]] ; then
echo Removing user: $name
net user $name /delete && echo OK.
elif echo "$name" | grep -q -E "(sshd)|(cyg_server)|(slaproot)" ; then
echo Removing user: $name
net user $name /delete && echo OK.
for _name in $(NET USER) ; do
if [[ "${_name}" == ${slapos_user_basename}* ]] ; then
echo "Removing user: ${_name}"
NET USER ${_name} /DELETE && echo OK.
elif echo "${_name}" | grep -q -E "(sshd)|(cyg_server)|(${slapos_administrator})" ; then
echo "Removing user: ${_name}"
NET USER ${_name} /DELETE && echo OK.
fi
done
echo "Creating /etc/passwd ..."
......@@ -71,10 +91,10 @@ mkpasswd -l > /etc/passwd && echo OK.
#
# Remove local group installed by slapos node
#
for name in $(net localgroup | sed -n -e "s/^*//p" | sed -e "s/\\s//g") ; do
if [[ "$name" == grp_slapuser* ]] ; then
echo Removing localgroup: $name
net localgroup $name /delete && echo OK.
for _name in $(NET LOCALGROUP | sed -n -e "s/^*//p" | sed -e "s/\\s//g") ; do
if [[ "${_name}" == grp_${slapos_user_basename}* ]] ; then
echo "Removing localgroup: ${_name}"
NET LOCALGROUP ${_name} /DELETE && echo OK.
fi
done
echo "Creating /etc/group ..."
......@@ -91,16 +111,9 @@ rm -rf ~/.slapos && echo OK.
#
# Remove crontab
#
echo Removing /var/cron/tabs/slaproot
rm -rf /var/cron/tabs/slaproot && echo OK.
#
# Remove slapos-configure from windows startup item
#
slapos_run_key='\HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run'
slapos_run_entry=slapos-configure
echo Removing startup item "$slapos_run_key\\$slapos_run_entry"
regtool -q unset "$slapos_run_key\\$slapos_run_entry" && echo OK.
_filename=/var/cron/tabs/${slapos_administrator}
echo "Removing ${_filename}"
rm -rf ${_filename} && echo OK.
#
# Remove default instance root, because it belong to slapuser, and
......
......@@ -31,7 +31,6 @@ function show_usage()
echo ""
echo " Availabe options:"
echo ""
echo " -U, --user=XXX slapos administrator, default is slaproot"
echo " -P, --password=XXX password of administrator"
echo ""
echo " --computer-certificate=FILENAME"
......@@ -65,7 +64,7 @@ echo ""
# -----------------------------------------------------------
# Local variable
# -----------------------------------------------------------
declare _administrator=${slapos_user}
declare _administrator=${slapos_administrator}
declare _password=
declare _computer_certificate=
declare _computer_key=
......@@ -90,9 +89,6 @@ while test $# -gt 0; do
_password=$2
shift
;;
--user=*)
_administrator=$optarg
;;
-P)
_administrator=$2
shift
......@@ -168,25 +164,25 @@ csih_error "failed to create account ${_administrator}."
# Configure cygwin services: cygserver syslog-ng sshd
# -----------------------------------------------------------
csih_inform "Starting configure cygwin services ..."
if ! cygrunsrv --query cygserver > /dev/null 2>&1 ; then
if ! cygrunsrv --query ${cygserver_service_name} > /dev/null 2>&1 ; then
csih_inform "run cygserver-config ..."
/usr/bin/cygserver-config --yes || \
csih_error "failed to run cygserver-config"
else
csih_inform "the cygserver service has been installed"
fi
check_cygwin_service cygserver
check_cygwin_service ${cygserver_service_name}
if ! cygrunsrv --query syslog-ng > /dev/null 2>&1 ; then
if ! cygrunsrv --query ${syslog_service_name} > /dev/null 2>&1 ; then
csih_inform "run syslog-ng-config ..."
/usr/bin/syslog-ng-config --yes || \
csih_error "failed to run syslog-ng-config"
else
csih_inform "the syslog-ng service has been installed"
fi
check_cygwin_service syslog-ng
check_cygwin_service ${syslog_service_name}
if ! cygrunsrv --query sshd > /dev/null 2>&1 ; then
if ! cygrunsrv --query ${sshd_service_name} > /dev/null 2>&1 ; then
if csih_is_xp && [[ -z "${csih_PRIVILEGED_PASSWORD}" ]] ; then
slapos_request_password ${_administrator} "Install sshd service need the password of ${_administrator}."
fi
......@@ -197,10 +193,10 @@ if ! cygrunsrv --query sshd > /dev/null 2>&1 ; then
else
csih_inform "the sshd service has been installed"
fi
check_cygwin_service sshd
check_cygwin_service ${sshd_service_name}
# Use slapos-cron-config to configure slapos cron service.
if ! cygrunsrv --query cron > /dev/null 2>&1 ; then
if ! cygrunsrv --query ${cron_service_name} > /dev/null 2>&1 ; then
[[ -x ${slapos_cron_config} ]] ||
csih_error "Couldn't find slapos cron config script: ${slapos_cron_config}"
......@@ -214,7 +210,7 @@ if ! cygrunsrv --query cron > /dev/null 2>&1 ; then
else
csih_inform "the cron service has been installed"
fi
check_cygwin_service cron
check_cygwin_service ${cron_service_name}
csih_inform "Configure cygwin services OK"
echo ""
......@@ -314,9 +310,10 @@ csih_error "Invalid computer id '$computer_guid' specified."
csih_inform "Computer configuration information:"
csih_inform " interface name: ${slapos_ifname}"
csih_inform " GUID: $interface_guid"
csih_inform " ipv4_local_network: $ipv4_local_network"
csih_inform " computer_id: $computer_guid"
csih_inform " GUID: ${interface_guid}"
csih_inform " ipv4_local_network: ${ipv4_local_network}"
csih_inform " computer_id: ${computer_guid}"
csih_inform " user_base_name: ${slapos_user_basename}"
csih_inform
csih_inform " If ipv4_local_network confilcts with your local network, change it"
csih_inform " in the file: ${node_configure_file} "
......@@ -327,6 +324,7 @@ sed -i -e "s%^\\s*interface_name.*$%interface_name = $interface_guid%" \
-e "s%^#\?\\s*ipv6_interface.*$%# ipv6_interface =%g" \
-e "s%^ipv4_local_network.*$%ipv4_local_network = $ipv4_local_network%" \
-e "s%^computer_id.*$%computer_id = $computer_guid%" \
-e "s%^user_base_name =.*$%user_base_name = ${slapos_user_basename}%" \
${node_configure_file}
if [[ ! -f ${client_certificate_file} ]] ; then
......
......@@ -559,7 +559,7 @@ create_user() {
echo
echo "Attempting to find or create a privileged user."
for username in slaproot cyg_server cron_server sshd_server
for username in ${slapos_administrator} cyg_server cron_server sshd_server
do
if net user "${username}" 1> /dev/null 2>&1; then
[ -z "${first_account}" ] && first_account="${username}"
......@@ -690,15 +690,15 @@ install_service() {
echo "WARNING: Download the cygrunsrv package to start the cron daemon as a service."
servtest=no
else
cygrunsrv -Q cron > /dev/null 2>&1
cygrunsrv -Q ${cron_service_name} > /dev/null 2>&1
servtest=$?
fi
if [ "${servtest}" = "0" ]; then
cronusername="$(cygrunsrv -VQ cron | sed -n -e 's/^Account[ :]*//p')"
cronusername="$(cygrunsrv -VQ ${cron_service_name} | sed -n -e 's/^Account[ :]*//p')"
echo "Cron is already installed as a service under account ${cronusername}."
if request "Do you want to remove or reinstall it?"; then
if cygrunsrv -R cron; then
if cygrunsrv -R ${cron_service_name}; then
echo "OK. The cron service was removed."
echo
fi
......@@ -765,7 +765,7 @@ install_service() {
_password="${value}"
fi
if cygrunsrv -I cron -p /usr/sbin/cron -e CYGWIN="${cygenv}" \
if cygrunsrv -I ${cron_service_name} -p /usr/sbin/cron -e CYGWIN="${cygenv}" \
-a "-n" -d "Cron daemon" -u "$username" -w "$_password"
then
service="service"
......@@ -773,7 +773,7 @@ install_service() {
service="off"
fi
else
if cygrunsrv -I cron -p /usr/sbin/cron -e CYGWIN="${cygenv}" \
if cygrunsrv -I ${cron_service_name} -p /usr/sbin/cron -e CYGWIN="${cygenv}" \
-a "-n" -d "Cron daemon"
then
service="service"
......@@ -815,7 +815,7 @@ install_service() {
echo " To avoid that, launch cron as a service (using cygrunsrv)."
/usr/sbin/cron
else
cygrunsrv -S cron
cygrunsrv -S ${cron_service_name}
fi
[ $? -eq 0 ] && echo "OK. The cron daemon is now running."
elif [ "${service}" = "job" ]; then
......@@ -867,7 +867,8 @@ sanity_check || exit 1
get_NT || exit 1
slapos_administrator=${1:slaproot}
cron_service_name=${2:cron}
install_service $*
exit $?
......@@ -52,9 +52,10 @@ declare -r node_certificate_file=/etc/opt/slapos/ssl/computer.crt
declare -r node_key_file=/etc/opt/slapos/ssl/computer.key
declare -r node_configure_file=/etc/opt/slapos/slapos.cfg
declare -r slapos_ifname=re6stnet-boot
declare -r slapos_ifname=slapboot-re6stnet-lo
declare -r ipv4_local_network=10.202.29.0/24
declare -r ipv6_local_address=2001:67c:1254:e:32::1
declare -r slapos_user_basename=slapboot-user
declare -r slapos_installer_software=http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/heads/cygwin-share:/software/slapos-windows-installer/software.cfg
......@@ -245,7 +246,7 @@ sed -i -e "s%^\\s*interface_name.*$%interface_name = ${interface_guid}%" \
-e "s%^#\?\\s*ipv6_interface.*$%# ipv6_interface =%g" \
-e "s%^ipv4_local_network.*$%ipv4_local_network = ${ipv4_local_network}%" \
-e "s%^computer_id.*$%computer_id = ${computer_guid}%" \
-e "s%^user_base_name =.*$%user_base_name = slapguider%" \
-e "s%^user_base_name =.*$%user_base_name = ${slapos_user_basename}%" \
${node_configure_file}
csih_inform "type ${node_configure_file}:"
csih_inform "************************************************************"
......
#! /bin/bash
export PATH=/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin:$PATH
if ! source /usr/share/csih/cygwin-service-installation-helper.sh ; then
echo "Error: Download the csih package at first, I need this file:"
echo "Download the csih package at first, to run this script requires"
echo " /usr/share/csih/cygwin-service-installation-helper.sh"
exit 1
fi
......@@ -20,6 +20,8 @@ fi
# ======================================================================
# Constants
# ======================================================================
declare -r slapos_prefix=
declare -r slapos_client_home=~/.slapos
declare -r client_configure_file=$slapos_client_home/slapos.cfg
declare -r client_certificate_file=$slapos_client_home/certificate
......@@ -31,7 +33,6 @@ declare -r node_key_file=/etc/opt/slapos/ssl/computer.key
declare -r node_configure_file=/etc/opt/slapos/slapos.cfg
declare -r node_template_file=/etc/slapos/slapos.cfg.example
declare -r slapos_ifname=re6stnet-lo
# Change it if it confilcts with your local network
declare -r ipv4_local_network=10.201.67.0/24
......@@ -39,14 +40,20 @@ declare -r openvpn_tap_driver_inf=/etc/slapos/driver/OemWin2k.inf
declare -r openvpn_tap_driver_hwid=tap0901
declare -r re6stnet_configure_file=/etc/re6stnet/re6stnet.conf
declare -r re6stnet_service_name=re6stnet
declare -r slapos_cron_config=/usr/bin/slapos-cron-config
declare -r slaprunner_startup_file=/etc/slapos/scripts/slap-runner.html
declare -r slapos_run_key='\HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run'
declare -r slapos_run_entry=slapos-configure
declare -r slapos_user=slaproot
declare -r slapos_run_entry=${slapos_prefix:slapos}-configure
declare -r slapos_administrator=${slapos_prefix:slap}root
declare -r slapos_user_basename=${slapos_prefix:slap}user
declare -r slapos_ifname=${slapos_prefix}re6stnet-lo
declare -r re6stnet_service_name=${slapos_prefix}re6stnet
declare -r cron_service_name=${slapos_prefix}cron
declare -r sshd_service_name=${slapos_prefix}sshd
declare -r syslog_service_name=${slapos_prefix}syslog-ng
declare -r cygserver_service_name=${slapos_prefix}cygserver
# ======================================================================
# Routine: check_cygwin_service
......
......@@ -16,11 +16,11 @@ check_re6stnet_configure
# -----------------------------------------------------------
# Check cygwin services used by slapos
# -----------------------------------------------------------
check_cygwin_service cygserver
check_cygwin_service syslog-ng
check_cygwin_service sshd
check_cygwin_service cron
check_re6stnet_needed && check_cygwin_service re6stnet
check_cygwin_service ${cygserver_service_name}
check_cygwin_service ${syslog_service_name}
check_cygwin_service ${sshd_service_name}
check_cygwin_service ${cron_service_name}
check_re6stnet_needed && check_cygwin_service ${re6stnet_service_name}
# -----------------------------------------------------------
# Get computer reference and re6stnet network
......
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