1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/hotspot_ynh.git synced 2024-09-03 19:25:53 +02:00

Merge pull request #22 from labriqueinternet/upgrade

Improve the upgrade script
This commit is contained in:
Julien Vaubourg 2015-07-24 19:10:30 +02:00
commit 847dffe29e
2 changed files with 103 additions and 135 deletions

View file

@ -17,6 +17,9 @@
# 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=$([ "$HOTSPOT_UPGRADE" == 1 ] && echo true || echo false)
# Retrieve arguments
domain=${1}
url_path=${2}
@ -24,50 +27,47 @@ wifi_ssid=${3}
wifi_passphrase=${4}
firmware_nonfree=${5}
##
## These arguments are optional but YunoHost is not yet able to handle them with the web installer
## See manifest.json.options
##
#
#ip6_net=${6}
if ! $upgrade; then
# Check YunoHost version
ynh_version=$(sudo dpkg -l yunohost | grep ii | awk '{ print $3 }' | sed 's/\.//g')
# Check YunoHost version
ynh_version=$(sudo dpkg -l yunohost | grep ii | awk '{ print $3 }' | sed 's/\.//g')
if [ "${ynh_version}" -lt 220 ]; then
echo "ERROR: You need a YunoHost version equals or greater than 2.2.0"
exit 1
fi
if [ "${ynh_version}" -lt 220 ]; then
echo "ERROR: You need a YunoHost version equals or greater than 2.2.0"
exit 1
fi
sudo systemctl is-active dnsmasq &> /dev/null
sudo systemctl is-active dnsmasq &> /dev/null
if [ $? -ne 0 ]; then
echo "ERROR: You need to enable dnsmasq instead of bind9 (apt-get remove bind9 && systemctl start dnsmasq)"
exit 1
fi
if [ $? -ne 0 ]; then
echo "ERROR: You need to enable dnsmasq instead of bind9 (apt-get remove bind9 && systemctl start dnsmasq)"
exit 1
fi
# Check arguments
if [ -z "${wifi_ssid}" -o -z "${wifi_passphrase}" ]; then
echo "ERROR: Your Wifi Hotspot needs a name and a password" >&2
exit 1
fi
# Check arguments
if [ -z "${wifi_ssid}" -o -z "${wifi_passphrase}" ]; then
echo "ERROR: Your Wifi Hotspot needs a name and a password" >&2
exit 1
fi
wifi_passphrase_length="$(echo -n "${wifi_passphrase}" | wc -c)"
if [ "${wifi_passphrase_length}" -lt 8 -o "${wifi_passphrase_length}" -gt 63 ]; then
echo "ERROR: Your password must from 8 to 63 characters (WPA2 passphrase)" >&2
exit 1
fi
wifi_passphrase_length="$(echo -n "${wifi_passphrase}" | wc -c)"
if [ "${wifi_passphrase_length}" -lt 8 -o "${wifi_passphrase_length}" -gt 63 ]; then
echo "ERROR: Your password must from 8 to 63 characters (WPA2 passphrase)" >&2
exit 1
fi
echo "${wifi_passphrase}" | grep -qP '[^[:print:]]'
if [ $? -eq 0 ]; then
echo "ERROR: Only printable ASCII characters are permitted in your password (WPA2 passphrase)" >&2
exit 1
fi
echo "${wifi_passphrase}" | grep -qP '[^[:print:]]'
if [ $? -eq 0 ]; then
echo "ERROR: Only printable ASCII characters are permitted in your password (WPA2 passphrase)" >&2
exit 1
fi
# Check domain/path availability
sudo yunohost app checkurl ${domain}${url_path} -a hotspot
if [ ! $? -eq 0 ]; then
exit 1
fi
# Check domain/path availability
sudo yunohost app checkurl ${domain}${url_path} -a hotspot
if [ ! $? -eq 0 ]; then
exit 1
fi
# Install packages
@ -95,57 +95,50 @@ if [ $? -ne 0 ]; then
sudo apt-get --assume-yes --force-yes install ${packages}
fi
# Compute extra arguments
if [ -z "${ip6_net}" ]; then
ip6_net=none
ip6_addr=none
if ! $upgrade; then
if [ -e /tmp/.ynh-vpnclient-started ]; then
vpnclient_ip6_net=$(sudo yunohost app setting vpnclient ip6_net 2>&1)
vpnclient_ip6_addr=$(sudo yunohost app setting vpnclient ip6_addr 2>&1)
# Compute extra arguments
if [ -z "${ip6_net}" ]; then
ip6_net=none
ip6_addr=none
if [[ "${vpnclient_ip6_net}" =~ :: && "${vpnclient_ip6_addr}" =~ :: ]]; then
ip6_net=${vpnclient_ip6_net}
ip6_addr=${vpnclient_ip6_addr}
if [ -e /tmp/.ynh-vpnclient-started ]; then
vpnclient_ip6_net=$(sudo yunohost app setting vpnclient ip6_net 2>&1)
vpnclient_ip6_addr=$(sudo yunohost app setting vpnclient ip6_addr 2>&1)
if [[ "${vpnclient_ip6_net}" =~ :: && "${vpnclient_ip6_addr}" =~ :: ]]; then
ip6_net=${vpnclient_ip6_net}
ip6_addr=${vpnclient_ip6_addr}
fi
fi
fi
#else
# ip6_net=$(bash ../conf/ipv6_expanded "${ip6_net}")
#
# if [ -z "${ip6_net}" ]; then
# echo "ERROR: The IPv6 Delegated Prefix format looks bad" >&2
# exit 1
# fi
#
# ip6_addr="$(echo "${ip6_net}" | cut -d: -f1-7):42"
# ip6_net=$(bash ../conf/ipv6_compressed "${ip6_net}")
# ip6_addr=$(bash ../conf/ipv6_compressed "${ip6_addr}")
wifi_device=$(sudo bash ../conf/iw_devices | awk -F\| '{ print $1 }')
if [ -z "${wifi_device}" ]; then
echo "ERROR: No wifi interface found" >&2
exit 1
fi
# Save arguments
sudo yunohost app setting hotspot service_enabled -v 1
sudo yunohost app setting hotspot multissid -v 1
sudo yunohost app setting hotspot wifi_ssid -v "${wifi_ssid}"
sudo yunohost app setting hotspot wifi_secure -v 1
sudo yunohost app setting hotspot wifi_passphrase -v "${wifi_passphrase}"
sudo yunohost app setting hotspot wifi_device -v "${wifi_device}"
sudo yunohost app setting hotspot wifi_channel -v 6
sudo yunohost app setting hotspot ip6_addr -v "${ip6_addr}"
sudo yunohost app setting hotspot ip6_net -v "${ip6_net}"
sudo yunohost app setting hotspot ip6_dns0 -v 2001:913::8
sudo yunohost app setting hotspot ip6_dns1 -v 2001:910:800::12
sudo yunohost app setting hotspot ip4_dns0 -v 80.67.188.188
sudo yunohost app setting hotspot ip4_dns1 -v 80.67.169.12
sudo yunohost app setting hotspot ip4_nat_prefix -v 10.0.242
sudo yunohost app setting hotspot vpnclient -v no
fi
wifi_device=$(sudo bash ../conf/iw_devices | awk -F\| '{ print $1 }')
if [ -z "${wifi_device}" ]; then
echo "ERROR: No wifi interface found" >&2
exit 1
fi
# Save arguments
sudo yunohost app setting hotspot service_enabled -v 1
sudo yunohost app setting hotspot multissid -v 1
sudo yunohost app setting hotspot wifi_ssid -v "${wifi_ssid}"
sudo yunohost app setting hotspot wifi_secure -v 1
sudo yunohost app setting hotspot wifi_passphrase -v "${wifi_passphrase}"
sudo yunohost app setting hotspot wifi_device -v "${wifi_device}"
sudo yunohost app setting hotspot wifi_channel -v 6
sudo yunohost app setting hotspot ip6_addr -v "${ip6_addr}"
sudo yunohost app setting hotspot ip6_net -v "${ip6_net}"
sudo yunohost app setting hotspot ip6_dns0 -v 2001:913::8
sudo yunohost app setting hotspot ip6_dns1 -v 2001:910:800::12
sudo yunohost app setting hotspot ip4_dns0 -v 80.67.188.188
sudo yunohost app setting hotspot ip4_dns1 -v 80.67.169.12
sudo yunohost app setting hotspot ip4_nat_prefix -v 10.0.242
sudo yunohost app setting hotspot vpnclient -v no
# Install custom scripts
sudo install -o root -g root -m 0755 ../conf/iw_multissid /usr/local/bin/
sudo install -o root -g root -m 0755 ../conf/iw_devices /usr/local/bin/
@ -203,10 +196,8 @@ sudo yunohost firewall allow --no-upnp UDP 67
# and the ynh-hotspot service handles them.
sudo systemctl disable hostapd
sudo systemctl stop hostapd
sudo systemctl enable php5-fpm
sudo systemctl restart php5-fpm
sudo systemctl reload nginx
# Remove IPv6 address set if there is a VPN installed
@ -217,10 +208,12 @@ if [ "${ip6_addr}" != none ]; then
fi
fi
sudo systemctl enable ynh-hotspot
sudo systemctl start ynh-hotspot
if ! $upgrade; then
sudo systemctl enable ynh-hotspot
sudo systemctl start ynh-hotspot
# Update SSO for wifiadmin
sudo yunohost app ssowatconf
sudo yunohost service add ynh-hotspot
sudo yunohost app ssowatconf
fi
exit 0

View file

@ -1,52 +1,27 @@
#!/bin/bash
APP=hotspot
OWNER=labriqueinternet
SERVICE="ynh-${APP}"
REPO="${APP}_ynh"
ynh_setting() {
app=${1}
setting=${2}
ARGS='domain path wifi_ssid wifi_passphrase'
sudo grep "^${setting}:" "/etc/yunohost/apps/${app}/settings.yml" | sed s/^[^:]\\+:\\s*[\"\']\\?// | sed s/\\s*[\"\']\$//
}
domain=$(ynh_setting hotspot domain)
path=$(ynh_setting hotspot path)
wifi_ssid=$(ynh_setting hotspot wifi_ssid)
wifi_passphrase=$(ynh_setting hotspot wifi_passphrase)
if dpkg -l firmware-linux-nonfree &> /dev/null; then
args_url='firmware_nonfree=yes'
firmware_nonfree=yes
else
args_url='firmware_nonfree=no'
firmware_nonfree=no
fi
install_time=$(sudo yunohost app setting "${APP}" install_time)
install_isotime=$(date -Iseconds --date="@${install_time}")
export HOTSPOT_UPGRADE=1
sudo bash /etc/yunohost/apps/hotspot/scripts/remove
bash ./install "${domain}" "${path}" "${wifi_ssid}" "${wifi_passphrase}" "${firmware_nonfree}"
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}/"
sudo yunohost app remove "${APP}"
sudo yunohost app install "https://github.com/${OWNER}/${REPO}" --args "${args_url}"
sudo systemctl stop "${SERVICE}"
install_time=$(sudo yunohost app setting "${APP}" install_time)
sudo cp -a "${tmpdir}/settings.yml" "/etc/yunohost/apps/${APP}/"
sudo yunohost app setting "${APP}" install_time -v "${install_time}"
sudo systemctl start "${SERVICE}"
sudo rm -r "${tmpdir}/"
sudo systemctl start ynh-hotspot
exit 0