mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
refactor: Move install to php53 branch if running an unsupported version of PHP (#8042)
* Move install to php53 branch if running an unsupport version of PHP * Update validate * Move PHP version check after update check. This will prevent us from moving no update users to the php53 branch. Hopefully if daily.php -f update fails it returns a non-zero and we can move them to the php53 branch still. * Wiggle things around more. * Also, send release installs to the php53 branch. * Set notification error for old PHP version.
This commit is contained in:
committed by
Neil Lathwood
parent
2fb8dd7904
commit
d515f5043e
@@ -53,7 +53,7 @@ class Php implements ValidationGroup
|
|||||||
|
|
||||||
// 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') && version_compare(PHP_VERSION, $min_version, '<')) {
|
if (Config::get('update') && version_compare(PHP_VERSION, $min_version, '<')) {
|
||||||
$validator->warn('PHP version 5.6.4 will be the minimum supported version on January 10, 2018. We recommend you update to PHP a supported version of PHP (7.1 suggested) to continue to receive updates. If you do not update PHP, LibreNMS will continue to function but stop receiving bug fixes and updates.');
|
$validator->warn('PHP version 5.6.4 is the minimum supported version as of January 10, 2018. We recommend you update to PHP a supported version of PHP (7.1 suggested) to continue to receive updates. If you do not update PHP, LibreNMS will continue to function but stop receiving bug fixes and updates.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -62,10 +62,17 @@ class Updates implements ValidationGroup
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($versions['local_branch'] != 'master') {
|
if ($versions['local_branch'] != 'master') {
|
||||||
$validator->warn(
|
if ($versions['local_branch'] == 'php53') {
|
||||||
"Your local git branch is not master, this will prevent automatic updates.",
|
$validator->warn(
|
||||||
"You can switch back to master with git checkout master"
|
"You are on the PHP 5.3 support branch, this will prevent automatic updates.",
|
||||||
);
|
"Update to PHP 5.6.4 or newer (PHP 7.1 recommended) to continue to receive updates."
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
$validator->warn(
|
||||||
|
"Your local git branch is not master, this will prevent automatic updates.",
|
||||||
|
"You can switch back to master with git checkout master"
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
37
daily.php
37
daily.php
@@ -34,25 +34,6 @@ if ($options['f'] === 'update') {
|
|||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($options['f'] === 'check_php_ver') {
|
|
||||||
$min_version = '5.6.4';
|
|
||||||
$warn_title = 'Warning: PHP version too low';
|
|
||||||
|
|
||||||
// if update is not set to false and version is min or newer
|
|
||||||
if (Config::get('update') && version_compare(PHP_VERSION, $min_version, '<')) {
|
|
||||||
new_notification(
|
|
||||||
$warn_title,
|
|
||||||
'PHP version 5.6.4 will be the minimum supported version on January 10, 2018. We recommend you update to PHP a supported version of PHP (7.1 suggested) to continue to receive updates. If you do not update PHP, LibreNMS will continue to function but stop receiving bug fixes and updates.',
|
|
||||||
1,
|
|
||||||
'daily.sh'
|
|
||||||
);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
remove_notification($warn_title);
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($options['f'] === 'rrd_purge') {
|
if ($options['f'] === 'rrd_purge') {
|
||||||
try {
|
try {
|
||||||
if (Config::get('distributed_poller')) {
|
if (Config::get('distributed_poller')) {
|
||||||
@@ -150,6 +131,24 @@ if ($options['f'] === 'handle_notifiable') {
|
|||||||
'daily.sh'
|
'daily.sh'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
} elseif ($options['t'] === 'phpver') {
|
||||||
|
$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 (Config::get('update') && $options['r']) {
|
||||||
|
new_notification(
|
||||||
|
$error_title,
|
||||||
|
'PHP version 5.6.4 is the minimum supported version as of January 10, 2018. We recommend you update to PHP a supported version of PHP (7.1 suggested) to continue to receive updates. If you do not update PHP, LibreNMS will continue to function but stop receiving bug fixes and updates.',
|
||||||
|
2,
|
||||||
|
'daily.sh'
|
||||||
|
);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
remove_notification($error_title);
|
||||||
|
exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
67
daily.sh
67
daily.sh
@@ -1,7 +1,8 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
################################################################################
|
################################################################################
|
||||||
# Copyright (C) 2015 Daniel Preussker, QuxLabs UG <preussker@quxlabs.com>
|
# Copyright (C) 2015 Daniel Preussker, QuxLabs UG <preussker@quxlabs.com>
|
||||||
# Layne "Gorian" Breitkreutz <Layne.Breitkreutz@thelenon.com>
|
# Copyright (C) 2016 Layne "Gorian" Breitkreutz <Layne.Breitkreutz@thelenon.com>
|
||||||
|
# Copyright (C) 2017 Tony Murray <murraytony@gmail.com>
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# This program is free software: you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
@@ -22,6 +23,7 @@
|
|||||||
# define DAILY_SCRIPT as the full path to this script and LIBRENMS_DIR as the directory this script is in
|
# define DAILY_SCRIPT as the full path to this script and LIBRENMS_DIR as the directory this script is in
|
||||||
DAILY_SCRIPT=$(readlink -f "$0")
|
DAILY_SCRIPT=$(readlink -f "$0")
|
||||||
LIBRENMS_DIR=$(dirname "$DAILY_SCRIPT")
|
LIBRENMS_DIR=$(dirname "$DAILY_SCRIPT")
|
||||||
|
COMPOSER="php ${LIBRENMS_DIR}/scripts/composer_wrapper.php"
|
||||||
|
|
||||||
# set log_file, using librenms $config['log_dir'], if set
|
# set log_file, using librenms $config['log_dir'], if set
|
||||||
# otherwise we default to <LibreNMS Install Directory>/logs
|
# otherwise we default to <LibreNMS Install Directory>/logs
|
||||||
@@ -31,7 +33,6 @@ LOG_DIR=$(php -r "@include '${LIBRENMS_DIR}/config.php'; echo isset(\$config['lo
|
|||||||
LIBRENMS_USER=$(php -r "@include '${LIBRENMS_DIR}/config.php'; echo isset(\$config['user']) ? \$config['user'] : 'root';")
|
LIBRENMS_USER=$(php -r "@include '${LIBRENMS_DIR}/config.php'; echo isset(\$config['user']) ? \$config['user'] : 'root';")
|
||||||
LIBRENMS_USER_ID=$(id -u "$LIBRENMS_USER")
|
LIBRENMS_USER_ID=$(id -u "$LIBRENMS_USER")
|
||||||
|
|
||||||
|
|
||||||
#######################################
|
#######################################
|
||||||
# Fancy-Print and run commands
|
# Fancy-Print and run commands
|
||||||
# Globals:
|
# Globals:
|
||||||
@@ -58,7 +59,7 @@ status_run() {
|
|||||||
|
|
||||||
printf "%-50s" "${arg_text}";
|
printf "%-50s" "${arg_text}";
|
||||||
echo "${arg_text}" >> ${log_file}
|
echo "${arg_text}" >> ${log_file}
|
||||||
tmp=$(bash -c "${arg_command}" 2>&1);
|
tmp=$(${arg_command} 2>&1);
|
||||||
exit_code=$?
|
exit_code=$?
|
||||||
echo "${tmp}" >> ${log_file}
|
echo "${tmp}" >> ${log_file}
|
||||||
echo "Returned: ${exit_code}" >> ${log_file}
|
echo "Returned: ${exit_code}" >> ${log_file}
|
||||||
@@ -118,6 +119,28 @@ set_notifiable_result() {
|
|||||||
php "${LIBRENMS_DIR}/daily.php" -f handle_notifiable -t ${arg_type} -r ${arg_result};
|
php "${LIBRENMS_DIR}/daily.php" -f handle_notifiable -t ${arg_type} -r ${arg_result};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# Check the PHP version and branch and switch to the appropriate branch
|
||||||
|
# Returns:
|
||||||
|
# Exit-Code: 0 >= min ver, 1 < min ver
|
||||||
|
#######################################
|
||||||
|
check_php_ver() {
|
||||||
|
local branch=$(git rev-parse --abbrev-ref HEAD)
|
||||||
|
local ver_res=$(php -r "echo (int)version_compare(PHP_VERSION, '5.6.4', '<');")
|
||||||
|
if [[ "$branch" == "php53" ]] && [[ "$ver_res" == "0" ]]; then
|
||||||
|
status_run "Supported PHP version, switched back to master branch." 'git checkout master'
|
||||||
|
branch="master"
|
||||||
|
elif [[ "$branch" != "php53" ]] && [[ "$ver_res" == "1" ]]; then
|
||||||
|
status_run "Unsupported PHP version, switched to php53 branch." 'git checkout php53'
|
||||||
|
branch="php53"
|
||||||
|
fi
|
||||||
|
|
||||||
|
set_notifiable_result phpver ${ver_res}
|
||||||
|
|
||||||
|
return ${ver_res};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#######################################
|
#######################################
|
||||||
# Entry into program
|
# Entry into program
|
||||||
# Globals:
|
# Globals:
|
||||||
@@ -129,6 +152,10 @@ set_notifiable_result() {
|
|||||||
#######################################
|
#######################################
|
||||||
main () {
|
main () {
|
||||||
local arg="$1";
|
local arg="$1";
|
||||||
|
local old_version="$2";
|
||||||
|
local new_version="$3";
|
||||||
|
local old_version="${old_version:=unset}" # if $1 is unset, make it mismatch for pre-update daily.sh
|
||||||
|
|
||||||
cd ${LIBRENMS_DIR};
|
cd ${LIBRENMS_DIR};
|
||||||
|
|
||||||
# if not running as $LIBRENMS_USER (unless $LIBRENMS_USER = root), relaunch
|
# if not running as $LIBRENMS_USER (unless $LIBRENMS_USER = root), relaunch
|
||||||
@@ -145,9 +172,12 @@ main () {
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -z "$arg" ]]; then
|
# make sure autoload.php exists before trying to run any php that may require it
|
||||||
status_run 'Checking PHP version' "php ${LIBRENMS_DIR}/daily.php -f check_php_ver" 'check_php_ver'
|
if [ ! -f "${LIBRENMS_DIR}/vendor/autoload.php" ]; then
|
||||||
|
${COMPOSER} install --no-dev
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -z "$arg" ]]; then
|
||||||
up=$(php daily.php -f update >&2; echo $?)
|
up=$(php daily.php -f update >&2; echo $?)
|
||||||
if [[ "$up" == "0" ]]; then
|
if [[ "$up" == "0" ]]; then
|
||||||
${DAILY_SCRIPT} no-code-update
|
${DAILY_SCRIPT} no-code-update
|
||||||
@@ -155,16 +185,19 @@ main () {
|
|||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
status_run 'Checking PHP version' 'check_php_ver'
|
||||||
|
php_ver_ret=$?
|
||||||
|
|
||||||
# make sure the vendor directory is clean
|
# make sure the vendor directory is clean
|
||||||
git checkout vendor/ --quiet > /dev/null 2>&1
|
git checkout vendor/ --quiet > /dev/null 2>&1
|
||||||
|
|
||||||
update_res=0
|
update_res=0
|
||||||
if [[ "$up" == "1" ]]; then
|
if [[ "$up" == "1" ]] || [[ "$php_ver_ret" == "0" ]]; then
|
||||||
# Update to Master-Branch
|
# Update current branch to latest
|
||||||
old_ver=$(git show --pretty="%H" -s HEAD)
|
old_ver=$(git rev-parse --short HEAD)
|
||||||
status_run 'Updating to latest codebase' 'git pull --quiet' 'update'
|
status_run 'Updating to latest codebase' 'git pull --quiet' 'update'
|
||||||
update_res=$?
|
update_res=$?
|
||||||
new_ver=$(git show --pretty="%H" -s HEAD)
|
new_ver=$(git rev-parse --short HEAD)
|
||||||
elif [[ "$up" == "3" ]]; then
|
elif [[ "$up" == "3" ]]; then
|
||||||
# Update to last Tag
|
# Update to last Tag
|
||||||
old_ver=$(git describe --exact-match --tags $(git log -n1 --pretty='%h'))
|
old_ver=$(git describe --exact-match --tags $(git log -n1 --pretty='%h'))
|
||||||
@@ -177,13 +210,8 @@ main () {
|
|||||||
set_notifiable_result update 0
|
set_notifiable_result update 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$old_ver" != "$new_ver" ]]; then
|
|
||||||
status_run "Updated from $old_ver to $new_ver" ''
|
|
||||||
set_notifiable_result update 1 # only clear the error if update was a success
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Call ourself again in case above pull changed or added something to daily.sh
|
# Call ourself again in case above pull changed or added something to daily.sh
|
||||||
${DAILY_SCRIPT} post-pull
|
${DAILY_SCRIPT} post-pull ${old_ver} ${new_ver}
|
||||||
else
|
else
|
||||||
case $arg in
|
case $arg in
|
||||||
no-code-update)
|
no-code-update)
|
||||||
@@ -193,6 +221,15 @@ main () {
|
|||||||
status_run 'Cleaning up DB' "$DAILY_SCRIPT cleanup"
|
status_run 'Cleaning up DB' "$DAILY_SCRIPT cleanup"
|
||||||
;;
|
;;
|
||||||
post-pull)
|
post-pull)
|
||||||
|
# Check if we need to revert (Must be in post pull so we can update it)
|
||||||
|
if [[ "$old_version" != "$new_version" ]]; then
|
||||||
|
check_php_ver # check php version and switch branches
|
||||||
|
|
||||||
|
# new_version may be incorrect if we just switch branches... ignoring that detail
|
||||||
|
status_run "Updated from $old_version to $new_version" ''
|
||||||
|
set_notifiable_result update 1 # only clear the error if update was a success
|
||||||
|
fi
|
||||||
|
|
||||||
# List all tasks to do after pull in the order of execution
|
# List all tasks to do after pull in the order of execution
|
||||||
status_run 'Updating SQL-Schema' 'php includes/sql-schema/update.php'
|
status_run 'Updating SQL-Schema' 'php includes/sql-schema/update.php'
|
||||||
status_run 'Updating submodules' "$DAILY_SCRIPT submodules"
|
status_run 'Updating submodules' "$DAILY_SCRIPT submodules"
|
||||||
|
71
scripts/composer_wrapper.php
Executable file
71
scripts/composer_wrapper.php
Executable file
@@ -0,0 +1,71 @@
|
|||||||
|
#!/usr/bin/env php
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* composer_wrapper.php
|
||||||
|
*
|
||||||
|
* Wrapper for composer to use system provided composer or download and use composer.phar
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* @package LibreNMS
|
||||||
|
* @link http://librenms.org
|
||||||
|
* @copyright 2017 Tony Murray
|
||||||
|
* @author Tony Murray <murraytony@gmail.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
$install_dir = realpath(__DIR__ . '/..');
|
||||||
|
chdir($install_dir);
|
||||||
|
|
||||||
|
// Set up proxy if needed
|
||||||
|
$proxy = getenv("HTTP_PROXY") ?: getenv("http_proxy");
|
||||||
|
if (!$proxy && $proxy = rtrim(shell_exec('git config --global --get http.proxy'))) {
|
||||||
|
// Use git http.proxy if available
|
||||||
|
putenv("HTTP_PROXY=$proxy");
|
||||||
|
}
|
||||||
|
|
||||||
|
$exec = false;
|
||||||
|
|
||||||
|
$path_exec = shell_exec("which composer 2> /dev/null");
|
||||||
|
if (!empty($path_exec)) {
|
||||||
|
$exec = trim($path_exec);
|
||||||
|
} elseif (is_file($install_dir . '/composer.phar')) {
|
||||||
|
$exec = 'php ' . $install_dir . '/composer.phar';
|
||||||
|
} else {
|
||||||
|
if ($proxy) {
|
||||||
|
$stream_default_opts = array(
|
||||||
|
'http' => array(
|
||||||
|
'proxy' => str_replace('http://', 'tcp://', $proxy),
|
||||||
|
'request_fulluri' => true,
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
stream_context_set_default($stream_default_opts);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Download composer.phar (code from the composer web site)
|
||||||
|
$sha = trim(file_get_contents('http://composer.github.io/installer.sig'));
|
||||||
|
@copy('http://getcomposer.org/installer', 'composer-setup.php');
|
||||||
|
if (@hash_file('SHA384', 'composer-setup.php') === $sha) {
|
||||||
|
// Installer verified
|
||||||
|
shell_exec('php composer-setup.php');
|
||||||
|
$exec = 'php ' . $install_dir . '/composer.phar';
|
||||||
|
}
|
||||||
|
@unlink('composer-setup.php');
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($exec) {
|
||||||
|
passthru("$exec " . implode(' ', array_splice($argv, 1)) . ' 2>&1');
|
||||||
|
} else {
|
||||||
|
echo "Composer not available, please manually install composer.\n";
|
||||||
|
}
|
Reference in New Issue
Block a user