-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsetupssh
More file actions
executable file
·33 lines (33 loc) · 1.97 KB
/
Copy pathsetupssh
File metadata and controls
executable file
·33 lines (33 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/bin/bash
function setupssh() {
continueon=y
if [ -e ~/migration/migstuff/id_rsa ] && [[ $(migrun whoami 2>/dev/null) -eq $(head -n 1 ~/migration/migstuff/source.txt 2>/dev/null | cut -d '@' -f1) ]] && [[ $(head -n 1 ~/migration/migstuff/source.txt 2>/dev/null | cut -d '@' -f1) ]]; then #if a source server is already set up
echo "ssh is already set for $(head -n 1 ~/migration/migstuff/source.txt 2>/dev/null | cut -d '@' -f1). would you like to setup for a diferent server?"
read -p "type y or n > " continueon
fi #end if a source server is already set up
if [[ ! $(echo $continueon | grep y) ]]; then # if they diddnt say yes
echo sounds good, you are all set you run commands on $(head -n 1 ~/migration/migstuff/source.txt)
else # if they did say yes
sshline=$1
if [[ $1 == '' ]]; then # if no ssh line was provided
read -p "provide (user@ip). > " sshline
fi # end if no ssh line was provided
if [[ $(ls ~/migration/migstuff/id_rsa 2>/dev/null) ]]; then #if key already exists
echo key exists, continuing with existing key
else #if key doesnt exist
mkdir -p ~/migration/{migstuff,files,dbs}
ssh-keygen -f ~/migration/migstuff/id_rsa -t rsa -N '' >/dev/null
echo created key
fi #end if key already exists
echo $sshline >~/migration/migstuff/source.txt
ifile=$(ls ~/migration/migstuff/id_rsa)
sourcessh="ssh -i $ifile $sshline"
ssh-copy-id -i ~/migration/migstuff/id_rsa.pub $sshline >/dev/null
if [ ! $? -eq 0 ]; then #end key was coppied to the source server
echo "could not coppy ssh key to remote server we ran
ssh-copy-id -i ~/migration/migstuff/id_rsa.pub $sshline
" >~/migration/errorlog
fi #end if key was coppied to the source server
fi # end if they diddnt say yes
}
setupssh