forked from sashka/tools
-
Notifications
You must be signed in to change notification settings - Fork 1
/
copyenv
executable file
·79 lines (68 loc) · 1.58 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
71
72
73
74
75
76
77
78
#!/bin/bash
# this script gonna copy my environment to remote server
PROGNAME=$(basename $0)
AKEY_TMPL="~/.ssh/authorized_keys"
AKEY_FILE=$(eval echo "$AKEY_TMPL")
DEFAULT_AUTHCOPY=NO
RHOST=""
print_usage() {
echo "Usage: $PROGNAME [-A] -H hostname"
echo ""
echo "-A enables authorized_keys copy (with overwrite), default: $DEFAULT_AUTHCOPY"
echo ""
echo "-H sets the hostname where should data be copied to"
}
print_help() {
echo "$PROGNAME"
echo ""
print_usage
echo ""
echo "This script will copy my (and may be even your) environment to remote host"
}
if [ -z "$1" ];then
echo "no params were specified, use \"$0 -h\" to obtain help"
echo ""
print_help
exit 2
fi
AUTHCOPY=$DEFAULT_AUTHCOPY
while getopts ":hAH:" Option; do
case $Option in
h)
print_help
exit $STATE_UNKNOWN
;;
H)
RHOST=${OPTARG}
;;
A)
AUTHCOPY="YES"
;;
*)
print_help
exit 2
;;
esac
done
shift $(($OPTIND - 1))
if [ "x$RHOST" = "x" ];then
echo "hostname is not set!"
print_help
exit 2
fi
akey=""
cd ~
if [ "x$AUTHCOPY" = "xYES" ];then
echo "copying $AKEY_FILE"
akey=$(cat $AKEY_FILE)
if [ $? -eq 0 -a ! -z "$akey" ];then
ssh "$RHOST" "mkdir -p ~/.ssh;chmod 700 .ssh;echo "$akey" > $AKEY_TMPL;chmod 600 $AKEY_TMPL"
else
echo "$AKEY_FILE wasn't copyied - empty/unable to read, skipping"
fi
fi
for i in bin .vimrc .vim .screenrc .profile .bash_profile .bashrc .gitconfig .hgrc .tmux.conf ;do
if [ -r $i ];then
scp -r "$i" "$RHOST":
fi
done