-
Notifications
You must be signed in to change notification settings - Fork 4
/
rc.local
executable file
·65 lines (56 loc) · 2.24 KB
/
rc.local
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
#!/usr/bin/env bash
clean_env() {
systemctl stop NetworkManager 2>/dev/null
systemctl stop firewalld 2>/dev/null
iptables -F 2>/dev/null
nft flush ruleset 2>/dev/null
# setenforce 0 2>/dev/null
}
set_ip() {
if=$(ip link | grep -v 'lo:' | grep -oE '^ *[0-9]+:[[:blank:]]+[0-9a-zA-Z]+' | head -1 | grep -oE '[^[:blank:]]+$')
mac=$(ip link | grep -A 1 "${if}:" | grep -oE 'ether [^[:blank:]]+' | grep -oE '[^[:blank:]]+$')
field1=$(echo $(( 0x$(echo $mac | grep -Eo '[0-9a-zA-Z]{2}:[0-9a-zA-Z]{2}$' | grep -Eo '^[0-9a-zA-Z]{2}') )))
field2=$(echo $(( 0x$(echo $mac | grep -Eo '[0-9a-zA-Z]{2}$') )))
addr="10.10.${field1}.${field2}/8"
ip addr flush dev $if
ip addr add $addr dev $if
ip link set $if up
ip route replace default via 10.0.0.1 dev $if
ip link set lo up
}
ssh_login() {
user="root"
# passwd -d $user
sed -ri."" 's/^ *#* *(PermitEmptyPasswords).*/\1 yes/' /etc/ssh/sshd_config
sed -ri."" 's/^ *#* *(PermitRootLogin).*/\1 yes/' /etc/ssh/sshd_config
sed -ri."" 's/^ *#* *(UseDNS).*/\1 no/' /etc/ssh/sshd_config
systemctl restart sshd \
|| service sshd restart \
|| rc-service sshd restart \
|| systemctl restart ssh \
|| service ssh restart \
|| rc-service sshd restart \
|| rc-service ssh restart
}
set_pub_key() {
PUBKEY="ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDk/CSaXip7wwa2xsDaZm6eKmyET91fI28ufdVMZvsym7s8y0QVxdO16t9IlbH9ognp/zLETJSl1MxoEz1R2I9rE+R0eraeBT/LIsF5nIyMBZ/Zk5SRNrociW+9w4AxWZHcugGznVFIxbeC2Ja/q4xxDWRbtPB5nv2R92eTwZZ6TovxjmSGXUcBVRVFgvE0k7KgdRCGK9q0JOUZMT2d3fs8FkOJPeSznnawaUiLlLYFsY1R4F/+0r+zlbDgKrBmnjv1GYKohBcFMsw10m08cU3UjJym67R0I2NKMAFhWBZAh4IGMIfg7w3Ua2K4nHQwlcnOWuZ7jzll/nYRmrS9T3LF root@718f9c9841a8"
sshpath="/root/.ssh"
mkdir -p $sshpath
echo $PUBKEY > ${sshpath}/authorized_keys
chmod -R 0600 $sshpath
}
start_ttrexec_daemon() {
cmd="ttrexec-daemon"
cmd_path="/usr/local/bin/${cmd}"
($cmd_path -a 0.0.0.0 -p 22000 2>/tmp/${cmd}_stderr.log >/tmp/${cmd}_stdout.log) &
}
start_hawk_agent() {
cmd="hawk-agent"
(bash -x /usr/local/bin/${cmd}/tool/start.sh 2>/tmp/${cmd}_stderr.log >/tmp/${cmd}_stdout.log) &
}
clean_env
set_ip
ssh_login
set_pub_key
start_ttrexec_daemon
start_hawk_agent