Key Manager Code
Status: Beta
Brought to you by:
zapman449
#!/bin/bash
################################################################################
# This file is part of key-manager.
#
# key-manager is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# key-manager is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this key-manager. If not, see <http://www.gnu.org/licenses/>.
################################################################################
#first ask questions.
echo "Where would you like the key-manager to be installed?"
echo "The key-manager, as well as some helper scripts will be placed here."
read -p 'Install Path: [/usr/local/etc] ' INSTALLPATH
echo
if [ -z "$INSTALLPATH" ]; then
INSTALLPATH=/usr/local/etc
fi
if [ ! -d $INSTALLPATH ]; then
echo "$INSTALLPATH does not exist. Would you like for me to create it?"
read -p '(y/n): [y]' RESPONSE
echo
if [ "$RESPONSE" == 'y' ]; then
mkdir -p $INSTALLPATH
elif [ -z "$RESPONSE" ]; then
mkdir -p $INSTALLPATH
else
exit 255
fi
fi
echo "Where would you like the datastore to be saved?"
read -p "Data store Path: [${INSTALLPATH}] " STATEPATH
echo
if [ -z "$STATEPATH" ]; then
STATEPATH=$INSTALLPATH
fi
if [ ! -d $STATEPATH ]; then
echo "$STATEPATH does not exist. Would you like for me to create it?"
read -p '(y/n): [y]' RESPONSE
echo
if [ "$RESPONSE" == 'y' ]; then
mkdir -p $STATEPATH
elif [ -z "$RESPONSE" ]; then
mkdir -p $STATEPATH
else
exit 255
fi
fi
echo "What filename would you like the datastore to have?"
read -p 'Data store name: [key-manager-state] ' STATENAME
echo
if [ -z "$STATENAME" ]; then
STATENAME=key-manager-state
fi
# don't create (touch) the file. The key-manager needs to do that.
chmod 755 $INSTALLPATH
if [ "$INSTALLPATH" != "$STATEPATH" ]; then
chmod 755 $STATEPATH
fi
for file in key-manager km_access_audit km_batch_copy km_batch_execute km_dot_profile_additions km_update_known_hosts pxssh.py pexpect.py ; do
cp $file $INSTALLPATH
chmod 755 $INSTALLPATH/$file
done
cd $INSTALLPATH
mv key-manager key-manager.orig
sed "s,^ keyStateFile = '.*' # NOT VALIDATED.*$, keyStateFile = '${STATEPATH}/${STATENAME}' # VALIDATED," key-manager.orig > key-manager
# Note, this line is very near the bottom of the key-manager program as of current writing.
rm key-manager.orig
echo "import py_compile
py_compile.compile(\"$INSTALLPATH/pxssh.py\")
py_compile.compile(\"$INSTALLPATH/pexpect.py\")" | python
chmod 644 *
for file in key-manager km_access_audit km_batch_copy km_batch_execute km_update_known_hosts ; do
chmod 755 $file
done