Improve upgrade script

This commit is contained in:
Julien VAUBOURG 2015-07-24 19:22:07 +02:00
parent 6d4e04f2fa
commit ad2697c0f0
4 changed files with 56 additions and 225 deletions

View File

@ -1,85 +0,0 @@
{
"name": "VPN Client",
"id": "vpnclient",
"description": {
"en": "VPN Client",
"fr": "Client VPN"
},
"license": "AGPL-3",
"developer": {
"name": "Julien Vaubourg",
"email": "julien@vaubourg.com",
"url": "http://julien.vaubourg.com"
},
"multi_instance": "false",
"arguments": {
"install" : [
{
"name": "domain",
"ask": {
"en": "Choose a domain for the web administration",
"fr": "Choisissez un domaine pour l'administration web"
},
"example": "domain.org"
},
{
"name": "path",
"ask": {
"en": "Choose a path for the web administration",
"fr": "Choissez un chemin pour l'administration web"
},
"example": "/vpnadmin",
"default": "/vpnadmin"
},
{
"name": "server_name",
"ask": {
"en": "Select a VPN server",
"fr": "Sélectionnez un serveur VPN"
},
"example": "access.ldn-fai.net",
"default": "access.ldn-fai.net"
},
{
"name": "crt_client",
"ask": {
"en": "Select the local path of your client certificate (will be moved ; leave empty if not necessary or if you want to upload it later through the web admin)",
"fr": "Sélectionnez le chemin local de votre certificat client (le fichier sera déplacé ; laisser vide si non-nécessaire ou que vous souhaitez le téléverser plus tard via l'admin web)"
},
"example": "/tmp/user.crt"
},
{
"name": "crt_client_key",
"ask": {
"en": "Select the local path of your client certificate key (will be moved ; leave empty if not necessary or if you want to upload it later through the web admin)",
"fr": "Sélectionnez le chemin local de la clé de votre certificat client (le fichier sera déplacé ; laisser vide si non-nécessaire ou que vous souhaitez le téléverser plus tard via l'admin web)"
},
"example": "/tmp/user.key"
},
{
"name": "crt_server_ca",
"ask": {
"en": "Select the local path of the server CA (will be moved ; leave empty for uploading it later through the web admin)",
"fr": "Sélectionnez le chemin local du CA du serveur (le fichier sera déplacé ; laisser vide pour le téléverser plus tard via l'admin web)"
},
"example": "/tmp/ca-server.crt"
},
{
"name": "credentials_user",
"ask": {
"en": "Select your VPN username (leave empty if not necessary)",
"fr": "Sélectionnez votre nom d'utilisateur VPN (laisser vide si non-nécessaire)"
},
"example": "michu"
},
{
"name": "credentials_passphrase",
"ask": {
"en": "Select your VPN password (leave empty if not necessary)",
"fr": "Sélectionnez votre mot de passe VPN (laisser vide si non-nécessaire)"
},
"example": "XVCwSbDkxnqQ"
}
]
}
}

View File

@ -17,66 +17,28 @@
# 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/>.
# This is an upgrade?
upgrade=$([ "$VPNCLIENT_UPGRADE" == 1 ] && echo true || echo false)
# Retrieve arguments
domain=${1}
url_path=${2}
server_name=${3}
##
## These arguments are optional but YunoHost is not yet able to handle them with the web installer
## See manifest.json.options
##
#
#crt_client_path=${4}
#crt_client_key_path=${5}
#crt_server_ca_path=${6}
#login_user=${7}
#login_passphrase=${8}
if ! $upgrade; then
# Check arguments
if [ -z "${server_name}" ]; then
echo "ERROR: You need a VPN server name" >&2
exit 1
fi
# Check arguments
if [ -z "${server_name}" ]; then
echo "ERROR: You need a VPN server name" >&2
exit 1
fi
# Check domain/path availability
sudo yunohost app checkurl ${domain}${url_path} -a vpnclient
if [ ! $? -eq 0 ]; then
exit 1
fi
#if [ \( -z "${crt_client_path}" -a ! -z "${crt_client_key_path}" \)\
# -o \( ! -z "${crt_client_path}" -a -z "${crt_client_key_path}" \) ]; then
#
# echo "ERROR: A client certificate is needed when you suggest a key (or vice versa)" >&2
# exit 1
#fi
#
#if [ ! -z "${crt_client_key_path}" -a -z "${crt_server_ca_path}" ]; then
# echo "ERROR: If you can suggest a local path for the client certificates, you probably can suggest one other for the (mandatory) CA server" >&2
# exit 1
#fi
#
#if [ \( -z "${login_user}" -a ! -z "${login_passphrase}" \)\
# -o \( ! -z "${login_user}" -a -z "${login_passphrase}" \) ]; then
#
# echo "ERROR: A login password is needed when you suggest a login user (or vice versa)" >&2
# exit 1
#fi
#
#if [ ! -z "${crt_client_path}" -a ! -f "${crt_client_path}" ]; then
# echo "ERROR: The local path <${crt_client_path}> does not exist" >&2
# exit 1
#fi
#
#if [ ! -z "${crt_client_key_path}" -a ! -f "${crt_client_key_path}" ]; then
# echo "ERROR: The local path <${crt_client_key_path}> does not exist" >&2
# exit 1
#fi
#
#if [ ! -z "${crt_server_ca_path}" -a ! -f "${crt_server_ca_path}" ]; then
# echo "ERROR: The local path <${crt_server_ca_path}> does not exist" >&2
# exit 1
#fi
# Check domain/path availability
sudo yunohost app checkurl ${domain}${url_path} -a vpnclient
if [ ! $? -eq 0 ]; then
exit 1
fi
# Install packages
@ -90,15 +52,19 @@ if [ $? -ne 0 ]; then
sudo apt-get --assume-yes --force-yes install ${packages}
fi
# Save arguments
sudo yunohost app setting vpnclient service_enabled -v 1
sudo yunohost app setting vpnclient server_name -v "${server_name}"
sudo yunohost app setting vpnclient server_port -v 1194
sudo yunohost app setting vpnclient server_proto -v udp
sudo yunohost app setting vpnclient ip6_addr -v none
sudo yunohost app setting vpnclient ip6_net -v none
sudo yunohost app setting vpnclient login_user -v "${login_user}"
sudo yunohost app setting vpnclient login_passphrase -v "${login_passphrase}"
if ! $upgrade; then
# Save arguments
sudo yunohost app setting vpnclient service_enabled -v 1
sudo yunohost app setting vpnclient server_name -v "${server_name}"
sudo yunohost app setting vpnclient server_port -v 1194
sudo yunohost app setting vpnclient server_proto -v udp
sudo yunohost app setting vpnclient ip6_addr -v none
sudo yunohost app setting vpnclient ip6_net -v none
sudo yunohost app setting vpnclient login_user -v "${login_user}"
sudo yunohost app setting vpnclient login_passphrase -v "${login_passphrase}"
fi
# Install IPv6 scripts
sudo install -o root -g root -m 0755 ../conf/ipv6_expanded /usr/local/bin/
@ -126,26 +92,6 @@ sudo find /var/www/vpnadmin/ -type d -exec chmod +x {} \;
sudo mkdir -pm 0770 /etc/openvpn/keys/
sudo chown root:admins /etc/openvpn/keys/
#[ ! -z "${crt_client_path}" ] &&\
# sudo install -b -o root -g admins -m 0660 "${crt_client_path}" /etc/openvpn/keys/user.crt
#
#[ ! -z "${crt_client_key_path}" ] &&\
# sudo install -b -o root -g admins -m 0660 "${crt_client_key_path}" /etc/openvpn/keys/user.key
#
#[ ! -z "${crt_server_ca_path}" ] &&\
# sudo install -b -o root -g admins -m 0660 "${crt_server_ca_path}" /etc/openvpn/keys/ca-server.crt
#
#sudo rm -f "${crt_client_path}" "${crt_client_key_path}" "${crt_server_ca_path}"
# Credentials file for (optional) login
#sudo cat << EOF > /etc/openvpn/keys/credentials
#${login_user}
#${login_passphrase}
#EOF
#
#sudo chown -R root:admins /etc/openvpn/keys/credentials
#sudo chmod 0460 /etc/openvpn/keys/credentials
# Fix confs
## nginx
sudo sed "s|<TPL:NGINX_LOCATION>|${url_path}|g" -i "/etc/nginx/conf.d/${domain}.d/vpnadmin.conf"
@ -177,25 +123,22 @@ sudo systemctl restart php5-fpm
sudo systemctl reload nginx
sudo systemctl enable ynh-vpnclient
sudo systemctl start ynh-vpnclient
# Update SSO for vpnadmin
sudo yunohost app ssowatconf
if ! $upgrade; then
sudo systemctl start ynh-vpnclient
# Restart hotspot service if installed (and started) to change NAT configuration (now on tun0)
# A new start will fix the interface without unsetting all stuff
#if [ -e /tmp/.ynh-hotspot-started ]; then
# sudo ynh-hotspot start
#fi
sudo yunohost service add ynh-vpnclient
sudo yunohost app ssowatconf
# Check configuration consistency
if [ -z "${crt_server_ca_path}" ]; then
echo "WARNING: VPN Client is not started because you need to define a server CA through the web admin" >&2
fi
if [ -z "${crt_client_key_path}" -a -z "${login_user}" ]; then
echo "WARNING: VPN Client is not started because you need either a client certificate, either a username (or both)" >&2
# Check configuration consistency
if [ -z "${crt_server_ca_path}" ]; then
echo "WARNING: VPN Client is not started because you need to define a server CA through the web admin" >&2
fi
if [ -z "${crt_client_key_path}" -a -z "${login_user}" ]; then
echo "WARNING: VPN Client is not started because you need either a client certificate, either a username (or both)" >&2
fi
fi
exit 0

View File

@ -41,8 +41,4 @@ sudo systemctl reload nginx
# Remove sources
sudo rm -rf /var/www/vpnadmin/
# Remove packets
# The yunohost policy is currently to not uninstall packets (dependency problems)
## sudo apt-get --assume-yes --force-yes remove openvpn php5-fpm sipcalc
exit 0

View File

@ -1,50 +1,27 @@
#!/bin/bash
APP=vpnclient
OWNER=labriqueinternet
SERVICE="ynh-${APP}"
REPO="${APP}_ynh"
ynh_setting() {
app=${1}
setting=${2}
ARGS='domain path server_name'
sudo grep "^${setting}:" "/etc/yunohost/apps/${app}/settings.yml" | sed s/^[^:]\\+:\\s*[\"\']\\?// | sed s/\\s*[\"\']\$//
}
install_time=$(sudo yunohost app setting "${APP}" install_time)
install_isotime=$(date -Iseconds --date="@${install_time}")
domain=$(ynh_setting vpnclient domain)
path=$(ynh_setting vpnclient path)
server_name=$(ynh_setting vpnclient server_name)
commits=$(sudo curl -s "https://api.github.com/repos/${OWNER}/${REPO}/commits?since=${install_isotime}" | wc -l)
if [ "${commits}" -le 3 ]; then
echo "${APP}: Up-to-date"
exit 0
fi
for i in ${ARGS}; do
value=$(sudo yunohost app setting "${APP}" "${i}")
value=$(php -r "echo rawurlencode('$value');")
args_url="${args_url}&${i}=${value}"
done
tmpdir=$(mktemp -dp /tmp/ "${APP}-upgrade-XXXXX")
sudo systemctl stop "${SERVICE}"
sudo cp -a "/etc/yunohost/apps/${APP}/settings.yml" "${tmpdir}/"
tmpdir=$(mktemp -dp /tmp/ vpnclient-upgrade-XXXXX)
sudo systemctl stop ynh-vpnclient
sudo cp -a /etc/openvpn/keys/ "${tmpdir}/"
sudo yunohost app remove "${APP}"
sudo yunohost app install "https://github.com/${OWNER}/${REPO}" --args "${args_url}"
export VPNCLIENT_UPGRADE=1
sudo bash /etc/yunohost/apps/vpnclient/scripts/remove
bash ./install "${domain}" "${path}" "${server_name}"
sudo systemctl stop "${SERVICE}"
install_time=$(sudo yunohost app setting "${APP}" install_time)
sudo cp -a "${tmpdir}/settings.yml" "/etc/yunohost/apps/${APP}/"
sudo cp -a "${tmpdir}/keys/"* /etc/openvpn/keys/ 2> /dev/null
sudo yunohost app setting "${APP}" install_time -v "${install_time}"
sudo systemctl start "${SERVICE}"
sudo rm -r "${tmpdir}/"
sudo systemctl start ynh-vpnclient
exit 0