Send to PHP 71/Python2 support branch

This commit is contained in:
Tony Murray
2020-05-02 01:37:22 -05:00
parent 0900f9513e
commit 55e70be6ba
2 changed files with 80 additions and 23 deletions

View File

@@ -172,15 +172,13 @@ if ($options['f'] === 'handle_notifiable') {
} }
} elseif ($options['t'] === 'phpver') { } elseif ($options['t'] === 'phpver') {
$error_title = 'Error: PHP version too low'; $error_title = 'Error: PHP version too low';
$warn_title = 'Warning: PHP version too low';
remove_notification($warn_title); // remove warning
// if update is not set to false and version is min or newer // if update is not set to false and version is min or newer
if (Config::get('update') && $options['r']) { if (Config::get('update') && $options['r']) {
if ($options['r'] === 'php53') { if ($options['r'] === 'php53') {
$phpver = '5.6.4'; $phpver = '5.6.4';
$eol_date = 'January 10th, 2018'; $eol_date = 'January 10th, 2018';
} elseif ($options['r'] === 'php56') { } elseif ($options['r'] === 'php56' || $options['r'] === 'php71') {
$phpver = Php::PHP_MIN_VERSION; $phpver = Php::PHP_MIN_VERSION;
$eol_date = Php::PHP_MIN_VERSION_DATE; $eol_date = Php::PHP_MIN_VERSION_DATE;
} }
@@ -195,6 +193,32 @@ if ($options['f'] === 'handle_notifiable') {
} }
} }
remove_notification($error_title);
exit(0);
} elseif ($options['t'] === 'pythonver') {
$error_title = 'Error: Python requirements not met';
// if update is not set to false and version is min or newer
if (Config::get('update') && $options['r']) {
if ($options['r'] === 'python3-missing') {
new_notification(
$error_title,
"Python 3 is required to run LibreNMS as of May, 2020. You need to install Python 3 to continue to receive updates. If you do not install Python 3 and required packages, LibreNMS will continue to function but stop receiving bug fixes and updates.",
2,
'daily.sh'
);
exit(1);
} elseif ($options['r'] === 'python3-deps') {
new_notification(
$error_title,
"Python 3 dependencies are missing. You need to install them via pip3 install -r requirements.txt or system packages to continue to receive updates. If you do not install Python 3 and required packages, LibreNMS will continue to function but stop receiving bug fixes and updates.",
2,
'daily.sh'
);
exit(1);
}
}
remove_notification($error_title); remove_notification($error_title);
exit(0); exit(0);
} }
@@ -219,7 +243,7 @@ if ($options['f'] === 'bill_data') {
$table = 'bill_data'; $table = 'bill_data';
$sql = "DELETE bill_data $sql = "DELETE bill_data
FROM bill_data FROM bill_data
INNER JOIN (SELECT bill_id, INNER JOIN (SELECT bill_id,
SUBDATE( SUBDATE(
SUBDATE( SUBDATE(
ADDDATE( ADDDATE(
@@ -242,7 +266,7 @@ if ($options['f'] === 'alert_log') {
WHERE alerts.state=0 AND alert_log.time_logged < DATE_SUB(NOW(),INTERVAL ? DAY) WHERE alerts.state=0 AND alert_log.time_logged < DATE_SUB(NOW(),INTERVAL ? DAY)
"; ";
lock_and_purge_query($table, $sql, $msg); lock_and_purge_query($table, $sql, $msg);
# alert_log older than $config['alert_log_purge'] days match now only the alert_log of active alerts # alert_log older than $config['alert_log_purge'] days match now only the alert_log of active alerts
# in case of flapping of an alert, many entries are kept in alert_log # in case of flapping of an alert, many entries are kept in alert_log
# we want only to keep the last alert_log that contains the alert details # we want only to keep the last alert_log that contains the alert details

View File

@@ -120,31 +120,61 @@ set_notifiable_result() {
} }
####################################### #######################################
# Check the PHP version and branch and switch to the appropriate branch # Check the PHP and Python version and branch and switch to the appropriate branch
# Returns: # Returns:
# Exit-Code: 0 >= min ver, 1 < min ver # Exit-Code: 0 >= min ver, 1 < min ver
####################################### #######################################
check_php_ver() { check_dependencies() {
local branch=$(git rev-parse --abbrev-ref HEAD) local branch=$(git rev-parse --abbrev-ref HEAD)
scripts/check_requirements.py > /dev/null 2>&1 || pip3 install -r requirements.txt > /dev/null 2>&1
local ver_56=$(php -r "echo (int)version_compare(PHP_VERSION, '5.6.4', '<');") local ver_56=$(php -r "echo (int)version_compare(PHP_VERSION, '5.6.4', '<');")
local ver_71=$(php -r "echo (int)version_compare(PHP_VERSION, '7.1.3', '<');") local ver_71=$(php -r "echo (int)version_compare(PHP_VERSION, '7.1.3', '<');")
if [[ "$branch" == "php53" ]] && [[ "$ver_56" == "0" ]]; then local ver_72=$(php -r "echo (int)version_compare(PHP_VERSION, '7.2.5', '<');")
status_run "Supported PHP version, switched back to master branch." 'git checkout master' local python3=$(python3 -c "import sys;print(int(sys.version_info < (3, 5)))" 2> /dev/null)
branch="master" local python_deps=$(scripts/check_requirements.py > /dev/null 2>&1; echo $?)
elif [[ "$branch" == "php56" ]] && [[ "$ver_71" == "0" ]]; then local phpver="master"
status_run "Supported PHP version, switched back to master branch." 'git checkout master' local pythonver="master"
branch="master"
elif [[ "$branch" != "php53" ]] && [[ "$ver_56" == "1" ]]; then local old_branches="php53 php56 php71-python2"
status_run "Unsupported PHP version, switched to php53 branch." 'git checkout php53' if [[ " $old_branches " =~ " $branch " ]] && [[ "$ver_72" == "0" && "$python3" == "0" && "$python_deps" == "0" ]]; then
branch="php53" status_run "Supported PHP and Python version, switched back to master branch." 'git checkout master'
elif [[ "$branch" != "php56" ]] && [[ "$ver_71" == "1" ]]; then elif [[ "$ver_56" != "0" ]]; then
status_run "Unsupported PHP version, switched to php56 branch." 'git checkout php56' phpver="php53"
branch="php56" if [[ "$branch" != "php53" ]]; then
status_run "Unsupported PHP version, switched to php53 branch." 'git checkout php53'
fi
elif [[ "$ver_71" != "0" ]]; then
phpver="php56"
if [[ "$branch" != "php56" ]]; then
status_run "Unsupported PHP version, switched to php56 branch." 'git checkout php56'
fi
elif [[ "$ver_72" != "0" || "$python3" != "0" || "$python_deps" != "0" ]]; then
local msg=""
if [[ "$ver_72" != "0" ]]; then
msg="Unsupported PHP version, $msg"
phpver="php71"
fi
if [[ "$python3" != "0" ]]; then
msg="python3 is not available, $msg"
pythonver="python3-missing"
elif [[ "$python_deps" != "0" ]]; then
msg="Python 3 dependencies missing, $msg"
pythonver="python3-deps"
fi
if [[ "$branch" != "php71-python2" ]]; then
status_run "${msg}switched to php71-python2 branch." 'git checkout php71-python2'
fi
fi fi
set_notifiable_result phpver ${branch} set_notifiable_result phpver ${phpver}
set_notifiable_result pythonver ${pythonver}
return ${ver_res}; if [[ "$phpver" == "master" && "$pythonver" == "master" ]]; then
return 0;
fi
return 1;
} }
@@ -192,7 +222,7 @@ main () {
exit exit
fi fi
check_php_ver check_dependencies
php_ver_ret=$? php_ver_ret=$?
# make sure the vendor directory is clean # make sure the vendor directory is clean
@@ -234,6 +264,9 @@ main () {
status_run 'Cleaning up DB' "$DAILY_SCRIPT cleanup" status_run 'Cleaning up DB' "$DAILY_SCRIPT cleanup"
;; ;;
post-pull) post-pull)
# re-check dependencies after pull with the new code
check_dependencies
# Check for missing vendor dir # Check for missing vendor dir
if [ ! -f vendor/autoload.php ]; then if [ ! -f vendor/autoload.php ]; then
git checkout 609676a9f8d72da081c61f82967e1d16defc0c4e -- vendor/ git checkout 609676a9f8d72da081c61f82967e1d16defc0c4e -- vendor/
@@ -244,7 +277,7 @@ main () {
# Check if we need to revert (Must be in post pull so we can update it) # Check if we need to revert (Must be in post pull so we can update it)
if [[ "$old_version" != "$new_version" ]]; then if [[ "$old_version" != "$new_version" ]]; then
check_php_ver # check php version and switch branches check_dependencies # check php and python version and switch branches
# new_version may be incorrect if we just switch branches... ignoring that detail # new_version may be incorrect if we just switch branches... ignoring that detail
status_run "Updated from $old_version to $new_version" '' status_run "Updated from $old_version to $new_version" ''