Tuesday, December 28, 2010

Android Sensor API

Ubuntu 10.10
Android 2.1
Netbeans 6.9


Codes:

  • https://github.com/som4r/som4r/tree/master/robot/wvapp_veiculo
Status:
  • Funcionando Aplicacão Android para Navegacão Manual por botões na tela, usando webview hospedada no servidor do robô, usando javascript chamando funcões no aplicativo android para ler sensor (acelerômetro) e enviando comandos por ajax, usando jquery, javascript e sensormanager.
Info:

Links:

Sunday, December 12, 2010

Instalando Apache, Php e Mysql no Ubuntu

Ubuntu 10.10
Apache httpd 2.0
Php 5.3.3
Mysql 5.


Status:
  • Instalados e Funcionando.
ToDo:
  • [CONFIG] incluir endereco de escuta - ServerName localhost - no /etc/apache2/httpd.conf
Instalacão:
  • sudo -i # root
  • apt-get update

  • # Apache 2
  • apt-get install apache2

  • # Php 5.3
  • apt-get install libapache2-mod-php5 php5-adodb php5-imagick php5-mcrypt php5-suhosin php5-cgi php5-cli php5-common php5-curl php5-gd php5-ldap php5-mysql php5-pgsql php5-sqlite php5-xmlrpc php5-xsl php5-sybase

  • # Configuracão do Php5
  • nano /etc/php5/apache2/php.ini
  • ## memory_limit (128M padrao, 256M recomendado)
  • ## post_max_size (8M padrao, recomendado 50M)
  • ## upload_max_filesize (2M padrao, recomendado 50M)

  • # Teste da instalacão do Php
  • mkdir -p /var/www/php
  • nano /var/www/php/index.php [ ?php phpinfo();? ]

  • ## Habilitando mod_rewrite
  • a2enmod rewrite
  • nano /etc/apache2/sites-available/default
  • dentro do bloco: [Directory /var/www/] mudar de AllowOverride None para AllowOverride All

  • ## Reiniciar o apache
  • /etc/init.d/apache2 restart
  • http://localhost/php

  • # Mysql
  • apt-get install mysql-server
  • ## senha de root do mysql

  • # phpMyAdmin
  • apt-get install phpmyadmin
  • ## selecionar apache2
  • ## configure with dbcommons? yes
  • ## senha do mysql root
  • ## senha do phpmyadmin (em branco a senha gera senha automatica, recomendado)
Info:
  • Apache httpd 2
  • Php
  • Mysql
Links:

Thursday, October 21, 2010

Instalando OpenCV 2.1 no Ubuntu 10.10

Ubuntu 10.10
OpenCV 2.1


Status:
  • 2011.12.10 - Alterando procedimento para Ubuntu 11.04 e OpenCV-2.3.1.a.
  • 2011.07.26 - Corrigido procedimento de instalacão no Ubuntu 10.10. Exemplos em Python estão funcionando.
  • 2011.06.18 - Criado exemplo de wsrest_face_detect com get retornando dados xml da posicao e tamanho das faces detectadas, e gravando cada face num arquivo.
  • 2011.03.07 - Instalado e funcionando os exemplos em C (facedetect=+-600ms) e em Python (facedetect=+-400ms).

ToDo:
  • 2011.06.18 - Ver possibilidade de retornar a imagem no get junto com o xml.

Instalacão:
  • sudo apt-get install build-essential pkg-config libavcodec-dev libavformat-dev libjpeg62-dev libtiff4-dev cmake libswscale-dev libjasper-dev python-opencv  libgtk2.0-dev libcv-dev libhighgui-dev
  • wget https://launchpad.net/ubuntu/+source/gtk+2.0/2.22.0-0ubuntu1/+build/1977449/+files/libgtk2.0-dev_2.22.0-0ubuntu1_i386.deb
  • wget https://launchpad.net/ubuntu/+source/gtk+2.0/2.24.4-0ubuntu2/+build/2437921/+files/libgtk2.0-dev_2.24.4-0ubuntu2_i386.deb
  • cd /opt
  • wget http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.1/OpenCV-2.1.0.tar.bz2
  • sudo tar xvf OpenCV-2.1.0.tar.bz2
  • cd OpenCV-2.1.0

  • Ubuntu 11.04:
  • wget http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/...../OpenCV-2.3.1a.tar.bz2
  • Problema: O OpenCV2.3.1 foi instalado manualmente (p/fontes) em cima do OpenCV-2.1 nativo do ubuntu natty. Funcionaram alguns exemplos do opencv (c e python), aparentemente os problemas estavam relacionados com a interface gráfica e com o acesso as imagens das câmeras. Workaround: desinstalar opencv2.1 e apagar pasta opencv2.3, reiniciar, reinstalar opencv2.1 nativo do natty (synaptic libcv2.1 libcv2.1-dev libcv-dev libhighgui2.1 libhighgui-dev), testar o opencv (mesmo problema), reinstalar o opencv2.1 pelos fontes (deu erro no make em ), reinstalar opencv2.3.1 e testar (funcionou! n sei como ou porquê).

  • sudo cmake -D BUILD_PYTHON_SUPPORT=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D BUILD_NEW_PYTHON_SUPPORT=ON . (verifique se FFMPEG = 1)
  • sudo make (zzz.)
  • sudo make install

  • ### Ignorar linha abaixo para o Ubuntu 11.04
  • sudo mv /usr/local/lib/python2.6/site-packages/cv.so /usr/local/lib/python2.6/dist-packages/cv.so

  • sudo nano /etc/ld.so.conf.d/opencv.conf (new file with this content: /usr/local/lib)
  • sudo ldconfig
  • sudo gedit /etc/bash.bashrc
  • Acrescente no final do arquivo o conteúdo das duas linhas abaixo:
  • PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
  • export PKG_CONFIG_PATH
Compilando exemplos em C:
  • cd /opt/OpenCV-2.1.0/samples/c
  • sudo chmod +x build_all.sh
  • sudo ./build_all.sh
Testando exemplos em C:
  • cd /opt/OpenCV-2.1.0/samples/c
  • ./facedetect --cascade="/opt/OpenCV-2.1/data/haarcascades/haarcascade_frontalface_alt.xml" --scale=1.5 lena.jpg
  • ./facedetect --cascade="/opt/OpenCV-2.1/data/haarcascades/haarcascade_frontalface_alt.xml" --scale=1.5
Testando exemplos em Python:
  • synaptic (python-opencv python-dev)
  • cd /opt/OpenCV-2.1.0/samples/python
  • copiar pasta "OpenCV"/data para "OpenCV"/samples
  • ./facedetect.py 0
  • ./motempl.py (contorno e movimento)
  • ./laplace.py (contorno)

Links:

Saturday, October 16, 2010

Serial Port access with Python

Ubuntu 10.10
Python 2.6.6
PySerial 2.3.1


Status:
  • Funcionando web service (webpy-apache) que acessa a porta serial do GPS.
ToDo:
  • Configurar permissões de acesso nas portas seriais para acesso pelo WS rodando no Apache.
  • sudo chmod 666 /dev/ttyUSB0 (colocado no /etc/init.d/rc.local)
Instalacão:
  • synaptic (python-serial)
Teste:
  • import serial
  • ser = serial.Serial('/dev/ttyUSB0', 9600, timeout=1)
  • print ser.readline()
Info:

Tuesday, October 12, 2010

Instalando Ubuntu 10.10

Ubuntu 10.10


Status:
  • Ubuntu Instalado.

ToDo:
  • Instalar software (bibliotecas, componentes, ...) necessários ao Robô.

Gerar Mídia de Instalacão:
  • Download da imagem (ubuntu.com)
  • USB: System -> Administration -> Startup Disk Creator
  • CD: Right click iso file and 'Write to Disc'

Após a instalacão Padrão do Ubuntu:

Configurar rede wireless:
  • Se a placa wifi não foi detectada, instalar drivers:
  • apt-get install bcmwl-kernel-source
  • System -> Administrator -> Hardware Drivers -> escolha "Driver sem fio Broadcom STA", clique sobre ele, clique "ativar"
Configurar Driver de Vídeo:
  • Se não foi detectada corretamente, ou seja, resolucão máxima de 800x600.
  • para SIS 671/771:
  • download 32 bit driver sisimedia
  • download xorg para driver sisimedia
  • download ferramenta de controle placas sisimedia
  • Descompactar xorg.conf na pasta /etc/X11
  • Descompactar driver na pasta /usr/lib/xorg/modules/drivers
  • Instalar pacote .deb das ferramentas
  • restart
Instalar JVM:
  • Habilitar repositório canonical partner (http://archive.canonical.com/ubuntu maverick partner)
  • apt-get install sun-java6-jdk sun-java6-jre openjdk-6-jdk
  • Verificar versão do Java:
  • java -version
  • Verificar java path:
  • which java
  • Selecionar JVM default:
  • sudo update-alternatives --config java
Instalar Netbeans, Eclipse, Vlc, Chromium e FlashPlugin:
  • Synaptic (Netbeans, Eclipse, Vlc, vlc-plugin-pulse, mozilla-plugin-vlc, libavcodec-extra-52, Chromium, flashplugin-installer)
Instalar plugins do Eclipse:
  • SVN http://subclipse.tigris.org/update_1.2.x [item Subclipse completo]
  • FatJar http://kurucz-grafika.de/fatjar [tudo]
  • QuantumDB http://quantum.sourceforge.net/update-site [item core completo]
  • Maven http://m2eclipse.sonatype.org/update/ ou http://m2eclipse.sonatype.org/sites/m2e [item Maven Integration completo]
Instalar Plugins do Firefox:
  • REST Client
  • FireFTP
  • FireBug
  • Web Developer
  • DownThemAll
Instalar Drivers opcionais (QuickCam) para WebCam:
  • apt-get install qc-usb-source qc-usb-utils usbutils
Instalar Subversion:
  • Synaptic (SubVersion, RapidSVN GUI Client)
Instalar Joomla e seus prerrequisitos:
Instalar Python:
  • sudo apt-get install python python-dev python-setuptools python-espeak libespeak-dev python-serial python-numpy libusb libusb-dev
Instalar GStreamer:
  • sudo aptitude install gstreamer-tools gstreamer0.10-tools gstreamer0.10-x libgstreamer0.10-0 libgstreamer0.10-dev python-gst0.10 python-gst0.10-dev python-gst0.10-rtsp gstreamer0.10-ffmpeg
Instalar USB-Python:
Instalar Reconhecimento de Voz:

Links:

Thursday, September 30, 2010

Instalando Joomla no Ubuntu usando Lampp

Ubuntu 10.04
Xampp (Apache, Mysql, Php5) 1.7.3a
Joomla 1.5.20


Status:
  • Funcionando.

ToDo:
  • Configuracões Globais (URLs amigáveis, htaccess)
  • Instalar extensões (Mobile, Morfeo,

Info:


Instalacão:
  • Download Lampp
  • Download Joomla
  • sudo -i (muda usuário p/ root
  • cd /opt
  • tar zxvf /...../downloads/xampp-linux-1.7.3a.tar.gz
  • cd lampp/
  • ./lampp --help
  • ./lampp start (também inicia o ProFtpd)
  • cd htdocs/
  • mkdir portal
  • cd portal
  • unzip /...../downloads/Joomla_1.5.20-Stable-Full_Package.zip
  • cd ..
  • chown nobody:root portal -R
  • ./lampp restart
  • Mudar o parâmetro display_errors=off no arquivo /opt/lampp/etc/php.ini
Autostart:
  • sudo ln -s /opt/lampp/lampp /etc/init.d/lampp
  • sudo update-rc.d lampp defaults
Undo Autostart:
  • sudo rm /etc/init.d/lampp
  • sudo update-rc.d -f lampp remove

Links:

Sunday, September 5, 2010

Jython - Python para JVM

Ubuntu 10.04
Python 2.6.5
Jython 2.5.1rc3
Eclipse 3.5.2
Netbeans 6.8



Status:

ToDo:
  • Testar criar objeto em java a partir de uma classe jython compilada em bytecodes java (.jar).
  • Observar as diferencas (tempos de acesso, performance,..) usando PySystemState e PyInterpreter.
  • Outra possibilidade é usar Py4J, onde códigos Java e Python podem se comunicar em tempo de execucão, trocando objetos (via proxy), ou seja, comunicacão entre processos do interpretador Python e da JVM.

Instalacão:


IDE Plugins:


Info:

Tutorial:
  • Criar pasta do projeto com a estrutura abaixo:
  • - /servletProjectTest
  • --- NewJythonServlet.py (outros servlets devem ficar nesse nível de pasta)
  • --- /WEB-INF
  • ----- web.xml
  • ----- sun-web.xml
  • ----- /lib
  • ------- jython.jar
  • ------- servlet-api-2.5.jar
  • Compactar os arquivos e pastas dentro de servletProjectTest e renomear para .war
  • Deploy no glassfish

Links:

Sunday, August 29, 2010

SVN SubVersion - Versionamento de Conteúdo

Ubuntu 10:04
SVN Subversion
RapidSVN 00:12


Status:
  • 20111217 Acscentado procedimento de backup e restore entre servidores SVN.
  • Running SVN Server (svnserve -d -r /home/marcus/svn - dentro de /etc/init.d/rc.local)
  • SVN Client RapidSVN to svn: / / javasoftware.com.br.
ToDo:
  • See the possibility of using SVN for versioning the content of resources. A first level "cache" of the previous values of the state of a resource are maintained in the table (tbl_recursos - id: long and state: text) DBMS. The idea is to create a permanent repository for data, where they are stored in an optimized way to occupy little space for media.
  • View integration python-subversion.

Info:

SVN Server installation:
  • sudo aptitude install subversion

SVN clients:
  • sudo aptitude install RapidSVN - RapidSVN (Docs) (Linux or Windows)
  • Tortoise (Windows)

Linha de comando:
  • // Instalar o servidor SVN no LINUX pelo Gerenciador de Pacotes

  • // Criando repositório:
  • - mkdir /opt/snv_repo
  • - svnadmin create /opt/snv_repo

  • // Importando os dados iniciais:
  • - svn import ~/temp/first_project file://opt/snv_repo/trunk/first_project -m "initial import"
  • // Checkout
  • - svn checkout svn://localhost/trunk/first_project first_project

  • // Configurando o autostart:
  • ??? /etc/inetd.conf ???

  • // Configurar o acesso nos arquivos passwd e svnserve.conf
  • // arquivo /opt/svn_repo/conf/svnserve.conf
  • [general]
  • anon-access = none
  • auth-access = write
  • password-db = passwd
  • realm = Repositorio Modelo
  • // arquivo /opt/svn_repo/conf/passwd
  • [users]
  • marcus = 123

  • // Start o Subversion Server
  • // Startar como deamon.
  • - svnserve -d -r /opt/svn_repo
  • // Startar de modo automatico.
  • - svnserve -i
  • - e alterar o /etc/inetd.conf colocando o repositorio.

  • // Conecte ao repositório:
  • - svn://localhost/

  • // Backup e restore em servidores diferentes.
  • svnadmin dump /path/to/repository > repo_name.svn_dump
  • svnadmin create /path/to/repository
  • svnadmin load /path/to/repository < repo_name.svn_dump

  • // Import de um repositório SVN existente para outro servidor (eg GoogleCode)
  • // Google Code repository must be reset to revision 0.
  • svnsync init --username YOURUSERNAME https://YOURPROJECT.googlecode.com/svn file:///path/to/localrepos
  • svnsync sync --username YOURUSERNAME https://YOURPROJECT.googlecode.com/svn

  • // Mudar IP do servidor SVN na workcopy.
  • svn switch --relocate svn://OLD.IP.ADDR svn://NEW.IP.ADDR

Links:

Saturday, August 21, 2010

Instalando ARToolKit no Ubuntu 10.04

Ubuntu 10.04
Augmented Reality - ARToolKit 2.72.1


Status:
  • Estão funcionando, usando GStreamer, os exemplos do ARToolKit em C.

ToDo:
  • Imprimir landmarks do projeto SACRA para testar colisão entre objetos virtuais.
  • Usar exemplo exview.c (samples) para testar precisão do posicionamento informado pela API.
  • Tentar encapsular as funcões do ARToolKit para programar em Python, ou, se já existe esta integracão e exemplos de ARTolKit em Python.


ARToolKit Info:
Packages:

Instalacão a partir dos fontes:
  • wget http://downloads.sourceforge.net/project/artoolkit/artoolkit/2.72.1/ARToolKit-2.72.1.tgz
  • tar -zxvf ARToolKit-2.72.1.tgz
  • sudo apt-get install freeglut3-dev libxmu-dev libxmu6 libxi6 libxi-dev
Para usar V4L2 siga as instrucões abaixo. Para usar V4L ignore o passo abaixo (erro no make, nos dois casos):
  • wget http://img.vivaolinux.com.br/imagens/artigos/comunidade/artk-v4l2-2.72.1.20080427.patch
  • ou wget http://staff.aist.go.jp/k.kojima/artoolkit/artk-yuv422-v4l2-2.72.1.20090801.patch
  • patch -p0 -d . < artk-yuv422-v4l2-2.72.1.20090801.patch
  • ou patch -p0 -d . < artk-v4l2-2.72.1.20080427.patch
  • copie o conteúdo da pasta criada pelo comando acima para a pasta ARToolKit
Para usar GStreamer:
  • sudo aptitude install gstreamer-tools gstreamer0.10-tools gstreamer0.10-x libgstreamer0.10-0 libgstreamer0.10-dev python-gst0.10 python-gst0.10-dev python-gst0.10-rtsp gstreamer0.10-ffmpeg

Continuando a instalacão:
  • cd ./ARToolKit
  • ./Configure
Nesse ponto selecione o driver V4L, V4L2 ou GStreamer e responda as perguntas conforme listado abaixo:

  • Color conversion should use x86 assembly (choose 'n' for 64bit systems)?

  • Enter : n
  • Do you want to create debug symbols? (y or n) Enter : n
  • Build gsub libraries with texture rectangle support? (y or n)
  • GL_NV_texture_rectangle is supported on most NVidia graphics cards
  • and on ATi Radeon and better graphics cards.
  • Enter : y
Compilando o ARToolKit e gerando os exemplos:
  • make
Configurando variável do ambiente:
  • para V4L:
  • export ARTOOLKIT_CONFIG="-dev=/dev/video??? -palette=YUV420P -width=640 -height=480"
  • para V4L2:
  • export ARTOOLKIT_CONFIG="v4l2src device=/dev/video??? use-fixed-fps=false ! ffmpegcolorspace ! capsfilter caps=video/x-raw-rgb,bpp=24,width=960,height=720 ! identity name=artoolkit ! fakesink"
  • para GSTreamer:
  • export ARTOOLKIT_CONFIG="v4l2src device=/dev/video??? use-fixed-fps=false ! ffmpegcolorspace ! capsfilter caps=video/x-raw-rgb,bpp=24 ! identity name=artoolkit ! fakesink"
Testando os exemplos gerados (necessário exportar variável de ambiente, acima):
  • cd ./bin
  • ./videoTest
  • ./simpleTest
  • ./exview (câmera)
  • ./optical
  • ./collideTest (Distance)

Easy Mobile Augmented Reality using Python (Magnet, S60Nokia):
  • http://ojs.pythonpapers.org/index.php/tppm/article/view/95/95

Links:

Thursday, August 5, 2010

Linux - Commands

Linux


ToDo:
  • Add more tips.

Terminal Commands:
  • wc -l filename.ext  -  Count the number of lines (-l), words (-w) ou letters (-c) of a file.
  • sudo ufw status  - Status to Firewall
  • alias  -  Funciona como um apelido para um comando, uma expressão regular e/ou instrução. Exemplo:  alias ll='ls -l'
  • Mounting File Systems:
    • mount /dev/fd /floppy =Mount a file system.
      • exFAT:
        • sudo mount -t exfat /dev/sdc1 /media/exfat
      • NTFS:
        • sudo mount -t ntfs -o nls=utf8,umask=0222 /dev/sdb1 /media/windows
    • umount /floppy = Unmount a file system.
  • find /home -name "file*" 2> /dev/null = Search for files, ignoring access errors.
  • which <app-name-or-command> = Prints the full path to shell commands
  • test -f <filename> = Test if a file exist.
  • scp -r ~/Desktop/test  <user>@<ip_address_of_user>:/home/user/Desktop  =  Copying an entire directory.
  • cp <source> <destination> = Copy files and/or folders:
    • -r  or -R = recursive copy
    • -p = preserves the following characteristics of each source file in the corresponding destination file: data modification,  last access, ownership, and the file permission bits. 
    • -f = force copy. Also, ignore errors if the file/folder does not exist.
  • rsync -vap --ignore-existing <source_file> <destination_file> = copy files and directories to a destination, similar to the cp command. However, it also allows copying to remote locations and can provide a progress bar.
    • Key flags:
      • v = verbose
      • r = recursive
      • p = preserve permissions
      • g = group
      • o = owner
      • a = archive
      • --progress = progresss bar
  • cat file1.txt file2.txt > files1and2merged.txt = Cria um novo arquivo com o merge dos arquivos 1 e 2.
  • cat file1.txt >> file2.txt = Add file1 at the end of file2.
  • > <file-name> = Clear the file without deleting it.
  • touch <filename.ext> = Create an empty file named <filename.ext>(0Kb).
  • ln -s source_file symbolic_link =  Create a symbolic link to a given file.
  • mkdir -p /folder/subfolder  =  Create directory trees with a single command.
  • CURL:
    • curl http://some.url --output some.file = faz o download do arquivo e salva.
    • curl -IL mail.com = Test an HTTP 301 redirect
  • grep -i -r -n search4 * = Procura palavra (search4) dentro de arquivos texto.
  • whereis eclipse = Procura por aplicativo instalado.
  • echo "Line 1"  >  ./test.txt = Cria um arquivo com o conteúdo "Line 1". Se o arquivo existir ele será sobrescrito.
  • echo "Line 2"  >>  ./test.txt = Acrescenta o conteúdo no final do arquivo. Se o arquivo não existir será criado.
  • rm -r * = Remove diretórios e arquivos simultaneamente.
  • rm -f file_* = Force remove files
  • find . -name "*.ptz" -delete = Delete a huge number of files.
  • pwd  =  Prints the current directory to the screen.
  • printenv = List environment variables.
  • Managing Users and Groups:
    • passwd = Change user's password
    • passwd -d  <user> =  remove the password for a user
    • getent passwd =  List the users
    • whoami = List the current user.
    • who =  List all logged users.
    • w = List all logged users.
    • sudo adduser -m <username> = Cria um novo usuário chamado 'git'. (-m) cria a pasta do usuario
    • usermod -aG username sudo <username> = adiciona o usuário 'username' ao SUDOERS
    • usermod --shell /bin/bash <username> = Change the login shell for the specified user.
    • chsh -s /bin/bash = Change your login shell.
    • echo $SHELL = The shell for the current user but not necessarily the shell that is running at the moment
    • usermod -aG <username> <group-name> = adiciona o usuário 'username' ao grupo 'group-name'
    • sudo deluser --remove-home <username> = remove o usuário `git` e o seu folder (e.g: /home/git)
    • groupdel group-name = Remove o grupo.
    • gpasswd -d group-name username = Remove o usuário do grupo.
    • groups user-name = List groups of the user
    • id -nG = List groups of the current user
    • groups = Lista todos os grupos
    • getent group = List all groups and its users
    • getent group <group-name> = List group info
    • cut -d : -f 1 /etc/passwd = Lista os usuários do Linux
    • cat /etc/passwd = Lista os usuários do Linux
    • echo username:newpassword | chpasswd = Change the user's password without asking for any input
  • mkpasswd -l 8 =  Generates a complex random password at the specified length.
  • wall "<my-message>" = Send a message to everyone connected to the machine.
  • uname -a = Lista versão do kernel, inclusive se é 32 ou 64 bits
  • iwconfig = Lista dispositivos de rede wireless
  • iwlist =  Lista informações adicionais da interface de rede wifi, não listadas pelo comando iwconfig
  • ifconfig = List the configured network devices
  • ip a -c =  List network devices
  • ifconfig -a = List the configured network devices, regardless they are configured or not.
  • sudo ifconfig wlan0 up = Activate the 'wlan0' network adapter. 
  • sudo ifconfig wlan0 down = Deactivate the 'wlan0' network adapter. 
  • Managing used space on disk per folder:
    • du -sh ./* = Find out the weight of a directory or file with the specified mask (./*)
    • sudo du -h --max-depth=1 | sort -hr = finding out which directories are using all your space
    • du -h -s = List the summarized disk space used by a folder.
  • Free up disk space:
    • sudo journalctl --vacuum-time=3d
    • sudo apt-get autoremove
    • sudo apt-get clean - This will remove the content of the /var/cache/apt/archives directory.
    • sudo apt-get autoclean - Unlike clean, autoclean only removes the packages that are not possible to download from the repositories.
    • sudo du -sh /var/cache/apt
    • du -h /var/lib/snapd/snaps
    • du -sh ~/.cache/thumbnails
  • List the 10 largest files:
    • sudo find . -type f -exec ls -l '{}' \; | awk '{print $5, $NF}' | sort -n | tail -10
    • sudo find . -printf '%s  %p\n' | sort -nr | head -10
  • List the 10 largest folders:
    • du -h --max-depth=1 | sort -rh | head -n 10
    • du -h --max-depth=1 /path/to/directory | sort -rh | head -n 10
  • pidof svnserve = Show the PID of the process "svnserve", if it's running.
  • ps aux = List all running processes in Linux
  • kill -9 <process-id> = sends a SIGKILL signal indicating to a service to shut down immediately. An unresponsive program will ignore a kill command, but it will shut down whenever a kill -9 command is issued. Use this command with caution. It bypasses the standard shutdown routine so any unsaved data will be lost.
  • sudo = Run commands as a root user (See details)
  • sudo su - = Will put you into a root environment, but it will ask you for your user password instead of the root password.
  • cat ~/.bash_history = Listagem de comando executados no terminal (por usuário).
  • history -f = Show the date and time in the history command output in zsh shell.
  • history -c = Delete the command log history file of the current user.
  • history -d <history-id> = remove the line number <history-id> from history
  • history -a = Salva no arquivo ~/.bash_history cada comando executado no terminal durante a sessão atual. Force your shell to append every command entered during a current shell session into ~/.bash_history file.
  • history -r = Read the commands saved in the file ~/.bash_history and update the list in memory. If you want your history to be updated and to reflect changes in your ~/.bash_history file, you can read all history commands from the ~/.bash_history file.
  • To force it to automatically store every command into a ~/.bash_history file immediately after command execution you can take a look at HERE.
  • cat /dev/null > ~/.bash_history && history -c && exit  = Delete the log of executed commands, including the list saved in the memory\.
  • runuser -l <username> -c '<command>' = Run command as another user.
  • Running multiple commands in one line:
    • A ; B       # Run A and then B, regardless of the success of A
    • A && B  # Run B if and only if A succeeded
    • A || B       # Run B if and only if A failed
    • A &         # Run A in the background.
  • yes | <command> = For commands or scripts that require an interactive response.
  • 32-bits or 64-bits:
    • lscpu =  Show if the Linux kernel is 32 bits or 64 bits. (CPU op-modes).
    • file /usr/bin/file = Show if the Linux kernel is 32 bits or 64 bits.
    • arch = Show if the Linux kernel is 32 bits or 64 bits.
    • pdkg --print-architecture = Show if the Linux kernel is 32 bits or 64 bits.
    • getconf LONG_BIT = Show if the Linux kernel is 32 bits or 64 bits.
  • Ubuntu Desktop ou Server:
    • dpkg -l ubuntu-desktop   =  Returns "dpkg-query: no packages found matching ubuntu-desktop", if using Ubuntu Server.
  • Hostname:
    • hostname -I =  List all IPs of the machine.
    • hostnamectl  =  Lista o nome do host.
    • Mudar o nome do host:
      • sudo hostnamectl set-hostname newNameHere
      • sudo nano /etc/hosts
        • Replace any occurrence of the existing computer name with your new one
      • sudo reboot
  • How to detect the OS from a Bash script:
    • echo $OSTYPE
    • echo `uname`
    • platform=$(uname) && echo $platform
  • SSH:
    • sudo apt install openssh-server -y  =  Install ssh server
    • ssh-copy-id -i <id_rsa.pub> <remote-user>@<remote-host-ip-or-name>  =  Copy the public ssh-key to the remote computer, then you can log in to this <remote-host-ip-or-name> server without a password from this particular system.
  • Public IP: We can get the public IP address of a machine using the Linux bash terminal by making a request to a web service that returns the IP address of the machine making the request. Here are a few examples using different web services: 
    • curl ifconfig.me
    • curl api.ipify.org
    • curl ipecho.net/plain
  • df = reports file system disk space usage.
    • df - h
    • df -Th = include the file system type on a particular disk partition
  • lsblk = Listar as informações de blocos dos dispositivos conectados e seus mapeamentos.
  • sudo fdisk -l  ~= lsblk
  • lsusb = Lista dispositivos usb.
  • lspci = Lista informações (tipo e modelo) dos dispositivos encontrados pelo sistema.
  • lshw = Informações da configuração de hardware.
  • lsmod = Lista os módulos que foram carregados (eg. bluetooth, ip_tables, network drivers).
  • lscpu = Show CPU information
  • lsmem = List the ranges of available memory with their online status
  • lsof = Identifies which files are in use by which processes
  • cat /proc/meminfo = Find ram size
  • watch <command> = Periodically running that <command> at a certain set interval of time (2s default). 
  • wpa_passphrase <ssid> [passphrase] = retorna [passphrase] criptografada para a rede <ssid>.
  • Find out the Linux distribution and version:
    • uname -a
    • lsb_release -a
    • cat /etc/os-release
    • cat /etc/*release
    • hostnamectl
  • diff -u <(ls -l /directory/) <(ls -l /directory/) | colordiff  = Comparing output of two ls commands
  • nohup <command> = Keep your command running in the background, even if you accidentally close the terminal window.
  • screen = You can connect to a remote machine, start a screen session, and launch a process. You can disconnect from the remote host, reconnect, and your process will still be running. You can share a screen session between two different SSH connections so two people can see the same thing, in real-time.
    • screen = Start a screen session.
    • screen -ls = Get a list of the detached sessions
    • screen -r <screen-session-id> = Attach to session <screen-session-id>
  • echo $BASH_VERSION = Show bash shell version
  • netstat -ltpn = Display network socket related information.
    • -l = to print all listening sockets
    • -t = shows all TCP connections
    • -u = displays all UDP connections
    • -p = enables printing of application/program name listening on the port
    • -n = To print numeric values rather than service names
  • nslookup google.com = Get information about servers on the internet or your local network. It queries DNS to find the name server information and can be useful for network debugging.
  • Display Routing Table
    • netstat -rn
    • sudo route -n
    • ip route list
  • ss -nlt = Display network socket related information on a Linux system.
    • -l - display listening sockets only
    • -t - display all TCP connection
    • -n - do not try to resolve service names
  • amixer sset 'Master' 50% - Increase the volume.
  • <Ctrl><r> - procurar no histórico de comandos do usuário.
  • cd - = voltar para a pasta anterior.
  • acpi -i -b = informa o status de carga da bateria.
  • upower -i /org/freedesktop/UPower/devices/battery_BAT0  - Checar o status da bateria do laptop.
  • date -s "19 APR 2012 11:14:00" -   Atualiza a data e hora.
  • sudo timedatectl set-ntp off    sudo timedatectl set-ntp on - Atualiza a data e hora online.
  • sudo add-apt-repository  ppa:PPA_REPOSITORY_NAME/PPA - Add a PPA Repository
  • sudo add-apt-repository --remove ppa:PPA_REPOSITORY_NAME/PPA - Remove a PPA Repository
  • sudo apt-cache policy <package-name> - Shows which version is currently installed and which versions are available to install
  • sudo apt search <package-name> -  Show detailed information about the package.
  • sudo apt show <package-name> -  Show Detailed info with description and depends.
  • while! <command>; do sleep 1; done = Repeating a command until it successfully completes.
  • SystemD / SystemCtl:
    • Important note: The environment variables are not "visible" by the service unit. If your service unit needs to use environment variables you need to declare them into the service unit configuration file. (e.g: [Service] Environment="GITHUB_TOKEN=xpto...")
    • systemctl --type=service - List all loaded services on your system (whether active; running, exited or failed)
    • systemctl -l -t service | less - List all Systemd services
    • systemctl start <application-name>.service  - Start a systemd service.
    • systemctl stop <application-name>.service  - Stop a currently running service.
    • systemctl restart <application-name>.service  - Restart a currently running service.
    • systemctl reload <application-name>.service  - Reload its configuration files.
    • systemctl enable <application-name>.service   - To start a service at boot.
    • systemctl disable <application-name>.service   - To disable the service from starting automatically.
    • systemctl status <application-name>.service  - To check the status of a service.
    • systemctl list-units  - To see a list of all of the active units that systemd knows about.
    • systemctl list-dependencies <application-name>.service - To see a unit’s dependency tree.
    • systemctl show <application-name>.service - To see the low-level properties of a unit.
    • systemctl reset-failed - Resets any units from failed state
    • systemctl daemon-reload - Reload the service files to include a new service.
  • Service - The service command is used to manage running services
    • service <service-name> start / stop / restart / status
    • service <service-name> reload - Reload the configuration files for the service after they have been edited.
    • chkconfig --list - Displays the current service configuration
  • Number of computer Cores:
    • grep -c ^processor /proc/cpuinfo
    • nproc --all
    • getconf _NPROCESSORS_ONLN       # works on macOS
    • grep -c 'cpu[0-9]' /proc/stat
  • Ping:
    • sudo nmap -sn -PE 192.168.1.0/24 - Ping todos os 256 ip's da rede 192.168.1.0. Using /24 will search 256 address, /23 will search 512 address, /22 will search 1024. Options meaning:  -sn (No port scan) -PE (ICMP ping echo).
    • ping -c 3 192.168.1.255 | grep 'bytes from' | awk '{ print $4 }' | sort | uniq   -   Ping the broadcast address to return all devices on the network.
    • ping 192.168.1 | arp -a   -   Ping all IP's and return their MAC address.
    • for ip in {1..254}; do ping -c 1 -W 1 192.168.1.$ip | grep "64 bytes"; echo -ne $(( 100 * $ip/254)) % done \\r; done - Ping all IP's in the range of the "for"
  • tail [-n 10] /var/log/ppp.log  -  View the VPN PPP log. (-n = Number of lines, default is 10)
  • DNS:
    • nmcli dev show 2>/dev/null | grep DNS | sed 's/^.*:\s*//'   -  Show DNS server IPs.
    • systemd-resolve --status | grep 'DNS Servers' -A2  -  Show DNS server IPs.
  • traceroute - Investigate the routes of network packets.
  • Check Memory Use:
    • free -m -t - used/available memory and the swap memory in megabytes.
    • cat /proc/meminfo - It contains real-time information about the system’s memory usage.
    • vmstat - provides general information about processes, memory, paging, block IO, traps, and CPU activity.
    • top - useful to check memory and CPU usage per process
    • htop - A complete overview of all processes running on your system, along with details such as process IDs, CPU and RAM usage, and how long they've been running.
    • System Monitor - Checking Memory Usage in Linux using the GUI
  • Command Grouping in Bash:
    • Placing commands in () creates a subshell in which the grouped commands are executed. That means that any changes to variables made in subshell, stay in subshell.
      • (cd /workspace/foo && python main.py) & (cd /workspace/boo && python main,py)
Autostart:
  • Autostart scripts no Ubuntu: Adicionar o script no arquivo /etc/init.d/rc.local
  • Exemplo:
  • - export SOMEPATH="/some/path:$SOMEPATH"
  • - cd /opt/test
  • - sh /opt/test/test.sh
  • - echo 'Test loaded!'
  • To remove autostart service:
  • sudo update-rc.d apache2 disable

Arquivos:
  • /etc/init.d/rc.local => Pode ser usado para Autostart de aplicacões.
  • /etc/rc.local => Pode ser usado para Autostart de aplicacões.
  • ~/.bashrc => Pode ser usado para Autostart de aplicacões.
  • ~/.bash_history => Histórico de comandos executados pelo usuário no terminal (Ex: /root/.bash_history ?)
  • /etc/resolv.conf  =>  DNS configuration file
  • /etc/apt/sources.list  =>  apt-get configuration file
  • ls /etc/apt/sources.list.d  => apt-get repository names
  • /etc/network/interfaces  =>  Network interfaces configuration file
Outros:
  • "Could not get lock /var/lib/dpkg/lock" or "unable to acquire the dpkg frontend lock"
    • sudo rm /var/lib/dpkg/lock
    • sudo rm /var/lib/apt/lists/lock
    • sudo rm /var/cache/apt/archives/lock
    • [Optional] sudo dpkg --configure -a
  • Create a new json file with "{}" content for each file found at folder ".":
    • find . -exec /bin/sh -c ‘echo \{\} > {}.json’ \;

Referências:

Monday, August 2, 2010

USB access with Python

Ubuntu 10.04
Python 2.6.5

PyUSB 1.0a0


Status:
  • Funcionando acesso r/w ao dispositivo USB.

ToDo:
  • Como definir explicitamente as permissões p/ outro usuário (não root).
  • Testar permissoes necessárias para integracão com apache-webpy.


Instalacão (usuario root):
  • apt-get install python python-dev python-numpy libusb libusb-dev
  • Download and Unzip pyusb-1.0.0-a0.tar.gz
  • cd ./pyusb-1.0.0-a0
  • python setup.py install
  • export PYTHONPATH="/usr/local/lib/python2.6/dist-packages:$PYTHONPATH"
  • Para testar é necessário usuário root, ou (ToDo) definir explicitamente as permissões p/ outro usuário.


Libs:
Referenced Libs:

Wednesday, July 14, 2010

Configurando Serviço de Correio do Google para um Domínio

Google
ZoneEdit
Registro.Br


Configurando o Google para responder como servidor de correio de um domínio.

Passo 1:

Passo 2:
  • Acesse http://www.google.com/a/marcusveloso.net
  • Faça o login com a conta criada anteriormente
  • Confirme a propriedade do domínio (registrar CNAME no zoneedit)
  • Aguarde a confirmação pelo Google.
  • Crie um ALIAS para o acesso web (ex: webmail.marcusveloso.net)


Saturday, May 29, 2010

Instalando GlassFish no Ubuntu

Ubuntu 9.04
GlassFish v3
sun-java6-jdk ou openjdk-6-jdk


Instalar JVM - Java Virtual Machine:
  • Habilitar repositório canonical no Synaptic
  • apt-get install sun-java6-jdk sun-java6-jre openjdk-6-jdk
  • Verificar versão do Java:
  • java -version
  • Verificar java path:
  • which java
  • Selecionar JVM default:
  • sudo update-alternatives --config java

Instalar GlassFish V3:
  • sudo -s
  • cd /opt
  • wget http://download.java.net/glassfish/v3/release/glassfish-v3.zip
  • unzip glassfish-v3.zip
  • useradd --system glassfish -d /opt/glassfishv3
  • sudo chgrp -R admin /opt/glassfishv3
  • sudo chown -R glassfish /opt/glassfishv3
  • sudo chmod -R +x /opt/glassfishv3/bin/
  • sudo chmod -R +x /opt/glassfishv3/glassfish/bin/
  • /opt/glassfishv3/bin/asadmin start-domain domain1

Testes:
  • http://localhost:8080 (Web Server)
  • http://localhost:4848 (Administration)

Deploy, Undeploy, List e Stop por linha de comando:
  • wget https://glassfish.dev.java.net/downloads/quickstart/hello.war
  • asadmin deploy .../hello.war
  • asadmin undeploy hello
  • asadmin list-applications
  • asadmin stop-domain domain1

Mudando as portas default:
  • asadmin set server.http-service.http-listener.http-listener-1.port=8090
  • asadmin set server.http-service.http-listener.admin-listener.port=8888

Security:


Http methodBehavior
GETall can access GET method
POSTonly authenticated users with role javaee can access POST method


Links: