如何为Ruby 1.9.3安装openssl

时间:2015-05-21 16:02:04

标签: ruby openssl

这让我发疯了。无休止的谷歌搜索对于什么应该是一个简单的任务产生零帮助。我有一个ruby脚本需要' openssl'库,一个以前在我将Ruby构建升级到2.2.2之前工作的脚本。这搞砸了我现有的所有红宝石,所以我回到原来的1.9.3版本,而openssl现在已经不见了。我试过了

<?php
header('Content-Type: application/json; charset=UTF-8');
$argv = $_SERVER['argv'];
$totalArgv = count($argv);
// Use PDO to connect to the DB
$dsn = 'mysql:dbname=busaweb_stores;host=127.0.0.1';
$dsn_training = 'mysql:dbname=busaweb_busaedu;host=127.0.0.1';
$user = 'busaweb_*****';
$password = '*****';

try {
$dbs = new PDO($dsn, $user, $password);
$dbt = new PDO($dsn_training, $user, $password);
$dbs->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 
$dbt->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
//echo 'Connected to SQL Server';
} 
catch (PDOException $e) {
die_with_error('PDO Connection failed: ' . $e->getMessage());
}

//Check request
if (is_ajax()) {
if (isset($_POST["action"]) && !empty($_POST["action"])) { //Checks if action value exists
$action = $_POST["action"];
switch($action) { //Switch case for value of action
  case "move":
    move_files(); 
    echo_success("Files have been moved.");
    break;
  case "update-stores":
    $count = update_stores_db($dbs);
    echo_success("DB Updated.<br>" . $count . " Stores Geocoded.");
    break;
  case "geocode":
    $count = geocode_remaining($dbs);
    echo_success($count . " stores geocoded.");
    break;
  case "update-training":
    update_training_db($dbt);
    echo_success("Training DB Updated.");
    break;
  case "update-all":
    $count = update_stores_db($dbs);
    update_training_db($dbt);
    echo_success("DB Updated.<br>" . $count . " Stores Geocoded.");
    break;
  case "backup":
    $backupFile = backup_db();
    echo_success("DB Backed Up: <br>" . $backupFile);
    break;
  default:
    //Close PDO Connections
    $dbs = null;
    $dbt = null;
    break;
}
}
}
//if being executed from the shell, update all
else if($totalArgv > 0){
$count = update_stores_db($dbs);
update_training_db($dbt);
echo_success("DB Updated.<br>" . $count . " Stores Geocoded.");
break;
};

//Function to check if the request is an AJAX request
function is_ajax() {
return isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest';
}

//Error handling
function die_with_error($error) {
$return = array(
    "status" => "Failed",
    "data" => $error
);
//Close PDO Connections
$dbs = null;
$dbt = null;
die(json_encode($return));
}

function echo_success($message){
$return = array(
    "status" => "OK",
    "data" => $message
);
$return["json"] = json_encode($return);
echo json_encode($return);
//Close PDO Connections
$dbs = null;
$dbt = null;
}

//Move all files
function move_files(){
try {
    move_file('sfinder/StoreList.txt');
    move_file('sfinder/StoreProductIndex.txt');
    move_file('sfinder/StoreTypeIndex.txt');
    move_file('training/TrainingCustomerList.txt');
}
catch(Exception $e){
    die_with_error($e->getMessage());
}

//sleep(1);
//Return JSON
$return["json"] = json_encode($return);
echo json_encode($return);
}

//Move a file
function move_file($filename){
$source ="/home/busaweb/public_html/b3/" . $filename;
$dest = "/home/busaweb/public_html/adminportal/includes/sfupdate/" . $filename;
if(!copy($source, $dest)){
    throw new Exception("Failed to copy file: " . $filename);
}
else{
    //echo "Successfully moved $filename.<br>";
}
}

//Empty a SQL Table
function empty_table($dbconnection, $tablename){
try{
    $sql = "TRUNCATE TABLE " . $tablename;
    $sth = $dbconnection->prepare($sql);
    //$sth->bindParam(':tablename', $tablename, PDO::PARAM_STR);

    // The row is actually inserted here
    $sth->execute();
    //echo " [+]Table '" . $tablename . "' has been emptied.<br>";
    $sth->closeCursor();
}
catch(PDOException $e) {  
    die_with_error($e->getMessage()); 
}
}

//Import CSV file from JDE to DB
function load_csv($dbconn, $filename, $tablename){
try{
    $sql = "LOAD DATA LOCAL INFILE '/home/busaweb/public_html/adminportal/includes/sfupdate/" . $filename . "' INTO TABLE  " . $tablename . " FIELDS TERMINATED BY  '\\t' ENCLOSED BY  '\"' ESCAPED BY  '\\\' LINES TERMINATED BY  '\\n'";
    $sth = $dbconn->prepare($sql);

    // The row is actually inserted here
    $sth->execute();
    //echo " [+]CSV File for '" . $tablename . "' Table Imported.<br>";
    $sth->closeCursor();
}
catch(PDOException $e) {  
    die_with_error($e->getMessage()); 
}
}
function update_stores_db($dbs){
move_files();
empty_table($dbs, "stores");
load_csv($dbs, 'sfinder/StoreList.txt', 'stores');
empty_table($dbs, 'stores_product_type_link');
load_csv($dbs, 'sfinder/StoreProductIndex.txt', 'stores_product_type_link');
empty_table($dbs, 'stores_store_type_link');
load_csv($dbs, 'sfinder/StoreTypeIndex.txt', 'stores_store_type_link');
return $count;
}

function update_training_db($dbt){
move_file('training/TrainingCustomerList.txt');
empty_table($dbt, 'customers');
load_csv($dbt, 'training/TrainingCustomerList.txt', 'customers');
}
}
?>

以及其他一些变体,但这只会引发错误

gem install 'openssl'

有人能告诉我如何在Ruby安装中获得openssl吗?

2 个答案:

答案 0 :(得分:1)

我建议尝试ruby-build,这是一个ruby安装程序。

即使您不打算长期使用它,也可以安装所有依赖项,例如SSL。如果ruby-build为您成功,那么您可以查看其日志以了解它是如何成功的。

答案 1 :(得分:0)

好的,所以我的问题是一个愚蠢的问题,甚至没有意义。 Openssl不是问题所在,我能够解决自己的问题。如果管理员可以关闭甚至删除此帖子,那对每个人来说都可能是最好的。