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.

Anuncios
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