Skip to content

Instantly share code, notes, and snippets.

@Jiab77
Last active June 27, 2024 21:01
Show Gist options
  • Save Jiab77/d015f8a9630c0fb3548bcdf17d29f69f to your computer and use it in GitHub Desktop.
Save Jiab77/d015f8a9630c0fb3548bcdf17d29f69f to your computer and use it in GitHub Desktop.
In this document, I will explain how to upgrade the default nut (Network UPS Tools) version from 2.7.4-5.1ubuntu2 to 2.7.4-11ubuntu4.

Upgrade nut on Ubuntu 18.04

In this document, I will explain how to upgrade the default nut (Network UPS Tools) version from 2.7.4-5.1ubuntu2 to 2.7.4-11ubuntu4.

It is basically the same process as the one used in my previous upgrade gist, Upgrade systemd on Ubuntu 18.04.

The main reason why you would follow this gist is because by default the UPS detection tool nut-scanner is not available by default on Ubuntu 18.04 and can't be compiled correctly from source due to non standard library linking used that does not find the shared library even if it is correctly installed / loaded on the system.

Maybe you have been more lucky than me on your side and then you can simply leave this gist 😅 but on my side every fix attempts resulted in:

$ ./Projects/nut/tools/nut-scanner/nut-scanner
Cannot load USB library (/usr/lib/x86_64-linux-gnu/libusb.so) : file not found. USB search disabled.
No start IP, skipping NUT bus (old connect method)

You can get more references from here:

Install required dependencies

sudo apt install build-essential libpowerman0-dev libusb-dev libltdl-dev

You might need to provide more dependencies to cover all the features provided by nut (Network UPS Tools)

Enable source repositories

# Patch sources file
sudo sed -e 's/# deb-src/deb-src/' -i /etc/apt/sources.list

# Update package cache
sudo apt update --fix-missing -y

Install build dependencies

sudo apt build-dep nut

Download required sources

wget https://launchpad.net/ubuntu/+archive/primary/+sourcefiles/nut/2.7.4-11ubuntu4/nut_2.7.4.orig.tar.gz
wget https://launchpad.net/ubuntu/+archive/primary/+sourcefiles/nut/2.7.4-11ubuntu4/nut_2.7.4-11ubuntu4.debian.tar.xz
wget https://launchpad.net/ubuntu/+archive/primary/+sourcefiles/nut/2.7.4-11ubuntu4/nut_2.7.4-11ubuntu4.dsc

Unpack downloaded sources

# Move to home
cd $HOME

# Uncompress orig archive
tar xvzf nut_2.7.4.orig.tar.gz

# Move to decompressed folder
cd nut-2.7.4

# Uncompress debian files
tar xvJf ../nut_2.7.4-11ubuntu4.debian.tar.xz

Compile everything

This will also generate debian packages to install in next step.

dpkg-buildpackage -us -uc -d

This step is pretty long so be patient if you don't have a lot of CPU cores.

The argument -d is required to bypass the requested ubuntu version.

Install generated packages

Now we will install the new compiled nut version.

# Move back to home
cd $HOME

# List generated debian packages
ll | grep deb

# Create dedicated folder for debian packages
mkdir -v nut-274-debs

# Move all created packages
mv -v *.*deb nut-274-debs/

# Move to debian packages folder
cd nut-274-debs

# Install generated packages
sudo dpkg --auto-deconfigure -i *.deb

# Fix missing package like "powerman"
sudo apt --fix-broken install

Verify installed version

This command will give us two things:

  1. The proof that nut-scanner has been correctly compiled and installed
  2. Returns the installed nut version
nut-scanner --version

I've tried all the ups* commands and none of them has a -V or --version argument available, only nut-scanner has one.

It should return something similar:

SNMP library not found. SNMP search disabled.
Neon library not found. XML search disabled.
Network UPS Tools - 2.7.4

Run detection test

# Scan all available devices (default)
$ nut-scanner

# Scan USB devices only
$ nut-scanner -U

# Scan USB devices only but print in ups.conf format
$ nut-scanner -UN

Side notes

In case you would like to try the compilation process on your side, here is what I've tried on my side before moving to the install from debian packages process:

# Install required dependencies
sudo apt install libusb-dev libltdl-dev

# Clone the project
git clone https://github.com/networkupstools/nut.git

# Move to the cloned project folder
cd nut

# Generation configuration files
./autogen.sh

# Get configuration options
./configure --help

# Provide minimal options to compile 'nut' with the 'nut-scanner' tool
# The provided '--with-user' and '--with-group' values has been
# cloned from what is used under Ubuntu 20.04.x
./configure --with-user=nut --with-group=nut --with-usb --with-dev

# Run compilation process with all CPU cores
make -j $(nproc)

# Move to the 'nut-scanner' folder
cd tools/nut-scanner/

# See if it works
./nut-scanner

If the last commands returns something like:

Cannot load USB library (/usr/lib/x86_64-linux-gnu/libusb.so) : file not found. USB search disabled.
No start IP, skipping NUT bus (old connect method)

But running find /usr/lib/x86_64-linux-gnu/ -iname "libusb.so" returns:

/usr/lib/x86_64-linux-gnu/libusb.so

Then it means that you're getting suck at the point I was and I can only wish you "good luck" if you want to keep going on the installation from sources or you can simply follow steps described in this gist.

References

Other references

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment