Linux

How to install tailscale in Alpine Linux

My recommendation is to just use the community repository:

echo http://dl-2.alpinelinux.org/alpine/edge/community/ >> /etc/apk/repositories
apk add -U tailscale

Now you need to add tailscaled to the autostart list and then start the service so you can use it right now:

rc-update add tailscale
/etc/init.d/tailscale start

 

Posted by Uli Köhler in Alpine Linux

How to install usermod in Alpine Linux

Problem:

When trying to use usermod in Alpine Linux, you see the following error message:

-ash: usermod: not found

Solution:

Install usermod and related tools by adding the community repositories and using

echo http://dl-2.alpinelinux.org/alpine/edge/community/ >> /etc/apk/repositories
apk add -U shadow

 

Posted by Uli Köhler in Alpine Linux

How to install gcsfuse on Ubuntu in 15 seconds

export GCSFUSE_REPO=gcsfuse-`lsb_release -c -s`
echo "deb http://packages.cloud.google.com/apt $GCSFUSE_REPO main" | sudo tee /etc/apt/sources.list.d/gcsfuse.list
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
sudo apt-get update
sudo apt-get install gcsfuse

If that doesn’t work (such as for Ubuntu 21.10 impish at the time of writing this post), use the following method:

curl -L -O https://github.com/GoogleCloudPlatform/gcsfuse/releases/download/v0.39.2/gcsfuse_0.39.2_amd64.deb
sudo dpkg --install gcsfuse_0.39.2_amd64.deb
rm gcsfuse_0.39.2_amd64.deb

 

 

This is a summary from the official docs.

Posted by Uli Köhler in Cloud, Linux

How to install gcloud on Ubuntu in 10 seconds

sudo snap install google-cloud-cli --classic

This is the summary from the official docs. I recommend to install it as snap package as opposed to a deb package since it will auto-update, it’s much easier to use and just works better out of the box in my experience.

Posted by Uli Köhler in Cloud, Linux

How to fix OpenStage 40 ERR_SSL_VERSION_OR_CIPHER_MISMATCH

Problem:

When trying to access your OpenStage 40 IP phone using Chrome or Firefox, you see the following error message:

ERR_SSL_VERSION_OR_CIPHER_MISMATCH

Solution:

This is because your OpenStage firmware currently does not support a recent TLS version.

You can easily resolve this by using an old browser that does not block old TLS versions.

Just download Firefox 50.0.2 portable from (Linux version) https://releases.mozilla.org/pub/firefox/releases/50.0.2/linux-x86_64/en-US/ , download the .tar.bz2 from the link, untar it using tar xjvf *.tar.bz2cd firefox and run it portably with autoupdate disabled using

mkdir -p profile && ./firefox -profile $PWD/profile
Posted by Uli Köhler in Linux, Networking

How to create systemd service timer that runs Nextcloud cron.php in 10 seconds

This post shows you a really quick method to create a systemd timer that runs cron.php on dockerized nextcloud (using docker-compose). We created a script that automatically creates a systemd timer and related service to run cron.php hourly using the command from our previous post How to run Nextcloud cron in a docker-compose based setup:

 

In order to run our autoinstall script, run:

wget -qO- https://techoverflow.net/scripts/install-nextcloud-cron.sh | sudo bash /dev/stdin

from the directory where docker-compose.yml is located. Note that the script will use the directory name as a name for the service and timer that is created. For example, running the script in /var/lib/nextcloud-mydomain will cause nextcloud-mydomain-cron to be used a service name.

Example output from the script:

Creating systemd service... /etc/systemd/system/nextcloud-mydomain-cron.service
Creating systemd timer... /etc/systemd/system/nextcloud-mydomain-cron.timer
Enabling & starting nextcloud-mydomain-cron.timer
Created symlink /etc/systemd/system/timers.target.wants/nextcloud-mydomain-cron.timer → /etc/systemd/system/nextcloud-mydomain-cron.timer.

The script will create /etc/systemd/systemd/nextcloud-mydomain-cron.service containing the specification on what exactly to run:

[Unit]
Description=nextcloud-mydomain-cron

[Service]
Type=oneshot
ExecStart=/usr/bin/docker-compose exec -T -u www-data nextcloud php cron.php
WorkingDirectory=/var/opt/nextcloud-mydomain

and /etc/systemd/systemd/nextcloud-mydomain-cron.timer containing the logic when the .service is started:

[Unit]
Description=nextcloud-mydomain-cron

[Timer]
OnCalendar=hourly
Persistent=true

[Install]
WantedBy=timers.target

and will automatically start and enable the timer. This means: no further steps are needed after running this script!

In order to show the current status of the service, use e.g.

sudo systemctl status nextcloud-mydomain-cron.timer

Example output:

● nextcloud-mydomain-cron.timer - nextcloud-mydomain-cron
     Loaded: loaded (/etc/systemd/system/nextcloud-mydomain-cron.timer; enabled; vendor preset: disabled)
     Active: active (waiting) since Fri 2022-04-01 00:33:48 UTC; 6min ago
    Trigger: Fri 2022-04-01 01:00:00 UTC; 19min left
   Triggers: ● nextcloud-mydomain-cron.service

Apr 01 00:33:48 CoreOS systemd[1]: Started nextcloud-mydomain-cron.

In the

Trigger: Fri 2020-12-11 00:00:00 CET; 20h left

line you can see when the service will be run next. By default, the script generates tasks that run OnCalendar=daily, which means the service will be run on 00:00:00 every day. Checkout the systemd.time manpage for further information on the syntax you can use to specify other timeframes.

In order to run the backup immediately (it will still run daily after doing this), do

sudo systemctl start nextcloud-mydomain-cron.service

(note that you need to run systemctl start on the .service! Running systemctl start on the .timer will only enable the timer and not run the service immediately).

In order to view the logs, use

sudo journalctl -xfu nextcloud-mydomain-cron.service

(just like above, you need to run journalctl -xfu on the .service, not on the .timer).

In order to disable automatic backups, use e.g.

sudo systemctl disable nextcloud-mydomain-cron.timer

Source code:

#!/bin/bash
# Create a systemd service & timer that runs cron.php on dockerized nextcloud
# by Uli Köhler - https://techoverflow.net
# Licensed as CC0 1.0 Universal
export SERVICENAME=$(basename $(pwd))-cron

export SERVICEFILE=/etc/systemd/system/${SERVICENAME}.service
export TIMERFILE=/etc/systemd/system/${SERVICENAME}.timer

echo "Creating systemd service... $SERVICEFILE"
sudo cat >$SERVICEFILE <<EOF
[Unit]
Description=$SERVICENAME

[Service]
Type=oneshot
ExecStart=$(which docker-compose) exec -T -u www-data nextcloud php cron.php
WorkingDirectory=$(pwd)
EOF

echo "Creating systemd timer... $TIMERFILE"
sudo cat >$TIMERFILE <<EOF
[Unit]
Description=$SERVICENAME

[Timer]
OnCalendar=hourly
Persistent=true

[Install]
WantedBy=timers.target
EOF

echo "Enabling & starting $SERVICENAME.timer"
sudo systemctl enable $SERVICENAME.timer
sudo systemctl start $SERVICENAME.timer

 

Posted by Uli Köhler in Docker, Linux, Nextcloud

How to run systemd timer every ten minutes

The syntax to run a systemd timer every ten minutes is:

OnCalendar=*-*-* *:00,10,20,30,40,50:00

i.e. run it on the first second (:00) of every 10th minute (00,10,20,30,40,50).

Posted by Uli Köhler in systemd

How to generate filename containing date & time on the command line

The following snippet is useful for backups to generate a unique yet sortable filename containing both date and time:

mysqldump-$(date +%F_%H-%M-%S).sql

This generates filenames like

mysqldump-2022-03-26_20-47-01.sql

which are compatible with both Windows and Linux as they don’t contain special characters like :

Posted by Uli Köhler in Linux

How to delete all files containing a specific string using ack-grep (ag)

Based on our previous post How to list filenames containing a specific string using ack-grep (ag) this example shows how to delete all files in the current directory containing the string 403 Forbidden.

For example, in order to list filenames containing the string 403 Forbidden, use

ag -0 -l "403 Forbidden" | xargs -0 rm -v

Using ag -0 is neccessary to handle filenames containing spaces correctly.

Posted by Uli Köhler in Linux

How to install Xen guest utilities on Ubuntu

Install the package using

sudo apt -y install xe-guest-utilities

Now reboot, which will automatically start the management agent service:

sudo reboot

 

Posted by Uli Köhler in Linux, Virtualization

A simple systemd service autoinstall script

I use this in git repositories to ease the deployment process

#!/bin/bash
# This script installs and enables/starts a systemd service
# It also installs the service file
export NAME=MyService

cat >/etc/systemd/system/${NAME}.service <<EOF
# TODO Copy & paste the systemd .service file here
EOF

# Enable and start service
systemctl enable --now ${NAME}.service

The following example automatically installs a docker-compose systemd .service:

#!/bin/bash
# This script installs and enables/starts a systemd service
# It also installs the service file
export NAME=UkraineBase

cat >/etc/systemd/system/${NAME}.service <<EOF
[Unit]
Description=${NAME}
Requires=docker.service
After=docker.service

[Service]
Restart=always
User=root
Group=docker
WorkingDirectory=$(pwd)
# Shutdown container (if running) before unit is being started
ExecStartPre=$(which docker-compose) -f docker-compose.yml down
# Start container when unit is started
ExecStart=$(which docker-compose) -f docker-compose.yml up
# Stop container when unit is stopped
ExecStop=$(which docker-compose) -f docker-compose.yml down

[Install]
WantedBy=multi-user.target
EOF

# Enable and start service
systemctl enable --now ${NAME}.service
Posted by Uli Köhler in Docker, systemd

How to fix apt E: Unable to locate package rpi-imager

Problem:

While trying to install rpi-imager using

sudo apt install rpi-imager

you see this error message:

Reading package lists... Done
Building dependency tree       
Reading state information... Done

No apt package "rpi-imager", but there is a snap with that name.
Try "snap install rpi-imager"

E: Unable to locate package rpi-imager

Solution:

sudo apt -y install rpi-imager only works on Raspbian. On Ubuntu etc, you can install rpi-imager using

sudo snap install rpi-imager

Then start it using

rpi-imager

Posted by Uli Köhler in Linux, Raspberry Pi

How to skip SSL certificate verification during git clone

Problem:

When running git clone, you see an error message like

Cloning into 'MyProject'...
fatal: unable to access 'https://gitlab.mydomain.com/projects/MyProject.git': server certificate verification failed. CAfile: /etc/ssl/certs/ca-certificates.crt CRLfile: none

Solution:

The quick solution is to prepend

GIT_SSL_NO_VERIFY=true

to the git clone command, example:

GIT_SSL_NO_VERIFY=true https://gitlab.mydomain.com/projects/MyProject.git

Note that skipping SSL verification is a security risk, so the correct method of fixing this issue is appropriately updating the CA certificates (something like sudo apt install ca-certificates) but this is sometimes not feasibel since not any outdated computer can be updated easily.

Posted by Uli Köhler in git, Linux