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:
commit
847dffe29e
2 changed files with 103 additions and 135 deletions
|
@ -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,12 +27,7 @@ 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')
|
||||
|
@ -70,6 +68,8 @@ if [ ! $? -eq 0 ]; then
|
|||
exit 1
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
# Install packages
|
||||
packages='php5-fpm sipcalc hostapd iptables iw dnsmasq'
|
||||
export DEBIAN_FRONTEND=noninteractive
|
||||
|
@ -95,6 +95,8 @@ if [ $? -ne 0 ]; then
|
|||
sudo apt-get --assume-yes --force-yes install ${packages}
|
||||
fi
|
||||
|
||||
if ! $upgrade; then
|
||||
|
||||
# Compute extra arguments
|
||||
if [ -z "${ip6_net}" ]; then
|
||||
ip6_net=none
|
||||
|
@ -109,17 +111,6 @@ if [ -z "${ip6_net}" ]; then
|
|||
ip6_addr=${vpnclient_ip6_addr}
|
||||
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}")
|
||||
fi
|
||||
|
||||
wifi_device=$(sudo bash ../conf/iw_devices | awk -F\| '{ print $1 }')
|
||||
|
@ -146,6 +137,8 @@ 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
|
||||
|
||||
# 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
|
||||
|
||||
if ! $upgrade; then
|
||||
sudo systemctl enable ynh-hotspot
|
||||
sudo systemctl start ynh-hotspot
|
||||
|
||||
# Update SSO for wifiadmin
|
||||
sudo yunohost service add ynh-hotspot
|
||||
sudo yunohost app ssowatconf
|
||||
fi
|
||||
|
||||
exit 0
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue