Sábado, Febrero 7, 2009

rsync, root and sudo

Here is the thing, the other day I wanted to copy one subdirectory from one computer to another, I can not rely on scp because I needed root permissions, neither tar worked because there was symlinks, different file permissions and owners, and there wasn’t space enough to do it (of course, you can send the tar using netcat…). The perfect solution to do such a copy is use rsync, it works nice, and can be used to reupdate a backup, and so on.

The problem is I need both root permissions on both machines, on the local machine having root permissions is the easy part but how should we proceed to get root permissions at the other end ?

You can do several things, like creating the root user, disable sudo asking for password, … but I won’t recommend them. The solution I came across ( I don’t remember from where ) is simple, but quite forgivable (that’s why I’m writing a post-to-myself). Here it is:

stty -echo; ssh myUser@REMOTE_SERVER "sudo -v"; stty echo
rsync -avze ssh --rsync-path='sudo rsync' myUser@REMOTE_SERVER:/REMOTE_PATH/ LOCAL_PATH

The second line tells sudo to execute “sudo rsync” instead of “rsync” on the remote host. Without the first line sudo will prompt for a password (and we won’t be able to input it), the “sudo -v” is the one which does the trick. It simply touches the timestamp sudo has to avoid asking the password on each call.

The “stty [-]echo” avoid others to have a look at our passwords while we type them :)

posteado por PpluX @ 9:21 pm tags:English, linux/unix, recetas  

Miércoles, Noviembre 26, 2008

from subversion to git

Recently I’ve been playing with git and I found it fascinating!, for those that still don’t know what it is, git is a really fast distributed revision control system (wikipedia). Now the problem is how to switch from subversion to git, fortunately git-svn helps a lot and we can play with git and subversion in many ways. Let’s talk about them from the easiest to the not-so-easy way. I’m supposing here that you want to move from a centralized subversion to a git repository that probably will be online on a server.

Complete migration from subversion to git

This is for those that want to throw subversion away completely, for some reason this is the easiest way to switch. First what you would do on the server:

# first clone the repository from subversion
# if you can use file:// it will be faster,
# otherwise use
http://your-project-url.com/svn/MySuperProject
[server]$ git svn clone -s file:///home/pplux/…/svn/MySuperProject tmp
# clone to a bare new git repository (with no track of subversion)
[server]$ git clone –bare file://`pwd`/tmp MySuperProject
# remove the old git repo from subversion, no longer needed
[server]$ rm -rf tmp/
# update server info, for “dumb” servers this is needed
[server]$ cd MySuperProject/
[server]$ git –bare update-server-info

Now clients can simple clone your repository and start working:
# use this for normal-read-only, or maybe you could use ssh://
# if you plan to upload data.

[client] $ git clone http://your-server-url.com/git/MySuperProject

Mirroring the subversion repository and keep subversion

Here we want to keep the subversion repository like the main reference of the project, but let people (or ourselves) use git for development. The reason to mirror the subversion is just a matter of speed, it is much faster to clone an existing git repository than cloning from subversion each time.

Here we will need to do a bit more of work, but it’s a much smoother way to migrate from subversion to git. First what we need to do on the server:

# Create and initialize a bare git repository
[server]$ mkdir MySuperProject[server]$ cd MySuperProject/
[server]$ git –bare init
Initialized empty Git repository in /home/pplux/…/MySuperProject/


# set svn project to import
[server]$ git –bare svn init -s http://your-server-url.com/svn/MySuperProject


# fetch svn data (sloooow)
[server]$ git –bare svn fetch –all
A src/CMakeLists.txt
A CMakeLists.txt
W: +empty_dir: trunk/include



# auxiliary files to help “dumb” servers
[server]$ git –bare update-server-info

Now the client, here we will do much more work than before to setup both the origin from the git mirror and the subversion config to commit there future changes.

# Create and initialize our copy of the git repository
[client] $ mkdir MySuperProject
[client] $ cd MySuperProject/
[client] $ git init
Initialized empty Git repository in /Users/pplux/projects/MySuperProject/.git/


# setup the server as the initial origin of data
[client] $ git remote add origin http://your-server-url.com/git/MySuperProject


# also tell git to fecth data from the remote origin(that case svn)
[client] $ git config –add remote.origin.fetch ‘+refs/remotes/*:refs/remotes/*’


# fetch data from the git mirror(takes a bit)
[client] $ git fetch
got 2c68737541f19685f667f601a502447425d1fcfe
walk 2c68737541f19685f667f601a502447425d1fcfe
got d4916373650b9bb636c0284dd501e6c7bfa8e304
got 13af9568120f8e7771bd386d9b7dadf69f1181cb



# setup the original subversion as
[client] $ git svn -s init http://your-server-url.com/svn/MySuperProject


# rebuild data…
[client] $ git svn fetch
Rebuilding .git/svn/trunk/.rev_map.1a3bf6a2-ba3d-0410-9263-a3f888f14dcd …
r1 = 126490373bfbc2a770d762398b67fffeef73bead
r2 = a2288725c8c68ef426b97cf2b28a9135a34734d3
r3 = 4158b92a5c68489bb6ff2b4f4567cf8f830d7282


# to start working create a master that will track “trunk”
[client] $ git checkout -b master -t trunk

Reasons for switching to git

The post ends here you can safely stop reading now, but if you ask me, there are some good reasons to switch to git:

  • it’s faster, not only faster when doing actual SCM work, it allows you to develop faster, no need to wait while the commit is transmitted to the server, you can work offline wherever you are…
  • it works well with subversion, you can use it even if the main project never moves from a subversion repository or you are the only one using git while everybody else is using subversion
  • you don’t need to develop a full feature before a commit, you can work on your own doing commits often without worrying about anybody else.
  • git is meant to work on branches, this is a different approach from the normal subversion use, with git you are supposed to work on branches, and it’s great! I like to develop different “features” on different branches, I can switch the branch, do several things at the same time… and so on.
  • you have the whole history, not just the last commit.
  • it’s secure, you don’t need several people to share the same repository, git “default” model works in a different way where each person has its own public git. But, everything in git is hashed, even branches, so you can easily check if your private git has the same things as the remote git (that’s difficult to achieve with subversion)
  • it’s like vim vs notepad! I like git because is fun, it can do many many things, and it’s always good to have something new to play with.
  • if CVS was for dinosaurs when you started using SVN, now SVN is for the Neanderthals… so start using git!
  • You don’t have to be a ruby developer to use git! git is another SCM… not the cool tool just for cool ruby developers… come on.
  • Because Linus Torvalds made it:
  • … well, maybe Linus is not a good reason to use it… I don’t fancy calling people ugly and idiot, anyway git is great.

And big thanks to slack for pointing me out git, if he says something is good stuff… believe him :)

Other good links about what we’ve talked here:

http://www.gnome.org/~federico/news-2008-11.html#27
http://markmcb.com/tag/workflow/
http://utsl.gen.nz/talks/git-svn/intro.html#howto-track-rebuildmeta
http://www.viget.com/extend/effectively-using-git-with-subversion/
http://techbase.kde.org/Development/Tutorials/Git#Interfacing_KDE.27s_SVN_repository_with_git-svn
http://live.gnome.org/GitForGnomeDevelopers
http://tsunanet.blogspot.com/2007/07/learning-git-svn-in-5min.html
http://blogs.gnome.org/johncarr/2008/06/21/git-mirrorgnomeorg/
http://markmcb.com/2008/09/17/migrating-a-subversion-svn-project-and-server-to-git/

posteado por PpluX @ 3:55 pm tags:English, git, recetas, subversion  

Lunes, Noviembre 24, 2008

The return to the dark side

Since October 31st, around 9:45am, I’m the proudly owner of a new macbook! So again I’m quitting linux, not really, but for a notebook apple is the only one that delivers a truly “notebook-experience”, IMHO. I could not do without the close-the-lid-and-leave thing, the unix feeling, and my terminal,but it took me some days to tweak this things to feel back at home, and just as a reminder for myself I’m going to write down some little tips.
(más…)

posteado por PpluX @ 11:50 am tags:Apple, English, recetas  

Martes, Abril 29, 2008

Trabajar en consola: Terminator & screen

Terminator logo

¿Quién dijo que la consola estaba muerta? no śe vosotros, pero personalmente es de lo primero que arranco cada mañana para trabajar. ¿Por qué? pues sencillamente por ser invariante en el tiempo, gnome cambia, kde cambia, mac os X cambia, cada vez las interfaces son mejores, pero mi consola responde igual desde el primer día que empecé a usarla. Más aun, te sirve para trabajar remotamente y muchas otras veces es la única opción para arreglar catástrofes (vamos, que no está de más aprender a usarla).

Pese a que a día de hoy hay aplicaciones gráficas para bajar ficheros, torrents, mover/copiar/pegar directorios, conectarse a unidades samba, etc… personalmente, en la mayoría de los casos, sigo prefiriendo arrancar una consola y hacerlo a mano, wget, cp/rm/mv/rsync, smbclient, smbfs, … ¿ya sabes, no?

Y si, como yo, eres un adicto a la terminal, conocerás screen el multiplexador-de-terminales (si no, o si quieres aprender a usarlo, prueba aquí ) multiplataforma, super funcional, y con la maravillosa opción de poder detachear y atachear sesiones.

Y qué hacer con las pantallas de hoy día, son grandes, muy grandes, caben muchas consolas, o una a pantalla completa con screen (que permite dividir la consola en varias regiones)… pues mejor que eso podemos usar terminator, del que ya podemos disfrutar en hoary. Terminator permite arrancar una terminal y, en vez de usar tabs, podemos dividir horizontal y verticalmente la consola las veces como queramos, sacando partido de verdad a los nuevos tamaños de pantalla que tenemos ahora.

Terminator is a program that allows users to set up flexible arrangements of GNOME terminals. It is aimed at those who normally arrange lots of terminals near each other, but don’t want to use a frame based window manager.

Gracias a que usa gnome-terminals se integra muy bien con las preferencias de gnome-terminal (toma los colores que use este, el tipo de letra, control+, control-, etc..) y tiene atajos de teclado para cambiar de región ($man terminator).

¡ Un placer !

posteado por PpluX @ 11:33 am tags:linux/unix, recetas  

Viernes, Abril 11, 2008

Color de auto-completado del vim

No sé qué razón se oculta tras la configuración por defecto de mi vim/gvim que el auto-completado se ve de pena. Tenía un color rosa de fondo con letras blancas, con tan poco contraste que molesta. Para cambiar esta opción y que nuestro vim deje de tener pluma, podemos hacer lo siguiente:

Completado del vim, resultado

highlight Pmenu guibg=blue guifg=white ctermbg=blue ctermfg=white
highlight PmenuSel guibg=white guifg=blue ctermbg=white ctermfg=blue

Esto en el ~/.vimrc y problema resuelto.

Gracias al vim-tip-1486

posteado por PpluX @ 8:32 am tags:Vim, recetas  

Martes, Abril 1, 2008

vim: Completando nombres de ficheros

Estoy demasiado acostumbrado a como completa bash los nombres de ficheros, escribes un cacho le das a TAB y esperas a que complete hasta donde pueda… si insistes te saca una lista de opciones y vas completando hasta llegar al destino. Vim, cuando estás en modo comando, tiene la fea costumbre de completar todo el nombre con cada TAB… en un directorio con varios ficheros suele ser un suplicio llegar al que toca. Pero afortunadamente todo en vim es configurable, en este caso la opción se llama wildmode.

Para tener un comportamiento similar al bash, puedes poner esto en tu ~/.vimrc:

set wildmode=longest,list:longest

wildmode tiene hasta dos parámetros separados por ‘,’ el primero es lo que ocurre justo después del primer TAB, el segundo cuando el TAB se vuelve a pulsar. En este caso le estamos pidiendo que haga un match con la entrada común más larga posible (por defecto es full, que viene a decir un match completo), y si vuelves a presionar TAB mostará una lista y seguirá haciendo match con la entrada común más larga.

Para más info ‘:h wildmode’

posteado por PpluX @ 2:30 pm tags:Vim, recetas  

Jueves, Marzo 27, 2008

Recodificar video y subtítulos para el iphone/ipod-touch

Se me había olvidado que tenía hecho desde hace tiempo un script para pasar un video al formato del iphone (básicamente genera un mpeg4 con el tamaño adecuado para ahorrar espacio) y que además empotra los subtítulos si los encuentra. Todo ello usando mencoder y ffmpeg.

De alguna parte saqué las opciones pero ya no me acuerdo, el caso es que funciona :) (en linux por lo menos)

posteado por PpluX @ 4:06 pm tags:Apple, linux/unix, recetas  

Lunes, Marzo 24, 2008

ver videos de Youtube en HD

Buscando el último trailer de wall-e por youtube me encuentro con esto:

El autor pone “HD” por ahí pero se ve bastante mal. Haciendo scroll encuentro un tipet que dice:

añade &fmt=18 a cualquier url de youtube y se verá en alta resolución

así que probé:

http://youtube.com/watch?v=pC96tIhLDN0
http://youtube.com/watch?v=pC96tIhLDN0&fmt=18

y algo hace! El truco no es nuevo pero yo no tenía ni idea, por si algún despistado tampoco lo sabía… ahí queda.

posteado por PpluX @ 6:43 pm tags:Tecnología, google, recetas  
Entradas siguientes »

Gestionado con WordPress