moved non functional deploy code to sshbackup_v0.3
This commit is contained in:
parent
63e0109b16
commit
4de41f8a2d
78
deploy.sh
78
deploy.sh
|
@ -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
|
||||
|
|
@ -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 ****
|
||||
|
||||
|
|
Reference in New Issue