Linux

How to install entr on Ubuntu

entr is a utility to automatically restart a script if one or more files change.

Installing it on Ubuntu as is as easy as

sudo apt -y install entr

 

Posted by Uli Köhler in Linux

How to install .NET Core SDK on Ubuntu 22.04

wget https://packages.microsoft.com/config/ubuntu/22.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
rm packages-microsoft-prod.deb
sudo apt-get update && sudo apt-get install -y dotnet-sdk-7.0

Source for these commands: Microsoft documentation

Posted by Uli Köhler in C#, Linux

LumenPnP: Always assign the same serial port number on Linux

It is certainly a hassle when you always have to re-configure OpenPnP to open the correct serial device for LumenPnP.

In order to fix, this, we’ll create an alias /dev/lumenpnp that points to /dev/ttyACM0 or /dev/ttyACM1 or any other port that gets assigned to LumenPnP. Create /etc/udev/rules.d/99-lumenpnp.rules:

ACTION=="add", ENV{ID_VENDOR_ID}=="0483", ENV{ID_MODEL_ID}=="5740", SYMLINK+="lumenpnp"

Now, reload udev to activate the rule:

sudo udevadm control --reload-rules && sudo udevadm trigger

Now, open ~/.openpnp2/machine.xml, find this line:

<serial line-ending-type="LF" port-name="ttyACM0" baud="115200" ...

and set port-name to lumenpnp:

<serial line-ending-type="LF" port-name="lumenpnp" baud="115200" ...

After this, you need to restart OpenPnP. Typically, it works without reconnecting the device (due to udevadm trigger). If it doesn’t work, unplug and re-plug the mainboard USB connector.

Posted by Uli Köhler in Linux, LumenPnP

How to add route to local network in Linux even if VPN is active

If you route all your traffic via a VPN on Linux, you will typically not be able to access local networks except for the network which you are directly connected to via L2.

In order to fix this, you can simply add a route, which typically takes precedence over the VPN route even with additional options.

The following example will add a route to 10.1.2.0/24 (local network) via the gateway=local router we’re connected via L2 to (192.168.1.1)

sudo ip route add 10.1.2.0/24 via 192.168.1.1

 

Posted by Uli Köhler in Linux, Networking

How to recursively move all .ics files to a single folder on the Linux command line

This command will move all *.ics files from the current directory and

mkdir -p ICS
find . -name "*.ics" -type f -exec mv --backup=numbered -v {} ICS/ \;

Due to --backup=numbered, files with the same name won’t overwrite anything but instead mv will append a number such as ~2~ to the filename.

Posted by Uli Köhler in Linux

How to recursively sha256sum a directory

This command will run sha256sum recursively on all files in a directory:

find . -type f -print0 | xargs -0 sha256sum

You can also pipe it into a file

find . -type f -print0 | xargs -0 sha256sum > recursive-sha256sum.txt

 

Posted by Uli Köhler in Linux

How to fix dji_irp: error while loading shared libraries: libdirp.so: cannot open shared object file: No such file or directory

Problem:

When you try to run dji_irp from the DJI thermal SDK on Linux, you see the following error message:

./utility/bin/linux/release_x64/dji_irp: error while loading shared libraries: libdirp.so: cannot open shared object file: No such file or directory

Solution:

The libdirp.so library is included with the SDK but it is in a subfolder (the same subfolder where dji_irp is located) where the shell can’t find it.

In order to fix the issue, prefix the command you’re using with

LD_LIBRARY_PATH=./utility/bin/linux/release_x64/

For example:

LD_LIBRARY_PATH=./utility/bin/linux/release_x64/ ./utility/bin/linux/release_x64/dji_irp

 

 

Posted by Uli Köhler in Audio/Video, Linux

How to remove all lines from file, starting from a known line, using sed

This command will look for a line starting with volumes: and remove all lines after said line from the file (including the line starting with volumes: itself).

sed -i -e '/^volumes:/,$d' myfile

The command edits the file in-place (-i), no copy (or backup) of the file will be created.

Posted by Uli Köhler in Linux

How to randomize image order using the feh image viewer

feh is a modern image viewer which you can parameterize on the command line.

Use the -z flag (or --randomize) to randomize the order of the images.

Posted by Uli Köhler in Linux

jq: Select entry from list of objects for which key equals value

This example selects, given a list of JSON entries, all entries where .service equals "mongodb" (i.e. {"service": "mongo"}:

jq 'map(select(.service=="mongo"))'

 

Posted by Uli Köhler in Linux

How to allow remote SMB/CIFS access to /home/pi on the Raspberry Pi

First, install samba using

sudo apt -y install samba

then append the following to /etc/samba/smb.conf

[pi]
   comment = pi
   path = /home/pi
   writeable = yes
   browseable = yes
   public = yes
   create mask = 0644
   directory mask = 0755
   force user = pi

and finally restart samba:

sudo systemctl restart smbd

Now your /home/pi will be accessible via SMB (including write access).

Posted by Uli Köhler in Linux, Raspberry Pi

How to install dropbearconvert on Ubuntu

In order to install the Dropbear SSH key converter dropbearconvert on recent Ubuntu versions, run

sudo apt -y install dropbear-bin

 

Posted by Uli Köhler in Linux

How to run ssh-keygen non-interactively to generate a SSH key file

Problem:

If you want to generate a key file using ssh-keygen, it will prompt you for a key password:

$ ssh-keygen -t ed25519 -f id_ed25519´
Generating public/private ed25519 key pair.
Enter passphrase (empty for no passphrase): 

For scripts and automated deployments, however, you want to avoid the prompt and disable the password encryption of the key.

Solution:

Use -N "" to set an empty password:

ssh-keygen -t ed25519 -f id_ed25519 -N ""

For example:

$ ssh-keygen -t ed25519 -f id_ed25519 -N ""
Generating public/private ed25519 key pair.
Your identification has been saved in id_ed25519
Your public key has been saved in id_ed25519.pub
The key fingerprint is:
SHA256:o/PVrBXpccLOjrVi6vfGWcmNtoubpINfrMxbz4EXtrU [email protected]
The key's randomart image is:
+--[ED25519 256]--+
|                 |
|                 |
|                 |
|           . .   |
|        S   *.++.|
|       . . B B*+o|
|      o  ...#++E |
|       o.+=%+B.. |
|       .+=X*B.+. |
+----[SHA256]-----+

 

Posted by Uli Köhler in Linux

How to list installed files for package on Alpine Linux

In order to list the installed files for an Alpine package such as dropbear, use

apk info -qL NAME_OF_PACKAGE

For example:

# apk info -qL dropbear
usr/bin/dropbearkey
usr/sbin/dropbear

Note: This might list the installed files for the most recent version of the package, not the installed package.

Posted by Uli Köhler in Alpine Linux

How to correctly use apk in Dockerfile

In Dockerfiles you should always use apk with --no-cache to prevent extra files being deposited on the containers, for example:

FROM alpine:3.17
RUN apk add --no-cache python3-dev

 

Posted by Uli Köhler in Alpine Linux, Docker

How to install bup on Alpine Linux

In order to install the bup backup software on Alpine Linux, you currently have to compile it yourself.

First, install the prerequisites:

apk add bash make g++ python3-dev git automake autoconf par2cmdline py3-pip && pip3 install wheel && pip3 install pyxattr

Now we can clone bup:

git clone -b 0.33 --depth 1 https://github.com/bup/bup

and build:

cd bup && ./configure && make -j4 install PREFIX=/usr

After this, bup should be installed in /usr/bin/bup. The bup clone directory we created in the first step is not needed any more.

Posted by Uli Köhler in Alpine Linux, bup

How to install “autom4te” on Alpine Linux

Problem:

When trying to build applications on Alpine Linux, you sometimes see messages like

sh: autom4te: not found
aclocal: error: autom4te failed with exit status: 127

but when you try to apk install autom4te you see that the package can not be found:

fetch https://dl-cdn.alpinelinux.org/alpine/v3.17/main/x86_64/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.17/community/x86_64/APKINDEX.tar.gz
ERROR: unable to select packages:
  autom4te (no such package):
    required by: world[autom4te]

Solution:

autom4te is available from the autoconf package. Therefore, in order to fix the issue, you can run

apk install autoconf

 

Posted by Uli Köhler in Alpine Linux

How to install “aclocal” on Alpine Linux

Problem:

When trying to build applications on Alpine Linux, you sometimes see messages like

./automake.sh: line 5: aclocal: not found

but when you try to apk install aclocal you see that the package can not be found:

fetch https://dl-cdn.alpinelinux.org/alpine/v3.17/main/x86_64/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.17/community/x86_64/APKINDEX.tar.gz
ERROR: unable to select packages:
  aclocal (no such package):
    required by: world[aclocal]

Solution:

aclocal is available from the automake package. Therefore, in order to fix the issue, you can run

apk install automake

 

Posted by Uli Köhler in Alpine Linux

How to install “cpp” on Alpine Linux

Problem:

When trying to build applications on Alpine Linux, you often see messages like

Looking for cpp (not found)

but when you try to apk install cpp you see an error message like

fetch https://dl-cdn.alpinelinux.org/alpine/v3.17/main/x86_64/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.17/community/x86_64/APKINDEX.tar.gz
ERROR: unable to select packages:
  cpp (no such package):
    required by: world[cpp]

Solution:

cpp is just an alias for any C++ compiler. In practice, that means either installing clang++ or g++. I typically recommend g++, even though both will work for most applications.

Therefore, in order to fix the issue, you can run

apk install g++

 

Posted by Uli Köhler in Alpine Linux

Command line: When to use “-” (single hyphen) or “–” (double hyphen)

On the command line, the - character is used to indicate a short form argument, which is a single-letter argument that can be specified using a single hyphen and the letter of the argument. For example, the -h argument is commonly used to show the help message for a command, and the -v argument is commonly used to enable verbose output. You can only use the single hyphen (-) when the argument consists of a single letter.

Examples where single hyphen can be used: -h-Rand-f, but you can not use single hyphens for multi-letter arguments such as -verbose or -help.

The -- characters are used to indicate a long form argument, which is a multi-letter argument that can be specified using a double hyphen and the name of the argument. For example, the --help argument is commonly used to show the help message for a command, and the --verbose argument is commonly used to enable verbose output.

Examples where double hyphens can be used: --verbose--server and --help, but you can’t use them for single-letter arguments like --h or --R 

Examples of how to use single or double hyphens:

# Show the help message for a command using the -h short form argument
my_command -h

# Enable verbose output for a command using the --verbose long form argument
my_command --verbose

# Combine multiple arguments
my_command --verbose --server https://techoverflow.net -f 0.1

 

Posted by Uli Köhler in Linux