xcat-core/xCAT-server/share/xcat/install/scripts/pre.ubuntu
otubo 6ada293424 Fix for bug #3391036
git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@10284 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
2011-08-13 18:12:46 +00:00

94 lines
2.2 KiB
Bash

#!/bin/sh
if [ ! -c /dev/vcs ]; then
mknod /dev/vcs c 7 0
fi
cat >/tmp/foo.sh <<EOF
#!/bin/sh
#
# If no arguments:
#
# 1) Start child process to connect as client to master, and re-execute this script to send
# "installmonitor" to master. Do not wait for child process.
#
# 2) Loop forever. For each iteration, start child process as server waiting for a client
# connection. Once a connection is established, child process re-executes this script to
# handle request from that particular client.
#
if [ \$# -eq 0 ]; then
xcatdhost="#XCATVAR:XCATMASTER#"
xcatdport="#TABLE:site:key=xcatiport:value#"
/usr/bin/nc "\$xcatdhost" "\$xcatdport" -e /tmp/foo.sh install_monitor &
while true; do
/usr/bin/nc -l -p 3001 -e /tmp/foo.sh serve_client
done
exit 1 # never reached; reboot ends this
fi
#
# If the script was called with the "install_monitor" argument, stdin and stdout are
# connected to an xCAT daemon on the master. Write the "installmonitor" request to the
# daemon.
#
if [ "\$1" = "install_monitor" ]; then
cmd=""
while [ "\$cmd" != "done" ]; do
read cmd remainder
if [ "\$cmd" == "ready" ]; then
echo "installmonitor"
fi
done
exit 0
fi
#
# When execution reaches here, script called with "serve_client" argument, which means
# stdin and stdout are connected to a client. Read the request from the client, provide
# the answer to the client, and terminate.
#
read cmd arg remainder
case "\$cmd" in
# "sh") #TODO: ENABLE IF DEBUG
# output=\$(eval \$arg \$remainder)
# echo "\$output"
# echo "EOO"
# ;;
"screendump")
output=\$(eval chvt \$arg; cat /dev/vcs)
echo "\$output"
;;
"stat")
sedcmds='/^[^ ]+ +[^ ]+ +install /h; \${ g; s,^[^ ]+ +[^ ]+ +install +([^ ]+) +[^ ]+ ([^ ]+).*,installing \1 \2,; p }'
output=\$(sed -nre "\$sedcmds" /target/var/log/dpkg.log 2>/dev/null)
if [ -z "\$output" ]; then
output="installing prep"
fi
echo "\$output"
;;
esac
exit 0
EOF
chmod 755 /tmp/foo.sh
/tmp/foo.sh >/tmp/foo.log 2>&1 &
exit 0