mirror of
https://github.com/YunoHost-Apps/hotspot_ynh.git
synced 2024-09-03 19:25:53 +02:00
Update upgrade
This commit is contained in:
parent
81993b700a
commit
979e467ef0
2 changed files with 100 additions and 135 deletions
121
scripts/install
121
scripts/install
|
@ -17,6 +17,9 @@
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
# 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/>.
|
# 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
|
# Retrieve arguments
|
||||||
domain=${1}
|
domain=${1}
|
||||||
url_path=${2}
|
url_path=${2}
|
||||||
|
@ -24,50 +27,47 @@ wifi_ssid=${3}
|
||||||
wifi_passphrase=${4}
|
wifi_passphrase=${4}
|
||||||
firmware_nonfree=${5}
|
firmware_nonfree=${5}
|
||||||
|
|
||||||
##
|
if ! $upgrade; then
|
||||||
## These arguments are optional but YunoHost is not yet able to handle them with the web installer
|
|
||||||
## See manifest.json.options
|
|
||||||
##
|
|
||||||
#
|
|
||||||
#ip6_net=${6}
|
|
||||||
|
|
||||||
# Check YunoHost version
|
# Check YunoHost version
|
||||||
ynh_version=$(sudo dpkg -l yunohost | grep ii | awk '{ print $3 }' | sed 's/\.//g')
|
ynh_version=$(sudo dpkg -l yunohost | grep ii | awk '{ print $3 }' | sed 's/\.//g')
|
||||||
|
|
||||||
if [ "${ynh_version}" -lt 220 ]; then
|
if [ "${ynh_version}" -lt 220 ]; then
|
||||||
echo "ERROR: You need a YunoHost version equals or greater than 2.2.0"
|
echo "ERROR: You need a YunoHost version equals or greater than 2.2.0"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
sudo systemctl is-active dnsmasq &> /dev/null
|
sudo systemctl is-active dnsmasq &> /dev/null
|
||||||
|
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo "ERROR: You need to enable dnsmasq instead of bind9 (apt-get remove bind9 && systemctl start dnsmasq)"
|
echo "ERROR: You need to enable dnsmasq instead of bind9 (apt-get remove bind9 && systemctl start dnsmasq)"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check arguments
|
# Check arguments
|
||||||
if [ -z "${wifi_ssid}" -o -z "${wifi_passphrase}" ]; then
|
if [ -z "${wifi_ssid}" -o -z "${wifi_passphrase}" ]; then
|
||||||
echo "ERROR: Your Wifi Hotspot needs a name and a password" >&2
|
echo "ERROR: Your Wifi Hotspot needs a name and a password" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
wifi_passphrase_length="$(echo -n "${wifi_passphrase}" | wc -c)"
|
wifi_passphrase_length="$(echo -n "${wifi_passphrase}" | wc -c)"
|
||||||
if [ "${wifi_passphrase_length}" -lt 8 -o "${wifi_passphrase_length}" -gt 63 ]; then
|
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
|
echo "ERROR: Your password must from 8 to 63 characters (WPA2 passphrase)" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "${wifi_passphrase}" | grep -qP '[^[:print:]]'
|
echo "${wifi_passphrase}" | grep -qP '[^[:print:]]'
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
echo "ERROR: Only printable ASCII characters are permitted in your password (WPA2 passphrase)" >&2
|
echo "ERROR: Only printable ASCII characters are permitted in your password (WPA2 passphrase)" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check domain/path availability
|
# Check domain/path availability
|
||||||
sudo yunohost app checkurl ${domain}${url_path} -a hotspot
|
sudo yunohost app checkurl ${domain}${url_path} -a hotspot
|
||||||
if [ ! $? -eq 0 ]; then
|
if [ ! $? -eq 0 ]; then
|
||||||
exit 1
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Install packages
|
# Install packages
|
||||||
|
@ -95,8 +95,10 @@ if [ $? -ne 0 ]; then
|
||||||
sudo apt-get --assume-yes --force-yes install ${packages}
|
sudo apt-get --assume-yes --force-yes install ${packages}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Compute extra arguments
|
if ! $upgrade; then
|
||||||
if [ -z "${ip6_net}" ]; then
|
|
||||||
|
# Compute extra arguments
|
||||||
|
if [ -z "${ip6_net}" ]; then
|
||||||
ip6_net=none
|
ip6_net=none
|
||||||
ip6_addr=none
|
ip6_addr=none
|
||||||
|
|
||||||
|
@ -109,42 +111,33 @@ if [ -z "${ip6_net}" ]; then
|
||||||
ip6_addr=${vpnclient_ip6_addr}
|
ip6_addr=${vpnclient_ip6_addr}
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
#else
|
fi
|
||||||
# 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}")
|
|
||||||
fi
|
|
||||||
|
|
||||||
wifi_device=$(sudo bash ../conf/iw_devices | awk -F\| '{ print $1 }')
|
wifi_device=$(sudo bash ../conf/iw_devices | awk -F\| '{ print $1 }')
|
||||||
|
|
||||||
if [ -z "${wifi_device}" ]; then
|
if [ -z "${wifi_device}" ]; then
|
||||||
echo "ERROR: No wifi interface found" >&2
|
echo "ERROR: No wifi interface found" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Save arguments
|
# Save arguments
|
||||||
sudo yunohost app setting hotspot service_enabled -v 1
|
sudo yunohost app setting hotspot service_enabled -v 1
|
||||||
sudo yunohost app setting hotspot multissid -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_ssid -v "${wifi_ssid}"
|
||||||
sudo yunohost app setting hotspot wifi_secure -v 1
|
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_passphrase -v "${wifi_passphrase}"
|
||||||
sudo yunohost app setting hotspot wifi_device -v "${wifi_device}"
|
sudo yunohost app setting hotspot wifi_device -v "${wifi_device}"
|
||||||
sudo yunohost app setting hotspot wifi_channel -v 6
|
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_addr -v "${ip6_addr}"
|
||||||
sudo yunohost app setting hotspot ip6_net -v "${ip6_net}"
|
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_dns0 -v 2001:913::8
|
||||||
sudo yunohost app setting hotspot ip6_dns1 -v 2001:910:800::12
|
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_dns0 -v 80.67.188.188
|
||||||
sudo yunohost app setting hotspot ip4_dns1 -v 80.67.169.12
|
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 ip4_nat_prefix -v 10.0.242
|
||||||
sudo yunohost app setting hotspot vpnclient -v no
|
sudo yunohost app setting hotspot vpnclient -v no
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
# Install custom scripts
|
# 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_multissid /usr/local/bin/
|
||||||
|
@ -203,10 +196,8 @@ sudo yunohost firewall allow --no-upnp UDP 67
|
||||||
# and the ynh-hotspot service handles them.
|
# and the ynh-hotspot service handles them.
|
||||||
sudo systemctl disable hostapd
|
sudo systemctl disable hostapd
|
||||||
sudo systemctl stop hostapd
|
sudo systemctl stop hostapd
|
||||||
|
|
||||||
sudo systemctl enable php5-fpm
|
sudo systemctl enable php5-fpm
|
||||||
sudo systemctl restart php5-fpm
|
sudo systemctl restart php5-fpm
|
||||||
|
|
||||||
sudo systemctl reload nginx
|
sudo systemctl reload nginx
|
||||||
|
|
||||||
# Remove IPv6 address set if there is a VPN installed
|
# Remove IPv6 address set if there is a VPN installed
|
||||||
|
@ -217,10 +208,12 @@ if [ "${ip6_addr}" != none ]; then
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
sudo systemctl enable ynh-hotspot
|
if ! $upgrade; then
|
||||||
sudo systemctl start ynh-hotspot
|
sudo systemctl enable ynh-hotspot
|
||||||
|
sudo systemctl start ynh-hotspot
|
||||||
|
|
||||||
# Update SSO for wifiadmin
|
sudo yunohost service add ynh-hotspot
|
||||||
sudo yunohost app ssowatconf
|
sudo yunohost app ssowatconf
|
||||||
|
fi
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
|
|
@ -1,52 +1,24 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
APP=hotspot
|
yunohost_setting() {
|
||||||
OWNER=labriqueinternet
|
grep "^${1}:" "/etc/yunohost/apps/hotspot/settings.yml" | sed s/^[^:]\\+:\\s*[\"\']\\?// | sed s/\\s*[\"\']\$//
|
||||||
SERVICE="ynh-${APP}"
|
}
|
||||||
REPO="${APP}_ynh"
|
|
||||||
|
|
||||||
ARGS='domain path wifi_ssid wifi_passphrase'
|
domain=$(yunohost_setting domain)
|
||||||
|
path=$(yunohost_setting path)
|
||||||
|
wifi_ssid=$(yunohost_setting wifi_ssid)
|
||||||
|
wifi_passphrase=$(yunohost_setting wifi_passphrase)
|
||||||
|
|
||||||
if dpkg -l firmware-linux-nonfree &> /dev/null; then
|
if dpkg -l firmware-linux-nonfree &> /dev/null; then
|
||||||
args_url='firmware_nonfree=yes'
|
firmware_nonfree=yes
|
||||||
else
|
else
|
||||||
args_url='firmware_nonfree=no'
|
firmware_nonfree=no
|
||||||
fi
|
fi
|
||||||
|
|
||||||
install_time=$(sudo yunohost app setting "${APP}" install_time)
|
export HOTSPOT_UPGRADE=1
|
||||||
install_isotime=$(date -Iseconds --date="@${install_time}")
|
/etc/yunohost/apps/hotspot/scripts/remove
|
||||||
|
./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)
|
sudo systemctl start ynh-hotspot
|
||||||
|
|
||||||
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}/"
|
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
|
Loading…
Reference in a new issue