#Appunti su Ubuntu

## Set timeout tra comandi sudo

	sudo nano /etc/sudoers
	
Cambiare: 

	Defaults        env_reset

in:

	Defaults        env_reset, timestamp_timeout=minuti_timeout



##Preparazione di una chiatte USB bootstrappabile

Questa procedura usa un PC Windown per preparare la chiavetta

* Scaricare una immagine di Ubuntu da [www.ubuntu.com](http://www.ubuntu.com/download)
* Scaricare l'utility per Windows [UNetbootbin](https://sourceforge.net/projects/unetbootin/) e segure le istruzioni
per creare con questa una chiavetta bootstrappabile partendo dall'immagine ISO di Ubuntu

## Creare una ramfs

<pre class="terminal">
$ sudo mkdir /mnt/ramdisk
$ sudo mount -t ramfs -o size=1.5g tmpfs /mnt/ramdisk
$ sudo chmod 777 /mnt/ramdisk
</pre>

##Ricerche su file

Cerca la stringa *pattern* nei file con estensione .c e .h

<pre class="terminal">
$ find -name "*.[ch]" | xargs -r grep -n "pattern"
</pre>

Cerca tutti i file con estensione .h e .c

<pre class="terminal">
$ find -name "*.[ch]"
</pre>

##Accedere a minicom da user

<pre class="terminal">
$ sudo usermod -G dialout -a tanzilli
</pre>



##Accedere a minicom da un qualsiasi utente

Edit /etc/udev/rules.d/50-ttyusb.rules:

<pre class="terminal">
$ sudoedit /etc/udev/rules.d/50-ttyusb.rules
</pre>

and add 

<pre class="terminal">
KERNEL=="ttyUSB[0-9]*",NAME="tts/USB%n",SYMLINK+="%k",GROUP="uucp",MODE="0666"
</pre>

Detach and insert again the ttyUSB adapter.

* [Source Article](http://askubuntu.com/questions/112568/how-do-i-allow-a-non-default-user-to-use-serial-device-ttyusb0)


##Rigenerare la chiave ssh

<pre class="terminal">
# rm target-rootfs/etc/ssh/ssh_host_*_key*
# dpkg-reconfigure openssh-server
</pre>

##Montare una directory remota via ssh

<pre class="terminal">
$ sudo apt-get install sshfs
$ sudo usermod -a -G fuse [user_name]
$ exec su -l $USER
$ sshfs my_user@remote_host:/path/to/directory [local_mount_point]
</pre>

##Lancio di comandi remoti via ssh

<pre class="terminal">
$ ssh tanzilli@acmesystems.it "ls /var/www/new-acme-website"
</pre>

* [Tutorial](http://xmodulo.com/2013/04/how-to-mount-remote-directory-over-ssh-on-linux.html)

##Watch

<pre class="terminal">
$ watch ifconfig
</pre>

<pre class="terminal">
$ watch "dmesg | tail -20"
</pre>

##Crea file pattern

Crea un file da 256MB con contenuto casuale

<pre class="terminal">
$ dd if=/dev/urandom of=pattern bs=1 count=256M
</pre>

##Confronta due file binari

<pre class="terminal">
$ xxd file1.bin > file1.hex
$ xxd file2.bin > file2.hex
$ diff file1.hex file2.hex
</pre>

##rsync

<pre class="terminal">
$ rsync -avc foxg20-modules/lib/. root@192.168.1.90:/lib/.
</pre>

##Disattivare un account

<pre class="terminal">
$ sudo passwd -l username
</pre>

Per riattivarlo:

<pre class="terminal">
$ sudo passwd -u username
</pre>

##Accedere a minicom da user

<pre class="terminal">
$ sudo usermod -G dialout -a tanzilli
</pre>

## Maurizio Scarpa

<pre class="terminal"> 
# iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
</pre> 

Abilita il forwarding di pacchetti non locali - FONDAMENTALE

<pre class="terminal"> 
# echo 1 > /proc/sys/net/ipv4/ip_forward
</pre> 

Ignora finti messaggi di errore ICMP

<pre class="terminal"> 
# echo 1 > /proc/sys/net/ipv4/icmp_ignore_bogus_error_responses
</pre>

Non risponde ai ping inviati al broadcast della subnet

<pre class="terminal"> 
# echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts
</pre>

Non accetta pacchetti ICMP di route redirection

<pre class="terminal"> 
# echo 0 > /proc/sys/net/ipv4/conf/all/accept_redirects
</pre>

<pre class="terminal"> 
# logger -s "Hard disk full"
</pre>

* [How_to_use_USB_device_networking](https://developer.ridgerun.com/wiki/index.php/How_to_use_USB_device_networking)



##Grabbing view 1080p

<pre class="terminal">
~#ffmpeg -f x11grab -s 1920x1080 -r 25 -i :0.0 -sameq /tmp/out1.mpg
</pre>

##Disabilita l'auto-open delle finestre al mount

The simplest option is to open a terminal with Ctrl+Alt+T, and type:

<pre class="terminal">
gsettings set org.gnome.desktop.media-handling automount-open false
</pre>

Turns out, it is. You will need dconf-editor tool, which can be 
installed by with sudo apt-get install dconf-tools. 
Run dconf-editor in your terminal. Browse to 
org -> gnome -> desktop - media-handling. Uncheck automount-open.

##Installazione C

<pre class="terminal">
~# apt-get install make
~# apt-get install gcc
~# apt-get install make libjpeg-dev libv4l-dev
~# cd /usr/include/linux
~# ln -s ../libv4l1-videodev.h videodev.h
</pre>

##USB Gadget

<pre class="terminal">
$ modprobe g_ether
$ ifconfig usb0 192.168.10.1
$ /etc/modprobe.d/options
</pre>

* [USB_Gadget](http://www.armadeus.com/wiki/index.php?title=USB_Gadget)
* [usb-file-storage-gadget](http://linlog.blogspot.com/2011/02/usb-file-storage-gadget.html)

##Creare una tmpfs
/etc/fstab tmpfs /tmp tmpfs defaults 0 0

##Watch dog
http://lxr.linux.no/linux+v2.6.38/Documentation/watchdog/
http://coleman.jandasoft.biz/?p=25

##Swap su chiavetta

<pre class="terminal">
mkswap /dev/sda1 && swapon /dev/sda1
</pre>

# Appunti su Linux Kernel

* [Come lavorare su linix-next](https://www.kernel.org/doc/man-pages/linux-next.html)


# Appunti su Apache

##Abilitazione proxy per dts builder

<pre class="terminal">
$ sudo a2enmod proxy_http
</pre>

Alla fine di /etc/apache2/apache2.conf

<pre class="terminal">
ProxyPass /builder http://terzo.acmesystems.it
</pre>

<pre class="terminal">
$ sudo apache2ctl restart
</pre>

* [How to](http://www.microhowto.info/howto/configure_apache_as_a_reverse_proxy.html)

#Appunti su device tree


##Abilitazione DMA su seriali

###/dev/ttyS1

<pre class="minicom">
      usart0: serial@f801c000 {
        pinctrl-0 = <&pinctrl_usart0 &pinctrl_usart0_rts &pinctrl_usart0_cts>;
        status = "okay";
        atmel,use-dma-rx;
        atmel,use-dma-tx;
        dmas = <&dma0 2 0x3>,
               <&dma0 2 0x204>;
        dma-names = "tx", "rx";
      };
</pre>


###/dev/ttyS2

<pre class="minicom">
      usart1: serial@f8020000 {
        pinctrl-0 = <&pinctrl_usart1 &pinctrl_usart1_rts &pinctrl_usart1_cts>;
        status = "okay";
        atmel,use-dma-rx;
        atmel,use-dma-tx;
        dmas = <&dma0 2 0x5>,
           <&dma0 2 0x206>;
        dma-names = "tx", "rx";
      };
</pre>

###/dev/ttyS3 (da verificare)

<pre class="minicom">
      usart2: serial@f8024000 {
        pinctrl-0 = <&pinctrl_usart2>;
        status = "okay";
        /* Inizio aggiunta */
        atmel,use-dma-rx;
        atmel,use-dma-tx;
        dmas = <&dma0 2 0x7>,
           <&dma0 2 0x208>;
        dma-names = "tx", "rx";
      };
</pre>

<hr/>

In case someone else will need it...
This made my Aria ttyS3 use DMA and work fine at speed 460800.
(Kernel 3.14.23)

<pre class="minicom">
/* /dev/ttyS3 */
      usart2: serial@f8024000 {
        interrupts = <7 IRQ_TYPE_LEVEL_HIGH 5>;
        pinctrl-names = "default";
        pinctrl-0 = <&pinctrl_usart2>;
        atmel,use-dma-rx;
        atmel,use-dma-tx;
        dmas = <&dma1 1 AT91_DMA_CFG_PER_ID(12)>,
               <&dma1 1 (AT91_DMA_CFG_PER_ID(13) | AT91_DMA_CFG_FIFOCFG_ASAP)>;
        dma-names = "tx", "rx";
        status = "okay";
      };
</pre>

#Customers tips

##WiFi su Arietta

Hans Schneider <hans.schneider@gmx.ch>

Hi Sergio,

I spent several hours with my beloved Arietta ;-) and figured out a solution for the problem with multiple 
WiFi and IP over USB that really works. Will mean that Arietta is to reach over USB IP 192.168.10.10 
and over another IP as get on DHCP, eg. 192.168.1.71 at the same time. This is important if Arietta 
is in an non-WiFi-environment. The problem with the missing internet connection as I described yesterday 
is solved also with this solution.

Because it's quite confusing now, here again are the complete rows that are inserted into the files.

<pre class="terminal">
nano /etc/network/interfaces

# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo

iface lo inet loopback

allow-hotplug wlan0
auto wlan0
iface wlan0 inet dhcp
pre-up wpa_supplicant -D wext -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf -B

pre-up modprobe g_ether
auto usb0
iface usb0 inet static
address 192.168.10.10
netmask 255.255.255.0
gateway 192.168.10.20
</pre>

#Eliminare il bash bug

##VerificaTest

<pre class="terminal">
env x='() { :;}; echo vulnerable' bash -c "echo this is a test"
</pre>

##Aggiornamento

Changing squeeze to wheezy in /<b>etc/apt/sources.list</b> and then running:

<pre class="minicom">
apt-get update
apt-get install --only-upgrade bash
</pre>

##Ripristino Unity su Ubuntu

<pre class="terminal">
dconf reset -f /org/compiz/
setsid unity
</pre>

<a href="http://ubuntuhandbook.org/index.php/2014/04/reset-unity-and-compiz-settings-in-ubuntu-14-04/">More info...</a>

#Git

###Inserire codice da GitHub sul sito Acme

* [Gist](http://gist-it.appspot.com/)

###Memorizzare in cache la password

* [Memorizzare in cache la password](https://help.github.com/articles/caching-your-github-password-in-git#platform-linux)

###Mettere i tag

<pre class="terminal">
$ git tag -a v1.01 -m 'Version 1.01'
$ git push origin v1.01
</pre>

###Controllare cosa fa una patch

<pre class="terminal">
$ git apply --stat acme.patch
</pre>

###Controllare se funziona una patch

<pre class="terminal">
$ git apply --check acme.patch
</pre>

###Applica la patch senza fare il commit:

<pre class="terminal">
$ git apply < acme.patch
</pre>

###Applica la patch e fa il commit:

<pre class="terminal">
git am --signoff < acme.patch
</pre>

[Tutorial su Git](https://www.atlassian.com/git/tutorial/undoing-changes#!clean)

###Importare un branch da un altro repository

<pre class="terminal">
git remote add nomedicomodo ../repository
git fetch nomedicomodo
git branch nuovobranch nomedicomodo/branchdaimportare
</pre>

###Eliminare tutti i file unstaged

<pre class="terminal">
git checkout -- .
</pre>

###Cancellare un branch

<pre class="terminal">
git branch -D branchname
</pre>

## Node js su PC Ubuntu

<pre class="terminal">
$ apt-get install nodejs
$ sudo ln -s "$(which nodejs)" /usr/bin/node
$ apt-get install npm
$ npm install dnode
</pre>

###Doc dnode:

https://www.npmjs.com/package/dnode

##Disabilita l'auto-open delle finestre al mount

The simplest option is to open a terminal with Ctrl+Alt+T, and type:

<pre class="terminal">
gsettings set org.gnome.desktop.media-handling automount-open false
</pre>

Turns out, it is. You will need dconf-editor tool, which can be 
installed by with sudo apt-get install dconf-tools. 
Run dconf-editor in your terminal. Browse to 
org -> gnome -> desktop - media-handling. Uncheck automount-open.





