init
This commit is contained in:
3
CHANGELOG.md
Normal file
3
CHANGELOG.md
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# 0.0.1
|
||||||
|
|
||||||
|
Start project
|
||||||
15
Dockerfile
Executable file
15
Dockerfile
Executable file
@@ -0,0 +1,15 @@
|
|||||||
|
ARG BUILD_FROM
|
||||||
|
FROM $BUILD_FROM
|
||||||
|
|
||||||
|
ENV LANG C.UTF-8
|
||||||
|
|
||||||
|
# Install requirements for add-on
|
||||||
|
RUN apk --no-cache --no-progress upgrade && \
|
||||||
|
apk --no-cache --no-progress add jq openvpn \
|
||||||
|
rm -rf /tmp/*
|
||||||
|
|
||||||
|
# Copy data for add-on
|
||||||
|
COPY run.sh /
|
||||||
|
RUN chmod a+x /run.sh
|
||||||
|
|
||||||
|
CMD [ "/run.sh" ]
|
||||||
11
README.md
Normal file
11
README.md
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
# OpenVPN Client Add-On
|
||||||
|
|
||||||
|
This is a Add-On for [Home Assistant](https://www.home-assistant.io) which enables to tunnel the communication of your Home Assistant server with the world through a VPN connection.
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
Move your client.ovpn file to hassio/share folder in your server.
|
||||||
|
|
||||||
|
Just navigate to the Hass.io panel in your Home Assistant frontend and add the OpenVPN Client add-on repository: https://github.com/Ailme/homeassistant-openvpn-client-addon
|
||||||
|
|
||||||
|
Then, scroll down and locate the OpenVPN Client Hass.io Add-Ons section. Click on OpenVPN Client, then INSTALL and Start.
|
||||||
19
config.json
Executable file
19
config.json
Executable file
@@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"name": "OpenVPN Client",
|
||||||
|
"version": "0.0.1",
|
||||||
|
"slug": "openvpn_client",
|
||||||
|
"description": "OpenVPN Client",
|
||||||
|
"url": "https://github.com/Ailme/homeassistant-openvpn-client-addon",
|
||||||
|
"arch": ["armhf", "armv7", "aarch64", "amd64", "i386"],
|
||||||
|
"startup": "application",
|
||||||
|
"boot": "auto",
|
||||||
|
"host_network": true,
|
||||||
|
"privileged": ["NET_ADMIN"],
|
||||||
|
"options": {
|
||||||
|
"ovpnfile": "client.ovpn"
|
||||||
|
},
|
||||||
|
"schema": {
|
||||||
|
"ovpnfile": "str"
|
||||||
|
},
|
||||||
|
"map" : ["share:rw"]
|
||||||
|
}
|
||||||
6
repository.json
Normal file
6
repository.json
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"name": "OpenVPN Client",
|
||||||
|
"url": "https://github.com/Ailme/homeassistant-openvpn-client",
|
||||||
|
"maintainer": "Alexandr Tumaykin <alexandrtumaykin@gmail.com>"
|
||||||
|
}
|
||||||
|
|
||||||
91
run.sh
Executable file
91
run.sh
Executable file
@@ -0,0 +1,91 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set +u
|
||||||
|
|
||||||
|
CONFIG_PATH=/data/options.json
|
||||||
|
|
||||||
|
OVPNFILE="$(jq --raw-output '.ovpnfile' $CONFIG_PATH)"
|
||||||
|
OPENVPN_CONFIG=/share/${OVPNFILE}
|
||||||
|
|
||||||
|
########################################################################################################################
|
||||||
|
# Initialize the tun interface for OpenVPN if not already available
|
||||||
|
# Arguments:
|
||||||
|
# None
|
||||||
|
# Returns:
|
||||||
|
# None
|
||||||
|
########################################################################################################################
|
||||||
|
function init_tun_interface(){
|
||||||
|
# create the tunnel for the openvpn client
|
||||||
|
|
||||||
|
mkdir -p /dev/net
|
||||||
|
if [ ! -c /dev/net/tun ]; then
|
||||||
|
mknod /dev/net/tun c 10 200
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
########################################################################################################################
|
||||||
|
# Check if all required files are available.
|
||||||
|
# Globals:
|
||||||
|
# REQUIRED_FILES
|
||||||
|
# STORAGE_LOCATION
|
||||||
|
# Arguments:
|
||||||
|
# None
|
||||||
|
# Returns:
|
||||||
|
# 0 if all files are available and 1 otherwise
|
||||||
|
########################################################################################################################
|
||||||
|
function check_files_available(){
|
||||||
|
failed=0
|
||||||
|
|
||||||
|
if [[ ! -f ${OPENVPN_CONFIG} ]]
|
||||||
|
then
|
||||||
|
echo "File ${OPENVPN_CONFIG} not found"
|
||||||
|
failed=1
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ ${failed} == 0 ]]
|
||||||
|
then
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
########################################################################################################################
|
||||||
|
# Wait until the user has uploaded all required certificates and keys in order to setup the VPN connection.
|
||||||
|
# Globals:
|
||||||
|
# REQUIRED_FILES
|
||||||
|
# CLIENT_CONFIG_LOCATION
|
||||||
|
# Arguments:
|
||||||
|
# None
|
||||||
|
# Returns:
|
||||||
|
# None
|
||||||
|
########################################################################################################################
|
||||||
|
function wait_configuration(){
|
||||||
|
|
||||||
|
echo "Wait until the user uploads the files."
|
||||||
|
# therefore, wait until the user upload the required certification files
|
||||||
|
while true; do
|
||||||
|
|
||||||
|
check_files_available
|
||||||
|
|
||||||
|
if [[ $? == 0 ]]
|
||||||
|
then
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
|
||||||
|
sleep 5
|
||||||
|
done
|
||||||
|
echo "All files available!"
|
||||||
|
}
|
||||||
|
|
||||||
|
init_tun_interface
|
||||||
|
|
||||||
|
# wait until the user uploaded the configuration files
|
||||||
|
wait_configuration
|
||||||
|
|
||||||
|
echo "Setup the VPN connection with the following OpenVPN configuration."
|
||||||
|
|
||||||
|
# try to connect to the server using the used defined configuration
|
||||||
|
openvpn --config ${OPENVPN_CONFIG}
|
||||||
Reference in New Issue
Block a user