コード例 #1
0
ファイル: version.php プロジェクト: ArtFaks/berryio
function version_upgrade()
{
    // Must be run in CLI mode
    if ($GLOBALS['EXEC_MODE'] != 'cli') {
        return FALSE;
    }
    // Fetch the current version
    if (($latest_version = version_latest()) === FALSE) {
        echo 'Unable to fetch the latest version number at this time, are you connected to the Internet?';
        return FALSE;
    }
    // Introdution
    echo PHP_EOL;
    echo 'Current Version: ' . $GLOBALS['VERSION_NO'] . ' (' . $GLOBALS['VERSION_DATE'] . ')' . PHP_EOL;
    echo 'Latest Version:  ' . $latest_version[VERSION_NO] . ' (' . trim($latest_version[VERSION_DATE]) . ')' . PHP_EOL;
    echo PHP_EOL;
    // Version check
    if ($latest_version[VERSION_NO] == $GLOBALS['VERSION_NO'] && $latest_version[VERSION_DATE] == $GLOBALS['VERSION_DATE']) {
        echo 'Your version appears to be the latest.' . PHP_EOL . 'We will sync anyway in case there are any minor updates....' . PHP_EOL . PHP_EOL;
    } else {
        echo 'Your current version appears to be different to the latest version.' . PHP_EOL . 'Starting the upgrade process....' . PHP_EOL . PHP_EOL;
    }
    // Sync with github
    echo 'Syncing the application files....' . PHP_EOL;
    exec('cd ' . BASE . '; git pull origin master 2>&1', $output, $return_var);
    if ($return_var != 0) {
        echo 'Failed to sync!' . PHP_EOL . PHP_EOL;
        echo 'The output was as follows:' . PHP_EOL;
        echo implode(PHP_EOL, $output);
        return FALSE;
    }
    // Restart apache
    echo 'Restarting Apache....' . PHP_EOL;
    exec('service apache2 restart 2>&1', $output, $return_var);
    if ($return_var != 0) {
        echo 'Apache failed to restart!' . PHP_EOL . PHP_EOL;
        echo 'The output was as follows:' . PHP_EOL;
        echo implode(PHP_EOL, $output);
        return FALSE;
    }
    echo PHP_EOL . 'Upgrade successful!' . PHP_EOL;
    return TRUE;
}
コード例 #2
0
ファイル: check_version.php プロジェクト: summychou/berryio
<?php

/*------------------------------------------------------------------------------
  BerryIO Check Version Command
------------------------------------------------------------------------------*/
$title = 'Version Check';
// Load the version control functions
require_once FUNCTIONS . 'version.php';
// Fetch the current version
if (($latest_version = version_latest()) === FALSE) {
    $content .= message('ERROR: Unable to fetch the latest version number at this time, are you connected to the Internet?');
    return FALSE;
}
if ($latest_version[VERSION_NO] == $GLOBALS['VERSION_NO'] && $latest_version[VERSION_DATE] == $GLOBALS['VERSION_DATE']) {
    $content .= message(REAL_NAME . ' is up to date' . PHP_EOL . 'V' . $GLOBALS['VERSION_NO'] . ' is the current version', 'about');
} else {
    // Find out the command line executable (if this is not running on the command line we are going to need to guess)
    $berryio = $GLOBALS['EXEC_MODE'] != 'cli' ? 'berryio' : $GLOBALS['EXEC'];
    $title = 'An upgrade is available!';
    $content .= view('pages/upgrade_available', array('berryio' => $berryio, 'version_number' => $latest_version[VERSION_NO], 'version_date' => $latest_version[VERSION_DATE]));
}
コード例 #3
0
ファイル: version.php プロジェクト: ikonron/berryio
function version_upgrade()
{
    // Must be run in CLI mode
    if ($GLOBALS['EXEC_MODE'] != 'cli') {
        return FALSE;
    }
    // Fetch the current version
    if (($latest_version = version_latest()) === FALSE) {
        echo 'Unable to fetch the latest version number at this time, are you connected to the Internet?';
        return FALSE;
    }
    // Introduction
    echo PHP_EOL;
    echo 'Current Version: ' . $GLOBALS['VERSION_NO'] . ' (' . $GLOBALS['VERSION_DATE'] . ')' . PHP_EOL;
    echo 'Latest Version:  ' . $latest_version[VERSION_NO] . ' (' . trim($latest_version[VERSION_DATE]) . ')' . PHP_EOL;
    echo PHP_EOL;
    // Version check
    if ($latest_version[VERSION_NO] == $GLOBALS['VERSION_NO'] && $latest_version[VERSION_DATE] == $GLOBALS['VERSION_DATE']) {
        echo 'Your version appears to be the latest.' . PHP_EOL . 'We will sync anyway in case there are any minor updates....' . PHP_EOL . PHP_EOL;
    } else {
        echo 'Your current version appears to be different to the latest version.' . PHP_EOL . 'Starting the upgrade process....' . PHP_EOL . PHP_EOL;
    }
    // Sync with github
    echo 'Syncing the application files....' . PHP_EOL;
    exec('cd ' . BASE . '; git pull origin master 2>&1', $output, $return_var);
    if ($return_var != 0) {
        echo 'Failed to sync!' . PHP_EOL . PHP_EOL;
        echo 'The output was as follows:' . PHP_EOL;
        echo implode(PHP_EOL, $output);
        return FALSE;
    }
    // Patch the apache site config file for the new GPIO location
    $patch_file = '/etc/apache2/sites-available/berryio';
    $patch_example = '/usr/share/berryio/default_config/apache2/sites-available/';
    $patch_before = 'php_admin_value open_basedir "/usr/share/berryio/:/etc/berryio/:/sys/class/gpio/:/sys/devices/virtual/gpio/"';
    $patch_after = 'php_admin_value open_basedir "/usr/share/berryio/:/etc/berryio/:/sys/class/gpio/:/sys/devices/virtual/gpio/:/sys/devices/"';
    if (!file_exists($patch_file)) {
        echo 'WARNING:' . PHP_EOL . 'Your Apache site config file cannot be found, you will need to perform any updates manually.' . PHP_EOL;
        echo 'An example can be found in ' . $patch_example . PHP_EOL . PHP_EOL;
    } else {
        // Get the file
        $contents = file_get_contents($patch_file);
        if (strpos($contents, $patch_before) !== FALSE) {
            echo 'Patching the Apache site config file....' . PHP_EOL;
            $contents = strtr($contents, array($patch_before => $patch_after));
            if (file_put_contents($patch_file, $contents) === FALSE) {
                echo 'WARNING:' . PHP_EOL . 'Your Apache site config file could not be patched, you will need to perform the changes manually.' . PHP_EOL;
                echo 'An example can be found in ' . $patch_example . PHP_EOL . PHP_EOL;
            }
        } elseif (strpos($contents, $patch_after) === FALSE) {
            echo 'WARNING:' . PHP_EOL . 'Your Apache site config file is non standard, you will need to perform any updates manually.' . PHP_EOL;
            echo 'An example can be found in ' . $patch_example . PHP_EOL . PHP_EOL;
        }
    }
    // Restart apache
    echo 'Restarting Apache....' . PHP_EOL;
    exec('service apache2 restart 2>&1', $output, $return_var);
    if ($return_var != 0) {
        echo 'Apache failed to restart!' . PHP_EOL . PHP_EOL;
        echo 'The output was as follows:' . PHP_EOL;
        echo implode(PHP_EOL, $output);
        return FALSE;
    }
    echo PHP_EOL . 'Upgrade successful!' . PHP_EOL;
    return TRUE;
}