-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup_host
executable file
·86 lines (76 loc) · 2.56 KB
/
setup_host
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
#!/bin/ksh
#sshd: https:/github.com/vedetta-com/vedetta/blob/master/src/usr/local/share/doc/vedetta/OpenSSH_Principals.md
set -o errexit
set -o nounset
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/root/Bin
BACKUPDIR="/root/Backups/ssh"
SSHDIR="/etc/ssh"
tmpdir=$(mktemp -d)
appdir=$(pwd)
hostname=$(hostname -s)
domainname=$(hostname | sed "s/$(hostname -s).//")
egressinterface=$(ifconfig egress | cut -d : -f1 | head -n1)
if [ "$hostname" = "cyberanarkhia" ];then
routerid=$(ifconfig "${egressinterface}" | grep inet |grep -v inet6 | cut -d ' ' -f2)
else
routerid=$(ifconfig vether0 | grep inet |grep -v inet6 | cut -d ' ' -f2)
fi
publicip=$(ifconfig "${egressinterface}" | grep inet |grep -v inet6 | cut -d ' ' -f2)
UID=$(id -u)
if [[ $UID -ne 0 ]]; then
print $0 "you've got to run $0 as UID=0 \n"
exit 1
fi
function error_exit {
echo "${app}: ${1:-"Unknown Error"}" 1>&2
exit 1
}
function pidof {
ps axc -o pid,command | awk "\$2~/^`echo $1`\$/ {print \$1}"
}
if [[ ! -d "$BACKUPDIR" ]]; then
mkdir "$BACKUPDIR"
fi
install -o root -g wheel -m 0750 src/etc/ssh/sshd_config /etc/ssh
continue=false
for i in $(ifconfig gre |awk '{print $1}' | grep gre*[0-9] | cut -d : -f1); do
ifconfig "${i}" down
done
ifconfig gre0 up
echo "waiting for network.."
while [[ "${continue}" == false ]]; do
[[ "cyberanarkhia.telecom.lobby." == $(dig A web.telecom.lobby +short @172.16.17.106 | head -n 1) ]] && continue=true
done
cd "$SSHDIR"
if [[ ! -e ssh_host_ed25519_key-cert.pub ]]; then
wget "http://web.telecom.lobby/CA_transfer/$hostname.$domainname/ssh_host_ed25519_key-cert.pub"
else
rm -rf ssh_host_ed25519_key-cert.pub
wget "http://web.telecom.lobby/CA_transfer/$hostname.$domainname/ssh_host_ed25519_key-cert.pub"
fi
cd ca
if [[ ! -e ssh_ca_ed25519.pub ]]; then
wget http://web.telecom.lobby/CA_transfer/ssh_ca_ed25519.pub
else
rm -rf ssh_ca_ed25519.pub
wget http://web.telecom.lobby/CA_transfer/ssh_ca_ed25519.pub
fi
cd "$SSHDIR"
if [[ ! -d principals/ ]]; then
mkdir -m 750 principals/
else
rm -rf principals/
mkdir -m 750 principals/
fi
echo "wheel" > principals/taglio
chmod 0440 principals/taglio
cd "$SSHDIR"
sed -i "s/\/ROUTERID\//$routerid/g" sshd_config
sed -i "s/\/PUBLICIP\//$publicip/g" sshd_config
if [[ -e "$SSHDIR/ssh_host_rsa_key.pub" ]]; then
mv {ssh_host_dsa_key,ssh_host_dsa_key.pub,ssh_host_ecdsa_key,ssh_host_ecdsa_key.pub,ssh_host_rsa_key,ssh_host_rsa_key.pub} "$BACKUPDIR"
fi
rcctl restart sshd || error_exit "$LINENO: ERROR: sshd failed."
for i in $(ifconfig gre |awk '{print $1}' | grep gre*[0-9] | cut -d : -f1); do
ifconfig "${i}" up
done