Skip to content

Instantly share code, notes, and snippets.

@sergiobuj
Created March 20, 2012 22:52
Show Gist options
  • Save sergiobuj/2142178 to your computer and use it in GitHub Desktop.
Save sergiobuj/2142178 to your computer and use it in GitHub Desktop.
Apolo admin script
#!/bin/bash
#
#
# Script name: Que belleza
# Author: Sergio Botero sbotero2[a]eafit.edu.co
#
#
## IP
readonly ips="10.10.60."
#readonly ips="10.10.61."
#readonly ips="200.12.189."
## IP default range
start_ip=10
last_ip=36
function print_help {
echo ""
echo "$0 [options]"
echo " "
echo "options:"
echo -e "\t-h, --help \t\tshow brief help"
echo -e "\t-c COMMAND \t\tone time command (quote for multiple words)"
echo -e "\t--boinc \t\tinstall boinc"
echo -e "\t--update-apt\t\tupdate packages"
echo -e "\t--condor \t\tinstall condor"
echo -e "\t--clean \t\tcleaner output"
echo -e "\t--coffee \t\tperform script in parallel -give it some coffee-"
echo -e "\t--target IP \t\tspecify one machine to work on"
echo -e "\t--range IP1 IP2 \tspecify IP range, where IP1 < IP2"
}
if [ $# -eq 0 ]; then
print_help
exit 0
else
while [ $# -gt 0 ]; do
case $1 in
-h | --help )
print_help
exit 0;;
--boinc ) boinc_ins=true;;
--condor ) condor_ins=true;;
--update-apt ) update_apt=true;;
--coffee ) go_parallel=true;;
--clean ) clean_out=true;;
--target )
shift
start_ip=$1
last_ip=$1
;;
-c )
shift
one_time_command=$1
;;
--range )
shift
start_ip=$1
shift
last_ip=$1
if [ "$last_ip" -lt "$start_ip" ]; then
echo "Invalid IP range"
exit 1
fi;;
*) echo "Unrecognized option \"$1\""
exit 1;;
esac
shift
done
fi
## SSH function
sshfunc (){
/usr/bin/ssh root@$ips$1 $2
}
## SCP function
scpfunc (){
/usr/bin/scp $2 root@$ips$1:$3
}
condor_installation () {
echo -e "Installing Condor.\n"
sshfunc $1 "apt-get install condor -y --force-yes"
scpfunc $1 condor_config.local "/etc/condor/"
sshfunc $1 "/etc/init.d/condor restart"
true
}
boinc_installation () {
echo -e "Installing Boinc.\n"
sshfunc $1 "apt-get install boinc-client -y --force-yes"
sshfunc $1 "/usr/sbin/update-rc.d boinc-client remove"
sshfunc $1 "/etc/init.d/boinc-client stop"
scpfunc $1 account_www.worldcommunitygrid.org.xml "/var/lib/boinc-client/account_www.worldcommunitygrid.org.xml"
sshfunc $1 "/etc/init.d/condor restart"
true
}
misc () {
#scpfunc $1 condor_config "/etc/condor/"
#scpfunc $1 condor_config.local "/etc/condor/"
#scpfunc $1 condor_config.local.dedicated.resource "/etc/condor/"
#sshfunc $1 "cat /etc/condor/condor_config.local"
#sshfunc $1 "ls -R /var/lib/boinc-client/slots"
#sshfunc $1 "sed -i 's/a7204b0c9bcb5b2d1e2d0b2b9a845c14/3cad487498d4519647fec78d9e534559/g' /var/lib/boinc-client/*.org.xml"
#sshfunc $1 poweroff
#sshfunc $1 "ls /var/lib/boinc-client"
#sshfunc $1 "condor_reconfig"
#sshfunc $1 "/etc/init.d/boinc-client stop"
#sshfunc $1 "ps ax | grep boinc"
#sshfunc $1 "ps ax | grep condor"
#sshfunc $1 "/etc/init.d/condor restart"
true
}
clean_up(){
true
}
work_machine (){
if [ "$go_parallel" ]; then
exec > $ips$1.apolo.log 2>&1
fi
if [ -z $clean_out ]; then
echo -e "\n***** Host $ips$1 *****"
fi
if [ "$one_time_command" ]; then
sshfunc $1 "$one_time_command"
else
#ssh-copy-id $ips$1
#ssh-copy-id -oStrictHostKeyChecking=no -oCheckHostIP=no -L $ips$1
# [[ "$go_parallel" =~ "go" ]]
## Test connection
#sshfunc $1 "uname -a"
## Update apt-get
if [ $condor_ins ] || [ $boinc_ins ] || [ $update_apt ]; then
scpfunc $1 sources.list "/etc/apt"
sshfunc $1 "apt-get update"
fi
## Condor Install
if [ $condor_ins ]; then
condor_installer $1
fi
## Boinc Install
if [ $boinc_ins ]; then
boinc_installer $1
fi
## Misc after install
misc $1
fi
if [ -z $clean_out ]; then
echo -e "***** Done with host $ips$1 *****"
fi
}
## Loop
shopt -s nocasematch
for server in `seq $start_ip $last_ip`; do
if [ "$server" -eq 1 ] || [ "$server" -eq 0 ]; then
if [ -z $clean_out ]; then
echo -e "\n***** Skipping Host $ips$1 *****"
fi
continue
fi
if [ -n "$go_parallel" ]; then
work_machine $server &
else
work_machine $server
fi
done
shopt -u nocasematch
wait
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment