Browse Source

Improve upgrade script

Julien VAUBOURG 9 years ago
parent
commit
f0b5546e3d
2 changed files with 39 additions and 54 deletions
  1. 28 14
      scripts/install
  2. 11 40
      scripts/upgrade

+ 28 - 14
scripts/install

@@ -18,18 +18,25 @@
 # 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=$([ "$TORCLIENT_UPGRADE" == 1 ] && echo true || echo false)
+
 # Retrieve arguments
 domain=${1}
 url_path=${2}
 
-# Check domain/path availability
-sudo yunohost app checkurl ${domain}${url_path} -a torclient
-if [ ! $? -eq 0 ]; then
-  exit 1
-fi
+if ! $upgrade; then
+
+  # Check domain/path availability
+  sudo yunohost app checkurl ${domain}${url_path} -a torclient
+  if [ ! $? -eq 0 ]; then
+    exit 1
+  fi
+  
+  if [ ! -e /tmp/.ynh-hotspot-started ]; then
+    echo "WARNING: Hotspot app not installed or not started" >&2
+  fi
 
-if [ ! -e /tmp/.ynh-hotspot-started ]; then
-  echo "hotspot not started and/or not installed"
 fi
 
 echo 'deb http://deb.torproject.org/torproject.org jessie main' | sudo tee "/etc/apt/sources.list.d/torproject.list"
@@ -42,9 +49,13 @@ packages='tor php5-fpm'
 sudo apt-get update
 DEBIAN_FRONTEND=noninteractive sudo apt-get --assume-yes --force-yes install ${packages}
 
-# Save arguments
-sudo yunohost app setting torclient service_enabled -v 0
-sudo yunohost app setting torclient wifi_device_id -v -1
+if ! $upgrade; then
+
+  # Save arguments
+  sudo yunohost app setting torclient service_enabled -v 0
+  sudo yunohost app setting torclient wifi_device_id -v -1
+
+fi
 
 sudo install -o root -g root -m 0644 ../conf/torrc /etc/tor/torrc.tpl
 sudo install -b -o root -g root -m 0644 ../conf/nginx_torclient.conf "/etc/nginx/conf.d/${domain}.d/torclient.conf"
@@ -94,11 +105,14 @@ sudo systemctl restart php5-fpm
 sudo systemctl reload nginx
 
 sudo systemctl enable ynh-torclient
-sudo systemctl start ynh-torclient
 
-# Update SSO for torclient
-sudo yunohost app ssowatconf
+if ! $upgrade; then
+  sudo systemctl start ynh-torclient
 
-echo "WARNING: Tor Client is not started because you need to define an associated wifi hotspot through the web admin" >&2
+  sudo yunohost service add ynh-torclient
+  sudo yunohost app ssowatconf
+
+  echo "WARNING: Tor Client is not started because you need to define an associated wifi hotspot through the web admin" >&2
+fi
 
 exit 0

+ 11 - 40
scripts/upgrade

@@ -1,48 +1,19 @@
 #!/bin/bash
 
-APP=torclient
-OWNER=labriqueinternet
-SERVICE="ynh-${APP}"
-REPO="${APP}_ynh"
+ynh_setting() {
+  app=${1}
+  setting=${2}
 
-ARGS='domain path'
+  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}")
+domain=$(ynh_setting torclient domain)
+path=$(ynh_setting torclient path)
 
-commits=$(sudo curl -s "https://api.github.com/repos/${OWNER}/${REPO}/commits?since=${install_isotime}" | wc -l)
+export TORCLIENT_UPGRADE=1
+sudo bash /etc/yunohost/apps/torclient/scripts/remove
+bash ./install "${domain}" "${path}"
 
-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-torclient
 
 exit 0