Refactor wo update

This commit is contained in:
VirtuBox
2019-10-28 06:52:23 +01:00
parent 9bf0a78f3d
commit 2c2b9c28fb
6 changed files with 55 additions and 25 deletions

View File

@@ -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

View File

@@ -653,6 +653,9 @@ 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'; }
@@ -660,7 +663,7 @@ wo_init() {
if [ -f ./setup.py ]; then
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 ""

View File

@@ -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',

View File

@@ -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')

View File

@@ -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

View File

@@ -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"