Odroid XU3 Lite – unrar non-free missing

In case you own Odroid XU3 Lite with Ubuntu you might not have unrar in the system. Somehow apt-get won’t see such package.

There is unrar-free, but this is too immature and has non standard CLI API.

Here’s what you have to do – build it for yourself! :-)

wget http://www.rarlab.com/rar/unrarsrc-5.2.5.tar.gz
tar xfvz unrarsrc-5.2.5.tar.gz
cd unrar/
make
sudo cp unrar /usr/bin/unrar-nonfree
sudo rm /etc/alternatives/unrar #might fail, don't worry
sudo ln -s /usr/bin/unrar-nonfree /etc/alternatives/unrar

From now on, you have system wide unrar cmd available to use. And SABnzbdPlus won’t complain :-)

Raspberry PI arrived – setup howto

TL;DR

This is mainly a reference for myself how and what to install/configure on a fresh Raspberry PI

Hope it helps you too

Instructions

Have a Raspberry PI

  • on a 8GB card download and install an image: Raspbian
  • Power on Raspberry PI
  • First time installation
    • via GUI: maximize hard drive
    • set GPU RAM to 16
    • enable SSH
    • setup static DHCP address on home router
    • setup another system user (thanks to this post) and make sure it can do `sudo` without password prompt
      • adduser foo
        echo "foo ALL=(ALL) NOPASSWD: ALL" >>/etc/sudoers
        userdel pi
    • add yourself to disk group
      • sudo vigr # find disk, add your username
    • setup SSH
      • sshkey-gen
        remote$ ssh-add foo@..
        remote$ ssh-copy-id foo@..
        vim /etc/ssh/sshd_config
        PermitRootLogin no
        #http://blog.self.li/post/63281257339/raspberry-pi-part-1-basic-setup-without-cables
    • setup /etc/hosts
      • sudo vi /etc/hosts #add your fav hostnames here
    • Setup timezone
      • sudo tzselect
    • Update OS (2nd step might take a while)
      • sudo apt-get update
        sudo apt-get upgrade
  • Install useful software
    • sudo apt-get install vim samba screen mc git-core htop tig pydf nmap gqview iotop iperf nmap pydf tig cryptsetup ftp pv gitk evince curl w3m lynx xdu baobab mutt git fbset libpcre3-dev libboost-dev omxplayer libgstreamer1.0-0-dbg gstreamer1.0-tools libgstreamer-plugins-base1.0-0 gstreamer1.0-plugins-good gstreamer1.0-plugins-bad-dbg gstreamer1.0-omx gstreamer1.0-alsa dcfldd tcpdump zip subversion libudev-dev make build-essential cec-utils
    • sudo apt-get install
    • vim /etc/apt/sources.list
      deb-src http://archive.raspbian.org/raspbian wheezy main contrib non-free rpi
      sudo apt-get update
      mkdir ~/unrar-nonfree && cd ~/unrar-nonfree
      sudo apt-get build-dep unrar-nonfree
      sudo apt-get source -b unrar-nonfree
      sudo dpkg -i unrar_4.1.4-1_armhf.deb
      cd && sudo rm -rf ~/unrar-nonfree
      sudo apt-get install unrar-free
  • Setup of my dotfiles (vimrc, bashrc for better console cmd history)
    • cd; mkdir -p github; git clone https://github.com/nthx/dotfiles.git; cd dotfiles; ./install
  • setup WiFi
    • Router: Disable “Enable AP Isolation” – this prevented my laptop accessing RPi network
    • Bus 001 Device 005: ID 148f:5370 Ralink Technology, Corp. RT5370 Wireless Adapter
    • cp /etc/network/interfaces /etc/network/interfaces.backup
      cp /etc/wpa_supplicant/wpa_supplicant.conf /etc/wpa_supplicant/wpa_supplicant.conf.backup
    • #vim /etc/network/interfaces
      auto lo
      iface lo inet loopback
      iface eth0 inet dhcp
      auto wlan0
      allow-hotplug wlan0
      iface wlan0 inet dhcp
         post-up iwconfig wlan0 power off
      wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
    • #vim /etc/wpa_supplicant/wpa_supplicant.conf
      ctrl_interface=/var/run/wpa_supplicant
      ctrl_interface_group=0
      update_config=1
      network={
       ssid="***-24"
       psk="***"
       id_str="rpi-0"
      }
    • sudo ifdown wlan0
      sudo ifup wlan0
      sudo wpa_cli status
    • In order to make Raspberry Pi automatically reconnect to Wifi after router down, use this solution:
      https://raspberrypi.stackexchange.com/a/5341/28218
      Works perfectly for me
    • For TP-LINK TL-WN725N card use this tutorial: https://www.raspberrypi.org/forums/viewtopic.php?p=462982#p462982
      • wget https://dl.dropboxusercontent.com/u/80256631/8188eu-v7-20150212.tar.gz
        wget https://dl.dropboxusercontent.com/u/80256631/8188eu-v7-20150818.tar.gz
        
        
  • Samba
    • cp /etc/samba/smb.conf /etc/samba/smb.conf.backup
      socket options = TCP_NODELAY
      workgroup = FOOBAR
      [pictures]
         comment = opt
         writable = no
         locking = no
         path = /mnt/foo/bar
         public = yes
    • service samba restart
  • Ruby
    • rvm (this is long, like hours of compilation)
      • https://rvm.io/rvm/install
  • SqueezeBox server
    • http://allthingspi.webspace.virginmedia.com/lms.php
  • DLNA Server
    • http://bbrks.me/rpi-minidlna-media-server/
    • apt-get install minidlna
      vi /etc/minidlna.conf
      #inotify=yes
      #db_dir=.... #setup to your hdd, not sd
      #log_dir=... #setup to your hdd, not sd
      #listening_ip=0.0.0.0 #though, my version failed on this - I had to disable and start /usr/bin/minidlnad -f /etc/minidlna.conf manually once
      #friendly_name=foo...
      #serial=bar...
      #notify_interval=895
      echo 120000 > /proc/sys/fs/inotify/max_user_watches
      sudo sysctl fs.inotify.max_user_watches=66538
      sudo service minidlna restart
  • PS3 Eye camera video straming
    • sudo apt-get install motion ffmpeg
      sudo vi /etc/default/motion # start_motion_daemon=yes
  • Console based bandwith speed test
    • wget https://raw.github.com/sivel/speedtest-cli/master/speedtest_cli.py
      chmod a+rx speedtest_cli.py ; ./speedtest_cli.py
  • Udev rules for auto-mounting HDD
    • ls -l /dev/disk/by-uuid/ #find your uuid and:
      sudo vi /etc/fstab
      UUID=41b81019-8838-4d22-9bf2-3673ca855ce7 /mnt/foobar ext4 noauto,user,sync,noatime,errors=remount-ro 0 2
    • udevadm info --name=/dev/sda1 --attribute-walk
      
      sudo vi /etc/udev/rules.d/81-my-drives.rules
      ACTION=="add", KERNELS=="sd*1", ATTRS{size}=="312581745", ATTRS{partition}=="1", SYMLINK+="foobar", RUN+="/bin/mount /mnt/foobar/"
      ACTION=="remove", KERNELS=="sd*1", ATTRS{size}=="312581745", ATTRS{partition}=="1", SYMLINK+="foobar", RUN+="/bin/umount -lf /mnt/foobar/"
      sudo udevadm control --reload-rules
      sudo udevadm test -a -p $(udevadm info -q path -n /dev/sda1)
  • Local DNS server for access of local servers by name
    • http://www.ducky-pond.com/posts/2013/Oct/how-to-setup-a-dns-server-with-powerdns-on-raspberry-pi/
    • sudo apt-get install pdns-serve
      sudo sed -i 's/# recursor=/recursor=8.8.8.8/g' /etc/powerdns/pdns.conf
      sudo sed -i 's/allow-recursion=127.0.0.1/allow-recursion=127.0.0.1,192.168.1.0\/24/g' /etc/powerdns/pdns.conf
      sudo service pdns restart
      sudo apt-get install dnsutils
    • vim /etc/powerdns/bind/example.com.zone
      $ORIGIN example.com     ; base for unqualified names
      $TTL 1h                 ; default time-to-live
      @                       IN      SOA ns.example.com hostmaster.example.com (
                                      1; serial
                                      1d; refresh
                                      2h; retry
                                      4w; expire
                                      1h; minimum time-to-live
                              )
                              IN      NS      ns
                              IN      A       192.168.1.15
      ns                      IN      A       192.168.1.15
    • nslookup example.com localhost
    • Then in your device in network configuration add Rpi IP address to list of DNS servers. Also in search domain enter: “example.com”
  • Firewall
    • sudo apt-get install ufw
      sudo ufw allow 22 #ssh
      sudo ufw allow 21 #ftp
      sudo ufw allow 53 #dns
      sudo ufw allow 137,138,139,445/tcp #samba
      sudo ufw allow 80 #www
      sudo ufw allow 8080 #www
      sudo ufw allow 111,2049/tcp #port mapper (nfs, glusterfs)
      sudo ufw allow 8554 #vlc
      sudo ufw allow 631 #cups
      #glusterfs
      sudo ufw allow 24007,24008/tcp
      sudo ufw allow 24009,24010,24011/tcp
      sudo ufw allow 49152,49153,49154/tcp
      sudo ufw allow 38465,38466,38467/tcp
      sudo ufw allow 24008/tcp
      sudo ufw enable
    • fail2ban – this I don’t yet cover here, as not yet sure how it works. Was banning myself too much ;-)
  • Software watchdog of network connectivity to your home router
    • */5 * * * * /home/foo/bin/soft-watchdog-wifi.sh
    • In order for Wifi to reconnect see this solution: http://raspberrypi.stackexchange.com/questions/4120/how-to-automatically-reconnect-wifi?newreg=e44a9ccb623b402094502f27c554e1c5
    • cd /etc/ifplugd/action.d/
      mv ifupdown ifupdown.original
      cp /etc/wpa_supplicant/ifupdown.sh ./ifupdown
      sudo reboot
  • Usenet with Sabnzbd
    • http://www.howtogeek.com/142249/how-to-turn-a-raspberry-pi-into-an-always-on-usenet-machine/
      sudo apt-get install sabnzbdplus par2
  • FTP server for backup of my iPhone pics
    sudo apt-get install vsftpd
    sudo adduser ftpsecure
    sudo vi /etc/vsftpd.conf
    #listen=YES
    #allow_writeable_chroot=YES
    #local_umask=022
    #write_enable=YES
    #chroot_local_user=YES
    #nopriv_user=ftpsecure
    #chroot_list_enable=YES
    #chroot_list_file=/etc/vsftpd.chroot_list
    
    sudo vi /etc/vsftpd.chroot_list
    foo
    sudo service vsftpd restart
  • For iPhone iOS app PhotoSync in order to backup pics/videos via ftp this has to be also done (if one wants other than ~/Pictures dir only)
    mount --bind /foo/bar/archived-synced/ /home/foo/Pictures/
  • Photos management

    https://www.linux.com/learn/how-sort-and-remove-duplicate-photos-linux

    sudo apt-get install  fdupes exiftool
  • NFS
    sudo apt-get install nfs-kernel-server nfs-common portmap
    sudo update-rc.d rpcbind enable && sudo update-rc.d nfs-common enable
    sudo vi /etc/exports
    /mnt/foo/bar/ *(rw,sync,no_root_squash,no_subtree_check)
    sudo exportfs -av
    sudo service nfs-kernel-server restart
    sudo service rpcbind restart
  • HDD maintenance
    sudo apt-get install smartmontools gsmartcontrol
    sudo smartctl --all /dev/sdd
    
    touch /forcefsck
    sudo shutdown -rF now
    
    sudo apt-get install gnome-disk-utility
    sudo gnome-disks #somehow on raspbian it's missing :-?
    sudo gsmartcontrol
  • crontab logs
    • sudo vi /etc/rsyslog.conf
      #ucomment #cron
      sudo /etc/init.d/rsyslog restart
  • security
    • list all services running on the system
      sudo service --status-all
  • screenfetch – show system details on a console
    wget https://raw.github.com/KittyKatt/screenFetch/master/screenfetch-dev
    chmod a+rx screenfetch-dev
    ./screenfetch-dev
  • dd with progress
    dd if=/dev/zero | pv --size 16g | dd of=/dev/sdb
    dcfldd if=/tmp/in of=/tmp/out
  • camera
    sudo modprobe bcm2835-v4l2
    echo bcm2835-v4l2 >> /etc/modules
    sudo apt-get install vlc v4l-utils motion
    raspivid -o - -t 0 -n -w 1280 -h 720 | cvlc -vvv stream:///dev/stdin --sout '#rtp{sdp=rtsp://:8888/}' :demux=h264
  • sound
    echo snd-bcm2835 >> /etc/modules
    vi /etc/asound.conf
    
    pcm.!default {
      type hw    
      card 0 }
    ctl.!default {
    type hw
    card 0   }
  • print server
    sudo apt-get install cups
    sudo cupsctl --remote-any
    sudo usermod -a -G lpadmin nthx
    sudo apt-get install avahi-discover #for air print
    #canon ip4700 works
    sudo /etc/init.d/cups restart 
    browser http://localhost:631/
    #add your driver
  • purge some extra space
    sudo apt-get install localepurge deborphan wajig 
    sudo localepurge
    sudo apt-get autoremove
    sudo apt-get autoclean
    sudo apt-get clean
    sudo apt-get purge wolfram-engine minecraft-pi sonic-pi gnome-accessibility-themes gnome-themes* gnome-icon-theme-extras gnome-icon-theme-symbolic gnome-games*
    
    wajig large #and analyze..
    baobab #and analyze
  • Process Canon RAW files
    sudo apt-get install ufraw ufraw-batch
    ufraw-batch --out-type png *.crw

 

  • VNC
    sudo apt-get install xtightvncviewer
    sudo apt-get install tightvncserver
  • Power off Raspberry PI
    sudo poweroff

 

Upgrading to Raspberry PI 2

  • on existing Rpi1 apt-get update && apt-get upgrade && apt-get dist-upgrade
  • copy entire SD card to another dd if=/dev/mmcblk0 of=backup-of-mmcblk0
  • mount /dev/mmcblk0p2 /mnt/memcard
  • vi /etc/hostname #modify hostname
  • vi /etc/hosts #modify hostname
  • ssh-keygen
  • raspi-config

Backend is important, it’s just the last of components

This post belongs to a broader mini-series on how we do Single Page Apps. So I advice to have a quick look there to know context a bit

Let’s recall why backend is important?

  • backend serves persistence, so all your data changes are stored safely, and you can go back to it any time
  • backend often is the guardian-of-the-secrets between frontend and external services like Facebook API, Pusher API. We do not want to publish secret API keys to the Pusher (realtime websocket communication) to anyone with View HTML Source power
  • in times where browser is the VM and console.log is available to everyone, backend validates user actions in environment isolated from end-user
  • backend used to contain application business logic that was meant to be reusable by different views (desktop, mobile, REST APIs, …), but failed to deliver in understandable way
  • it’s the place for fancy tricks to optimize resources usage and allowing service to run fast and failure free

So why would anyone want to skip backend in order to do what ..?

Well, it happens there are many cool things we can gain by treating the backend as just another plugin to our overall architecture and infrastructure. When we start thinking about it as an optional component many new ideas raise

  • first of all, in times when even-my-wife-can-code (RailsGirls) it is important (from a customer point of view) to get working software earlier. “Earlier” – means to work in limited time on limited things; to prioritize features; to focus on customer oriented benefits. Which are: simplest, working software prototype
  • in times where we all fail to deliver software up to the initial spec it is important to get customer feedback as early as we can. We achieve that by doing MVP products with most valuable, but minimal enough set of features. So we need to skip some parts first. What to skip?
  • time is money, losing time is losing money. Why would we develop things in areas of backend, persistence, load balancing, etc.. when nowadays products often change, pivot or are even abandoned if it’s a better option
  • it looks OK to deliver what customer wants, but it’s lot cooler to deliver what customer needs!
    What does customer need? I suppose often he/she doesn’t know. It’s fine. It is also our (devs) responsibility to work with the customer and advice on solutions, ideas, possibilities, alternatives. To propose and educate the customer within product scope. But how customer can know if what he wants is what he/she needs? Let’s validate the product. Does the product make sense at all? So let’s develop early a functional product that we can use and work
  • we cooperate with many developers and not everybody knows the Rails stack. It appears it’s not so easy for a newbie to install MySQL, Rails, irb, bundle, rvm, compile gems, watch Coffee to JS, etc..
    Why should devs struggle with it when it’s possible to just to run static index.html in the browser? Why should a developer start with infrastructure problems if they can start with solving customer problems first?

One conclusion from above is we may skip software parts not essential to a customer

In order to have a working app:

  • we cannot skip the view – we need to show, use, click in the app. So this part is essential
  • we cannot skip the domain. We have to understand and code underlying business and processes of the customer. So business domain is – again – essential
  • it’s the browser world, so the frontend, JavaScript code is a must. Better to have code (html, JS, css) natively in the browser, than to generate and concatenate it via a MVC framework

The parts that we can can skip and we do are:

  • persistence in database on the server side
    Each of our apps first has a persistence limited to current user session. With ability to provide different data states initially we’re able to play different game/app scenarios
  • routes
    As there is no backend, nothing to route. Our frontend code talks to middle layer first, a thing called “server side adapter”. Only production server side adapter talks to URLs. Initial in-memory-adapter talks to simple plain old JS example objects
  • controllers
    As we develop domain logic inside usecases, and they drive the behaviours and use cases and the glue connects different layers/services, there is no need for this structure. Or at least it looks different.

How we achieve it?

  • having server side adapters for communication from frontend to backend.
    We tend to have 2: in-memory-adapter, that is violatile and with CTRL+R will start fresh set of data. But also starts with predefined set of data. Easily configurable. Running in browser only. In plain, old JS variables, arrays, hashes.
    And real server-side-adapter (production ready) where full blown implementation is delivered. It connects to backend via Ajax calls to server url resources.
    Both share same API. It’s just that in-memory is being delivered first and needs almost zero programming efforts
  • separating domain and view completely. They don’t know each other. This separation gives better understanding of the domain in early stages. And allows to modify it more freely.
    Independent view is easier to be delivered earlier. View developers have its API defined clearly and can focus in these areas only. We can also replace view implementations in the whole system with little efforts (let it be DOM/CSS implementation or Canvas)
  • “unit” testing of domain from command line.
    For JS/Coffee code we use Mocha or Jasmine. The former one allows to write test-first within the first hour of the project
  • in multiplayer games we tend to load domain multiple times and simulate multiplayer locally in the browser.
    It’s lot of fun and effective and a mind-opener

Do we need persistence or any external services implemented at the stage of demonstrating a working app to the customer: sure not … yet!