2019-03-11 20:30:16 +01:00

113 lines
3.8 KiB
Bash

#!/bin/bash
# VPN Client app for YunoHost
# Copyright (C) 2015 Julien Vaubourg <julien@vaubourg.com>
# Contribute at https://github.com/labriqueinternet/vpnclient_ynh
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source /usr/share/yunohost/helpers
source _common.sh
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
# Retrieve arguments
domain=$YNH_APP_ARG_DOMAIN
path_url=$(ynh_normalize_url_path "$YNH_APP_ARG_PATH")
app=$YNH_APP_INSTANCE_NAME
final_path="/var/www/$app"
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
ynh_print_info "Validating installation parameters..."
# Check destination directory
test ! -e "$final_path" || ynh_die "Path is already in use: ${final_path}."
# Register (book) web path
ynh_webpath_register "$app" "$domain" "$path_url"
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
ynh_print_info "Storing installation settings..."
ynh_app_setting_set "$app" domain "$domain"
ynh_app_setting_set "$app" final_path "$final_path"
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# INSTALL DEPENDENCIES
#=================================================
ynh_print_info "Installing dependencies..."
ynh_install_app_dependencies "$pkg_dependencies"
#=================================================
# DEPLOY FILES FROM PACKAGE
#=================================================
ynh_print_info "Deploy files from package..."
vpnclient_deploy_files_and_services "${domain}" "${app}" "${service_name}"
#=================================================
# RELOAD SERVICES
#=================================================
ynh_print_info "Reloading services..."
# Set default inits
# The boot order of these services are important, so they are disabled by default
# and the vpnclient service handles them.
systemctl disable openvpn
systemctl stop openvpn
systemctl restart php7.0-fpm
systemctl reload nginx
# main service
yunohost service add $service_name --description "Tunnels the internet traffic through a VPN" --need_lock
yunohost service enable $service_name
# checker service
yunohost service add $service_checker_name --description "Makes sure that the VPN service is running" --need_lock
yunohost service start $service_checker_name
yunohost service enable $service_checker_name
systemctl start $service_checker_name.timer
systemctl enable $service_checker_name.timer
#=================================================
# END OF SCRIPT
#=================================================
ynh_print_info "Installation of $app completed"