Created
July 29, 2013 04:13
-
-
Save kazeburo/6102110 to your computer and use it in GitHub Desktop.
carton install with mysql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
do 'mysql_helper.pl'; | |
requires 'DBD::mysql'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use File::Temp qw/tempdir/; | |
use Cwd; | |
my $MYSQL_VERSION = '5.5.32'; # 5.5.x or 5.6.x | |
$MYSQL_VERSION =~ m!^(5\.[5-6])\.\d+$! or die "non supported version"; | |
my $version_major = $1; | |
my $cwd = getcwd(); | |
my @path = split /:/,$ENV{PATH}; | |
push @path, '/usr/local/mysql/bin'; | |
push @path, $cwd.'/local/bin'; | |
my $mysql_config; | |
my $bin_path; | |
for my $path (@path){ | |
if ( -x $path . '/mysql_config' ) { | |
$mysql_config = $path . '/mysql_config'; | |
$bin_path = $path; | |
last; | |
} | |
} | |
if ( $mysql_config ) { | |
warn "mysql_config found in $mysql_config"; | |
my $version = `$mysql_config --version`; | |
if ( $version =~ m!^4! ) { | |
$mysql_config = undef; | |
} | |
} | |
if ( !$mysql_config ) { | |
my $dir = tempdir( CLEANUP => 1 ); | |
my $shell = <<'EOF'; | |
#!/bin/sh | |
set -e | |
CDIR=$(cd $(dirname $0) && pwd) | |
cd $CDIR | |
wget http://ftp.jaist.ac.jp/pub/mysql/Downloads/MySQL-<% VERSION_MAJOR %>/mysql-<% VERSION %>.tar.gz | |
tar zxf mysql-<% VERSION %>.tar.gz | |
cd mysql-<% VERSION %> | |
cmake . -DCMAKE_INSTALL_PREFIX=<% INSTALL_PREFIX %>/local \ | |
-DDEFAULT_CHARSET=utf8 \ | |
-DWITH_EXTRA_CHARSETS=all \ | |
-DDEFAULT_COLLATION=utf8_general_ci \ | |
-DWITH_DEBUG=0 \ | |
-DWITH_READLINE=1 \ | |
-DWITH_ZLIB=bundled | |
make | |
make install | |
EOF | |
$shell =~ s!<% VERSION_MAJOR %>!$version_major!g; | |
$shell =~ s!<% VERSION %>!$MYSQL_VERSION!g; | |
$shell =~ s!<% INSTALL_PREFIX %>!$cwd!g; | |
open my $fh, '>', "$dir/setup.sh"; | |
$fh->print($shell); | |
my $ret = system('/bin/bash',"$dir/setup.sh"); | |
die "failed to install mysql to local" if $ret != 0; | |
$ENV{PATH} = "local/bin:".$ENV{PATH}; | |
} | |
elsif ( $bin_path eq '/usr/local/mysql/bin' || $bin_path eq "$cwd/local/bin" ) { | |
$ENV{PATH} = $bin_path.":".$ENV{PATH}; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment