127 lines
2.6 KiB
Bash
Executable File
127 lines
2.6 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
this_dir="$(dirname $(readlink -f $0))"
|
|
user=$2
|
|
ip=$3
|
|
password=$4
|
|
AUTORUN=distccd.autorun
|
|
|
|
usage ()
|
|
{
|
|
echo "Usage: $0 [OPTION]..."
|
|
echo "Create and Deploy compiler environment for distributed build."
|
|
echo ""
|
|
echo "--create Clone the current compilation environment."
|
|
echo "--deploy Username IP Password Deploy the chroot environment to the remote host and start the compilation service."
|
|
echo "--remove Username IP Password Delete the chroot environment and related settings of the remote host."
|
|
echo "--start Username IP Password Start the compilation service in the remote host chroot environment."
|
|
echo "--stop Username IP Password Stop the compilation service in the remote host chroot environment."
|
|
echo "--reinit Username IP Password Redeploy the chroot environment on the remote host."
|
|
}
|
|
|
|
create()
|
|
{
|
|
local _create=$this_dir/distcc-create-env
|
|
local args_strings=
|
|
|
|
|
|
if ! command -v distcc >/dev/null; then
|
|
echo "Cannot find distributes compilation program 'distcc'."
|
|
exit 1
|
|
fi
|
|
|
|
if [ -x /usr/lib/distcc/gcc ]; then
|
|
args_strings="--gcc /usr/bin/gcc /usr/bin/g++"
|
|
fi
|
|
|
|
if [ -x /usr/lib/distcc/clang ]; then
|
|
args_strings="${args_strings} --addfile /usr/bin/clang --addfile /usr/bin/clang++"
|
|
fi
|
|
|
|
if [ -x $_create -a -n "$args_strings" ]; then
|
|
$_create $args_strings
|
|
exit $?
|
|
fi
|
|
|
|
echo "Failed to create environment."
|
|
exit 1
|
|
}
|
|
|
|
deploy()
|
|
{
|
|
if [ -x distcc.autoscp ]; then
|
|
./distcc.autoscp $user $ip $password
|
|
return $?
|
|
fi
|
|
return 1
|
|
}
|
|
|
|
remove()
|
|
{
|
|
expect <<EOF
|
|
set timeout 50
|
|
spawn ssh -t $user@$ip sudo -p suprompt ~/distcc.autorun autoremove
|
|
expect {
|
|
"yes/no" { send "yes\r";exp_continue }
|
|
"password" { send "$password\r" }
|
|
"suprompt" { send "$password\r" }
|
|
}
|
|
expect eof
|
|
EOF
|
|
}
|
|
|
|
start()
|
|
{
|
|
if [ -x distcc.start-stop]; then
|
|
./distcc.start-stop $user $ip $password start
|
|
exit $?
|
|
fi
|
|
echo "Failed to start"
|
|
exit 1
|
|
}
|
|
|
|
stop()
|
|
{
|
|
if [ -x distcc.start-stop]; then
|
|
./distcc.start-stop $user $ip $password stop
|
|
exit $?
|
|
fi
|
|
echo "Failed to stop"
|
|
exit 1
|
|
}
|
|
|
|
reinit()
|
|
{
|
|
remove
|
|
deploy
|
|
}
|
|
|
|
|
|
|
|
while true; do
|
|
case "$1" in
|
|
--create)
|
|
create # Clone the current compilation environment.
|
|
exit 0;;
|
|
--deploy)
|
|
deploy # Deploy the chroot environment to the remote host and start the compilation service.
|
|
exit 0;;
|
|
--remove)
|
|
remove
|
|
exit 0;;
|
|
--start)
|
|
start
|
|
exit 0;;
|
|
--stop)
|
|
stop
|
|
exit 0;;
|
|
--reinit)
|
|
reinit
|
|
exit 0;;
|
|
*)
|
|
usage
|
|
exit 1
|
|
;;
|
|
esac
|
|
done
|