From ee0b1de8c146bc420e0d0cc4e74fb8f6606c4f74 Mon Sep 17 00:00:00 2001 From: Julien VAUBOURG Date: Mon, 13 Jul 2015 15:59:05 +0200 Subject: [PATCH] Add upgrade script --- scripts/upgrade | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 scripts/upgrade diff --git a/scripts/upgrade b/scripts/upgrade new file mode 100644 index 0000000..b3bfb79 --- /dev/null +++ b/scripts/upgrade @@ -0,0 +1,46 @@ +#!/bin/bash + +APP=hotspot +OWNER=labriqueinternet +SERVICE="ynh-${APP}" +REPO="${APP}_ynh" + +ARGS='domain path wifi_ssid wifi_passphrase' + +if dpkg -l firmware-linux-nonfree &> /dev/null; then + args_url='firmware_nonfree=yes' +else + args_url='firmware_nonfree=no' +fi + +install_time=$(sudo yunohost app setting "${APP}" install_time) +install_isotime=$(date -Iseconds --date="@${install_time}") + +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 cp -a "${tmpdir}/settings.yml" "/etc/yunohost/apps/${APP}/" +sudo systemctl restart "${SERVICE}" + +rm -r "${tmpdir}/" + +exit 0