# IT - FEDORA
## INSTALL
* Descargar versión *live*: [link][dwld_fedora]
* Descargar *linux live ubs*: [link][dwnld_llu]
## SO
### BÁSICO
```bash
$ ctrl+K #delete current line
$ mkdir directorio #create directory
$ mv ~/ruta_archivo/archivo ~/ruta_destino/ #move file
$ rm -r <folder> #delete "folder"
$ cat > /folder/file.extension #create file
$ mv filename newname #rename file
$ cd /sys/class/
$ cat max_brightness #set brightness default file
$ cat /etc/issue #fedora version
$ uname -a #system information
$ amixer set Master X% on #set volume
$ ln -s /ruta_ejecutable/ejecutable /home/usuario/.local/bin/ #create *soft link* to an executable into bin
$ /sbin/shutdown -h now #halts system
$ /sbin/shutdown -r now #reboots system
$ localectl set-locale LANG=en_US.utf8 #change system language
```
### MANTENCIÓN
* `$ su -c 'yum update'`
* `$ su -c 'dnf upgrade'`
#### AGREGAR APP AL PATH
* `echo $PATH` (ver qué hay en el PATH)
* Meter el *soft link* en el *bin* de *home*, sino existe el directorio, crearlo
* `mkdir`
#### TRANSMISSION
* `$ transmission-daemon #start daemon`
* `$ transmission-remote --add "magnet:<...>" #add torrent`
* `$ transmission-remote-cli #start cli`
#### [VIM][vim_url]
```bash
vim> i #insert mode
vim> ESC #command mode
vim> :q! #discard changes
vim> :wq #save and quit
vim> alt+V #select line
vim> ctrl+v #select block
vim> ctrl+q #select block
vim> d #cut line
vim> y #copy line
vim> p #paste line
```
#### [COMMAND LINE CALCULATOR][prmpt_clc]
```bash
$ sudo dnf install bc #if not installed
$ bc #open bc
bc> 1+1 #made operation
bc> 2 #prompt give result
$ echo '1+1' | bc
```
#### [MYSQL][mysql_url]
* `$ sudo dnf install https://dev.mysql.com/get/mysql57-community-release-fc22-7.noarch.rpm`
* `$ sudo dnf install mysql-community-server`
* `$ sudo systemctl start mysqld.service # start after update`
* `$ sudo systemctl enable mysqld.service # autostart service`
* `$ sudo /usr/bin/mysql_secur_installation #start mysql secure installation`
* `root:250707mnk++`
* `$ sudo firewall-cmd --permanent --zone=public --add-service=mysql #add rule to firewall`
* `$ sudo systemctl restart firewalld.service #restart firewall service`
##### QUERYS
* `mysql> SELECT * FROM User,Host FROM mysql.user #Mostrar ususarios`
* `mysql> show databases #Mostrar dbs`
* `mysql> use <db> #Accede a "db"`
* `mysql> show tables #muestra tablas de "db"`
#### ATOOL
* `$ sudo dnf install atool`
* `$ aunpack archivo` (descomprimir archivo)
#### FIREFOX
* `$ sudo dnf install firefox`
#### F.LUX
* Descargar: [link][xflux]
* `$ tar -xvzf /path/to/file.tgz` #extraer
* `$ mv [YOUR EXTRACTION FOLDER]/xflux /home/<user>/.local/bin/` #mover a bin
* `$ chmod 755 /home/<user>/.local/bin/xflux` #dar privilegios
* `$ xflux --help` #probar
* `$ xflux -l <latitude> -g <longitude>` #configurar (l: 43, g:-81, London)
* Dejarlo al inicio: [link][flux.startup]
#### [REDSHIFT][redshift]
```bash
$ sudo dnf install redshift
$ redshift -l <latitude>:<longitude> -t <temperatureDay>:<temperatureNight>` #configure (-l 43:-81 [London] and -t 5600:3400)
```
#### [FLASH PLAYER][flash]
* Install:
```bash
$ sudo rpm -ivh http://linuxdownload.adobe.com/adobe-release/adobe-release-x86_64-1.0-1.noarch.rpm
$ sudo rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-adobe-linux
$ sudo dnf install flash-plugin alsa-plugins-pulseaudio libcurl
```
* [Verify][verifyFlash]
[flash]: https://www.if-not-true-then-false.com/2010/install-adobe-flash-player-10-on-fedora-centos-red-hat-rhel/
[verifyFlash]: https://www.adobe.com/software/flash/about/
#### BASH
```bash
$ cat > /dir/bash-name.sh #create file, then CTRL+C
$ mv ~/dir/bash-name.sh /home/d377/bin/ #move bash file
$ chmod u+x /home/d377/bin/bash-name.sh #give permissions
$ :sy enable #syntax highlighting
$ :syn enable #syntax highlighting
$ :syntax enable #syntax highlighting
$ bash-name.sh #run bash
```
## PROGRAMACIÓN
### PYTHON
* `$ touch a.py` (crea un archivo, en este caso, "a.py")
* `$ cd ~/proyecto/` (ir al código del proyecto)
* El proyecto tiene un archivo **manage.py**
* `$ cd env2.7/` (con esto voy al ambiente virtual del proyecto, en este caso para *Python* 2.7)
* `$ source bin/activate.fish` (el *fish* es sólo si uso **fish*, sirve para decirle a la *shell* que use las librerías del ambiente virtual)
* `$ source env2.7/bin/activate.fish` (resumen de últimas dos líneas)
* `$ python manage.py shell` (correr código *Python* desde *shell* desde el ambiente virtual)
* `$ python manage.py startapp app` (corre en la *shell* el programa "app")
* `$ python manage.py runserver` (para correr el código *Web*)
* `$ atom . ` (para editar archivos de *Python*)
* `$ code .` (lo mismo que atom, pero usando *Visual Studio Code*)
### Servidor
* `$ mosh saic-dev@` (conectarse al servidor)
* `$ tmux list-sessions` (ver sesiones disponibles del multiplexor de terminales)
* `$ tmux attach -t 0` (adjuntarse a la sesión cero)
* ctrl + b (prefijo)
* `$ prefijo + n` (nueva ventana)
* `$ prefijo + c` (crear ventana)
* `$ prefijo + d` (desadjuntarse de ventana)
### *Inventory*
`$ source env2.7/bin/activate.fish`
`$ cd ~/code/saic-erp-django/dev-django-inventory/`
`$ python manage.py startapp app`
`$ python manage.py runserver`
`$ atom . `
`$ cd ~/code/saic-erp-django/`
`$ git status`
`$ git pull`
`(@usach.cl:25.07.2007MnK++2GitLab)`
`$ git add . `
`$ git commit -m "mensaje"`
`$ git push`
(luego de modificar cosas)
`$ cd ~/code/saic-erp-django/dev-django-inventory/`
`$ python manage.py initialsetup`
`$ sqlitebrowser django_inventory/media/db.sqlite3`
`$ python manage.py runserver`
### *saic-inventario*
`$ git clone https://gitlab.com/wapapa/saic-inventario.git`
`(@usach.cl:25.07.2007MnK++2GitLab)`
`$ git checkout appinv`
`$ virtualenv venv-dj`
`$ source venv-dj/bin/activate.fish`
`$ pip install -r requirements.txt`
`$ cd inventario`
`$ bower install`
`$ python manage.py migrate`
`$ python manage.py runserver` (goto: http://localhost:8000/saic_inventario/profile/)
`$ git branch -a`
`$ git branch <branch>` (crear *branch*)
`$ git checkout <branch>` (usar *branch*)
<modificaciones de código>
`$ git status`
`$ git pull`
`(@usach.cl:25.07.2007MnK++2GitLab)`
`$ git add . `
`$ git commit -m "mensaje"`
`$ git push -u origin <branch>` (o bien `$ git push --set-upstream origin <branch>`)
### Rescatar HDD de *Windows*
* Para *bootear* desde un *live* de *Linux* se debe modificar la BIOS
* Debe estar sin seguridad y en modo *Legacy*
* Si el *laptop* nunca se apagó bien, es probable que *Windows* haya quedado en permanente estado *hibernate*
* Cuando eso ocurre, no dejará montar el HDD normalmente, por lo que hay que realizar
* ```bash
$ sudo mkdir /run/media/liveuser/ID #sacar el ID desde el comando que falló
$ sudo mount -t "ntfs" -ro "uhelper=udisks2,nodev,nosuid,uid=1000,gid=1000" "dev/sda<num>" "/run/media/liveuser/ID" #<num> debe ser un *sda* disponible donde se pueda montar. El ID es el del directorio creado anteriormente
```
* El disco se monta como "sólo lectura" (por la opción "-ro"), por lo que se pueden rescatar los datos
[prmpt_clc]: https://fedoramagazine.org/bc-command-line-calculator/
[dwld_fedora]: https://getfedora.org/
[dwnld_llu]: http://www.linuxliveusb.com/en/download
[flux.startup]: https://cialu.net/how-to-install-and-autostart-f-lux-on-fedora/
[mysql_url]: https://www.if-not-true-then-false.com/2010/install-mysql-on-fedora-centos-red-hat-rhel/
[redshift]: https://fedoramagazine.org/safe-eyes-redshift/
[vim_url]: http://www.radford.edu/~mhtay/CPSC120/VIM_Editor_Commands.htm
[vim2_url]: https://coderwall.com/p/adv71w/basic-vim-commands-for-getting-started
[xflux]: https://justgetflux.com/linux.html