From 2c2b9c28fb5369a765d2b23f66dd2df1fe87c3ef Mon Sep 17 00:00:00 2001 From: VirtuBox Date: Mon, 28 Oct 2019 06:52:23 +0100 Subject: [PATCH] Refactor `wo update` --- CHANGELOG.md | 2 ++ install | 45 +++++++++++++++++++++------------------- setup.py | 2 +- wo/cli/plugins/update.py | 26 ++++++++++++++++++++++- wo/core/download.py | 3 ++- wo/core/variables.py | 2 +- 6 files changed, 55 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c5200e..a2a8028 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - Added `/var/lib/php/sessions/` to open_basedir to allow php sessions storage - WordOps now check if a repository already exist before trying to adding it again. - Improved SSL certificate error messages by displaying domain IP and server IP +- Version check before updating WordOps with `wo update` is now directly handled by `wo` +- Refactored WordOps download function with python3-requests #### Fixed diff --git a/install b/install index 7124bf2..bef0b18 100755 --- a/install +++ b/install @@ -483,22 +483,22 @@ wo_upgrade_nginx() { if [ -n "$CHECK_NGINX_EE" ]; then if [ -x /usr/local/bin/wo ]; then [ -f /etc/apt/preferences.d/nginx-block ] && { mv /etc/apt/preferences.d/nginx-block /var/lib/wo/tmp/nginx-block; } - # stop nginx - service nginx stop - # remove previous package - apt-mark unhold nginx-ee nginx-common nginx-custom - apt-get autoremove nginx-ee nginx-common nginx-custom --allow-change-held-packages --purge -qq - # remove previous php-fpm pool configuration - if [ -n "$CHECK_PHP72" ]; then - apt-get purge php7.2-fpm -y -qq - rm -f /etc/php/7.2/fpm/pool.d/{www.conf,www-two.conf,debug.conf} - fi - if [ -d /etc/nginx ]; then - rm -rf /etc/nginx - fi - /usr/local/bin/wo stack install --nginx --php - rm -f /etc/nginx/common/acl.conf /etc/nginx/htpasswd-wo - /usr/bin/rsync -au --noatime /var/lib/wo-backup/nginx/ /etc/nginx/ + # stop nginx + service nginx stop + # remove previous package + apt-mark unhold nginx-ee nginx-common nginx-custom + apt-get autoremove nginx-ee nginx-common nginx-custom --allow-change-held-packages --purge -qq + # remove previous php-fpm pool configuration + if [ -n "$CHECK_PHP72" ]; then + apt-get purge php7.2-fpm -y -qq + rm -f /etc/php/7.2/fpm/pool.d/{www.conf,www-two.conf,debug.conf} + fi + if [ -d /etc/nginx ]; then + rm -rf /etc/nginx + fi + /usr/local/bin/wo stack install --nginx --php + rm -f /etc/nginx/common/acl.conf /etc/nginx/htpasswd-wo + /usr/bin/rsync -au --noatime /var/lib/wo-backup/nginx/ /etc/nginx/ /usr/local/bin/wo stack upgrade --nginx --force fi fi @@ -506,9 +506,9 @@ wo_upgrade_nginx() { # restore sites and configuration [ -f /etc/nginx/htpasswd-ee ] && { cp -f /etc/nginx/htpasswd-ee /etc/nginx/htpasswd-wo; } sed -i "s/locations.conf/locations-wo.conf/" /etc/nginx/sites-available/* - sed -i "s/locations-php7.conf/locations-wo.conf/" /etc/nginx/sites-available/* - sed -i "s/locations-php71.conf/locations-wo.conf/" /etc/nginx/sites-available/* - sed -i "s/locations-php72.conf/locations-wo.conf/" /etc/nginx/sites-available/* + sed -i "s/locations-php7.conf/locations-wo.conf/" /etc/nginx/sites-available/* + sed -i "s/locations-php71.conf/locations-wo.conf/" /etc/nginx/sites-available/* + sed -i "s/locations-php72.conf/locations-wo.conf/" /etc/nginx/sites-available/* sed -i "s/locations-php73.conf/locations-wo.conf/" /etc/nginx/sites-available/* sed -i "s/htpasswd-ee/htpasswd-wo/" /etc/nginx/common/acl.conf sed -i 's/ssl on;/#ssl on;/' /var/www/*/conf/nginx/ssl.conf @@ -653,14 +653,17 @@ wo_init() { if ! command_exists lsb_release; then apt-get install lsb-release -qq fi + if ! command_exists jq; then + apt-get install jq -qq + fi fi if [ "$wo_force_install" = "y" ]; then [ ! -f "$HOME/.gitconfig" ] && { bash -c 'echo -e "[user]\n\tname = $USER\n\temail = root@$HOSTNAME.local" > $HOME/.gitconfig'; } fi if [ -f ./setup.py ]; then - readonly wo_version_new=$(grep "version='" setup.py | awk -F "'" '{print$2}' 2>&1) + readonly wo_version_new=$(grep "version='" setup.py | awk -F "'" '{print $2}' 2>&1) else - readonly wo_version_new=$(curl -m 5 --retry 3 -sI https://github.com/WordOps/WordOps/releases/latest | grep tag | awk -F "/" '{print $8}' 2>&1) + readonly wo_version_new=$(curl -m 5 --retry 3 -sL https://api.github.com/repos/WordOps/WordOps/releases/latest | jq -r '.tag_name' 2>&1) fi echo "" diff --git a/setup.py b/setup.py index bc3b692..21a9b89 100644 --- a/setup.py +++ b/setup.py @@ -27,7 +27,7 @@ if os.geteuid() == 0: os.makedirs('/var/lib/wo/tmp/') setup(name='wordops', - version='3.9.9.4', + version='3.10.0', description='An essential toolset that eases server administration', long_description=LONG, long_description_content_type='text/markdown', diff --git a/wo/cli/plugins/update.py b/wo/cli/plugins/update.py index 49e0994..61989c3 100644 --- a/wo/cli/plugins/update.py +++ b/wo/cli/plugins/update.py @@ -2,9 +2,10 @@ import os import time from cement.core.controller import CementBaseController, expose - +from requests import RequestException, get, json from wo.core.download import WODownload from wo.core.logging import Log +from wo.core.variables import WOVar def wo_update_hook(app): @@ -43,6 +44,23 @@ class WOUpdateController(CementBaseController): def default(self): pargs = self.app.pargs filename = "woupdate" + time.strftime("%Y%m%d-%H%M%S") + + wo_current = WOVar.wo_version + try: + wo_github_latest = get( + 'https://api.github.com/repos/WordOps/WordOps/releases/latest', + timeout=(5, 30)).json() + except RequestException: + Log.debug( + self, "Request to GitHub API failed. " + "Switching to Gitea instance") + wo_github_latest = get( + 'https://git.virtubox.net/api/v1/repos/virtubox/WordOps/tags', + timeout=(5, 30)).json() + wo_latest = wo_github_latest[0]["name"] + else: + wo_latest = wo_github_latest["tag_name"] + install_args = "" if pargs.mainline or pargs.beta: wo_branch = "mainline" @@ -52,6 +70,12 @@ class WOUpdateController(CementBaseController): wo_branch = "master" if pargs.force: install_args = install_args + "--force " + else: + if not pargs.travis: + if wo_current == wo_latest: + Log.error( + self, "WordOps {0} is already installed" + .format(wo_latest)) if not os.path.isdir('/var/lib/wo/tmp'): os.makedirs('/var/lib/wo/tmp') diff --git a/wo/core/download.py b/wo/core/download.py index 38d0ede..f81cb42 100644 --- a/wo/core/download.py +++ b/wo/core/download.py @@ -23,7 +23,7 @@ class WODownload(): os.makedirs(directory) Log.info(self, "Downloading {0:20}".format(pkg_name), end=' ') with open(filename, "wb") as out_file: - req = get(url, timeout=15) + req = get(url, timeout=(5, 30)) if req.encoding is None: req.encoding = 'utf-8' out_file.write(req.content) @@ -34,3 +34,4 @@ class WODownload(): Log.error(self, "Unable to download file, {0}" .format(filename)) return False + return 0 diff --git a/wo/core/variables.py b/wo/core/variables.py index 4360ca9..0bafd50 100644 --- a/wo/core/variables.py +++ b/wo/core/variables.py @@ -14,7 +14,7 @@ class WOVar(): """Intialization of core variables""" # WordOps version - wo_version = "3.9.9.4" + wo_version = "3.10.0" # WordOps packages versions wo_wp_cli = "2.3.0" wo_adminer = "4.7.3"