-
Notifications
You must be signed in to change notification settings - Fork 3
/
fast-remote
executable file
·99 lines (87 loc) · 2.2 KB
/
fast-remote
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/bin/bash
menu(){
clear
echo -e '======================================================= \033[33;1m Select Server \033[m '
IFS_OLD=$IFS
IFS=";"
while read id ip name color user
do
shopt -s extglob
echo -e $id '\033['$color';1m'$name'\033[m' - $user@$ip
done < $FAST_REMOTE/servers.properties
echo -e '======================================================== \033[33;1m More Options \033[m '
echo -e 'q - to quit'
IFS=$IFS_OLD
}
install(){
define_bash_file
add_to_bash_file 'export FAST_REMOTE='$PWD;
add_to_bash_file 'export PATH=$PATH:$FAST_REMOTE'
chmod +x $0
echo "Installation successfully"
source_bash_file_msg
echo "usage: fast-remote --help"
}
source_bash_file_msg(){
echo "Run command: 'source "$HOME/$bash_file"' or logout/login"
}
add_to_bash_file(){
echo $1 >> $HOME/$bash_file;
}
define_default_user(){
define_bash_file
echo "Set default user name"
read username
add_to_bash_file 'export DEFAULT_USER_FAST_REMOTE='$username
source_bash_file_msg
}
define_bash_file(){
bash_file=".bashrc";
if [ `uname` = "Darwin" ] ; then
bash_file=".bash_profile";
fi
}
help_msg(){
echo -e "Usage:\n"
echo -e "'fast-remote install' to install"
echo -e "'fast-remote set_user' to define default user connect"
echo -e "'fast-remote' to connect ssh (ssh SERVER)"
echo -e "'fast-remote /home/user/file.tar' to transfer file scp (scp file SERVER:/HOME_DIR)\n"
}
start(){
menu
read option
user=`echo $option | cut -d ' ' -f 2`
option=`echo $option | cut -d ' ' -f 1`
server=`cat $FAST_REMOTE/servers.properties | egrep -i "^$option;"`
if [ $option = "q" ]; then
exit
elif [ -z "$server" ]; then
echo "Ivalid option"
else
if [ $user = $option ]; then
user=$DEFAULT_USER_FAST_REMOTE
if [ -z $DEFAULT_USER_FAST_REMOTE ]; then
user=$USER
fi
user_configured=`echo $server | cut -d \; -f 5`
if [ $user_configured ]; then
user=$user_configured
fi
fi
ip=`echo $server | cut -d \; -f 2`
if [ -z $1 ]; then
ssh $user@$ip
start
fi
scp $1 $user@$ip:.
fi
exit
}
case "$1" in
install) install;;
set_user) define_default_user;;
--help) help_msg;;
-h) help_msg;;
*) start $1;;
esac