Replace 'yunohost app setting' by a good old grep for more speed (close #11)

This commit is contained in:
Julien VAUBOURG
2015-07-24 20:56:40 +02:00
parent 09f23b5a08
commit 8cf1917cbc
2 changed files with 46 additions and 66 deletions

View File

@@ -33,19 +33,9 @@ has_hotspot_app() {
}
is_hotspot_knowme() {
gotcha=0
hotspot_vpnclient=$(ynh_setting_get hotspot vpnclient)
while [ "${gotcha}" -eq 0 ]; do
value=$(yunohost app setting hotspot vpnclient)
if [[ "${value}" =~ "An instance is already running" ]]; then
sleep $(($((RANDOM%5)) + 1))
else
gotcha=1
fi
done
[ "${value}" == yes ]
[ "${hotspot_vpnclient}" == yes ]
}
is_ip6addr_set() {
@@ -145,33 +135,19 @@ stop_openvpn() {
## Tools
moulinette_get() {
var=${1}
gotcha=0
ynh_setting_get() {
app=${1}
setting=${2}
while [ "${gotcha}" -eq 0 ]; do
value=$(yunohost app setting vpnclient "${var}")
if [[ "${value}" =~ "An instance is already running" ]]; then
sleep $(($((RANDOM%5)) + 1))
else
gotcha=1
fi
done
echo "${value}"
grep "^${setting}:" "/etc/yunohost/apps/${app}/settings.yml" | sed s/^[^:]\\+:\\s*[\"\']\\?// | sed s/\\s*[\"\']\$//
}
moulinette_set() {
var=${1}
value=${2}
ynh_setting_set() {
app=${1}
setting=${2}
value=${3}
msg=$(yunohost app setting vpnclient "${var}" -v "${value}")
if [ ! $? -eq 0 ]; then
echo "${msg}" >&2
exit 1
fi
yunohost app setting "${app}" "${setting}" -v "${value}"
}
if [ "$1" != restart ]; then
@@ -205,16 +181,16 @@ if [ "$1" != restart ]; then
echo -n "Retrieving Yunohost settings... "
ynh_service_enabled=$(moulinette_get service_enabled)
ynh_server_name=$(moulinette_get server_name)
ynh_server_port=$(moulinette_get server_port)
ynh_server_proto=$(moulinette_get server_proto)
ynh_ip6_addr=$(moulinette_get ip6_addr)
ynh_login_user=$(moulinette_get login_user)
ynh_service_enabled=$(ynh_setting_get vpnclient service_enabled)
ynh_server_name=$(ynh_setting_get vpnclient server_name)
ynh_server_port=$(ynh_setting_get vpnclient server_port)
ynh_server_proto=$(ynh_setting_get vpnclient server_proto)
ynh_ip6_addr=$(ynh_setting_get vpnclient ip6_addr)
ynh_login_user=$(ynh_setting_get vpnclient login_user)
old_ip6_gw=$(moulinette_get ip6_gw)
old_wired_device=$(moulinette_get wired_device)
old_server_ip6=$(moulinette_get server_ip6)
old_ip6_gw=$(ynh_setting_get vpnclient ip6_gw)
old_wired_device=$(ynh_setting_get vpnclient wired_device)
old_server_ip6=$(ynh_setting_get vpnclient server_ip6)
new_ip6_gw=$(ip -6 route | grep default\ via | awk '{ print $3 }')
new_wired_device=$(ip route | awk '/default via/ { print $NF; }')
@@ -280,9 +256,9 @@ case "${1}" in
fi
# Update dynamic settings
moulinette_set server_ip6 "${new_server_ip6}"
moulinette_set ip6_gw "${new_ip6_gw}"
moulinette_set wired_device "${new_wired_device}"
ynh_setting_set vpnclient server_ip6 "${new_server_ip6}"
ynh_setting_set vpnclient ip6_gw "${new_ip6_gw}"
ynh_setting_set vpnclient wired_device "${new_wired_device}"
# Fix configuration
if has_hotspot_app && ! is_hotspot_knowme; then