#!/bin/bash dummy_pwd=neutrinet clear cat <> neutrinet.variables done echo "vpn_client_crt=\"$vpn_client_crt\"" >> neutrinet.variables echo "vpn_client_key=\"$vpn_client_key\"" >> neutrinet.variables echo "vpn_ca_crt=\"$vpn_ca_crt\"" >> neutrinet.variables fi } modify_hosts() { # to resolve the domain properly echo "Modifying hosts..." set -x grep -q "olinux" /etc/hosts \ || echo "127.0.0.1 $domain olinux" >> /etc/hosts } set_locales() { [ "$(grep LC_ALL /etc/environment)" ] || echo 'LC_ALL="en_US.UTF-8"' >> /etc/environment source /etc/environment export LC_ALL } upgrade_system() { echo "Upgrading Debian packages..." set -x echo "deb http://repo.yunohost.org/debian jessie stable" > /etc/apt/sources.list.d/yunohost.list apt-get update -qq apt-get dist-upgrade -y } postinstall_yunohost() { echo "Launching YunoHost post-installation..." set -x yunohost tools postinstall -d $domain -p $dummy_pwd } create_yunohost_user() { echo "Creating the first YunoHost user..." set -x yunohost user create $username -f "$firstname" -l "$lastname" -m $email \ -q 0 -p $dummy_pwd } add_labriqueinternet_app_list() { echo "Adding labriqueinternet official app list for updates in the future..." yunohost app fetchlist -n labriqueinternet -u https://labriqueinter.net/apps/labriqueinternet.json } install_vpnclient() { echo "Installing the VPN client application..." set -x yunohost app install vpnclient \ --args "domain=$domain&path=/vpnadmin&server_name=vpn.neutrinet.be" } configure_vpnclient() { echo "Configuring the VPN connection..." set -x # Restrict user access to the app yunohost app addaccess vpnclient -u $username # Neutrinet related: add some VPN configuration directives cat > /etc/openvpn/client.conf.tpl < and # keep update their value on the web admin (they # are not only used for this file). client remote proto port pull nobind dev tun tun-ipv6 # keepalive 10 30 # neutrinet keepalive 10 120 comp-lzo adaptive resolv-retry infinite # Authentication by login auth-user-pass /etc/openvpn/keys/credentials # UDP only explicit-exit-notify # TLS tls-client remote-cert-tls server ns-cert-type server ca /etc/openvpn/keys/ca-server.crt cert /etc/openvpn/keys/user.crt key /etc/openvpn/keys/user.key # Logs verb 3 mute 5 status /var/log/openvpn-client.status log-append /var/log/openvpn-client.log # Routing route-ipv6 2000::/3 redirect-gateway def1 bypass-dhcp # neutrinet cipher AES-256-CBC tls-version-min 1.2 auth SHA256 topology subnet EOF # Copy certificates and keys mkdir -p /etc/openvpn/keys echo '-----BEGIN CERTIFICATE-----' > /etc/openvpn/keys/user.crt grep -Eo '"[^"]*"|[^" ]*' <<< $vpn_client_crt >> /etc/openvpn/keys/user.crt echo '-----END CERTIFICATE-----' >> /etc/openvpn/keys/user.crt echo '-----BEGIN PRIVATE KEY-----' > /etc/openvpn/keys/user.key grep -Eo '"[^"]*"|[^" ]*' <<< $vpn_client_key >> /etc/openvpn/keys/user.key echo '-----END PRIVATE KEY-----' >> /etc/openvpn/keys/user.key echo '-----BEGIN CERTIFICATE-----' > /etc/openvpn/keys/ca-server.crt grep -Eo '"[^"]*"|[^" ]*' <<< $vpn_ca_crt >> /etc/openvpn/keys/ca-server.crt echo '-----END CERTIFICATE-----' >> /etc/openvpn/keys/ca-server.crt # And credentials echo -e "$vpn_username\n$vpn_pwd" > /etc/openvpn/keys/credentials # Set rights chown admin:admins -hR /etc/openvpn/keys chmod 640 -R /etc/openvpn/keys # Configure VPN client yunohost app setting vpnclient server_name -v "vpn.neutrinet.be" yunohost app setting vpnclient server_port -v "1195" yunohost app setting vpnclient server_proto -v "udp" yunohost app setting vpnclient service_enabled -v "1" yunohost app setting vpnclient login_user -v "$vpn_username" yunohost app setting vpnclient login_passphrase -v "$vpn_pwd" yunohost app setting vpnclient ip6_net -v "$ip6_net" # Add the service to YunoHost's monitored services yunohost service add ynh-vpnclient -l /var/log/openvpn-client.log echo "Restarting OpenVPN..." systemctl restart ynh-vpnclient \ || (echo "Logs:" && cat /var/log/openvpn-client.log && exit 1) sleep 5 } install_hotspot() { echo "Installing the Hotspot application..." set -x yunohost app install hotspot --verbose \ --args "domain=$domain&path=/wifiadmin&wifi_ssid=$wifi_ssid&wifi_passphrase=$dummy_pwd&firmware_nonfree=yes" } configure_hostpot() { echo "Configuring the hotspot..." set -x # Removing the persistent Net rules to keep the Wifi device to wlan0 rm -f /etc/udev/rules.d/70-persistent-net.rules # Restrict user access to the app yunohost app addaccess hotspot -u $username # Ensure that the hotspot is activated and that the IPv6 prefix is set yunohost app setting hotspot service_enabled -v "1" yunohost app setting hotspot ip6_net -v "$ip6_net" yunohost app setting hotspot ip6_addr -v "${ip6_net}42" # Add the service to YunoHost's monitored services yunohost service add ynh-hotspot -l /var/log/syslog echo "Restarting the hotspot..." systemctl restart ynh-hotspot } install_doctorcube() { set -x echo "Installing doctorcube (this shouldn't do anything)..." yunohost app install doctorcube --verbose } install_neutrinet_ynh() { set -x echo "Installing neutrinet_ynh..." yunohost app install https://github.com/Neutrinet/neutrinet_ynh --verbose --args "domain=$domain&path=/neutrinet" } # ---------------------------------- # Optional steps # ---------------------------------- remove_dyndns_cron() { set -x yunohost dyndns update > /dev/null 2>&1 \ && echo "Removing the DynDNS cronjob..." \ || echo "No DynDNS to remove" rm -f /etc/cron.d/yunohost-dyndns } restart_api() { set -x systemctl restart yunohost-api } display_win_message() { ip6=$(ip -6 addr show tun0 | awk -F'[/ ]' '/inet/{print $6}' || echo 'ERROR') ip4=$(ip -4 addr show tun0 | awk -F'[/ ]' '/inet/{print $6}' || echo 'ERROR') cat < /dev/null 2>&1 || echo '') EOF cat <