[Lunar-commits] CVS: lunar-tools/colony colony,NONE,1.1
Auke Kok
sofar at lunar-linux.org
Fri Oct 29 11:12:19 UTC 2004
Update of /var/cvs/lunar/lunar-tools/colony
In directory espresso.foo-projects.org:/home/sofar/active/lunar-tools/colony
Added Files:
colony
Log Message:
Adding colony in here... I want to remove it from lunar & theedge ASAP
--- NEW FILE: colony ---
#!/bin/sh
############################################################
# #
# colony - executes commands on multiple remote systems #
# #
############################################################
# cabal is part of the sorcery spell management utility #
# Copyright 2001 by Kyle Sallee #
############################################################
# #
# this WAS the cabal script of a source based Linux distro,#
# calls Sorcerer GNU/Linux, or SGL. SGL is no longer #
# available with GPL license. Since this script was taken #
# before licensing scheme change, no legal problems I #
# guess. #
# #
# the code is re-written for Lunar. The previous Copyright #
# notices are kept; just in case some code is left :=) #
# Kagan Kongar <kongar at tsrsb.org.tr>, 20020519 #
# #
############################################################
# #
# Parts Copyrighted Jason Johnston 2002 under GPLv2 #
# #
# Parts Copyrighted Kagan Kongar 2002 under GPLv2 #
# #
############################################################
read_colony_names() {
mkdir -p $COLONY_DIRECTORY
OLD_IFS="$IFS"
IFS="$ENTER_IFS"
COUNT=0;
if [ -f $COLONY_NAMES ]; then
for NAME in `cat $COLONY_NAMES`; do
COLONYS[$COUNT]="$NAME"
(( COUNT++ ))
done
fi
export IFS="$OLD_IFS"
}
write_colony_names() {
rm -f $COLONY_NAMES
for (( COUNT=0; COUNT != MAX_COLONYS; COUNT++ )); do
echo "${COLONYS[$COUNT]}" >> $COLONY_NAMES
done
}
print_colony_names() {
for (( COUNT = 0; COUNT != MAX_COLONYS; COUNT++ )); do
echo "${COLONYS[$COUNT]}"
done
}
print_colony_numbers_names() {
for (( COUNT = 0; COUNT != MAX_COLONYS; COUNT++ )); do
echo "$COUNT"
if [ -n "${COLONYS[$COUNT]}" ]
then echo "${COLONYS[$COUNT]}"
else echo "Undefined"
fi
done
}
select_colony() {
$DIALOG --title "Cabal Selection Menu" \
--ok-label "Select" \
--cancel-label "Exit" \
--menu \
"Please Select a Cabal" \
0 0 0 \
$( print_colony_numbers_names )
}
edit_colonys() {
while SELECTED=`select_colony`
do edit_file "$COLONY_DIRECTORY/$SELECTED"
done
}
show_colonys() {
while SELECTED=`select_colony`
do show_file "$COLONY_DIRECTORY/$SELECTED"
done
}
generate_colony_key() {
while SELECTED=`select_colony`
do
mkdir -p $COLONY_KEYS
chmod 600 $COLONY_KEYS
ssh-keygen -t dsa \
-b 1024 \
-N "" \
-f $COLONY_KEYS/$SELECTED
done
}
all_colony_keys() {
for KEY in `ls $COLONY_KEYS*/ | grep -v "\.pub"`
do echo "-i"
echo "$KEY"
done
}
distribute_colony_key() {
while SELECTED=`select_colony`
do
mkdir -p $COLONY_KEYS
chmod 600 $COLONY_KEYS
if ! [ -e $COLONY_KEYS/$SELECTED.pub ]; then
$DIALOG --msgbox "Generate the key first!"
return
fi
AK2="/root/.ssh/authorized_keys2"
cat $COLONY_DIRECTORY/$SELECTED |
while read BOX
do cat $COLONY_KEYS/$SELECTED.pub |
ssh `all_colony_keys` \
root@$BOX \
"cat >> $AK2; \
sort $AK2 | \
uniq > $AK2"
done
done
}
revoke_colony_key() {
while SELECTED=`select_colony`
do
mkdir -p $COLONY_KEYS
chmod 600 $COLONY_KEYS
if ! [ -e $COLONY_KEYS/$SELECTED.pub ]; then
$DIALOG --msgbox "No key to revoke!"
return
fi
AK2="/root/.ssh/authorized_keys2"
cat $COLONY_DIRECTORY/$SELECTED |
while read BOX
do REVOKE=KEY="`cat $COLONY_KEYS/$SELECTED.pub`"
ssh `all_colony_keys` \
root@$BOX \
"grep -v "$REVOKE_KEY" $AK2 | \
sort > $AK2"
done
done
}
name_colonys() {
TITLE="Name Cabals Menu"
HELP="Please enter colony's name"
while SELECTED=`select_colony`
do
if NAME=`$DIALOG --title "$TITLE" \
--ok-label "Enter" \
--cancel-label "Cancel" \
--inputbox \
"$HELP" \
0 0 ${COLONYS[$SELECTED]}`
then
COLONYS[$SELECTED]="$NAME"
fi
done
write_colony_names
}
set_max_colonys() {
PROMPT="Please enter the maximum number of colonys"
if NEW_MAX=`$DIALOG --ok-label "Commit" \
--inputbox \
"$PROMPT" \
0 0 "$MAX_COLONYS"`
then
MAX_COLONYS=$NEW_MAX
TEMP=`grep -v "MAX_COLONYS=" $LOCAL_CONFIG`
echo "$TEMP" > $LOCAL_CONFIG
echo "MAX_COLONYS=$MAX_COLONYS" >> $LOCAL_CONFIG
fi
}
colony_name_menu() {
while
HELP=""
S_HELP="Show the names of the colonys"
E_HELP="Edit the names of the colonys"
TITLE="Cabal Name Menu"
COMMAND=`$DIALOG --title "$TITLE" \
--item-help \
--ok-label "Select" \
--cancel-label "Exit" \
--menu \
"$HELP" \
0 0 0 \
"S" "Show Cabal Names" "$S_HELP" \
"E" "Edit Cabal Names" "$E_HELP"`
do
case $COMMAND in
S) print_colony_names | view_file ;;
E) name_colonys ;;
esac
done
}
colony_key_menu() {
while
HELP="Generate, distribute, and revoke ssh2 keys to colony computers to enable root login without password prompts"
G_HELP="Create 2048 bit ssh2 dsa public/private keys for a colony."
D_HELP="Install the public key on all computer members of colony."
R_HELP="Remove a previously installed colony key"
TITLE="Cabal Key Menu"
COMMAND=`$DIALOG --title "$TITLE" \
--item-help \
--ok-label "Select" \
--cancel-label "Exit" \
--menu \
"$HELP" \
0 0 0 \
"G" "Generate Cabal Key" "$G_HELP" \
"D" "Distribute Cabal Key" "$D_HELP" \
"R" "Revoke Cabal Key" "$R_HELP"`
do
case $COMMAND in
G) generate_colony_key ;;
D) distribute_colony_key ;;
R) revoke_colony_key ;;
esac
done
}
colony_content_menu() {
while
HELP=""
S_HELP="Show the computers which belong to a colony"
E_HELP="Edit the computers which belong to a colony"
TITLE="Cabal Content Menu"
COMMAND=`$DIALOG --title "$TITLE" \
--item-help \
--ok-label "Select" \
--cancel-label "Exit" \
--menu \
"$HELP" \
0 0 0 \
"S" "Show Cabal" "$S_HELP" \
"E" "Edit Cabal" "$E_HELP"`
do
case $COMMAND in
S) show_colonys ;;
E) edit_colonys ;;
esac
done
}
colony_admin_menu() {
while
HELP=""
M_HELP="Define maximum amount of colonys."
N_HELP="Define and display the names of colonys"
C_HELP="Define and display the computers belong to a colony"
K_HELP="Generate and distribute keys for colonys"
TITLE="Cabal Admin Menu"
COMMAND=`$DIALOG --title "$TITLE" \
--item-help \
--ok-label "Select" \
--cancel-label "Exit" \
--menu \
"$HELP" \
0 0 0 \
"N" "Cabal Name Menu" "$N_HELP" \
"C" "Cabal Content Menu" "$C_HELP" \
"K" "Cabal Key Menu" "$K_HELP" \
"M" "Maximum Cabals: $MAX_COLONYS" "$M_HELP"`
do
case $COMMAND in
N) colony_name_menu ;;
C) colony_content_menu ;;
K) colony_key_menu ;;
M) set_max_colonys ;;
esac
done
}
select_order() {
$DIALOG --title "Order Selection Menu" \
--menu "" 0 0 0 \
"S" "Sequentially" \
"C" "Concurrently"
}
colony_copy() {
SOURCE_MESSAGE="Please enter source files and directories."
DEST_MESSAGE="Please enter destination directory."
mkdir -p $COLONY_OUTPUT
SOURCE=`$DIALOG --inputbox "$SOURCE_MESSAGE" 0 0` &&
DESTINATION=`$DIALOG --inputbox "$DEST_MESSAGE" 0 0` &&
COLONY=`select_colony` &&
ORDER=`select_order` &&
case $ORDER in
C) cat $COLONY_DIRECTORY/$COLONY |
while read BOX; do
scp -i $COLONY_KEYS/$COLONY \
-r $SOURCE \
root@${BOX}:$DESTINATION \
> $COLONY_OUTPUT/$BOX &
done
;;
S) cat $COLONY_DIRECTORY/$COLONY |
while read BOX; do
scp -i $COLONY_KEYS/$COLONY \
-r $SOURCE \
root@${BOX}:$DESTINATION
done
read -n 1 -p "Press any key to continue"
;;
esac
}
colony_execute() {
COMMAND_MESSAGE="Please enter command to be execute remotely on colony."
mkdir -p $COLONY_OUTPUT
COMMAND=`$DIALOG --inputbox "$COMMAND_MESSAGE" 0 0` &&
COLONY=`select_colony` &&
ORDER=`select_order` &&
case $ORDER in
C) cat $COLONY_DIRECTORY/$COLONY |
while read BOX; do
ssh -i $COLONY_KEYS/$COLONY \
root@${BOX} \
"$COMMAND" \
> $COLONY_OUTPUT/$BOX &
done
;;
S) cat $COLONY_DIRECTORY/$COLONY |
while read BOX; do
ssh -i $COLONY_KEYS/$COLONY \
root@${BOX} \
"$COMMAND"
done
read -n 1 -p "Press any key to continue"
;;
esac
sleep 10
}
colony_output() {
if [ -d $COLONY_OUTPUT ]; then
for FILE in `ls $COLONY_OUTPUT`; do
echo "$FILE Beginning Output"
cat $COLONY_OUTPUT/$FILE
echo "$FILE Ending Output"
done
fi
}
colony_enchantment_menu() {
while
HELP=""
C_HELP="Copy files and directories to colonys via scp"
E_HELP="Execute commands on colonys"
S_HELP="Show the output of previously execute concurrent commands and copies"
TITLE="Enchantment Menu"
COMMAND=`$DIALOG --title "$TITLE" \
--item-help \
--ok-label "Select" \
--cancel-label "Exit" \
--menu \
"$HELP" \
0 0 0 \
"C" "Copy" "$A_HELP" \
"E" "Execute" "$E_HELP" \
"S" "Show" "$S_HELP"`
do
case $COMMAND in
C) colony_copy ;;
E) colony_execute ;;
S) colony_output | view_file ;;
esac
done
}
colony_menu() {
while
read_colony_names
HELP="Administrate Multiple Boxes Simultaneously With Cabal"
A_HELP="Set up Cabals"
E_HELP="Execute scripts and copy files."
TITLE="Cabal Menu"
COMMAND=`$DIALOG --title "$TITLE" \
--item-help \
--ok-label "Select" \
--cancel-label "Exit" \
--menu \
"$HELP" \
0 0 0 \
"A" "Administration" "$A_HELP" \
"E" "Enchantment" "$E_HELP"`
do
case $COMMAND in
A) colony_admin_menu ;;
E) colony_enchantment_menu ;;
esac
done
More information about the Lunar-commits
mailing list