-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathezssh.py
71 lines (68 loc) · 1.9 KB
/
ezssh.py
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
#!/usr/bin/python3
import os
import sys
import getpass
from subprocess import call
name = 'server'
port = 22
ServerAliveInterval = 10
HostName = ''
user = getpass.getuser()
if sys.argv[1] == 'add':
name = 'server'
port = 22
ServerAliveInterval = 10
hostname = ''
user = getpass.getuser()
if len(sys.argv) > 5:
name = sys.argv[2]
port = 22
ServerAliveInterval = 10
hostname = ''
user = getpass.getuser()
for i, arg in enumerate(sys.argv):
if arg in ['-p', '--port']:
port = sys.argv[i+1]
elif arg in ['-n', '--name']:
name = sys.argv[i+1]
elif arg in ['-h', '--hostname']:
hostname = sys.argv[i+1]
else:
name = input('Name on this server: ')
if (port := input('Ssh port (default 22): ')) == '':
port = 22
hostname = input('Server address: ')
ServerAliveInterval = 10
os.system(f'bash {os.path.dirname(os.path.realpath(__file__))}/ezssh_add.sh {name} {user} {port} {hostname} {ServerAliveInterval}')
call(['ssh-copy-id', name])
os.system(f'\
cd ~/.bin/ezssh/syncrepo && \
cp ~/.ssh/config . && \
git pull origin master && \
git add config && \
git commit -m "added new server" && \
git push origin master --force && \
rm config && \
cd -')
elif sys.argv[1] == 'list':
os.system(ln )
os.system('python3 lssv/lssv')
elif sys.argv[1] == 'init':
gitrepo = input('Git remote address: ')
os.system(f'\
rm -rf ~/.bin/ezssh/syncrepo && \
mkdir ~/.bin/ezssh/syncrepo && \
cd ~/.bin/ezssh/syncrepo && \
git init && \
git remote add origin {gitrepo} && \
git pull origin master || true && \
cp ~/.ssh/config . && \
git add config && \
git commit -m "init" && \
git push origin master --force && \
rm config && \
cd -')
elif sys.argv[1] == 'update':
os.system(f'cd ~/.bin/ezssh/syncrepo && git pull origin master && cp ~/.ssh/config . && git add config && git commit -m "added new server" && git push origin master --force && rm config && cd -')
else:
call(['ssh', sys.argv[1]])