Refactor install

* remove all tweaking sections
* integrate them directly in wo
* add pip install from github repo
This commit is contained in:
VirtuBox
2019-10-23 12:24:30 +02:00
parent 3f259ca185
commit 5584d90a25
6 changed files with 38 additions and 102 deletions

View File

@@ -35,6 +35,6 @@ script:
- lsb_release -a
- sudo bash -c 'echo -e "[user]\n\tname = abc\n\temail = root@localhost.com" > /home/travis/.gitconfig'
- sudo echo "Travis Banch = $TRAVIS_BRANCH"
- sudo time bash install --travis -b "$TRAVIS_BRANCH"
- sudo time bash tests/travis.sh
- sudo -E time bash install --travis -b "$TRAVIS_BRANCH"
- sudo -E time bash tests/travis.sh
- sudo wo update --travis

View File

@@ -1,36 +0,0 @@
#!/usr/bin/env python3
import configparser
import os
import re
import shutil
# WordOps git configuration management
config = configparser.ConfigParser()
config.read(os.path.expanduser("~")+'/.gitconfig')
try:
wo_user = config['user']['name']
wo_email = config['user']['email']
except Exception:
print("WordOps (wo) require an username & and an email "
"address to configure Git (used to save server configurations)")
print("Your informations will ONLY be stored locally")
wo_user = input("Enter your name: ")
while wo_user == "":
print("Unfortunately, this can't be left blank")
wo_user = input("Enter your name: ")
wo_email = input("Enter your email: ")
while not re.match(r"^[A-Za-z0-9\.\+_-]+@[A-Za-z0-9\._-]+\.[a-zA-Z]*$",
wo_email):
print("Whoops, seems like you made a typo - "
"the e-mailaddress is invalid...")
wo_email = input("Enter your email: ")
os.system("git config --global user.name {0}".format(wo_user))
os.system("git config --global user.email {0}".format(wo_email))
if not os.path.isfile('/root/.gitconfig'):
shutil.copy2(os.path.expanduser("~")+'/.gitconfig', '/root/.gitconfig')

57
install
View File

@@ -130,7 +130,11 @@ _run() {
# 1 - Define variables for later use
###
if [ -z "$wo_branch" ]; then
wo_branch=master
if [ "$wo_travis" = "y" ]; then
wo_branch=updating-configuration
else
wo_branch=master
fi
fi
readonly wo_log_dir=/var/log/wo/
readonly wo_backup_dir=/var/lib/wo-backup/
@@ -419,32 +423,6 @@ wo_install_acme_sh() {
fi
}
wo_git_config() {
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
# .gitconfig inital setup
cd /var/lib/wo/tmp/WordOps-install || exit 1
python3 gitconfig.py
}
# Download WordOps
wo_download() {
rm -f /etc/bash_completion.d/wo_auto.rc
rm -rf /var/lib/wo/tmp/WordOps-*
if [ -z "$wo_version" ]; then
curl -sL https://github.com/WordOps/WordOps/archive/${wo_branch}.tar.gz | tar -I pigz -xf - -C /var/lib/wo/tmp
mv "/var/lib/wo/tmp/WordOps-$wo_branch" /var/lib/wo/tmp/WordOps-install
else
curl -sL https://github.com/WordOps/WordOps/archive/v${wo_version}.tar.gz | tar -I pigz -xf - -C /var/lib/wo/tmp
mv "/var/lib/wo/tmp/WordOps-$wo_version" /var/lib/wo/tmp/WordOps-install
fi
return 0
}
# WordOps install
wo_install() {
@@ -463,8 +441,12 @@ wo_travis_install() {
if [ -d ./dist ]; then
rm -rf dist
fi
python3 setup.py sdist bdist_wheel
python3 -m pip install --upgrade dist/*.whl
if [ -f ./setup.py ]; then
python3 setup.py sdist bdist_wheel
python3 -m pip install --upgrade dist/*.whl
else
python3 -m pip install git+git://github.com/WordOps/WordOps.git@$wo_branch #egg=wordops -U
fi
cp -rn /usr/local/lib/python3.*/dist-packages/usr/* /usr/
cp -rn /usr/local/lib/python3.*/dist-packages/etc/* /etc/
@@ -620,18 +602,6 @@ wo_mariadb_tweak() {
fi
}
wo_nginx_tweak() {
# increase nginx open_files_limit
if [ ! -d /etc/systemd/system/nginx.service.d ]; then
mkdir -p /etc/systemd/system/nginx.service.d
if [ ! -f /etc/systemd/system/nginx.service.d/limits.conf ]; then
echo -e '[Service]\nLimitNOFILE=500000' > /etc/systemd/system/nginx.service.d/limits.conf
systemctl daemon-reload
nginx -t && service nginx restart
fi
fi
}
wo_clean() {
rm -rf /usr/local/lib/python3.*/dist-packages/wo-*.egg /usr/local/lib/python3.*/dist-packages/wordops-*.egg
@@ -723,7 +693,6 @@ else
wo_lib_error "You already have WordOps $wo_version_new" 1
fi
fi
_run wo_backup_wo "Backing-up WO install"
_run wo_clean
# 2 - Migration from EEv3
elif [ -x /usr/local/bin/ee ]; then
@@ -742,7 +711,6 @@ else
# skip steps if travis
if [ -z "$wo_travis" ]; then
#_run wo_download "Downloading WordOps"
wo_git_config
_run wo_install "Installing WordOps"
else
_run wo_travis_install "Installing WordOps"
@@ -752,9 +720,6 @@ else
_run wo_clean_ee "Cleaning previous EasyEngine install"
fi
_run wo_install_acme_sh
if [ -x /usr/sbin/nginx ]; then
_run wo_nginx_tweak
fi
if [ -d /etc/systemd/system/mariadb.service.d ]; then
_run wo_mariadb_tweak
fi

View File

@@ -1,4 +1,3 @@
import codecs
import configparser
import os
import random
@@ -7,11 +6,8 @@ import string
import psutil
import requests
from wo.cli.plugins.site_functions import *
from wo.cli.plugins.stack_services import WOStackStatusController
from wo.core.apt_repo import WORepo
from wo.core.aptget import WOAptGet
from wo.core.checkfqdn import check_fqdn_ip
from wo.core.cron import WOCron
from wo.core.extract import WOExtract
from wo.core.fileutils import WOFileUtils
@@ -489,6 +485,16 @@ def post_pref(self, apt_packages, packages, upgrade=False):
"the cause of this issue", False)
else:
WOGit.add(self, ["/etc/nginx"], msg="Adding Nginx into Git")
if not os.path.isdir('/etc/systemd/system/nginx.service.d'):
WOFileUtils.mkdir('/etc/systemd/system/nginx.service.d')
if not os.path.isdir(
'/etc/systemd/system/nginx.service.d/limits.conf'):
with open(
'/etc/systemd/system/nginx.service.d/limits.conf',
encoding='utf-8', mode='w') as ngx_limit:
ngx_limit.write('[Service]\nLimitNOFILE=500000')
WOShellExec.cmd_exec(self, 'systemctl daemon-reload')
WOService.restart_service(self, 'nginx')
if set(WOVar.wo_php).issubset(set(apt_packages)):
WOGit.add(self, ["/etc/php"], msg="Adding PHP into Git")
@@ -1415,7 +1421,7 @@ def pre_stack(self):
self, '/lib/systemd/system/wo-kernel.service',
'wo-kernel-service.mustache', data)
WOShellExec.cmd_exec(self, 'systemctl enable wo-kernel.service')
WOShellExec.cmd_exec(self, 'systemctl start wo-kernel.service')
WOService.start_service(self, 'wo-kernel')
# open_files_limit tweak
if not WOFileUtils.grepcheck(self, '/etc/security/limits.conf', '500000'):
with open("/etc/security/limits.conf",

View File

@@ -49,7 +49,7 @@ class WORepo():
Log.error(self, "Unable to add repo")
if ppa is not None:
if WOShellExec.cmd_exec(
self, "LC_ALL=C.UTF-8 add-apt-repository -yu '{ppa_name}'"
self, "LC_ALL=C.UTF-8 add-apt-repository -y '{ppa_name}'"
.format(ppa_name=ppa)):
return True
return False
@@ -70,7 +70,7 @@ class WORepo():
WOVar().wo_repo_file)
try:
repofile = open(repo_file_path, "w+")
repofile = open(repo_file_path, "w+", encoding='utf-8')
repofile.write(repofile.read().replace(repo_url, ""))
repofile.close()
except IOError as e:
@@ -96,19 +96,14 @@ class WORepo():
Log.debug(self, "{0}".format(e))
Log.error(self, "Unable to import repo key")
def add_keys(self, keyids, keyserver=None):
def download_key(self, key_url):
"""
This function adds imports repository keys from keyserver.
default keyserver is hkp://keyserver.ubuntu.com
user can provide other keyserver with keyserver="hkp://xyz"
This function download gpg keys and add import them with apt-key add"
"""
all_keys = ' '.join(keyids)
try:
WOShellExec.cmd_exec(
self, "apt-key adv --keyserver {serv}"
.format(serv=(keyserver or
"hkp://keyserver.ubuntu.com")) +
" --recv-keys {keys}".format(keys=all_keys))
self, "curl -sL {0} ".format(key_url) +
"| apt-key add -")
except Exception as e:
Log.debug(self, "{0}".format(e))
Log.error(self, "Unable to import repo keys")

View File

@@ -4,6 +4,7 @@ import os
from datetime import datetime
from re import match
from socket import getfqdn
from shutil import copy2
from distro import linux_distribution
from sh import git
@@ -28,16 +29,18 @@ class WOVar():
wo_date = datetime.now().strftime('%d%b%Y-%H-%M-%S')
# WordOps core variables
# linux distribution
wo_distro = linux_distribution(
full_distribution_name=False)[0].lower()
wo_platform_version = linux_distribution(
full_distribution_name=False)[1].lower()
# distro codename (bionic, xenial, stretch ...)
wo_platform_codename = linux_distribution(
full_distribution_name=False)[2].lower()
# Get timezone of system
if os.path.isfile('/etc/timezone'):
with open("/etc/timezone", "r") as tzfile:
with open("/etc/timezone", mode='r', encoding='utf-8') as tzfile:
wo_timezone = tzfile.read().replace('\n', '')
if wo_timezone == "Etc/UTC":
wo_timezone = "UTC"
@@ -59,7 +62,7 @@ class WOVar():
# PHP user
wo_php_user = 'www-data'
# Get git user name and EMail
# WordOps git configuration management
config = configparser.ConfigParser()
config.read(os.path.expanduser("~")+'/.gitconfig')
try:
@@ -86,6 +89,9 @@ class WOVar():
git.config("--global", "user.name", "{0}".format(wo_user))
git.config("--global", "user.email", "{0}".format(wo_email))
if not os.path.isfile('/root/.gitconfig'):
copy2(os.path.expanduser("~")+'/.gitconfig', '/root/.gitconfig')
# MySQL hostname
wo_mysql_host = ""
config = configparser.RawConfigParser()