brew + cask

Cuando vas a formatear tu mac, es útil tener un script que te instale los programas habituales, en lugar de ir a la página web, descargarlos y guardarlos en Aplicaciones.

Dentro de brew, hay una aplicación que se encarga de instalar programas como Google Chrome o el navegador anónimo Tor. Se llama cask.

En este enlace esta la informacion de como se usa.

Un ejemplo de script de instalacion de varios programas.

brew + cask

Install brew

ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"

The command curl with options:
-f, –fail
(HTTP) Fail silently (no output at all) on server errors. This is mostly done to better enable scripts etc to better deal with failed attempts. In normal cases when an HTTP
server fails to deliver a document, it returns an HTML document stating so (which often also describes why and more). This flag will prevent curl from outputting that and
return error 22.

This method is not fail-safe and there are occasions where non-successful response codes will slip through, especially when authentication is involved (response codes 401
and 407).

-L, –location
(HTTP/HTTPS) If the server reports that the requested page has moved to a different location (indicated with a Location: header and a 3XX response code), this option will
make curl redo the request on the new place. If used together with -i, –include or -I, –head, headers from all requested pages will be shown. When authentication is used,
curl only sends its credentials to the initial host. If a redirect takes curl to a different host, it won’t be able to intercept the user+password. See also –location-
trusted on how to change this. You can limit the amount of redirects to follow by using the –max-redirs option.

When curl follows a redirect and the request is not a plain GET (for example POST or PUT), it will do the following request with a GET if the HTTP response was 301, 302, or
303. If the response code was any other 3xx code, curl will re-send the following request using the same unmodified method.

-s, –silent
Silent or quiet mode. Don’t show progress meter or error messages. Makes Curl mute.

-S, –show-error
When used with -s it makes curl show an error message if it fails.

rm -rf /usr/local/Cellar /usr/local/.git && brew cleanup
MacBook-Pro-de-Jose:~ jmprieto$ ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
==> This script will install:
/usr/local/bin/brew
/usr/local/Library/...
/usr/local/share/man/man1/brew.1
==> The following directories will be made group writable:
/usr/local/include
/usr/local/lib
/usr/local/share/man/man3
/usr/local/share/man/man5
/usr/local/share/man/man7
==> The following directories will have their group set to admin:
/usr/local/include
/usr/local/lib

Press RETURN to continue or any other key to abort
==> /usr/bin/sudo /bin/chmod g+rwx /usr/local/include /usr/local/lib /usr/local/share/man/man3 /usr/local/share/man/man5 /usr/local/share/man/man7
Password:
==> /usr/bin/sudo /usr/bin/chgrp admin /usr/local/include /usr/local/lib
==> /usr/bin/sudo /bin/chmod g+rwx /Library/Caches/Homebrew
==> Downloading and installing Homebrew...
remote: Counting objects: 189633, done.
remote: Compressing objects: 100% (51766/51766), done.
remote: Total 189633 (delta 136736), reused 189572 (delta 136694)
Receiving objects: 100% (189633/189633), 37.81 MiB | 2.62 MiB/s, done.
Resolving deltas: 100% (136736/136736), done.
From https://github.com/Homebrew/homebrew
 * [new branch]      master     -> origin/master
HEAD is now at 5d4034d utils: use the $stderr global variable.
==> Installation successful!
==> Next steps
Run `brew doctor` before you install anything
Run `brew help` to get started
Install brew

listar librerias java del servidor

Con este comando listamos todas las librerias del servidor y quitamos la ruta, nos quedamos solo con el nombre del jar.

locate *.jar | sed 's/// /g' | sed '/[a-z]*.jar$/ s/[a-z]* //g' | sort

comando locate *.jar : busca todos los ficheros que acaben por .jar
comando sed ‘s/// /g’ : elimina la barra y la sustituye por ‘ ‘(espacio en blanco).
comando sed ‘/[a-z]*.jar$/ s/[a-z]* //g’ : de todas las lineas que cumplan el patrón (la linea termina por .jar) elimina cualquier elemento que contemple el patron (letras seguidas de un espacio). Es decir, elimino la ruta de los ficheros.

listar librerias java del servidor

Install Maven3 on Ubuntu 12.04

previously install Java.

jmprieto@dev-server:~$ cd
jmprieto@dev-server:~$ ll
total 28
drwxr-xr-x 3 jmprieto jmprieto 4096 may  3 19:33 ./
drwxr-xr-x 3 root     root     4096 may  3 19:25 ../
-rw------- 1 jmprieto jmprieto  286 may  3 19:46 .bash_history
-rw-r--r-- 1 jmprieto jmprieto  220 may  3 19:25 .bash_logout
-rw-r--r-- 1 jmprieto jmprieto 3486 may  3 19:25 .bashrc
drwx------ 2 jmprieto jmprieto 4096 may  3 19:26 .cache/
-rw-r--r-- 1 jmprieto jmprieto  675 may  3 19:25 .profile
jmprieto@dev-server:~$ pwd
/home/jmprieto
jmprieto@dev-server:~$ wget http://apache.rediris.es/maven/maven-3/3.2.1/binaries/apache-maven-3.2.1-bin.tar.gz
--2014-05-03 20:05:38--  http://apache.rediris.es/maven/maven-3/3.2.1/binaries/apache-maven-3.2.1-bin.tar.gz
Resolviendo apache.rediris.es (apache.rediris.es)... 130.206.1.5
Conectando con apache.rediris.es (apache.rediris.es)[130.206.1.5]:80... conectado.
Petición HTTP enviada, esperando respuesta... 200 OK
Longitud: 6927918 (6,6M) [application/x-gzip]
Grabando a: “apache-maven-3.2.1-bin.tar.gz”

100%[======================================================================================================================================================================>] 6.927.918   1,74M/s   en 3,6s    

2014-05-03 20:05:42 (1,83 MB/s) - “apache-maven-3.2.1-bin.tar.gz” guardado [6927918/6927918]

jmprieto@dev-server:~$ tar -zxf apache-maven-3.2.1-bin.tar.gz 
jmprieto@dev-server:~$ ll
total 6800
drwxr-xr-x 4 jmprieto jmprieto    4096 may  3 20:06 ./
drwxr-xr-x 3 root     root        4096 may  3 19:25 ../
drwxrwxr-x 6 jmprieto jmprieto    4096 may  3 20:06 apache-maven-3.2.1/
-rw-rw-r-- 1 jmprieto jmprieto 6927918 feb 22 09:27 apache-maven-3.2.1-bin.tar.gz
-rw------- 1 jmprieto jmprieto     286 may  3 19:46 .bash_history
-rw-r--r-- 1 jmprieto jmprieto     220 may  3 19:25 .bash_logout
-rw-r--r-- 1 jmprieto jmprieto    3486 may  3 19:25 .bashrc
drwx------ 2 jmprieto jmprieto    4096 may  3 19:26 .cache/
-rw-r--r-- 1 jmprieto jmprieto     675 may  3 19:25 .profile
jmprieto@dev-server:~$ sudo cp -R apache-maven-3.2.1 /usr/local
jmprieto@dev-server:~$ ll /usr/local/apache-maven-3.2.1/
total 48
drwxr-xr-x  6 root root  4096 may  3 20:06 ./
drwxr-xr-x 11 root root  4096 may  3 20:06 ../
drwxr-xr-x  2 root root  4096 may  3 20:06 bin/
drwxr-xr-x  2 root root  4096 may  3 20:06 boot/
drwxr-xr-x  3 root root  4096 may  3 20:06 conf/
drwxr-xr-x  3 root root  4096 may  3 20:06 lib/
-rw-r--r--  1 root root 14865 may  3 20:06 LICENSE
-rw-r--r--  1 root root   182 may  3 20:06 NOTICE
-rw-r--r--  1 root root  2513 may  3 20:06 README.txt
jmprieto@dev-server:~$ vi ~/.profile
jmprieto@dev-server:~$ exit
export JAVA_HOME="/usr/lib/jvm/java-6-openjdk"
export M2_HOME="/usr/local/apache-maven-3.2.1"
export M2="$M2_HOME/bin"
export PATH="$M2:$PATH"
jmprieto@dev-server:~$ java -version
java version "1.6.0_27"
OpenJDK Runtime Environment (IcedTea6 1.12.6) (6b27-1.12.6-1ubuntu0.12.04.4)
OpenJDK Server VM (build 20.0-b12, mixed mode)
jmprieto@dev-server:~$ mvn -v
Apache Maven 3.2.1 (ea8b2b07643dbb1b84b6d16e1f08391b666bc1e9; 2014-02-14T18:37:52+01:00)
Maven home: /usr/local/apache-maven-3.2.1
Java version: 1.6.0_27, vendor: Sun Microsystems Inc.
Java home: /usr/lib/jvm/java-6-openjdk-i386/jre
Default locale: es_ES, platform encoding: UTF-8
OS name: "linux", version: "3.11.0-15-generic", arch: "i386", family: "unix"
Install Maven3 on Ubuntu 12.04

Firmar un JAR

para firmar un jar es muy sencillo, basta tener la JDK, un «key store» con su user/pass/alias/private pass.

A la hora de firmar un jar lo que se hace es:
1.- generar un hash de cada clase en SHA y lo agrega al manifest de la siguiente manera

Manifest-Version: 1.0
Implementation-Vendor: Gobierno de Espana
Implementation-Title: es.gob.afirma
Implementation-Version: build01
Application-Library-Allowable-Codebase: *
Specification-Vendor: Gobierno de Espana
Application-Name: Applet Cliente Afirma
Name: es/gob/afirma
Permissions: all-permissions
Specification-Title: Applet Cliente Afirma
Specification-Version: 3.3.1 u5
Caller-Allowable-Codebase: *
Codebase: *

Name: org/bouncycastle/jcajce/provider/digest/Whirlpool$Digest.class
SHA-256-Digest: FKks3RbQC/oJ2jlI2P9GKwYkEQdZNBOUW6dFI8uVdmM=

...

2.- Agrega unos ficheros que contienen el certificado, con el que se ha firmado, en la misma carpeta donde esta el MANIFEST.MF

En consola

jarsigner -keystore keystore.jks -storepass keystore_pass -keypass keystore_pass -signedjar jarsfirmados/LO_QUE_SEA.jar -verbose jars/LO_QUE_SEA.jar keystore_alias

Maven

			  <plugin>
				    <groupId>org.apache.maven.plugins</groupId>
				    <artifactId>maven-jarsigner-plugin</artifactId>
				    <version>1.2</version>
				    <executions>
				        <execution>
				            <id>sign</id>
				            <goals>
				                <goal>sign</goal>
				            </goals>
				        </execution>
				    </executions>
				    <configuration>
				        <keystore>/path/to/testkeystore</keystore>
				        <alias>myalias</alias>
				        <storepass>depo.root</storepass>
				    </configuration>
				</plugin>
Firmar un JAR

Creando un script para carbondump

# !/bin/sh
#
# ejemplo de ejecucion:
# sudo ./workerDump.sh 26638
# el numero 26638 se corresponde con el pid del servidor. se puede sacar con 'ps -ef | grep java'
# en este caso habria que buscar el proceso del worker

JAVA_HOME=/usr/lib/jvm/jdk1.7.0_40
export JAVA_HOME
cd /home/wso2/wso2worker/bin/
./carbondump.sh -carbonHome /home/tecnocom/wso2/wso2worker/ -pid $1

hay que tener instalado en el sistema:
zip (sudo apt-get install zip)
– jmap

https://docs.wso2.org/display/AS510/Capturing+the+State+of+the+System+in+Error+Situations

Creando un script para carbondump

Renombar espacios en blanco en nombres de ficheros

Este script funciona salvo cuando el nombre del fichero tiene espacios en blanco:]

sed -e 'p;s/evolu/involu/' | xargs -n2 mv

Con sed se pueden quitar los espacios en blanco:
solo el primer espacio:

ls | echo | sed ’s/s/./‘

todos los espacios en blanco:

ls | echo | sed 's/s/./g'

el script que lo soluciona:

for i in *; do mv "${i}" `echo ${i} | sed -e 's/s/./g'`; done
Renombar espacios en blanco en nombres de ficheros

Busqueda de ficheros desde la consola

# buscar en subdirectorios con grep
grep -rl "string" /path

# Busqueda en todos los jar y dentro de estos, busca un archivo xml
find webapps/ROOT/WEB-INF/lib/ -name '*.jar' -exec grep -Hls hibernate-spring.xml {} ;

# Busqueda todos los jar y dentro de estos, los xml y dentro de estos el texto: PathMatchingResourcePatternResolver
find . -name '*.jar' -exec grep -rl PathMatchingResourcePatternResolver . {} ;
Busqueda de ficheros desde la consola

tunnel ssh en consola

ssh -f user@personal-server.com -L 5865:personal-server.com:22 -N

-f indica a ssh que se ejecute en segundo plano despues de que ssh se ejecute

-L
5865 ese el puerto por el que va salir el tunnel.
22 puerto por el que nos conectamos al host remoto.

-N inidica que no ejecute ningun comando en el host remoto.

ssh -D 8080 -f -C -q -N myuser@myserver.com

-D [bind_address:]port
-f Requests ssh to go to background just before command execution.
-C Requests compression of all data
-q Quiet mode. Causes all warning and diagnostic messages to be suppressed.
-N Do not execute a remote command. This is useful for just for-warding ports (protocol version 2 only).

ssh -o "ServerAliveInterval 60" -o "ServerAliveCountMax 3" -f -C -N -D *:8080 user@my.proxy.server &> tunnel.log
tunnel ssh en consola

Subversion en consola

descargar un proyecto a la carpeta local:
svn checkout https://(projectname).(domain)/svn/(projectname)/(DIR) (projectname) –username [type-user-name-here]

svn add: añadir un fichero.
svn revert: si te equivocas.
svn blame: viendo el contenido de archivos específicos con la información de revisión y autor.
svn cat: ver el contenido de un archivo específico.
svn cleanup: destrabando una copia de trabajo.
svn copy: copiar un archivo o directorio en la copia de trabajo o en el repositorio.
svn delete/del/remove/rm: borrar un archivo o directorio desde tu copia local.
svn diff file1 file2: ver las diferencias entre archivos.
para comparar el archivo modificado localmente «index.php» contra el que se encuentra en el repositorio, debes tipear:
svn diff $SRC/…../index.html https://(projectname).(domain)/svn/(projectname)/trunk (projectname) –username [type-user-name-here]
svn diff -r 456:459 subfn.cpp
svn export: exportar un directorio limpio de archivos .svn a tu máquina local.
Con este comando puedes extraer una copia sin versionar (sin los archivos .svn) del proyecto, para obtener el directorio sin versionar de cualquier revisión debes escribir:
svn export [-r REV] [PATH]
svn help: ver la ayuda de subversion.
svn commit: subiendo tus cambios.
svn commit -m «Type your comment here» [files]
svn import: importando un archivo o directorio sin versionar al repositorio.
svn info: mostrar información acerca de paths en tu copia de trabajo.
svn list: listar los directorios en el repositorio.
svn log: mostrando los mensajes de log de los commits.
svn log -v .
svn log -r RevisionNumber http://URL/path/file
svn log -l 4 (solo las ultimas 4 entradas)
svn log -v –limit 4 (verbose)
svn log -r 1:HEAD (To list everything in ascending order)
svn log -r HEAD:1 (To list everything in descending order)
svn log -r 13:BASE (To list everything from the thirteenth to the base of the currently checked-out revision in ascending order)
svn log -r {2011-02-02}:{2011-02-03} (To get everything between the given dates)

svn merge: fusionado cambios.
svn mkdir: creando un nuevo directorio.
svn move: moviendo un archivo o directorio.
svn resolved: resolviendo conflictos.
svn status: obteniendo el estado de un archivo o directorio.
svn update: actualizando tu copia de trabajo.

Explicacion de las columnas:
The first column
‘ ‘: No modifications.
‘A’: Item is scheduled for Addition.
‘D’: Item is scheduled for Deletion.
‘M’: Item has been modified.
‘R’: Item has been replaced in your working copy. This means the file was scheduled for deletion, and then a new file with the same name was scheduled for addition in its place.
‘C’: The contents (as opposed to the properties) of the item conflict with updates received from the repository.
‘X’: Item is related to an externals definition.
‘I’: Item is being ignored (e.g. with the svn:ignore property).
‘?’: Item is not under version control.
‘!’: Item is missing (e.g. you moved or deleted it without using svn). This also indicates that a directory is incomplete (a checkout or update was interrupted).
‘~’: Item is versioned as one kind of object (file, directory, link), but has been replaced by different kind of object.

The second column tells the status of a file’s or directory’s properties.
‘ ‘: No modifications.
‘M’: Properties for this item have been modified.
‘C’: Properties for this item are in conflict with property updates received from the repository.

The third column is populated only if the working copy directory is locked. (See the section called “svn cleanup”.)
‘ ‘: Item is not locked.
‘L’:Item is locked.

The fourth column is populated only if the item is scheduled for addition-with-history.
‘ ‘:No history scheduled with commit.
‘+’: History scheduled with commit.

The fifth column is populated only if the item is switched relative to its parent (see the section called “Switching a Working Copy”).
‘ ‘: Item is a child of its parent directory.
‘S’: Item is switched.

The sixth column is populated with lock information.
‘ ‘: When –show-updates is used, the file is not locked. If –show-updates is not used, this merely means that the file is not locked in this working copy.
K: File is locked in this working copy.
O: File is locked either by another user or in another working copy. This only appears when –show-updates is used.
T: File was locked in this working copy, but the lock has been “stolen”and is invalid. The file is currently locked in the repository. This only appears when –show-updates is used.
B: File was locked in this working copy, but the lock has been “broken”and is invalid. The file is no longer locked This only appears when –show-updates is used.

The out-of-date information appears in the seventh column (only if you pass the –show-updates switch).
‘ ‘: The item in your working copy is up-to-date.
‘*’: A newer revision of the item exists on the server.

Realizar un tag:
svn copy http://host/repos/project/trunk http://host/repos/project/tags/TagName-1.4.5 -m «Tag Release 1.4.5»

Para darle un toque de color:
https://github.com/jmlacroix/svn-color/blob/master/svn-color.sh

Subversion en consola