commit a51ca08b1018c31d28ba6d2677047559aed4038d Author: Alexandr Tumaykin Date: Sat Jan 11 21:14:13 2020 +0300 init diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..1e5ec76 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,3 @@ +# 0.0.1 + +Start project \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100755 index 0000000..2adb674 --- /dev/null +++ b/Dockerfile @@ -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" ] diff --git a/README.md b/README.md new file mode 100644 index 0000000..64491a7 --- /dev/null +++ b/README.md @@ -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. \ No newline at end of file diff --git a/config.json b/config.json new file mode 100755 index 0000000..08b0591 --- /dev/null +++ b/config.json @@ -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"] +} diff --git a/repository.json b/repository.json new file mode 100644 index 0000000..e6cdc99 --- /dev/null +++ b/repository.json @@ -0,0 +1,6 @@ +{ + "name": "OpenVPN Client", + "url": "https://github.com/Ailme/homeassistant-openvpn-client", + "maintainer": "Alexandr Tumaykin " + } + \ No newline at end of file diff --git a/run.sh b/run.sh new file mode 100755 index 0000000..e7effbc --- /dev/null +++ b/run.sh @@ -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} \ No newline at end of file