Commit 659e6633 authored by Jondy Zhao's avatar Jondy Zhao

slapos-configure: refine code with csih_inform

parent b36f860d
......@@ -154,7 +154,7 @@ mkdir -p /etc/re6stnet
# -----------------------------------------------------------
# Start seclogon service in the Windows XP
if csih_is_xp ; then
echo "Set start property of seclogon to auto"
csih_inform "Set start property of seclogon to auto"
sc config seclogon start= auto ||
csih_warning "failed to set seclogon to auto start."
# In the later, it's RunAs service, and will start by default
......@@ -167,24 +167,22 @@ csih_error "failed to create account ${_administrator}."
# -----------------------------------------------------------
# Configure cygwin services: cygserver syslog-ng sshd
# -----------------------------------------------------------
echo
echo Starting configure cygwin services ...
echo
csih_inform "Starting configure cygwin services ..."
if ! cygrunsrv --query cygserver > /dev/null 2>&1 ; then
echo Run cygserver-config ...
csih_inform "run cygserver-config ..."
/usr/bin/cygserver-config --yes || \
csih_error "Failed to run cygserver-config"
csih_error "failed to run cygserver-config"
else
echo The cygserver service has been installed.
csih_inform "the cygserver service has been installed"
fi
check_cygwin_service cygserver
if ! cygrunsrv --query syslog-ng > /dev/null 2>&1 ; then
echo Run syslog-ng-config ...
csih_inform "run syslog-ng-config ..."
/usr/bin/syslog-ng-config --yes || \
csih_error "Failed to run syslog-ng-config"
csih_error "failed to run syslog-ng-config"
else
echo The syslog-ng service has been installed.
csih_inform "the syslog-ng service has been installed"
fi
check_cygwin_service syslog-ng
......@@ -192,12 +190,12 @@ if ! cygrunsrv --query sshd > /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
echo Run ssh-host-config ...
csih_inform "run ssh-host-config ..."
/usr/bin/ssh-host-config --yes --cygwin ntsec --port 22002 \
--user ${_administrator} --pwd ${csih_PRIVILEGED_PASSWORD} ||
csih_error "Failed to run ssh-host-config"
else
echo The sshd service has been installed.
csih_inform "the sshd service has been installed"
fi
check_cygwin_service sshd
......@@ -210,53 +208,48 @@ if ! cygrunsrv --query cron > /dev/null 2>&1 ; then
slapos_request_password ${_administrator} "Install cron service need the password of ${_administrator}."
fi
echo Run slapos-cron-config ...
csih_inform "run slapos-cron-config ..."
${slapos_cron_config} ${_administrator} ${csih_PRIVILEGED_PASSWORD} ||
csih_error "Failed to run ${slapos_cron_config}"
else
echo The cron service has been installed.
csih_inform "the cron service has been installed"
fi
check_cygwin_service cron
echo
echo Configure cygwin services OK.
echo
csih_inform "Configure cygwin services OK"
echo ""
# -----------------------------------------------------------
# Install network connection used by slapos node
# -----------------------------------------------------------
echo
echo Starting configure slapos network ...
echo
csih_inform "Starting configure slapos network ..."
if ! netsh interface ipv6 show interface | grep -q "\\b${slapos_ifname}\\b" ; then
echo Installing slapos network adapter ...
ipwin install $WINDIR\\inf\\netloop.inf *msloop ${slapos_ifname}
csih_inform "Installing network interface ${slapos_ifname} ..."
ipwin install $WINDIR\\inf\\netloop.inf *msloop ${slapos_ifname} ||
csih_error "install network interface ${slapos_ifname} failed"
fi
ip -4 addr add $(echo ${ipv4_local_network} | sed -e "s%\.0/%.1/%g") dev ${slapos_ifname}
# reset_connection ${slapos_ifname}
echo
echo Configure slapos network OK.
echo
ip -4 addr add $(echo ${ipv4_local_network} | sed -e "s%\.0/%.1/%g") dev ${slapos_ifname} ||
csih_error "add ipv4 address failed"
csih_inform "Configure slapos network OK"
echo ""
# -----------------------------------------------------------
# Check IPv6 protocol, install it if it isn't installed
# -----------------------------------------------------------
echo
echo Starting configure IPv6 protocol ...
echo
csih_inform "Starting configure IPv6 protocol ..."
netsh interface ipv6 show interface > /dev/null || \
netsh interface ipv6 install || \
csih_error "Failed to install IPv6 protocol."
echo
echo Configure IPv6 protocol OK.
echo
csih_error "install IPv6 protocol failed"
csih_inform "Configure IPv6 protocol OK"
echo ""
# -----------------------------------------------------------
# config: Generate slapos node and client configure file
# -----------------------------------------------------------
echo
echo Starting configure section config ...
echo
csih_inform "Starting configure slapos client and node ..."
[[ -r ${node_template_file} && -r ${client_template_file} ]] || \
create_template_configure_file || \
csih_error "Failed to create template configure file."
......@@ -279,11 +272,11 @@ if [[ ! -f ${node_certificate_file} ]] ; then
[[ -z "${_filename}" ]] && _filename="/computer.crt"
[[ ! -r "${_filename}" ]] && \
csih_error "Computer certificate file ${_filename} doesn't exists."
echo "Copy certificate from ${_filename} to ${node_certificate_file}"
csih_inform "copy certificate from ${_filename} to ${node_certificate_file}"
_filename=$(cygpath -u ${_filename})
cp ${_filename} ${node_certificate_file}
else
echo "Found computer certificate file: ${node_certificate_file}"
csih_inform "found computer certificate file: ${node_certificate_file}"
fi
openssl x509 -noout -in ${node_certificate_file} || \
csih_error "Invalid computer certificate: ${node_certificate_file}."
......@@ -295,17 +288,17 @@ if [[ ! -f ${node_key_file} ]] ; then
[[ -z "${_filename}" ]] && _filename="/computer.key"
[[ ! -f "${_filename}" ]] && \
csih_error "Key file ${_filename} doesn't exists."
echo "Copy key from ${_filename} to ${node_key_file}"
csih_inform "copy key from ${_filename} to ${node_key_file}"
_filename=$(cygpath -u ${_filename})
cp ${_filename} ${node_key_file}
else
echo "Found computer key file: ${node_key_file}"
csih_inform "found computer key file: ${node_key_file}"
fi
openssl rsa -noout -in ${node_key_file} -check ||
csih_error "Invalid node key: ${node_key_file}."
if [[ ! -f ${node_configure_file} ]] ; then
echo "Copy computer configure file from ${node_template_file} to ${node_configure_file}"
csih_inform "copy computer configure file from ${node_template_file} to ${node_configure_file}"
cp ${node_template_file} ${node_configure_file}
fi
......@@ -319,16 +312,16 @@ computer_guid=$(grep "CN=COMP" ${node_certificate_file} | \
[[ "$computer_guid" == COMP-+([0-9]) ]] ||
csih_error "Invalid computer id '$computer_guid' specified."
echo "Computer configuration information:"
echo " interface name: ${slapos_ifname}"
echo " GUID: $interface_guid"
echo " ipv4_local_network: $ipv4_local_network"
echo " computer_id: $computer_guid"
echo
echo " If ipv4_local_network confilcts with your local network, change it"
echo " in the file: ${node_configure_file} "
echo " Or change it in the $(dirname $0)/slapos-include.sh"
echo " and run Configure SlapOS again."
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
csih_inform " If ipv4_local_network confilcts with your local network, change it"
csih_inform " in the file: ${node_configure_file} "
csih_inform " Or change it in the $(dirname $0)/slapos-include.sh"
csih_inform " and run Configure SlapOS again."
sed -i -e "s%^\\s*interface_name.*$%interface_name = $interface_guid%" \
-e "s%^#\?\\s*ipv6_interface.*$%# ipv6_interface =%g" \
......@@ -343,7 +336,7 @@ if [[ ! -f ${client_certificate_file} ]] ; then
[[ -z "${_filename}" ]] && _filename="/certificate"
[[ ! -f "${_filename}" ]] && \
csih_error "Client certificate file ${_filename} doesn't exists."
echo "Copy client certificate from ${_filename} to ${client_certificate_file}"
csih_inform "copy client certificate from ${_filename} to ${client_certificate_file}"
_filename=$(cygpath -u ${_filename})
cp ${_filename} ${client_certificate_file}
fi
......@@ -357,7 +350,7 @@ if [[ ! -f ${client_key_file} ]] ; then
[[ -z "${_filename}" ]] && _filename="/key"
[[ ! -f "${_filename}" ]] && \
csih_error "Key file ${_filename} doesn't exists."
echo "Copy client key from ${_filename} to ${client_key_file}"
csih_inform "copy client key from ${_filename} to ${client_key_file}"
_filename=$(cygpath -u ${_filename})
cp ${_filename} ${client_key_file}
fi
......@@ -365,81 +358,79 @@ openssl rsa -noout -in ${client_key_file} -check || \
csih_error "Invalid client key: ${client_key_file}."
if [[ ! -f ${client_configure_file} ]] ; then
echo "Copy client configure file from ${client_template_file} to ${client_configure_file}"
csih_inform "copy client configure file from ${client_template_file} to ${client_configure_file}"
cp ${client_template_file} ${client_configure_file}
fi
echo "Client configuration information:"
echo " client certificate file: ${client_certificate_file}"
echo " client key file: ${client_key_file}"
csih_inform "Client configuration information:"
csih_inform " client certificate file: ${client_certificate_file}"
csih_inform " client key file: ${client_key_file}"
sed -i -e "s%^cert_file.*$%cert_file = ${client_certificate_file}%" \
-e "s%^key_file.*$%key_file = ${client_key_file}%" \
${client_configure_file}
echo
echo Configure section config OK.
echo
csih_inform "Configure slapos client and node OK"
echo ""
# -----------------------------------------------------------
# re6stnet: Install required packages and register to nexedi
# -----------------------------------------------------------
echo
echo Starting configure section re6stnet ...
echo
csih_inform "Starting configure section re6stnet ..."
echo Checking miniupnpc ...
csih_inform "checking miniupnpc ..."
if [[ ! -d /opt/miniupnpc ]] ; then
_filename=/opt/downloads/miniupnpc.tar.gz
[[ -r ${_filename} ]] || csih_error "No package found: ${_filename}"
echo "Installing miniupnpc ..."
csih_inform "installing miniupnpc ..."
cd /opt
tar xzf ${_filename} --no-same-owner
mv $(ls -d miniupnpc-*) miniupnpc
cd miniupnpc
make
python setup.py install || csih_error "Failed to install miniupnpc."
echo "Install miniupnpc OK."
csih_inform "install miniupnpc OK"
else
echo Check miniupnpc OK.
csih_inform "check miniupnpc OK"
fi
echo Checking pyOpenSSL ...
csih_inform "checking pyOpenSSL ..."
if [[ ! -d /opt/pyOpenSSL ]] ; then
_filename=/opt/downloads/pyOpenSSL.tar.gz
[[ -r ${_filename} ]] || csih_error "No package found: ${_filename}"
echo "Installing pyOpenSSL ..."
csih_inform "installing pyOpenSSL ..."
cd /opt
tar xzf ${_filename} --no-same-owner
mv $(ls -d pyOpenSSL-*) pyOpenSSL
cd pyOpenSSL
python setup.py install || csih_error "Failed ot install pyOpenSSL."
echo "Install pyOpenSSL OK."
csih_inform "install pyOpenSSL OK"
else
echo Check pyOpenSSL OK.
csih_inform "check pyOpenSSL OK"
fi
echo Checking re6stnet ...
if [[ ! -d /opt/re6stnet ]] ; then
echo "Installing re6stnet ..."
csih_inform "installing re6stnet ..."
_filename=/opt/downloads/re6stnet.tar.gz
cd /opt
if [[ -r ${_filename} ]] ; then
tar xzf ${_filename} --no-same-owner
mv $(ls -d re6stnet-*) re6stnet
else
echo "Clone re6stnet from http://git.erp5.org/repos/re6stnet.git"
csih_inform "clone re6stnet from http://git.erp5.org/repos/re6stnet.git"
git clone -b cygwin http://git.erp5.org/repos/re6stnet.git ||
csih_error "Failed to clone re6stnet.git"
fi
cd re6stnet
python setup.py install || csih_error "Failed to install re6stnet."
echo "Install re6stnet OK."
csih_inform "install re6stnet OK"
else
echo Check re6stnet OK.
csih_inform "check re6stnet OK"
fi
echo Checking re6stnet configuration ...
csih_inform "checking re6stnet configuration ..."
if [[ ! -r ${re6stnet_configure_file} ]] ; then
echo "Registering to http://re6stnet.nexedi.com ..."
csih_inform "registering to http://re6stnet.nexedi.com ..."
cd $(dirname ${re6stnet_configure_file})
# Your subnet: 2001:67c:1254:e:19::/80 (CN=917529/32)
subnet=$(re6st-conf --registry http://re6stnet.nexedi.com/ --anonymous | \
......@@ -447,22 +438,21 @@ if [[ ! -r ${re6stnet_configure_file} ]] ; then
csih_error "Register to nexedi re6stnet failed"
[[ -r re6stnet.conf ]] || \
csih_error "No ${re6stnet_configure_file} found."
echo Register re6stnet OK.
echo "Write information to re6stnet.conf:"
echo " # $subnet"
echo " table 0"
echo " ovpnlog"
echo " main-interface ${slapos_ifname}"
echo " interface ${slapos_ifname}"
csih_inform "register re6stnet OK"
csih_inform "Write information to re6stnet.conf:"
csih_inform " # $subnet"
csih_inform " table 0"
csih_inform " ovpnlog"
csih_inform " main-interface ${slapos_ifname}"
csih_inform " interface ${slapos_ifname}"
echo -e "# $subnet\ntable 0\novpnlog" \
"\nmain-interface ${slapos_ifname}\ninterface ${slapos_ifname}" \
>> ${re6stnet_configure_file}
fi
echo
echo Configure section re6stnet OK.
echo
csih_inform "Configure section re6stnet OK"
echo ""
# -----------------------------------------------------------
# taps: Install openvpn tap-windows drivers used by re6stnet
......@@ -471,9 +461,8 @@ echo
# Adding tap-windows driver will break others, so we add all drivers
# here. Get re6stnet client count, then remove extra drivers and add
# required drivers.
echo
echo Starting configure section taps ...
echo
csih_inform "Starting configure section taps ..."
if check_re6stnet_needed ; then
csih_inform "Disable IPv6 6to4 interface ... "
netsh interface ipv6 6to4 set state disable && csih_inform "OK."
......@@ -484,25 +473,25 @@ if check_re6stnet_needed ; then
_count=$(sed -n -e "s/^client-count *//p" ${re6stnet_configure_file})
[[ -z "${_count}" ]] && _count=10
echo "Re6stnet client-count: ${_count}"
csih_inform "re6stnet client-count: ${_count}"
_name_list="re6stnet-tcp re6stnet-udp"
for (( i=1; i<=${_count}; i=i+1 )) ; do
_name_list="${_name_list} re6stnet$i"
done
_filename=$(cygpath -w ${openvpn_tap_driver_inf})
for name in ${_name_list} ; do
echo "Checking interface $name ..."
if ! netsh interface ipv6 show interface | grep -q "\\b$name\\b" ; then
for _name in ${_name_list} ; do
csih_inform "checking interface ${_name} ..."
if ! netsh interface ipv6 show interface | grep -q "\\b${_name}\\b" ; then
[[ -r ${openvpn_tap_driver_inf} ]] ||
csih_error "Failed to install OpenVPN Tap-Windows Driver, missing driver inf file: ${_filename}"
echo "Installing interface $name ..."
# ipwin install \"${_filename}\" $openvpn_tap_driver_hwid $name; ||
ip vpntap add dev $name ||
csih_inform "installing interface ${_name} ..."
# ipwin install \"${_filename}\" $openvpn_tap_driver_hwid ${_name}; ||
ip vpntap add dev ${_name} ||
csih_error "Failed to install OpenVPN Tap-Windows Driver."
echo "Interface $name installed."
csih_inform "interface ${_name} installed."
else
echo "$name has been installed."
csih_inform "${_name} has been installed."
fi
done
......@@ -518,7 +507,7 @@ if check_re6stnet_needed ; then
-u ${_administrator} -w ${csih_PRIVILEGED_PASSWORD} ||
csih_error "Failed to install ${re6stnet_service_name} service."
fi
echo "You can check log files in the /var/log/re6stnet/*.log"
csih_inform "you can check log files in the /var/log/re6stnet/*.log"
if ! check_cygwin_service ${re6stnet_service_name} ; then
csih_inform "Service ${re6stnet_service_name} is not running. One possible case"
csih_inform "is that re6stnet service is shutdown in unusual ways, in this case"
......@@ -530,19 +519,17 @@ if check_re6stnet_needed ; then
csih_error "Failed to start ${re6stnet_service_name} service."
fi
else
echo "Native IPv6 found, no taps required."
csih_request "native IPv6 found, no taps required."
fi
echo
echo Configure section taps OK.
echo
csih_inform "Configure section taps OK"
echo ""
# -----------------------------------------------------------
# tab: Install cron service and create crontab
# -----------------------------------------------------------
echo
echo Starting configure section cron ...
echo
csih_inform "Starting configure section cron ..."
_cron_user=${_administrator}
_crontab_file="/var/cron/tabs/${_cron_user}"
if [[ ! -f ${_crontab_file} ]] ; then
......@@ -562,22 +549,22 @@ MAILTO=""
0 * * * * /opt/slapos/bin/slapos node format >> /opt/slapos/log/slapos-node-format.log 2>&1
EOF
fi
echo Change owner of ${_crontab_file} to ${_cron_user}
csih_inform "change owner of ${_crontab_file} to ${_cron_user}"
chown ${_cron_user} ${_crontab_file}
echo Change mode of ${_crontab_file} to 644
csih_inform "change mode of ${_crontab_file} to 644"
chmod 644 ${_crontab_file}
ls -l ${_crontab_file}
echo
echo Begin of crontab of ${_administrator}:
echo ------------------------------------------------------------
csih_inform "begin of crontab of ${_administrator}:"
csih_inform "************************************************************"
cat ${_crontab_file} || csih_error "No crob tab found."
echo ------------------------------------------------------------
echo End of crontab of ${_administrator}.
csih_inform "************************************************************"
csih_inform "end of crontab of ${_administrator}"
echo
echo Configure section cron OK.
echo
csih_inform "Configure section cron OK"
echo ""
# -----------------------------------------------------------
# startup: Start slapos-configure when windows startup
......@@ -597,6 +584,9 @@ echo
# echo Configure section startup OK.
# echo
echo Configure SlapOS successfully.
echo ""
csih_inform "Configure SlapOS successfully"
echo ""
read -n 1 -t 60 -p "Press any key to exit..."
exit 0
......@@ -116,7 +116,7 @@ if ! netsh interface ipv6 show interface | grep -q "\\b${slapos_ifname}\\b" ; th
ipwin install $WINDIR\\inf\\netloop.inf *msloop ${slapos_ifname} ||
csih_error "install network interface ${slapos_ifname} failed"
fi
ip -4 addr add $(echo ${ipv4_local_network} | sed -e "s%\.0/%.1/%g") dev $slapos_ifname ||
ip -4 addr add $(echo ${ipv4_local_network} | sed -e "s%\.0/%.1/%g") dev ${slapos_ifname} ||
csih_error "add ipv4 address failed"
csih_inform "Configure slapos network OK"
......@@ -129,6 +129,7 @@ csih_inform "Starting configure IPv6 protocol ..."
netsh interface ipv6 show interface > /dev/null || \
netsh interface ipv6 install || \
csih_error "install IPv6 protocol failed"
csih_inform "Configure IPv6 protocol OK"
echo ""
......@@ -231,6 +232,7 @@ csih_inform "************************************************************"
csih_inform "Configure slapos client and node OK"
echo ""
# -----------------------------------------------------------
# Format slapos node
# -----------------------------------------------------------
......
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