-
Notifications
You must be signed in to change notification settings - Fork 3
/
copyenv
executable file
·70 lines (56 loc) · 1.43 KB
/
copyenv
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/bash
# This script will copy my (and may be even yours) environment to remote host.
PROGNAME=$(basename $0)
AKEYS_FILE="~/.ssh/authorized_keys"
AKEYS_COPY="NO"
print_usage() {
echo "Usage: $PROGNAME [-A] user@hostname ..."
echo " -A enables authorized_keys copy (with overwrite), default: $AKEYS_COPY"
}
while getopts "hA" option; do
case $option in
h)
print_usage
exit 0
;;
A)
AKEYS_COPY="YES"
AKEYS_CONTENT=$(cat $AKEY_FILE)
;;
?)
print_usage
exit 2
;;
esac
done
shift $(($OPTIND - 1))
if [ -z "$*" ]; then
echo "Specify at least one hostname."
exit 2
fi
cd ~
for HOSTNAME in $*; do
host=`echo $HOSTNAME | cut -f1 -d':'`
port=`echo $HOSTNAME | cut -f2 -d':' -s`
if [ -z $port ]; then
port="22"
fi
if [ -z $host ]; then
echo "No host was found in '$HOSTNAME'!"
exit 2
fi
echo "Copying files to $HOSTNAME..."
if [ "x$AKEYS_COPY" = "xYES" ]; then
echo "Copying $AKEYS_FILE..."
if [ $? -eq 0 -a ! -z "$AKEYS_CONTENT" ]; then
ssh -p $port $host "mkdir -p ~/.ssh; chmod 700 .ssh; echo " $AKEYS_CONTENT " > $AKEYS_FILE; chmod 600 $AKEYS_FILE"
else
echo "$AKEYS_PATH wasn't copied - it is empty or unreadable. Skipping..."
fi
fi
for i in bin .config .vimrc .tmux.conf .screenrc .profile .bashrc .gitconfig .hgrc .zshrc .zsh; do
if [ -r $i ];then
scp -q -C -P $port -r "$i" $host:
fi
done
done