Páginas

domingo, 13 de noviembre de 2011

Instalar ruby on rails

Instalar ruby rails en plataforma de desarrollo gentoo.
http://www.rubyonrails.org.es/
http://www.guateonrails.com Javier Alvarez.

Si están aprendiendo Ruby on Rails este es un sitio de visita obligada y visualicen los videos del sitio, excelentemente sencillos. Guateonrails.

Ruby es un lenguaje de programación interpretado que funciona con cualquier sistema operativo, aunque con los sistemas tipo Unix es que mejor se integra.


Instalar ruby:

# emerge -av ruby

These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild  N     ] app-admin/eselect-ruby-20100603  2 kB
[ebuild  N     ] dev-lang/ruby-1.8.7_p352  USE="berkdb gdbm ipv6 ncurses readline ssl -debug -doc -examples -libedit -rubytests -socks5 -threads -tk -xemacs" 4,112 kB

Total: 2 packages (2 new), Size of downloads: 4,114 kB

Would you like to merge these packages? [Yes/No] y

Instalar rubygems:

# emerge -av rubygems

These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild  N     ] dev-ruby/rubygems-1.3.7-r1  USE="-doc -server" RUBY_TARGETS="ruby18 -jruby -ree18" 285 kB

Total: 1 package (1 new), Size of downloads: 285 kB

Would you like to merge these packages? [Yes/No] y

Al finalzar la instalación un mensaje nos advierte:

 * To switch between available Ruby profiles, execute as root:
 * eselect ruby set ruby(18|19|...)

Procedemos:

# eselect ruby list
Available Ruby profiles:
  [1]   ruby18 (with Rubygems) *
# eselect ruby set ruby18
Successfully switched to profile:
  ruby18

Averiguar versión instalada:                
# gem -v
1.3.7

Instalar rails a través de Rubygem:

 # gem18 install rails --include-dependencies
INFO:  `gem install -y` is now default and will be removed
INFO:  use --ignore-dependencies to install only the gems you list
Building native extensions.  This could take a while...
Depending on your version of ruby, you may need to install ruby rdoc/ri data:

<= 1.8.6 : unsupported
 = 1.8.7 : gem install rdoc-data; rdoc-data --install
 = 1.9.1 : gem install rdoc-data; rdoc-data --install
>= 1.9.2 : nothing to do! Yay!
...

En un futuro para actualizar Rails solo tendremos que teclear:

# gem update rails --include-dependencies

# emerge -av sqlite3-ruby

These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild  N     ] virtual/rubygems-1  RUBY_TARGETS="(ruby18)" 0 kB
[ebuild  N     ] dev-ruby/rake-0.8.7-r5  USE="-bash-completion -doc -test" RUBY_TARGETS="ruby18 -jruby -ree18" 101 kB
[ebuild  N     ] dev-ruby/hoe-2.8.0  USE="-doc -test" RUBY_TARGETS="ruby18 -jruby -ree18" 114 kB
[ebuild  N     ] dev-ruby/rake-compiler-0.7.5  USE="-test" RUBY_TARGETS="ruby18 -jruby -ree18" 26 kB
[ebuild  N     ] dev-ruby/sqlite3-ruby-1.3.2  USE="-doc -test" RUBY_TARGETS="ruby18 -ree18" 55 kB

Total: 5 packages (5 new), Size of downloads: 295 kB

Would you like to merge these packages? [Yes/No]

Instalar el paquete mysql de gems:

# gem install mysql
Building native extensions.  This could take a while...
Successfully installed mysql-2.8.1
1 gem installed
Installing ri documentation for mysql-2.8.1...
Installing RDoc documentation for mysql-2.8.1...

Verificar instalación y versión de rails:

# rails --version
Rails 3.1.1

Creando un esqueleto:
 $ rails new ~/code/ruby/weblog rails server
      create
      create  README
      create  Rakefile
      create  config.ru
      create  .gitignore
      create  Gemfile
      create  app
      create  app/assets/images/rails.png
      create  app/assets/javascripts/application.js
      create  app/assets/stylesheets/application.css
      create  app/controllers/application_controller.rb
      create  app/helpers/application_helper.rb
      create  app/mailers
      create  app/models
      create  app/views/layouts/application.html.erb
      create  app/mailers/.gitkeep
      create  app/models/.gitkeep
      create  config
      create  config/routes.rb
      create  config/application.rb
      create  config/environment.rb
      create  config/environments
      create  config/environments/development.rb
      create  config/environments/production.rb
      create  config/environments/test.rb
      create  config/initializers
      create  config/initializers/backtrace_silencers.rb
      create  config/initializers/inflections.rb
      create  config/initializers/mime_types.rb
      create  config/initializers/secret_token.rb
      create  config/initializers/session_store.rb
      create  config/initializers/wrap_parameters.rb
      create  config/locales
      create  config/locales/en.yml
      create  config/boot.rb
      create  config/database.yml
      create  db
      create  db/seeds.rb
      create  doc
      create  doc/README_FOR_APP
      create  lib
      create  lib/tasks
      create  lib/tasks/.gitkeep
      create  lib/assets
      create  lib/assets/.gitkeep
      create  log
      create  log/.gitkeep
      create  public
      create  public/404.html
      create  public/422.html
      create  public/500.html
      create  public/favicon.ico
      create  public/index.html
      create  public/robots.txt
      create  script
      create  script/rails
      create  test/fixtures
      create  test/fixtures/.gitkeep
      create  test/functional
      create  test/functional/.gitkeep
      create  test/integration
      create  test/integration/.gitkeep
      create  test/unit
      create  test/unit/.gitkeep
      create  test/performance/browsing_test.rb
      create  test/test_helper.rb
      create  tmp/cache
      create  tmp/cache/assets
      create  vendor/assets/stylesheets
      create  vendor/assets/stylesheets/.gitkeep
      create  vendor/plugins
      create  vendor/plugins/.gitkeep
         run  bundle install
Enter your password to install the bundled RubyGems to your system:
Fetching source index for http://rubygems.org/
Using rake (0.9.2.2)
Using multi_json (1.0.3)
Using activesupport (3.1.1)
Using builder (3.0.0)
Using i18n (0.6.0)
Using activemodel (3.1.1)
Using erubis (2.7.0)
Using rack (1.3.5)
Using rack-cache (1.1)
Using rack-mount (0.8.3)
Using rack-test (0.6.1)
Using hike (1.2.1)
Using tilt (1.3.3)
Using sprockets (2.0.3)
Using actionpack (3.1.1)
Using mime-types (1.17.2)
Using polyglot (0.3.3)
Using treetop (1.4.10)
Using mail (2.3.0)
Using actionmailer (3.1.1)
Using arel (2.2.1)
Using tzinfo (0.3.31)
Using activerecord (3.1.1)
Using activeresource (3.1.1)
Using bundler (1.0.21)
Installing coffee-script-source (1.1.3)
Installing execjs (1.2.9)
Installing coffee-script (2.2.0)
Using rack-ssl (1.3.2)
Using json (1.6.1)
Using rdoc (3.11)
Using thor (0.14.6)
Using railties (3.1.1)
Installing coffee-rails (3.1.1)
Installing jquery-rails (1.0.17)
Using rails (3.1.1)
Installing sass (3.1.10)
Installing sass-rails (3.1.4)
Installing sqlite3 (1.3.4) with native extensions
Installing uglifier (1.0.4)
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.

Comprobar dependencias:

$ bundle - Ruby
Using rake (0.9.2.2)
Using multi_json (1.0.3)
Using activesupport (3.1.1)
Using builder (3.0.0)
Using i18n (0.6.0)
Using activemodel (3.1.1)
Using erubis (2.7.0)
Using rack (1.3.5)
Using rack-cache (1.1)
Using rack-mount (0.8.3)
Using rack-test (0.6.1)
Using hike (1.2.1)
Using tilt (1.3.3)
Using sprockets (2.0.3)
Using actionpack (3.1.1)
Using mime-types (1.17.2)
Using polyglot (0.3.3)
Using treetop (1.4.10)
Using mail (2.3.0)
Using actionmailer (3.1.1)
Using arel (2.2.1)
Using tzinfo (0.3.31)
Using activerecord (3.1.1)
Using activeresource (3.1.1)
Using bundler (1.0.21)
Using coffee-script-source (1.1.3)
Using execjs (1.2.9)
Using coffee-script (2.2.0)
Using rack-ssl (1.3.2)
Using json (1.6.1)
Using rdoc (3.11)
Using thor (0.14.6)
Using railties (3.1.1)
Using coffee-rails (3.1.1)
Using jquery-rails (1.0.17)
Using rails (3.1.1)
Using sass (3.1.10)
Using sass-rails (3.1.4)
Using sqlite3 (1.3.4)
Using uglifier (1.0.4)
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.

$ bundle show

Gems included by the bundle:
  * actionmailer (3.1.1)
  * actionpack (3.1.1)
  * activemodel (3.1.1)
  * activerecord (3.1.1)
  * activeresource (3.1.1)
  * activesupport (3.1.1)
  * arel (2.2.1)
  * builder (3.0.0)
  * bundler (1.0.21)
  * coffee-rails (3.1.1)
  * coffee-script (2.2.0)
  * coffee-script-source (1.1.3)
  * erubis (2.7.0)
  * execjs (1.2.9)
  * hike (1.2.1)
  * i18n (0.6.0)
  * jquery-rails (1.0.17)
  * json (1.6.1)
  * mail (2.3.0)
  * mime-types (1.17.2)
  * multi_json (1.0.3)
  * polyglot (0.3.3)
  * rack (1.3.5)
  * rack-cache (1.1)
  * rack-mount (0.8.3)
  * rack-ssl (1.3.2)
  * rack-test (0.6.1)
  * rails (3.1.1)
  * railties (3.1.1)
  * rake (0.9.2.2)
  * rdoc (3.11)
  * sass (3.1.10)
  * sass-rails (3.1.4)
  * sprockets (2.0.3)
  * sqlite3 (1.3.4)
  * thor (0.14.6)
  * tilt (1.3.3)
  * treetop (1.4.10)
  * tzinfo (0.3.31)
  * uglifier (1.0.4)

$ bundle check
The Gemfile's dependencies are satisfied


$ bundle update
Fetching source index for http://rubygems.org/
Enter your password to install the bundled RubyGems to your system:
Using rake (0.9.2.2)
Using multi_json (1.0.3)
Using activesupport (3.1.1)
Using builder (3.0.0)
Using i18n (0.6.0)
Using activemodel (3.1.1)
Using erubis (2.7.0)
Using rack (1.3.5)
Using rack-cache (1.1)
Using rack-mount (0.8.3)
Using rack-test (0.6.1)
Using hike (1.2.1)
Using tilt (1.3.3)
Using sprockets (2.0.3)
Using actionpack (3.1.1)
Using mime-types (1.17.2)
Using polyglot (0.3.3)
Using treetop (1.4.10)
Using mail (2.3.0)
Using actionmailer (3.1.1)
Using arel (2.2.1)
Using tzinfo (0.3.31)
Using activerecord (3.1.1)
Using activeresource (3.1.1)
Using bundler (1.0.21)
Using coffee-script-source (1.1.3)
Using execjs (1.2.9)
Using coffee-script (2.2.0)
Using rack-ssl (1.3.2)
Using json (1.6.1)
Using rdoc (3.11)
Using thor (0.14.6)
Using railties (3.1.1)
Using coffee-rails (3.1.1)
Installing jquery-rails (1.0.18)
Using rails (3.1.1)
Using sass (3.1.10)
Installing sass-rails (3.1.5)
Using sqlite3 (1.3.4)
Installing uglifier (1.1.0)
Your bundle is updated! Use `bundle show [gemname]` to see where a bundled gem

Corregir error formato fecha:

# cd /usr/lib64/ruby/gems/1.8/specifications
# vim jquery-rails-1.0.17.gemspec

 cambiar:

 s.date = %q{2001-11-09 00.00.00 000000000Z}
por:
 s.date = %q{2011-11-13}

$ rails new ~/code/ruby/weblog
$ cd code/ruby/weblog/
$ bundle show

Corigiendo errores:

$ rails server
/usr/lib64/ruby/gems/1.8/gems/execjs-1.2.9/lib/execjs/runtimes.rb:47:in `autodetect': Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes. (ExecJS::RuntimeUnavailable)

$ sudo gem install 'execjs'
Password:

Successfully installed execjs-1.2.9
1 gem installed
Installing ri documentation for execjs-1.2.9...
Installing RDoc documentation for execjs-1.2.9...

$ sudo gem install 'therubyracer'
Fetching: libv8-3.3.10.2-x86_64-linux.gem (100%)
Fetching: therubyracer-0.9.9.gem (100%)
Building native extensions.  This could take a while...
Successfully installed libv8-3.3.10.2-x86_64-linux
Successfully installed therubyracer-0.9.9
2 gems installed
Installing ri documentation for libv8-3.3.10.2-x86_64-linux...
Installing ri documentation for therubyracer-0.9.9...
Installing RDoc documentation for libv8-3.3.10.2-x86_64-linux...
Installing RDoc documentation for therubyracer-0.9.9...

$ sudo gem install 'libv8'
Fetching: libv8-3.3.10.2-x86-linux.gem (100%)
Successfully installed libv8-3.3.10.2-x86-linux
1 gem installed
Installing ri documentation for libv8-3.3.10.2-x86-linux...
Installing RDoc documentation for libv8-3.3.10.2-x86-linux...


Añadir las siguientes líneas al archivo ~/code/ruby/weblog/config/boot.rb:

$ cd ~/code/ruby/weblog/config
$ vim boot.rb

 require 'rubygems'
 require 'execjs'
 require 'v8'

Iniciar el servidor:

$ cd ~/code/ruby/weblog
$ rails server
=> Booting WEBrick
=> Rails 3.1.1 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2011-11-13 16:50:49] INFO  WEBrick 1.3.1
[2011-11-13 16:50:49] INFO  ruby 1.8.7 (2011-06-30) [x86_64-linux]
[2011-11-13 16:50:49] INFO  WEBrick::HTTPServer#start: pid=10759 port=3000


Abrir firefox y teclear:
http://localhost:3000

Instalar jruby:
echo ">=dev-util/jay-1.1.1-r2 java" >> /etc/portage/package.use

# emerge -av jruby
These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild  N     ] dev-java/javatoolkit-0.3.0-r6  17 kB
[ebuild  N     ] dev-java/ant-core-1.8.1  USE="-doc -source" 5,740 kB
[ebuild  N     ] dev-java/ant-nodeps-1.8.1  0 kB
[ebuild  N     ] dev-java/jcodings-1.0.4  USE="-source" 89 kB
[ebuild  N     ] dev-java/xml-commons-external-1.3.04  USE="-doc -source" 645 kB
[ebuild  N     ] dev-java/joda-time-1.6  USE="-doc -examples -source -test" 1,242 kB
[ebuild  N     ] dev-java/constantine-0.7  USE="-source -test" 65 kB
[ebuild  N     ] dev-java/bcel-5.2-r2  USE="-doc -findbugs -source" 256 kB
[ebuild   R    ] dev-util/jay-1.1.1-r2  USE="java* -mono" 0 kB
[ebuild  N     ] dev-java/jline-1.0  USE="-source -test" 453 kB
[ebuild  N     ] dev-java/javacup-0.11a_beta20060608  USE="-doc -source" 280 kB
[ebuild  N     ] dev-java/xjavac-20110814  3 kB
[ebuild  N     ] dev-java/xml-commons-resolver-1.2  USE="-doc -source" 257 kB
[ebuild  N     ] dev-java/touchgraph-graphlayout-1.22  USE="-source" 199 kB
[ebuild  N     ] dev-java/jgraph-5.12.0.4  USE="-doc -examples -source" 3,380 kB
[ebuild  N     ] dev-java/junit-3.8.2-r1  USE="-doc -source" 451 kB
[ebuild  N     ] dev-java/java-getopt-1.0.13  USE="-doc -source" 45 kB
[ebuild  N     ] dev-java/log4j-1.2.16  USE="-doc -javamail -jms -jmx -source" 2,727 kB
[ebuild  N     ] dev-java/jakarta-oro-2.0.8-r2  USE="-doc -examples -source" 338 kB
[ebuild  N     ] dev-java/commons-logging-1.1.1  USE="-avalon-framework -avalon-logkit -doc -log4j -servletapi -source -test" 187 kB
[ebuild  N     ] dev-java/bytelist-1.0.6  USE="-source -test" 15 kB
[ebuild  N     ] dev-java/jffi-1.0.0  USE="-source -test" 1,590 kB
[ebuild  N     ] dev-java/xalan-serializer-2.7.1  USE="-doc -source" 6,138 kB
[ebuild  N     ] dev-java/nailgun-0.7.1  USE="-doc -source -test" 1,455 kB
[ebuild  N     ] dev-java/jgrapht-0.7.3  USE="-doc -source -test" 1,113 kB
[ebuild  N     ] dev-java/jnr-x86asm-0.1  USE="-doc -source" 82 kB
[ebuild  N     ] dev-java/jvyamlb-0.2.5  USE="-source -test" 1,727 kB
[ebuild  N     ] dev-java/xerces-2.9.1  USE="-doc -examples -source" 1,672 kB
[ebuild  N     ] dev-java/xalan-2.7.1  USE="-doc -source" 0 kB
[ebuild  N     ] dev-java/bsf-2.4.0-r1  USE="-doc -examples -javascript -python -source -tcl" 293 kB
[ebuild  N     ] dev-java/ant-owanttask-1.1-r12  10 kB
[ebuild  N     ] dev-java/asm-3.2  USE="-doc -source" 832 kB
[ebuild  N     ] dev-java/jaffl-0.5.1  USE="-doc -source -test" 546 kB
[ebuild  N     ] dev-java/joni-1.1.4  USE="-source" 118 kB
[ebuild  N     ] dev-java/jnr-posix-1.1.4  USE="-source -test" 191 kB
[ebuild  N     ] dev-java/jnr-netdb-1.0.1  USE="-doc -source -test" 656 kB
[ebuild  N     ] dev-java/jruby-1.5.6  USE="ssl -bsf -doc -source -test" 10,905 kB
[ebuild   R    ] dev-ruby/rubygems-1.3.7-r1  USE="-doc -server" RUBY_TARGETS="jruby* -ree18 -ruby18*" 0 kB
[ebuild  NS    ] virtual/rubygems-2 [1] RUBY_TARGETS="(jruby)" 0 kB
[ebuild  N     ] dev-ruby/bouncy-castle-java-1.5.0146.1  USE="-test" RUBY_TARGETS="jruby" 1,945 kB
[ebuild  N     ] dev-ruby/jruby-openssl-0.7.4  USE="-doc -test" RUBY_TARGETS="(jruby)" 609 kB

Total: 41 packages (38 new, 1 in new slot, 2 reinstalls), Size of downloads: 46,250 kB

Would you like to merge these packages? [Yes/No] y

MySQL para Ruby:

# emerge -av dev-ruby/dbd-mysql

These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild  N     ] dev-ruby/mysql-ruby-2.8.2  USE="-test" RUBY_TARGETS="ruby18 -ree18" 32 kB
[ebuild  N     ] dev-ruby/deprecated-2.0.1-r1  USE="-test" RUBY_TARGETS="ruby18 -jruby (-ruby19)" 13 kB
[ebuild  N     ] dev-ruby/ruby-postgres-0.7.9.20080128-r2  USE="-test" RUBY_TARGETS="ruby18 -ree18" 32 kB
[ebuild  N     ] dev-ruby/ruby-dbi-0.4.3  USE="mysql postgres sqlite -examples -odbc -sqlite3 -test" RUBY_TARGETS="ruby18" 80 kB
[ebuild  N     ] dev-ruby/dbd-mysql-0.4.4  USE="-test" RUBY_TARGETS="ruby18" 56 kB
[ebuild  N     ] dev-ruby/dbd-pg-0.3.8  USE="-test" 64 kB
[ebuild  N     ] dev-ruby/dbd-sqlite-0.1.2  USE="-test" 52 kB

Total: 7 packages (7 new), Size of downloads: 327 kB

Would you like to merge these packages? [Yes/No] y

>>> Verifying ebuild manifests

>>> Starting parallel fetch
....

$ sudo gem install mysql
Password: 
Building native extensions.  This could take a while...
Successfully installed mysql-2.8.1
1 gem installed
Installing ri documentation for mysql-2.8.1...
Installing RDoc documentation for mysql-2.8.1..

Iniciar un nuevo proyecto Ruby on Rails utilizando MysQL:
$ rails new webservmysql -d mysql
 create  
      create  README
      create  Rakefile
      create  config.ru
      create  .gitignore
      create  Gemfile
      create  app
...

$ cd webservmysl

En otra terminal:
MySQL debe estar iniciado:
# /etc/initd/mysql start

$ mysql -u root -p
Enter password:




mysql> CREATE DATABASE webservmysql;
Query OK, 1 row affected (0.00 sec)

mysql> use webservmysql;
Database changed
mysql> show tables;
Empty set (0.00 sec)

mysql> show tables;

+------------------------+
| Tables_in_webservmysql |
+------------------------+
| schema_migrations      |
+------------------------+
1 row in set (0.00 sec)


El archivo database.yml se verá así:
carlos@hypatia ~/code/webservmysql/config $ vi database.yml


Crear un modelo y migrar la base de datos (creará la tabla Persona):

carlos@hypatia ~/code/webservmysql $ rails g model Persona nombre:string      invoke  active_record
      create    db/migrate/20111127091342_create_personas.rb
      create    app/models/persona.rb
      invoke    test_unit
      create      test/unit/persona_test.rb
      create      test/fixtures/personas.yml
carlos@hypatia ~/code/webservmysql $ rake db:migrate
==  CreatePersonas: migrating =================================================
-- create_table(:personas)
   -> 1.6301s
==  CreatePersonas: migrated (1.6303s) ========================================

Ahora si volvemos la terminal anterior y nuevamente hacemos un show tables veremos la tabla persona ya creada:

mysql> show tables;
+------------------------+
| Tables_in_webservmysql |
+------------------------+
| personas               |
| schema_migrations      |
+------------------------+
2 rows in set (0.00 sec)





Linux es genial!.

sábado, 12 de noviembre de 2011

Mover usr a otra particion

Mover /usr a una partición independiente. Todo el proceso lo he realizado en un terminal desde gentoo.
Las etiquetas permiten la identificación de las particiones:

# tune2fs -L usr_gentoo /dev/sda8
tune2fs 1.41.14 (22-Dec-2010)

Sacando información del disco duro, hay varias maneras de conseguirlo:
# blkid
/dev/sda1: LABEL="boot" UUID="3bb6187d-1918-4512-96f3-2ed42fc50c19" TYPE="ext2"
/dev/sda2: LABEL="squeeze" UUID="33b01f6e-1e74-4225-84b5-a66c568b38aa" SEC_TYPE="ext2" TYPE="ext3"
/dev/sda3: LABEL="gentoo" UUID="86fd2e13-119f-4efb-aedd-aa5ebd7c77a8" TYPE="ext4"
/dev/sda5: UUID="afa7c31e-c8bf-41f5-a340-78da2c230362" TYPE="swap"
/dev/sda6: LABEL="squeeze_home" UUID="cd3805eb-25b6-4ba4-b99e-7575407f05be" SEC_TYPE="ext2" TYPE="ext3"
/dev/sda7: LABEL="data" UUID="1ddcb07d-b322-4039-837b-48f3daef1426" TYPE="ext3"
/dev/sda8: LABEL="usr_gentoo" UUID="18536501-37ee-4f40-a362-2d9173c43856" SEC_TYPE="ext2" TYPE="ext3"
/dev/sda9: UUID="a7163b55-b4c6-4e31-bf2b-8aeb6a34bdca" SEC_TYPE="ext2" TYPE="ext3"
/dev/sda10: LABEL="home_gentoo" UUID="bff4d21b-d8cb-422d-8c91-b35c4e43ffbf" TYPE="ext3"
/dev/sda11: LABEL="portage" UUID="a0c335fb-2c70-43d3-9138-ff638e360f36" TYPE="reiserfs"

# ls -l /dev/disk/by-label/
total 0
lrwxrwxrwx 1 root root 10 Nov 12 18:54 boot -> ../../sda1
lrwxrwxrwx 1 root root 10 Nov 12 18:29 data -> ../../sda7
lrwxrwxrwx 1 root root 10 Nov 12 18:29 gentoo -> ../../sda3
lrwxrwxrwx 1 root root 11 Nov 12 18:29 home_gentoo -> ../../sda10
lrwxrwxrwx 1 root root 11 Nov 12 18:29 portage -> ../../sda11
lrwxrwxrwx 1 root root 10 Nov 12 18:54 squeeze -> ../../sda2
lrwxrwxrwx 1 root root 10 Nov 12 18:54 squeeze_home -> ../../sda6
lrwxrwxrwx 1 root root 10 Nov 12 18:36 usr_gentoo -> ../../sda8

# fdisk -l

Disk /dev/sda: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders, total 976773168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x0000bac9

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048      210943      104448   83  Linux
/dev/sda2          210944    51410943    25600000   83  Linux
/dev/sda3        51410944   112850943    30720000   83  Linux
/dev/sda4       112852990   976771071   431959041    5  Extended
Partition 4 does not start on physical sector boundary.
/dev/sda5       112855040   117049343     2097152   82  Linux swap / Solaris
/dev/sda6       117051392   137531391    10240000   83  Linux
/dev/sda7       137533440   485693439   174080000   83  Linux
/dev/sda8       485695488   527927295    21115904   83  Linux
/dev/sda9       527929344   550371327    11220992   83  Linux
/dev/sda10      550373376   574251007    11938816   83  Linux
/dev/sda11      574259553   606453749    16097098+  83  Linux
Partition 11 does not start on physical sector boundary.

# cd /
# mkdir usr_nuevo
# mount -v -t ext3 /dev/sda8 /usr_nuevo/
# rm -rf /usr_nuevo/*
# cp -dpR /usr/* /usr_nuevo/
# umount /usr_nuevo
# mv /usr /usr_antiguo
# mkdir /usr
# mount /dev/sda8 /usr
# mount -a

Agregar entrada a /etc/fstab:
# vi /etc/fstab
# /etc/fstab: static file system information.
#
# noatime turns off atimes for increased performance (atimes normally aren't
# needed; notail increases performance of ReiserFS (at the expense of storage
# efficiency).  It's safe to drop the noatime options if you want and to
# switch between notail / tail freely.
#
# The root filesystem should have a pass number of either 0 or 1.
# All other filesystems should have a pass number of 0 or greater than 1.
#
# See the manpage fstab(5) for more information.
#
#                                          

 # NOTE: If your BOOT partition is ReiserFS, add the notail option to opts.
/dev/sda1     /boot          ext2       noauto              1 2
/dev/sda3     /              ext4       noatime             1 1
/dev/sda5     none           swap       sw                  0 0
/dev/sda8     /usr           ext3       auto,noatime        0 1
/dev/sda10    /home          ext3       defaults,noatime    0 2
/dev/sda11    /usr/portage   reiserfs   defaults           0 0
/dev/sda7     /media/data    ext3       defaults,noatime   0 0
/dev/cdrom    /mnt/cdrom     auto       noauto,ro           0 0
#/dev/fd0     /mnt/floppy    auto       noauto             0 0

# glibc 2.2 and above expects tmpfs to be mounted at /dev/shm for
# POSIX shared memory (shm_open, shm_unlink).
# (tmpfs is a dynamically expandable/shrinkable ramdisk, and will
#  use almost no memory if not populated with files)
 shm          /dev/shm    tmpfs     nodev,nosuid,noexec     0 0


Comprobando:
# mount
rootfs on / type rootfs (rw)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
udev on /dev type tmpfs (rw,nosuid,relatime,size=10240k,mode=755)
devpts on /dev/pts type devpts (rw,relatime,mode=600,ptmxmode=000)
/dev/sda3 on / type ext4 (rw,noatime,commit=0)
rc-svcdir on /lib64/rc/init.d type tmpfs (rw,nosuid,nodev,noexec,relatime,size=1024k,mode=755)
fusectl on /sys/fs/fuse/connections type fusectl (rw,relatime)
shm on /dev/shm type tmpfs (rw,nosuid,nodev,noexec,relatime)
/dev/sda8 on /usr type ext3 (rw,noatime,commit=0)
/dev/sda10 on /home type ext3 (rw,noatime,commit=0)
/dev/sda11 on /usr/portage type reiserfs (rw)
/dev/sda7 on /media/data type ext3 (rw,noatime,commit=0)
usbfs on /proc/bus/usb type usbfs (rw,noexec,nosuid,devmode=0664,devgid=85)

Es el momento de reiniciar el sistema. He reiniciado y todo funciona perfectamente.
Puede borrar el directorio /usr_antiguo.
# rm -rf /usr_antiguo

Linux es genial!.

jueves, 10 de noviembre de 2011

DNSChanger


El Troyano DNSChanger, es un archivo de pequeño tamaño (1.5 Kb aprox.) que como su nombre indica fue creado para cambiar los DNS (Domain Name System – Sistema de Nombres de Dominio-) de nuestro PC, y de ese modo redirigir nuestras búsquedas a sitios desde los cuales se puede infectar nuestro ordenador o nuestra red, de malware, realizar phishing, etc. Los servidores DNS traducen el nombre de la dirección web que se teclea en el navegador (por ejemplo: 'www.gentoo.org' a la dirección IP, numérica = 89.16.167.134.

DNSChanger afecta tanto a Windows como a Mac - puede alterar la configuración DNS en máquinas con los sistemas operativos mencionados.

DNSChanger envía a los usuarios desprevenidos a servidores piratas controlados por delincuentes informáticos, que les permite manipular la actividad de los usuarios.

Según el código malicioso que el troyano contenga.  También abre ventanas emergentes (PopUps) y relentiza los sistemas de la familia de Microsoft.

De esta manera es creada una inmensa red de ordenadores zombis (botnet) dedicados a la estafa en la Red..

Linux es genial!.

domingo, 6 de noviembre de 2011

PostgreSQL


Instalar PostgreSQL, phppgadmin en Gentoo.

Fuente: http://www.gentoo.org/doc/es/postgres-howto.xml
http://www.codigolibre.org


En mi sistema gentoo-linux actual tengo instalado el servidor web apache, el gestor de base de datos mysql y php. Instalar postgresql y phppgadmin, crear la base de datos sacademico y ejecutar un script para importar la estructura de las tablas y los datos, así lo hice:

Añadir al fichero /etc/make.conf la use postgres
# emerge -av postgresql-server

These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild   N   ] dev-db/postgresql-server-9.0.5  USE="nls pam xml -doc -perl -pg_legacytimestamp -python (-selinux) -tcl -uuid" LINGUAS="en es -af -cs -de -fa -fr -hr -hu -it -ko -nb -pl -pt_BR -ro -ru -sk -sl -sv -tr -zh_CN -zh_TW" 0 kB

Total: 1 package (1 install), Size of downloads: 14,015 kB

Would you like to merge these packages? [Yes/No]

Editar el fichero /etc/conf.d/postgresql-9.0, para el idioma castellano PG_INITDB_OPTS="--locale=es_ES.UTF-8":
# vim /etc/conf.d/postgresql-9.0

# Location of configuration files
 PGDATA="/etc/postgresql-9.0/"

 # Where the data directory is located/to be created
 DATA_DIR="/var/lib/postgresql/9.0/data"

 # Additional options to pass to initdb.
 # See 'man initdb' for available options.
 PG_INITDB_OPTS="--locale=en_US.UTF-8"

Crear el cluster de base de datos y almacenar los ficheros relacionados con el servidor en PGDATA y DATA_DIR.
# emerge --config dev-db/postgresql-server:9.0

Cambiando 'trust' a 'password' para las conexiones a localhost
vim /etc/postgresql-9.0/pg_hba.conf
# "local" is for Unix domain socket connections only
 local   all             all                        trust
 # IPv4 local connections:
 host    all             all       127.0.0.1/32     trust
 # IPv6 local connections:
host    all             all        ::1/128          trust

Agregar usuario al grupo postgres:
# gpasswd -a carlos postgres

Iniciar el servidor
# /etc/init.d/postgresql-9.0 start
 * Caching service dependencies ...           [ ok ]
 * Starting PostgreSQL ...                    [ ok ]

Abrir una conexión al servidor y cambiar la contraseña:
# psql -U postgres
psql (9.0.3)
Type "help" for help.

postgres=# \password
Enter new password:
Enter it again:
postgres=# \q

Crear un usuario y su password:
# su - postgres
 psql -U postgres
postgres@hypatia ~ $ createuser sacademico -Ws

Clave: kikla
postgres@hypatia ~ $ createdb sacademico


Enlace al script:

enlace_descarga_dhypatia.sql

*Insertar el script bdhypatia.sql:
postgres@hypatia:~$psql sacademico < bdhypatia.sql -U postgres

# /etc/init.d/postgresql-9.0 reload
postgresql-9.0 | * Reloading PostgreSQL configuration ...  [ ok ]

Iniciar postgresql con el sistema:
# rc-update add postgresql-9.0 default
 * service postgresql-9.0 added to runlevel default

Instalar phppgadmin

# emerge -av phppgadmin
Recompila php con soporte postgres e instala phppgadmin.

Para poder logearnos via navegador (/http://localhost/phppgadmin y no recibir un mensaje login failed será necesario editar el fichero /var/www/localhost/htdocs/phppgadmin/conf/config.inc.php y agregar 'localhost':
# vim /var/www/localhost/htdocs/phppgadmin/conf/config.inc.php

// use 'localhost' for TCP/IP connection on this computer
   $conf['servers'][0]['host'] = 'localhost';

# /etc/init.d/postgresql-9.0 reload



Linux es genial!.

viernes, 4 de noviembre de 2011

Fortune


Instalar fortune en Gentoo

# emerge -av fortune-mod

These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild  N     ] games-misc/fortune-mod-1.99.1-r2  USE="-offensive" 1,770 kB

Total: 1 package (1 new), Size of downloads: 1,770 kB

Would you like to merge these packages? [Yes/No]

Utilizaremos este codigo para llamar fortune desde /etc/bash/bashrc. Agregar al final del archivo:
# vim /etc/bash/bashrc

if [ $TERM != "dumb" ]; then
 fortune
fi

Al abrir una terminal comprobamos el resultado:

Instalar FBReader.

FBReader es un e-book reader. Soporta los principales formatos e-book y nos permitirá leer ebook's desde nuestro pc. Para Gentoo y gnome:
# echo "app-text/fbreader gtk -debug -qt4"
# emerge -av fbreader

These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild   R    ] app-text/fbreader-0.12.10  USE="gtk -debug -qt4" 0 kB

Total: 1 package (1 install), Size of downloads: 2,383 kB
Would you like to merge these packages? [Yes/No] y


Linux es genial!.

f.lux monitor

xflux es una aplicación multiplataforma que cambia la luminosidad de la pantalla de tu monitor cada cierto tiempo basándose en las coordenadas del lugar donde vives, (posición global), conociendo en cada momento si es de dia o de noche. Para las personas que pasamos muchas horas frente al ordenador significa cuidar nuestra vista y reducir considerablemente el cansancio producido por el uso intensivo, ajustando el brillo del monitor.

En gentoo x86_64 se necesitan las librerías de 32 bits:

[ebuild  N     ] app-emulation/emul-linux-x86-xlibs-20120127  USE="opengl -development" 2,414 kB
[ebuild  N     ] app-emulation/emul-linux-x86-opengl-20120127  USE="-development" 35,476 kB

Total: 2 packages (2 new), Size of downloads: 37,889 kB

Would you like to merge these packages? [Yes/No] y


Para conocer las coordenadas de su ciudad puede usar la herramienta que ha implementado la página oficial del programa f.lux:


Para Gentoo, descargar el programa desde la página de sus creadores:
http://stereopsis.com/flux/linux.html

Desplazarse a la parte inferior:

Command-line version (for older distros)
The command-line version remains available here: xflux.tgx

$ cd Downloads
$ tar -xzvf xflux.tgz
$ su
password:

Mover xflux a /usr/bin
# mv xflux /usr/bin/

Activamos el programa como usuario normal en mi caso utilizando las coordenadas 41.387917, 2.1699187:
# exit
$ xflux -l 41.387917, 2.1699187

Agregar a las aplicaciones que se inician con el sistema:


Se creará el archivo xflux.desktop en ~/.config/autostart/
$ cat ~/.config/autostart/xflux.desktop

[Desktop Entry]
Type=Application
Exec=xflux -l 41.387917, 2.1699187
Hidden=false
X-GNOME-Autostart-enabled=true
Name[en_US]=xflux
Name=xflux
Comment[en_US]=Ajustar brillo pantalla
Comment=Ajustar brillo pantalla


En los antiguos monitores ctr hacíamos algo parecido, con el comando:
$ xgamma -gamma x.x

Es similar a Brightness applet (mini aplicación de brillo).

Actualmente hay monitores que reaccionan a los niveles de luz del recinto donde se encuentran, si posees un monitor con estas características no es necesario xflux ya que estaria duplicando funciones.

Linux es genial!