david/sshbackup
david
/
sshbackup
Archived
1
0
Fork 0

moved non functional deploy code to sshbackup_v0.3

This commit is contained in:
david 2013-04-26 11:48:10 +02:00
parent 63e0109b16
commit 4de41f8a2d
2 changed files with 75 additions and 78 deletions

View File

@ -1,78 +0,0 @@
#!/bin/bash
# deploy remote config
# sshbackup
# basic config parameters
backupuser="sshbackup"
publickey="/home/david/.ssh/id_rsa.pub"
publickey=$(cat $publickey)
# ask if to continue when run as root
if [ $USER == "root" ]; then
echo "there is no need to run this script with root privileges."
echo "however, it is possible if you wish to do so anyway."
echo -e "do you want to continue as root [y/n]? \c"
read answer
if [ $answer == "y" ] || [ $answer == "Y" ]; then
:
else
exit 1
fi
fi
answer=""
echo -e "remote admin [$USER]: \c"
read answer
if [ -z $answer ]; then
remoteadmin=$USER
else
remoteadmin=$answer
fi
answer=""
echo -e "backupuser [$backupuser]: \c"
read answer
if [ -z $answer ]; then
:
else
backupuser=$answer
fi
answer=""
while [ -z $remotemachine ]; do
if [ -z $1 ]; then
echo -e "remote ip or hostname: \c"
read answer
remotemachine=$answer
else
remotemachine=$1
fi
done
answer=""
cat /etc/passwd | grep -e ^$backupuser
if [ \$? -eq 0 ]; then
echo "error: $backupuser already exists on $remotemachine"
echo "info: aborting mission."
exit 1
else
echo "info: attempting to create user: $backupuser"
useradd -m -d /home/$backupuser $backupuser
if [ \$? -eq 0 ]; then
mkdir /home/$backupuser/.ssh
echo $publickey >> /home/$backupuser/.ssh/authorized_keys
if [ \$? -eq 0 ]; then
echo "info: user created and public key added to authorized hosts."
else
echo "error: user created but adding the public key to authorized hosts returned a non-zero value. aborting mission."
fi
else
echo "error: useradd returned a non-zero value. aborting mission."
exit 1
fi
fi
exit

View File

@ -87,6 +87,81 @@ preflight()
}
deploy()
{
backupuser="sshbackup"
publickey="/home/david/.ssh/id_rsa.pub"
publickey=$(cat $publickey)
# ask if to continue when run as root
if [ $USER == "root" ]; then
echo "there is no need to run this script with root privileges."
echo "however, it is possible if you wish to do so anyway."
echo -e "do you want to continue as root [y/n]? \c"
read answer
if [ $answer == "y" ] || [ $answer == "Y" ]; then
:
else
exit 1
fi
fi
answer=""
echo -e "remote admin [$USER]: \c"
read answer
if [ -z $answer ]; then
remoteadmin=$USER
else
remoteadmin=$answer
fi
answer=""
echo -e "backupuser [$backupuser]: \c"
read answer
if [ -z $answer ]; then
:
else
backupuser=$answer
fi
answer=""
while [ -z $remotemachine ]; do
if [ -z $1 ]; then
echo -e "remote ip or hostname: \c"
read answer
remotemachine=$answer
else
remotemachine=$1
fi
done
answer=""
cat /etc/passwd | grep -e ^$backupuser
if [ \$? -eq 0 ]; then
echo "error: $backupuser already exists on $remotemachine"
echo "info: aborting mission."
exit 1
else
echo "info: attempting to create user: $backupuser"
useradd -m -d /home/$backupuser $backupuser
if [ \$? -eq 0 ]; then
mkdir /home/$backupuser/.ssh
echo $publickey >> /home/$backupuser/.ssh/authorized_keys
if [ \$? -eq 0 ]; then
echo "info: user created and public key added to authorized hosts."
else
echo "error: user created but adding the public key to authorized hosts returned a non-zero value. aborting mission."
fi
else
echo "error: useradd returned a non-zero value. aborting mission."
exit 1
fi
fi
}
# **** start of script ****