37
Tricks samuelba Sep 24, 2019

Tricks - Read the Docs

  • Upload
    others

  • View
    10

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Tricks - Read the Docs

Tricks

samuelba

Sep 24, 2019

Page 2: Tricks - Read the Docs
Page 3: Tricks - Read the Docs

Contents

1 Git 11.1 Delete Remote Branch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.2 Fix ^M . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.3 Multiple Users Rights . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.4 New User . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.5 Soft Reset / Undo Last Commit (if not published yet) . . . . . . . . . . . . . . . . . . . . . . . . 2

2 Programming 32.1 Cmake . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

2.1.1 Add Headers to IDE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32.2 Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

2.2.1 GDB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32.2.1.1 Python . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32.2.1.2 Catch and Locate Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

2.3 Regex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42.3.1 Replace std::cout with ROS_INFO_STREAM_NAMED() . . . . . . . . . . . . . . 4

3 Python 53.1 Install Package from GIT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53.2 Install Python3 Package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

4 ReadTheDocs 74.1 Pandoc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74.2 rst2pdf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74.3 Sphinx Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

5 ROS 95.1 AF_INET Fix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95.2 CMAKE Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

5.2.1 Append . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95.2.2 Remove . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

5.3 Deactivate genjava . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95.4 Debug . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

5.4.1 RQT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105.4.2 Normal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

5.5 Install Space . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105.5.1 Reset Install . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

5.6 rosdep . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105.7 ROS MASTER URI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

6 Ubuntu 11

i

Page 4: Tricks - Read the Docs

6.1 APT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116.1.1 Compare Version Number . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116.1.2 Package Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116.1.3 Hash Sum Mismatch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126.1.4 List Packages from Repository . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126.1.5 List Packages without Repository . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

6.2 Battery . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126.3 Bluetooth . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

6.3.1 Connect Logitech MX Master . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136.3.2 Connect Headphones . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

6.4 Find Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136.4.1 Delete Empty Folders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136.4.2 Delete Temporary Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136.4.3 Large Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

6.5 Grub . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146.5.1 Remove Old Ubuntu Kernel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146.5.2 Remove Old Ubuntu Kernel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146.5.3 Start Custom OS/Kernel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

6.6 Java . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156.6.1 Change Java Version . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

6.7 Network . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156.7.1 Scan IP Addresses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156.7.2 Show DNS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156.7.3 Set DNS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156.7.4 Restart Network Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156.7.5 Terminal Analyse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166.7.6 Share Internet Over WIFI/Ethernet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16

6.7.6.1 Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166.7.6.2 Client . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16

6.7.7 IP Tables - Jenkins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166.7.7.1 Add Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166.7.7.2 Remove Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

6.8 Problem Solving . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176.8.1 CLion Keyboard ibus Fix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176.8.2 dbus Fix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176.8.3 Graphics Card Repair (Black Screen) . . . . . . . . . . . . . . . . . . . . . . . . . . . 176.8.4 gvfs Fix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176.8.5 usbserial Fix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

6.9 SSH . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186.9.1 Start SSH Agent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

6.10 Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186.10.1 Audio Settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186.10.2 File Manager . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186.10.3 PDF Editor PDFtk . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

6.11 USB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186.11.1 USB Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

7 Debian Packaging 217.1 Build Debian Package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21

7.1.1 Sources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217.1.2 Install . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217.1.3 pbuilder Setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217.1.4 Prepare Package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

7.1.4.1 Create orig.tar.xz Archive (without debian folder) . . . . . . . . . . . . . . . . 257.1.4.2 Use dh_make . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26

7.1.5 Build Package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287.2 Rebuild Launchpad Debian Package (e.g. Backport) . . . . . . . . . . . . . . . . . . . . . . . . 28

7.2.1 Get Launchpad Sources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28

ii

Page 5: Tricks - Read the Docs

7.2.2 Prepare and Upload Package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287.2.2.1 Debuild Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28

7.2.3 Debian Package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29

8 Indices and tables 31

iii

Page 6: Tricks - Read the Docs

iv

Page 7: Tricks - Read the Docs

CHAPTER 1

Git

1.1 Delete Remote Branch

git push origin --delete feature/foo

1.2 Fix ^M

This means you have Windows line endings in your files. To fix call dos2unix file.txt.

sudo apt-get install dos2unixdos2unix file.txt

1.3 Multiple Users Rights

cd /home/john/gitsudo chown -R :developers "$PWD"sudo chmod -R g+swX "$PWD"

Add the following flag to .git/config

[core]sharedrepository = 1

1.4 New User

git config --set user.name "John Doe"git config --set user.email "[email protected]"

1

Page 8: Tricks - Read the Docs

Tricks

1.5 Soft Reset / Undo Last Commit (if not published yet)

git reset --soft HEAD~

2 Chapter 1. Git

Page 9: Tricks - Read the Docs

CHAPTER 2

Programming

2.1 Cmake

2.1.1 Add Headers to IDE

file(GLOB_RECURSE HeaderFiles "include/*.h")add_custom_target(headers SOURCES ${HeaderFiles})

2.2 Debugging

2.2.1 GDB

2.2.1.1 Python

gdb pythonrun /<path to your python script>

2.2.1.2 Catch and Locate Exceptions

• locate exceptions

gdb (python)set pagination offcatch throwcommandsbacktracecontinueendrun ...

3

Page 10: Tricks - Read the Docs

Tricks

2.3 Regex

A collection of regex patterns e.g. for search and replace, tested with JetBrains IDEs.

2.3.1 Replace std::cout with ROS_INFO_STREAM_NAMED()

Search

std::cout ([< "^\n.?\[\]&:\(\)'a-zA-Z0-9]{1,});

Replace

ROS_INFO_STREAM_NAMED(TAG, TAG $1);

4 Chapter 2. Programming

Page 11: Tricks - Read the Docs

CHAPTER 3

Python

3.1 Install Package from GIT

sudo pip install git+https://github.com/candidtim/vagrant-appindicator.git

3.2 Install Python3 Package

StackOverflow

sudo apt-get install python3-setuptoolssudo easy_install3 pipsudo pip3.4 install <package>

5

Page 12: Tricks - Read the Docs

Tricks

6 Chapter 3. Python

Page 13: Tricks - Read the Docs

CHAPTER 4

ReadTheDocs

4.1 Pandoc

Use Pandoc to convert a markdown file to reStructuredText.

pandoc --from markdown --to rst -o common.rst common.md

Or use the online converter.

4.2 rst2pdf

Use rst2pdf to convert a restructuredText document to PDF.

rst2pdf common.rst

4.3 Sphinx Documentation

ReadTheDocs works best with reStructuredText and Sphinx.

7

Page 14: Tricks - Read the Docs

Tricks

8 Chapter 4. ReadTheDocs

Page 15: Tricks - Read the Docs

CHAPTER 5

ROS

5.1 AF_INET Fix

The AF_INET error means your ROS instance cannot resolve a hostname. To solve the AF_INET problem, exportyour ROS_IP address or add your hostname and IP address to the other computers.

hostname -Iexport ROS_IP=192.168.0.100

5.2 CMAKE Arguments

5.2.1 Append

catkin config -a --cmake-args -DCMAKE_BUILD_TYPE=Release

5.2.2 Remove

catkin config -r --cmake-args -DCMAKE_BUILD_TYPE=Release

5.3 Deactivate genjava

echo "export ROS_LANG_DISABLE=genjava" >> ~/catkin_ws/devel/setup.bash

9

Page 16: Tricks - Read the Docs

Tricks

5.4 Debug

5.4.1 RQT

gdb python(gdb) run /home/sam/catkin_ws/src/rqt_multiplot/script/rqt_multiplot

5.4.2 Normal

The launch-prefix attribute of the <node> tag that, among other things, makes it easy to debug a ROS nodeprocess. Here are some example launch-prefixes you might find useful: - launch-prefix="xterm-e gdb --args" : run your node in a gdb in a separate xterm window, manually type run to start it -launch-prefix="gdb -ex run --args" : run your node in gdb in the same xterm as your launchwithout having to type run to start it - launch-prefix="valgrind" : run your node in valgrind -launch-prefix="xterm -e" : run your node in a separate xterm window - launch-prefix="nice": nice your process to lower its CPU usage - launch-prefix="screen -d -m gdb --args" : useful ifthe node is being run on another machine; you can then ssh to that machine and do screen -D -R to see thegdb session - launch-prefix="xterm -e python -m pdb" : run your python node a separate xtermwindow in pdb for debugging; manually type run to start it

ROS debug

catkin build --cmake-args -DCMAKE_BUILD_TYPE=Debug

5.5 Install Space

An install space will help you debugging ROS packages in preparation for a Debian package release.

catkin clean --allcatkin config --installcatkin build PACKAGE

5.5.1 Reset Install

catkin config --no-install

5.6 rosdep

rosdep install --from-paths WORKSPACE --ignore-src --rosdistro=ROSDISTROrosdep install rqt_multiplot --ignore-src

5.7 ROS MASTER URI

export ROS_MASTER_URI=http://<your host name or ip address>:11311

10 Chapter 5. ROS

Page 17: Tricks - Read the Docs

CHAPTER 6

Ubuntu

6.1 APT

6.1.1 Compare Version Number

dpkg --compare-versions 1.2.7-0trusty lt 1.2.7+0trusty && echo truetrue

lt: less thangt: greater than

6.1.2 Package Information

apt-cache policy PACKAGE_NAME

This will give you information about available versions and which version will be installed and from where:

$ apt-cache policy libqt5opengl5-dev

libqt5opengl5-dev:Installed: 5.2.1+dfsg-1ubuntu14.3Candidate: 5.2.1+dfsg-1ubuntu14.3Version table:

*** 5.2.1+dfsg-1ubuntu14.3 0500 http://ch.archive.ubuntu.com/ubuntu/ trusty-security/main amd64

→˓Packages500 http://ch.archive.ubuntu.com/ubuntu/ trusty-updates/main amd64 Packages100 /var/lib/dpkg/status

5.2.1+dfsg-1ubuntu14 0500 http://ch.archive.ubuntu.com/ubuntu/ trusty/main amd64 Packages

11

Page 18: Tricks - Read the Docs

Tricks

6.1.3 Hash Sum Mismatch

sudo rm -rf /var/lib/apt/lists/*sudo apt-get cleansudo apt-get update

6.1.4 List Packages from Repository

List all packages that are installed from a specific repository/ppa.

sudo apt-get install aptitudeaptitude search "?origin (ethz) ?installed"

6.1.5 List Packages without Repository

List all packages that are installed, but do not belong to a repository/ppa.

sudo apt-get install apt-show-versionsapt-show-versions | grep 'No available version'

6.2 Battery

TLP documentation

Install the following:

sudo add-apt-repository ppa:linrunner/tlpsudo apt-get update

sudo apt-get install tlp tlp-rdwsudo apt-get install tp-smapi-dkms acpi-call-dkms

Check which of the above modules (tp-smapi-dkms acpi-call-dkms) you need.

sudo tlp-stat -b -s -c

Modify the battery thresholds:

sudo vim /etc/default/tlp

Blacklist the Bluetooth device to avoid disconnections:

$ lsusb

Bus 003 Device 004: ID 8087:07dc Intel Corp.

add this 8087:07dc to the file /etc/default/tlp

USB_BLACKLIST="8087:07dc"

To (re)start tlp without a reboot:

sudo tlp start

Charge battery full (ignoring the threshold once):

12 Chapter 6. Ubuntu

Page 19: Tricks - Read the Docs

Tricks

sudo tlp fullcharge

Recalibrate the battery:

sudo tlp recalibrate

6.3 Bluetooth

6.3.1 Connect Logitech MX Master

If you already tried to connect the MX Master, remove the Bluetooth device. And execute the following steps.Source

bluetoothctl

[bluetooth]# power off[bluetooth]# power on[bluetooth]# scan on[bluetooth]# connect XX:XX:XX:XX:XX:XX[Arc Touch Mouse SE]# trust[Arc Touch Mouse SE]# connect XX:XX:XX:XX:XX:XX[Arc Touch Mouse SE]# pair[Arc Touch Mouse SE]# unblock[Arc Touch Mouse SE]# power off[bluetooth]# power on

6.3.2 Connect Headphones

To ensure the headphones connect with A2DP and not with HSP/HFP.

sudo vim /etc/bluetooth/audio.conf

Add the lines:

[General]Disable=Headset

Restart Bluetooth:

sudo service bluetooth restart

6.4 Find Files

6.4.1 Delete Empty Folders

find . -empty -type d -delete

6.4.2 Delete Temporary Files

find . -type f -name '*.~' -delete

6.3. Bluetooth 13

Page 20: Tricks - Read the Docs

Tricks

6.4.3 Large Files

sudo find / -size +1G -ls

6.5 Grub

6.5.1 Remove Old Ubuntu Kernel

dpkg -l | grep linux-image-

sudo apt-get purge linux-image-3.5.0-{17,18,19}-generic

6.5.2 Remove Old Ubuntu Kernel

First remove any leftover temporary files from previous kernel updates.

$ sudo rm -rv ${TMPDIR:-/var/tmp}/mkinitramfs-*

Determine the version number of the currently running kernel, which you DO NOT want to remove.

uname -r

List all the kernels, including the booted one (4.2.0-21-generic in this example), in the package database and theirstatuses.

dpkg -l | tail -n +6 | grep -E 'linux-image-[0-9]+'

To free space in /boot we’ll remove an initrd.img file for a suitable old kernel manually, this is necessary due to akenel packaging bug.

sudo update-initramfs -d -k 4.2.0-15-generic

Now we’ll use dpkg in order to TRY to purge the kernel package for the same old kernel:

sudo dpkg --purge linux-image-4.2.0-15-generic

NOTE: The previous command will probably fail, as there probably is a depending linux-image-extra packageinstalled together with a ‘generic’ kernel package. In general, the output of the previous command will tell whichpackage you need to remove first. In this example case you would run

sudo dpkg --purge linux-image-4.2.0-15-generic linux-image-extra-4.2.0-15-generic

Finally, we will fix the package installation process that previously failed.

sudo apt-get -f install ## Try to fix the broken dependency.

6.5.3 Start Custom OS/Kernel

sudo vim /etc/default/grub

Edit the following line:

GRUB_DEFAULT="Advanced options for Ubuntu>Ubuntu, with Linux 3.13.0-53-generic"

Update grub.

14 Chapter 6. Ubuntu

Page 21: Tricks - Read the Docs

Tricks

sudo update-grub

6.6 Java

6.6.1 Change Java Version

Download e.g. jdk-8u121-linux-x64.tar.gz from Oracle and unzip the folder to e.g. /opt/jdk1.8.0_121.

sudo update-alternatives --install /usr/bin/java java /opt/jdk/jdk1.8.0_121/bin/→˓java 1sudo update-alternatives --install /usr/bin/javac javac /opt/jdk/jdk1.8.0_121/bin/→˓javac 1

sudo update-alternatives --config javasudo update-alternatives --config javac

java -versionjavac -version

6.7 Network

6.7.1 Scan IP Addresses

Angry IP Scanner

sudo nmap -sP 192.168.0.0/24

sudo arp-scan --retry=8 --ignoredups -I wlan0 192.168.0.0/24

6.7.2 Show DNS

nmcli dev list iface wlan0 | grep IP4.DNS

6.7.3 Set DNS

sudo vim /etc/resolv.conf

nameserver 8.8.8.8nameserver 8.8.4.4

sudo vim /etc/resolvconf/resolv.conf.d/head

6.7.4 Restart Network Interface

sudo ifdown eth0sudo ifup eth0

6.6. Java 15

Page 22: Tricks - Read the Docs

Tricks

6.7.5 Terminal Analyse

bmontcptrack

6.7.6 Share Internet Over WIFI/Ethernet

iptables -t nat -A POSTROUTING -s 192.168.0.0/24 -o wlan0 -j MASQUERADEiptables -t nat -A POSTROUTING -s 10.42.0.0/24 -o eth0 -j MASQUERADE

6.7.6.1 Server

auto eth0iface eth0 inet staticaddress 10.42.0.1netmask 255.255.255.0network 10.42.0.0

6.7.6.2 Client

auto eth0iface eth0 inet staticaddress 10.42.0.2netmask 255.255.255.0network 10.42.0.0

6.7.7 IP Tables - Jenkins

6.7.7.1 Add Rules

Jenkins tutorial

List iptables rules:

iptables -L -n

Add rules:

sudo iptables -I INPUT 1 -p tcp --dport 8443 -j ACCEPTsudo iptables -I INPUT 1 -p tcp --dport 8080 -j ACCEPTsudo iptables -I INPUT 1 -p tcp --dport 443 -j ACCEPTsudo iptables -I INPUT 1 -p tcp --dport 80 -j ACCEPT

Add forwarding:

sudo iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 80 -j REDIRECT --to-port→˓8080sudo iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 443 -j REDIRECT --to-→˓port 8443

Save rules:

sudo sh -c "iptables-save > /etc/iptables.rules"sudo apt-get install iptables-persistent

16 Chapter 6. Ubuntu

Page 23: Tricks - Read the Docs

Tricks

6.7.7.2 Remove Rules

Remove rules

6.8 Problem Solving

6.8.1 CLion Keyboard ibus Fix

Source

This solution is if you would like to upgrade ibus in Ubuntu 14.04.4 LTS to the latest version (at the time of writingis 1.5.11).

I recently had to install Intellij on a clean installed Ubuntu machine. These are the steps I took:

1. Install the dependencies

sudo apt-get install libdconf-dev libnotify-dev intltool libgtk2.0-dev libgtk-→˓3-dev libdbus-1-dev

2. Download the ibus 1.5.11 source code (linked from here)

3. Extract the files (tar -xvf ibus-1.5.11.tar.gz) and cd into the extracted folder

4. While in the ibus source folder, follow the instructions from step 1 to install ibus 1.5.11:

./configure --prefix=/usr --sysconfdir=/etc && makesudo make install

5. Restart Intellij IDE or whichever jetbrain’s IDE that is in question

6.8.2 dbus Fix

Maybe rename ~/.dbus and ~/.dbus-keyrings.

sudo service dbus restartreboot

6.8.3 Graphics Card Repair (Black Screen)

Remove a (not working) Nvidia graphics card driver:

1. Boot

2. If screen is black, press Ctrl + Alt + F1

3. Login with your username and password

sudo stop lightdmsudo apt-get purge nvidia*sudo apt-get install xserver-xorg-video-nouveausudo reboot

6.8.4 gvfs Fix

sudo umount ~/.gvfssudo rm -rf ~/.gvfs

6.8. Problem Solving 17

Page 24: Tricks - Read the Docs

Tricks

6.8.5 usbserial Fix

sudo modprobe usbmonsudo modprobe usbserial vendor=<VENDOR ID> product=<PRODUCT ID>

6.9 SSH

6.9.1 Start SSH Agent

eval $(ssh-agent)ssh-add

6.10 Tools

6.10.1 Audio Settings

To change your audio settings in command line, use e.g. alsamixer.

alsamixer

6.10.2 File Manager

A command line file manager.

sudo apt-get install mc

6.10.3 PDF Editor PDFtk

E.g. take some pages and store them in a new PDF.

sudo apt-get install pdftkpdftk full.pdf cat 1-5 output outfile_p1-5.pdf

6.11 USB

6.11.1 USB Information

Get extended information about an USB device (serial, vendor/product id, . . . ).

udevadm info -q all -n /dev/ttyUSB0// orudevadm info --attribute-walk --name=/dev/ttyUSB0

Restart udev.

sudo systemctl restart udevsudo udevadm trigger

Get video information.

18 Chapter 6. Ubuntu

Page 25: Tricks - Read the Docs

Tricks

v4l2-ctl --all -d /dev/video0v4l2-ctl --list-formats -d /dev/video0

6.11. USB 19

Page 26: Tricks - Read the Docs

Tricks

20 Chapter 6. Ubuntu

Page 27: Tricks - Read the Docs

CHAPTER 7

Debian Packaging

7.1 Build Debian Package

7.1.1 Sources

• Setup pbuilder make clean debian packages

• Getting set up

• Packaging new software

• Chroots

• Building a debian package

7.1.2 Install

sudo apt-get install gnupg pbuilder debootstrap quilt ubuntu-dev-tools dh-make→˓packaging-dev

7.1.3 pbuilder Setup

• Setup pbuilder make clean debian packages

• pbuilder tricks

Create the following folders:

sudo mkdir /usr/lib/pbuilder/hookssudo mkdir /var/cache/pbuilder/reposudo chmod 777 /var/cache/pbuilder/repo

Create /usr/lib/pbuilder/hooks/C10shell with:

21

Page 28: Tricks - Read the Docs

Tricks

#!/bin/sh# invoke shell if build fails.

apt-get install -y --force-yes vim less bashcd /tmp/buildd/*/debian/../bin/bash < /dev/tty > /dev/tty 2> /dev/tty

Make /usr/lib/pbuilder/hooks/C10shell executable:

sudo chmod +x /usr/lib/pbuilder/hooks/C10shell

Create /usr/lib/pbuilder/hooks/D05deps with:

#!/bin/sh(cd /var/cache/pbuilder/repo; apt-ftparchive packages . > Packages && gzip -c→˓Packages >Packages.gz)apt-get update

Make /usr/lib/pbuilder/hooks/D05deps executable:

sudo chmod +x /usr/lib/pbuilder/hooks/D05deps

To enable ROS dependencies, create /usr/lib/pbuilder/hooks/D10addppa with:

#!/bin/sh

echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/→˓sources.list.d/ros-latest.listapt-key adv --keyserver hkp://ha.pool.sks-keyservers.net --recv-key→˓421C365BD9FF1F717815A3895523BAEEB01FA116apt-get update

Make /usr/lib/pbuilder/hooks/D10addppa executable:

sudo chmod +x /usr/lib/pbuilder/hooks/D10addppa

Create /etc/pbuilderrc with:

# this is your configuration file for pbuilder.# the file in /usr/share/pbuilder/pbuilderrc is the default template.# /etc/pbuilderrc is the one meant for editing.## read pbuilderrc.5 document for notes on specific options.

BASETGZ=/var/cache/pbuilder/base.tgzBUILDPLACE=/var/cache/pbuilder/build/OTHERMIRROR="deb file:///var/cache/pbuilder/repo ./"USEPROC=yesUSEDEVPTS=yesUSEDEVFS=noBUILDRESULT=/var/cache/pbuilder/result/

REMOVEPACKAGES="lilo"HOOKDIR="/usr/lib/pbuilder/hooks"# make debconf not interact with userexport DEBIAN_FRONTEND="noninteractive"DEBEMAIL=""# for pbuilder debuild (sudo -E keeps the environment as-is)BUILDSOURCEROOTCMD="fakeroot"PBUILDERROOTCMD="sudo -E"

# command to satisfy build-dependencies; the default is an internal shell

(continues on next page)

22 Chapter 7. Debian Packaging

Page 29: Tricks - Read the Docs

Tricks

(continued from previous page)

# implementation which is relatively slow; there are two alternate# implementations, the "experimental" implementation,# "pbuilder-satisfydepends-experimental", which might be useful to pull# packages from experimental or from repositories with a low APT Pin Priority,# and the "aptitude" implementation, which will resolve build-dependencies and# build-conflicts with aptitude which helps dealing with complex cases but does# not support unsigned APT repositoriesPBUILDERSATISFYDEPENDSCMD="/usr/lib/pbuilder/pbuilder-satisfydepends"

#Command-line option passed on to dpkg-buildpackage.DEBBUILDOPTS=""

#APT configuration files directoryAPTCONFDIR=""# the username and ID used by pbuilder, inside chroot. Needs fakeroot, reallyBUILDUSERID=1234BUILDUSERNAME=pbuilder

# BINDMOUNTS is a space separated list of things to mount# inside the chroot.BINDMOUNTS="/var/cache/pbuilder/repo"

# Set the debootstrap variant to 'buildd' type.# DEBOOTSTRAPOPTS[0]='--variant=buildd'# or work around bug in debootstrap 3.0.0 (314858)unset DEBOOTSTRAPOPTS

# Set the PATH I am going to use inside pbuilder: default is "/usr/sbin:/usr/bin:/→˓sbin:/bin:/usr/X11R6/bin"export PATH="/usr/sbin:/usr/bin:/sbin:/bin:/usr/X11R6/bin"

# SHELL variable is used inside pbuilder by commands like 'su'; and they need sane→˓valuesexport SHELL=/bin/bash

# The name of debootstrap command.DEBOOTSTRAP="debootstrap"

# default file extension for pkgname-logfilePKGNAME_LOGFILE_EXTENTION="_$(dpkg --print-architecture).build"

# default PKGNAME_LOGFILEPKGNAME_LOGFILE=""

Create your personal ~/.pbuilderrc with:

# Proxy configuration# Uncomment the next line if using apt-cacher-ng on the local machine#export http_proxy=http://localhost:3142/# Uncomment the next line if using squid-deb-proxy on the local machine.#export http_proxy=http://localhost:8000/

# Allow untrusted packages (TODO: required for local packages???)ALLOWUNTRUSTED=yes

# Codenames for Debian suites according to their alias. Update these when needed.TESTING_CODENAME="sid"STABLE_CODENAME="jessie"STABLE_BACKPORTS_SUITE="$STABLE_CODENAME-backports"

# List of Debian suites.

(continues on next page)

7.1. Build Debian Package 23

Page 30: Tricks - Read the Docs

Tricks

(continued from previous page)

DEBIAN_SUITES=($TESTING_CODENAME $STABLE_CODENAME"testing" "stable")

# List of Ubuntu suites. Update these when needed.UBUNTU_SUITES=("trusty" "xenial")

# Mirrors to use. Update these to your preferred mirror.DEBIAN_MIRROR="mirror.switch.ch/ftp/mirror"UBUNTU_MIRROR="mirror.switch.ch/ftp/mirror"

# Optionally use the changelog of a package to determine the suite to use if# none set.if [ -z "${DIST}" ] && [ -r "debian/changelog" ]; thenDIST=$(dpkg-parsechangelog | awk '/^Distribution: / {print $2}')# Use the unstable suite for certain suite values.if $(echo "experimental UNRELEASED" | grep -q $DIST); thenDIST="$UNSTABLE_CODENAME"fifi

# Optionally set a default distribution if none is used. Note that you can set# your own default (i.e. ${DIST:="unstable"}).: ${DIST:="$(lsb_release --short --codename)"}

# Optionally change Debian release states in $DIST to their names.case "$DIST" inunstable)DIST="$UNSTABLE_CODENAME";;testing)DIST="$TESTING_CODENAME";;stable)DIST="$STABLE_CODENAME";;esac

# Optionally set the architecture to the host architecture if none set. Note# that you can set your own default (i.e. ${ARCH:="i386"}).: ${ARCH:="$(dpkg --print-architecture)"}

NAME="$DIST"if [ -n "${ARCH}" ]; thenNAME="$NAME-$ARCH"DEBOOTSTRAPOPTS=("--arch" "$ARCH" "${DEBOOTSTRAPOPTS[@]}")fiBASETGZ="/var/cache/pbuilder/$NAME-base.tgz"# Optionally, set BASEPATH (and not BASETGZ) if using cowbuilder# BASEPATH="/var/cache/pbuilder/$NAME/base.cow/"DISTRIBUTION="$DIST"BUILDRESULT="/var/cache/pbuilder/$NAME/result/"APTCACHE="/var/cache/pbuilder/aptcache/$NAME/"BUILDPLACE="/var/cache/pbuilder/build/"

if $(echo ${DEBIAN_SUITES[@]} | grep -q $DIST); then# Debian configurationMIRRORSITE="http://$DEBIAN_MIRROR/debian/"COMPONENTS="main contrib non-free"# This is for enabling backports for the Debian stable suite.#if $(echo "$STABLE_CODENAME stable" | grep -q $DIST); then# EXTRAPACKAGES="$EXTRAPACKAGES debian-backports-keyring"

(continues on next page)

24 Chapter 7. Debian Packaging

Page 31: Tricks - Read the Docs

Tricks

(continued from previous page)

# OTHERMIRROR="$OTHERMIRROR | deb http://www.backports.org/debian $STABLE_→˓BACKPORTS_SUITE $COMPONENTS"#fielif $(echo ${UBUNTU_SUITES[@]} | grep -q $DIST); then# Ubuntu configurationMIRRORSITE="http://$UBUNTU_MIRROR/ubuntu/"COMPONENTS="main restricted universe multiverse"elseecho "Unknown distribution: $DIST"exit 1fi

Now we need to initialize the “Packages” file for the empty repo so we can work the first time:

dpkg-scanpackages /var/cache/pbuilder/repo > /var/cache/pbuilder/repo/Packages

(OPTIONAL, not yet tested) If you have lots of RAM (more than 4 GB) putting the pbuilder “build” chroot ontmpfs will speed it up immensely. so add the following to /etc/fstab (it should be all on one line starting with“tmpfs” and ending with the second zero).

tmpfs /var/cache/pbuilder/build tmpfs defaults,size=2400M 0 0and then mount it with "sudo mount /var/cache/pbuilder/build"

Now we need to initialize the pbuilder images for each OS variant, run the following command:

for arch in `echo i386 amd64` ; do for dist in `echo sid jessie trusty xenial` ;→˓do sudo DIST=${dist} ARCH=${arch} pbuilder --create --architecture ${arch} --→˓distribution ${dist} ; done ; done |tee /tmp/baseimage_create.log

Or only for trusty amd64 run:

sudo DIST=trusty ARCH=amd64 pbuilder --create --architecture amd64 --distribution→˓trusty

To update the distroots to current patches run:

for arch in `echo i386 amd64` ; do for dist in `echo sid jessie trusty xenial` ;→˓do sudo DIST=${dist} ARCH=${arch} pbuilder --update ; done ; done |tee /tmp/→˓baseimage_update.log

Or only for trusty amd64 run:

sudo DIST=trusty ARCH=amd64 pbuilder --update

7.1.4 Prepare Package

This section explains the necessary steps to build a debian package afterwards.

7.1.4.1 Create orig.tar.xz Archive (without debian folder)

Inside the package (same level as the CMakeLists.txt file), run (with the appropriate excludes. . . ):

tar -cJ --exclude-vcs --exclude='./.idea' --exclude='./debian' --exclude='./cmake-→˓build-debug' -f ../libxsensmt_4.2.orig.tar.xz .

7.1. Build Debian Package 25

Page 32: Tricks - Read the Docs

Tricks

7.1.4.2 Use dh_make

Inside the package (same level as the CMakeLists.txt file), run:

dh_make -s -p ros-indigo-variant-msgs_0.1.3 --createorig

* -s: single package

* -p: enter the final ROS package name following the version number _x.x.x

* --createorig: will create ros-indigo-variant-msgs_0.1.3.orig.tar.xz in /..

Inside the newly created debian folder you can delete some files:

cd debianrm *.exrm *.EXrm README.*rm docs

Edit changelog should then look something like this:

ros-indigo-variant-msgs (0.1.3-1~trusty0) trusty; urgency=low

* new release

-- Leggedrobotics RSL (APT) <[email protected]> Wed, 28 Dec 2016 09:53:48→˓+0100

trusty0 means

Edit rules, for ROS packages this should then look something like this (replace the the package nameros-indigo-variant-msgs with your package name):

#!/usr/bin/make -f# -*- makefile -*-# Sample debian/rules that uses debhelper.# This file was originally written by Joey Hess and Craig Small.# As a special exception, when this file is copied by dh-make into a# dh-make output file, you may use that output file without restriction.# This special exception was added by Craig Small in version 0.37 of dh-make.

# Uncomment this to turn on verbose mode.export DH_VERBOSE=1export DH_OPTIONS=-v --buildsystem=cmake# TODO: remove the LDFLAGS override. It's here to avoid esoteric problems# of this sort:# https://code.ros.org/trac/ros/ticket/2977# https://code.ros.org/trac/ros/ticket/3842export LDFLAGS=export PKG_CONFIG_PATH=/opt/ros/indigo/lib/pkgconfig# Explicitly enable -DNDEBUG, see:# https://github.com/ros-infrastructure/bloom/issues/327export DEB_CXXFLAGS_MAINT_APPEND=-DNDEBUG

%:dh $@

override_dh_auto_configure:# In case we're installing to a non-standard location, look for a setup.sh# in the install tree that was dropped by catkin, and source it. It will# set things like CMAKE_PREFIX_PATH, PKG_CONFIG_PATH, and PYTHONPATH.if [ -f "/opt/ros/indigo/setup.sh" ]; then . "/opt/ros/indigo/setup.sh"; fi &&

→˓\dh_auto_configure -- \

(continues on next page)

26 Chapter 7. Debian Packaging

Page 33: Tricks - Read the Docs

Tricks

(continued from previous page)

-DCATKIN_BUILD_BINARY_PACKAGE="1" \-DCMAKE_INSTALL_PREFIX="/opt/ros/indigo" \-DCMAKE_PREFIX_PATH="/opt/ros/indigo"

override_dh_auto_build:# In case we're installing to a non-standard location, look for a setup.sh# in the install tree that was dropped by catkin, and source it. It will# set things like CMAKE_PREFIX_PATH, PKG_CONFIG_PATH, and PYTHONPATH.if [ -f "/opt/ros/indigo/setup.sh" ]; then . "/opt/ros/indigo/setup.sh"; fi &&

→˓\dh_auto_build

override_dh_auto_test:# In case we're installing to a non-standard location, look for a setup.sh# in the install tree that was dropped by catkin, and source it. It will# set things like CMAKE_PREFIX_PATH, PKG_CONFIG_PATH, and PYTHONPATH.echo -- Running tests. Even if one of them fails the build is not canceled.if [ -f "/opt/ros/indigo/setup.sh" ]; then . "/opt/ros/indigo/setup.sh"; fi &&

→˓\dh_auto_test || true

override_dh_shlibdeps:# In case we're installing to a non-standard location, look for a setup.sh# in the install tree that was dropped by catkin, and source it. It will# set things like CMAKE_PREFIX_PATH, PKG_CONFIG_PATH, and PYTHONPATH.if [ -f "/opt/ros/indigo/setup.sh" ]; then . "/opt/ros/indigo/setup.sh"; fi &&

→˓\dh_shlibdeps -l$(CURDIR)/debian/ros-indigo-variant-msgs//opt/ros/indigo/lib/

override_dh_auto_install:# In case we're installing to a non-standard location, look for a setup.sh# in the install tree that was dropped by catkin, and source it. It will# set things like CMAKE_PREFIX_PATH, PKG_CONFIG_PATH, and PYTHONPATH.if [ -f "/opt/ros/indigo/setup.sh" ]; then . "/opt/ros/indigo/setup.sh"; fi &&

→˓\dh_auto_install

Edit control, and add the dependencies listed in your package.xml. For ROS packages add the prefix ros-indigo-, for other rosdeps add the specific package name NOT the rosdep key (lookup table here: rosdep list e.g. keylibqwt6 becomes libqwt-dev for trusty). Add the build-dependencies at Build-Depends and run-dependenciesat Depends. For ros-indigo-variant-msgs the control file looks like that:

Source: ros-indigo-variant-msgsSection: miscPriority: extraMaintainer: John Doe <[email protected]>Build-Depends: debhelper (>= 9.0.0), ros-indigo-catkin, ros-indigo-message-→˓generation, ros-indigo-std-msgsHomepage: http://github.com/ethz-asl/variantStandards-Version: 3.9.2

Package: ros-indigo-variant-msgsArchitecture: anyDepends: ${shlibs:Depends}, ${misc:Depends}, ros-indigo-message-runtime, ros-→˓indigo-std-msgsDescription: Variant messages are designed to accommodate the information content→˓of any invariant message.They are truly generic and can freely be converted to and from specific message→˓objects.

7.1. Build Debian Package 27

Page 34: Tricks - Read the Docs

Tricks

7.1.5 Build Package

Inside the package (same level as the debian directory is located), run the following commands.

To build a package for e.g. trusty amd64 run:

pdebuild --architecture amd64 --buildresult ~/pbuilder_ws/packages --pbuilderroot→˓"sudo DIST=trusty ARCH=amd64"

To build packages for multiple distributions, architectures run e.g.: Careful, you probably need differentchangelog and control files for different distributions.

pdebuild --architecture <i386|amd64> --buildresult /tmp --pbuilderroot "sudo DIST=→˓<sid|jessie|trusty|xenial> ARCH=<i386|amd64>"

7.2 Rebuild Launchpad Debian Package (e.g. Backport)

7.2.1 Get Launchpad Sources

dget https://launchpad.net/ubuntu/+archive/primary/+files/google-glog_0.3.4-0.1.dsc

7.2.2 Prepare and Upload Package

1. Unzip google-glog_0.3.4-0.1.debian.tar.xz

2. Unzip google-glog_0.3.4.orig.tar.gz

3. Structure:

• tmp

– glog-0.3.4

* debian

– google-glog_0.3.4.orig.tar.gz

4. cd tmp/glog-0.3.4

5. run sudo debuild -S -kE35F12BA (public launchpad gpg key id, gpg –list-keys)

6. cd ..

7. dput ppa:john-doe/google-glog google-glog_0.3.4-0trusty_source.changes

7.2.2.1 Debuild Options

Build source package (required for Launchpad)

sudo debuild -S

Do not sign package

-us Do not sign the source package.-uc Do not sign the .changes file.-S Source-only package-b Binary-only package-sa Forces the inclusion of the original source.

• dpkg-buildpackage Manpage

28 Chapter 7. Debian Packaging

Page 35: Tricks - Read the Docs

Tricks

• dpkg-genchanges Manpage

Sign package after

debsign -k E35F12BA *.dscdebsign -k E35F12BA *.changes

Sign debian package

debsigs --sign=origin -k E35F12BA libgoogle-glog-dev_0.3.4-0trusty_amd64.deb

debsigs Manpage

7.2.3 Debian Package

pdebuild --architecture amd64 --buildresult ~/pbuilder_ws/ws/glog/tmp/ --→˓pbuilderroot "sudo DIST=trusty ARCH=amd64"

7.2. Rebuild Launchpad Debian Package (e.g. Backport) 29

Page 36: Tricks - Read the Docs

Tricks

30 Chapter 7. Debian Packaging

Page 37: Tricks - Read the Docs

CHAPTER 8

Indices and tables

• genindex

• modindex

• search

31