Parcourir la source

Improve upgrade script

Julien VAUBOURG il y a 9 ans
Parent
commit
a623441882
3 fichiers modifiés avec 47 ajouts et 58 suppressions
  1. 27 17
      scripts/install
  2. 1 0
      scripts/remove
  3. 19 41
      scripts/upgrade

+ 27 - 17
scripts/install

@@ -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=$([ "$PIRATEBOX_UPGRADE" == 1 ] && echo true || echo false)
+
 # Retrieve arguments
 domain=${1}
 url_path=${2}
@@ -44,20 +47,24 @@ else
   opt_chat=0
 fi
 
-# Check domain/path availability
-sudo yunohost app checkurl ${domain}${url_path} -a piratebox
-if [ ! $? -eq 0 ]; then
-  exit 1
-fi
+if ! $upgrade; then
+
+  # Check domain/path availability
+  sudo yunohost app checkurl ${domain}${url_path} -a piratebox
+  if [ ! $? -eq 0 ]; then
+    exit 1
+  fi
+  
+  # Save arguments
+  sudo yunohost app setting piratebox service_enabled -v 0
+  sudo yunohost app setting piratebox opt_domain -v "${opt_domain}"
+  sudo yunohost app setting piratebox opt_name -v "${opt_name}"
+  sudo yunohost app setting piratebox opt_renaming -v "${opt_renaming}"
+  sudo yunohost app setting piratebox opt_deleting -v "${opt_deleting}"
+  sudo yunohost app setting piratebox opt_chat -v "${opt_chat}"
+  sudo yunohost app setting piratebox wifi_device_id -v -1
 
-# Save arguments
-sudo yunohost app setting piratebox service_enabled -v 0
-sudo yunohost app setting piratebox opt_domain -v "${opt_domain}"
-sudo yunohost app setting piratebox opt_name -v "${opt_name}"
-sudo yunohost app setting piratebox opt_renaming -v "${opt_renaming}"
-sudo yunohost app setting piratebox opt_deleting -v "${opt_deleting}"
-sudo yunohost app setting piratebox opt_chat -v "${opt_chat}"
-sudo yunohost app setting piratebox wifi_device_id -v -1
+fi
 
 # Install packages
 packages='php5-fpm iptables libnet-dns-perl git'
@@ -149,11 +156,14 @@ sudo systemctl restart php5-fpm
 sudo systemctl reload nginx
 
 sudo systemctl enable ynh-piratebox
-sudo systemctl start ynh-piratebox
+sudo yunohost service add ynh-piratebox
 
-# Update SSO
-sudo yunohost app ssowatconf
+if ! $upgrade; then
+  sudo systemctl start ynh-piratebox
 
-echo "WARNING: PirateBox is not started because you need to define an associated wifi hotspot through the web admin" >&2
+  echo "WARNING: PirateBox is not started because you need to define an associated wifi hotspot through the web admin" >&2
+fi
+
+sudo yunohost app ssowatconf
 
 exit 0

+ 1 - 0
scripts/remove

@@ -23,6 +23,7 @@ domain=$(sudo yunohost app setting piratebox domain)
 # The End
 sudo systemctl stop ynh-piratebox
 sudo systemctl disable ynh-piratebox
+sudo yunohost service remove ynh-piratebox
 sudo rm -f /etc/systemd/system/ynh-piratebox.service /usr/local/bin/ynh-piratebox
 sudo rm -f /tmp/.ynh-piratebox-*
 

+ 19 - 41
scripts/upgrade

@@ -1,52 +1,30 @@
 #!/bin/bash
 
-APP=piratebox
-OWNER=labriqueinternet
-SERVICE="ynh-${APP}"
-REPO="${APP}_ynh"
+ynh_setting() {
+  app=${1}
+  setting=${2}
 
-ARGS='domain path opt_domain opt_name opt_deleting opt_renaming opt_chat'
+  sudo grep "^${setting}:" "/etc/yunohost/apps/${app}/settings.yml" | sed s/^[^:]\\+:\\s*[\"\']\\?// | sed s/\\s*[\"\']\$//
+}
 
-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)
-commits_upstream=$(sudo curl -s "https://api.github.com/repos/jvaubourg/php-piratebox/commits?since=${install_isotime}" | wc -l)
-
-if [ "${commits}" -le 3 -a "${commits_upstream}" -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
+domain=$(ynh_setting piratebox domain)
+path=$(ynh_setting piratebox path)
+opt_domain=$(ynh_setting piratebox opt_domain)
+opt_name=$(ynh_setting piratebox opt_name)
+opt_deleting=$(ynh_setting piratebox opt_deleting)
+opt_renaming=$(ynh_setting piratebox opt_renaming)
+opt_chat=$(ynh_setting piratebox opt_chat)
 
 tmpdir=$(mktemp -dp /tmp/ "${APP}-upgrade-XXXXX")
-tmpdir_uploads=$(mktemp -dp /var/www/ "${APP}-upgrade-XXXXX")
-
-sudo systemctl stop "${SERVICE}"
-
-sudo cp -a "/etc/yunohost/apps/${APP}/settings.yml" "${tmpdir}/"
-sudo mv /var/www/piratebox/public/uploads/ "${tmpdir_uploads}/"
-
-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 mv "${tmpdir_uploads}/uploads/"* /var/www/piratebox/public/uploads/ 2> /dev/null
+sudo mv /var/www/piratebox/public/uploads/ "${tmpdir}/"
 
-sudo yunohost app setting "${APP}" install_time -v "${install_time}"
+export PIRATEBOX_UPGRADE=1
+sudo bash /etc/yunohost/apps/piratebox/scripts/remove
+bash ./install "${domain}" "${path}" "${opt_domain}" "${opt_name}" "${opt_deleting}" "${opt_renaming}" "${opt_chat}"
 
-sudo systemctl start "${SERVICE}"
+sudo mv "${tmpdir}/uploads/"* /var/www/piratebox/public/uploads/ 2> /dev/null
+sudo rm -r "${tmpdir}/"
 
-sudo rm -r "${tmpdir}/" "${tmpdir_uploads}/"
+sudo systemctl start ynh-piratebox
 
 exit 0