Repository navigation
Expand file tree
/
Copy pathubuntu.install
More file actions
executable file
·137 lines (119 loc) · 4.87 KB
/
Copy pathubuntu.install
File metadata and controls
executable file
·137 lines (119 loc) · 4.87 KB
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/bin/bash
set -e
export DEBIAN_FRONTEND=noninteractive
RED='\033[0;31m'
GREEN='\033[0;32m'
CYAN='\033[0;36m'
NC='\033[0m'
if [[ "x${EUID}" != "x0" ]]; then
printf "${RED}Please run as root${NC}\n"
exit 1
fi
printf "${CYAN}Configuring Samsung Smartthings Integration${NC}\n"
export SMARTTHINGS=''
SMARTTHINGS_FILE=/opt/remote-ctrl-gsm.json
if [[ ! -f "$SMARTTHINGS_FILE" ]]; then
export SMARTTHINGS_PAGE=' '
echo
read -p "Do you need Smartthings integration [y/n]? " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
echo
read -p "Do you run smarthings-phevctl on the raspberry Pi or analog inside Outlander PHEV [y/n]? " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
export SMARTTHINGS=false
export SMARTTHINGS_PAGE=' -p 8080:8080 -p 8099:8099 '
else
read -p 'Smartthings Admin password: ' ADMIN_PASSWORD
if [[ "x${ADMIN_PASSWORD}" = "x" ]]; then
printf "${RED}Error: admin password is empty${NC}\n"
exit 1
fi
export SMARTTHINGS=true
echo '{"port":8099,"portUI":8080,"portSMS":8098,"smartthings":{"devices":[]},"smartapp":["https://graph.api.smartthings.com","https://graph-na02-useast1.api.smartthings.com","https://graph-na04-useast2.api.smartthings.com","https://graph-eu01-euwest1.api.smartthings.com","https://graph-ap02-apnortheast2.api.smartthings.com"],"users":[{"id":"0","username":"admin","password":"'"${ADMIN_PASSWORD}"'"}],"connectionType":"local"}' >/opt/remote-ctrl-gsm.json
export SMARTTHINGS_PAGE=' -p 8080:8080 -p 8099:8099 -p 8098:8098 -v /opt/remote-ctrl-gsm.json:/opt/config/remote-ctrl-gsm.json '
fi
fi
printf "${GREEN}Smartthings integration configured${NC}\n"
else
export SMARTTHINGS_PAGE=' -p 8080:8080 -p 8099:8099 -p 8098:8098 -v /opt/remote-ctrl-gsm.json:/opt/config/remote-ctrl-gsm.json '
printf "${GREEN}Smartthings integration already configured${NC}\n"
fi
printf "${CYAN}Configuring VPN secrets${NC}\n"
FILE=/opt/config.json
if [[ ! -f "$FILE" ]]; then
read -p 'PPTP username: ' USER_NAME
if [[ "x${USER_NAME}" = "x" ]]; then
printf "${RED}Error: username is empty${NC}\n"
exit 1
fi
read -s -p 'PPTP password: ' USER_PASSWORD
if [[ "x${USER_PASSWORD}" = "x" ]]; then
printf "${RED}Error: password is empty${NC}\n"
exit 1
fi
export PORT_FORWARD=''
echo
read -p "Do you need PortForward EV-REMOTE(unsecured) [y/n]? " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
export PORT_FORWARD='{\"sourceIp\":\"192.168.8.46\",\"sourcePort\":\"8080\",\"destinationPort\":7894}'
fi
if [[ "x${SMARTTHINGS}" = "xfalse" ]]; then
echo
read -p 'Smartthings-PhevCtrl IP address(RaspberryPI): ' RASPBERRY_PI_IP
echo
if [[ "x${RASPBERRY_PI_IP}" = "x" ]]; then
printf "${RED}Error: IP is empty${NC}\n"
exit 1
fi
export PORT_FORWARD_SMARTTHINGS="{\"sourceIp\":\"${RASPBERRY_PI_IP}\",\"sourcePort\":\"8080\",\"destinationPort\":8080},{\"sourceIp\":\"${RASPBERRY_PI_IP}\",\"sourcePort\":\"8099\",\"destinationPort\":8099},{\"sourceIp\":\"${RASPBERRY_PI_IP}\",\"sourcePort\":\"8098\",\"destinationPort\":8098}"
if [[ "x${PORT_FORWARD}" = "x" ]]; then
PORT_FORWARD="${PORT_FORWARD_SMARTTHINGS}"
else
PORT_FORWARD="${PORT_FORWARD},${PORT_FORWARD_SMARTTHINGS}"
fi
fi
echo "{\"users\":{\"${USER_NAME}\":{\"password\":\"${USER_PASSWORD}\",\"ip\":\"192.168.122.10\",\"forwarding\":[${PORT_FORWARD}]}}}" >/opt/config.json
chown -R $(whoami):$(whoami) /opt/config.json
printf "${GREEN}PPTP secret created${NC}\n"
else
printf "${GREEN}PPTP secret exists${NC}\n"
fi
printf "${CYAN}Starting installing Docker${NC}\n"
apt-get update && sudo apt-get install -y iptables git iptables-persistent
apt-get remove docker docker.io containerd runc
curl -sSL https://get.docker.com | bash
set +e
groupadd docker
usermod -aG docker $USER
#newgrp docker
set -e
printf "${GREEN}Docker successfully installed${NC}\n"
printf "${CYAN}Starting configuring host${NC}\n"
echo "nf_nat_pptp" >> /etc/modules
echo "ip_gre" >> /etc/modules
iptables -I FORWARD -p gre -j ACCEPT
iptables-save > /etc/iptables/rules.v4
printf "${GREEN}IpTables successfully configured${NC}"
sysctl -w net.ipv4.ip_forward=1
sysctl -w net.netfilter.nf_conntrack_helper=1
echo "net.ipv4.ip_forward=1">/etc/sysctl.conf
echo "net.netfilter.nf_conntrack_helper=1">/etc/sysctl.conf
printf "${GREEN}enabled IP forwarding${NC}\n"
printf "${CYAN}running docker image${NC}\n"
set +e
docker stop remote-ctrl
docker rm remote-ctrl
docker image prune -a -f
set -e
if [[ "x${SMARTTHINGS}" = "x" ]]; then
export SMARTTHINGS=false
fi
docker run -d --name=remote-ctrl ${SMARTTHINGS_PAGE} -e SMARTTHINGS=${SMARTTHINGS} -p 1723:1723 -p 7894:7894 -v /opt/config.json:/opt/config.json --privileged --restart=always vassio/remote-ctrl-pptp:latest
printf "${CYAN}Rebooting${NC}\n"
reboot