Archive

Posts Tagged ‘freebsd packages’

Freebsd – Find which package provides certain files

August 24, 2021 Leave a comment

Default Freebsd pkg tool doesn’t have “provides” option like the one in Red Hats yum package manager

yum provides idn2.h

But thanks to Rodrigo Osorio, you can install “pkg-provides” plugin which adds provides option to pkg tool.

root@bsd12:~ # pkg install pkg-provides

All instructions are at the end of install process. Basically you have to add 3 lines to pkg.conf and run update provides database:

root@bsd12:~ # pkg plugins
NAME       DESC                                          VERSION   
provides   A plugin for querying which package provides a particular file 0.7.1     
root@bsd12:~ # pkg provides idn2.h
Provides database not found, please update first.
root@bsd12:~ # pkg provides -u
Fetching provides database: 100%   15 MiB   4.0MB/s    00:04    
Extracting database....succes
root@bsd12:~ # pkg provides idn2.h
Name : libidn2-2.3.0_1
Desc : Implementation of IDNA2008 internationalized domain names
Repo : FreeBSD
Filename: usr/local/share/gtk-doc/html/libidn2/libidn2.html
usr/local/share/gtk-doc/html/libidn2/libidn2-idn2.html
usr/local/include/idn2.h

Setup and full usage here:

Click to access freebsd_provides.pdf

FreeBSD Howto Mix Match Packages and Ports

October 9, 2020 Leave a comment

This document is not for best practices and/or proof of concept

This is a solution for my simple problem: I’m managing FreeBSD server with packages not ports but default package configuration doesn’t meet my needs.

Note: For mariadb there is already a DBD package:
p5-DBD-MariaDB
but it still requires mysql57-client

Current Scenario :

I use mariadb instead of mysql but FreeBSD 12.1-RELEASE defaults to mysql 5.7 meaning packages are build based on this version of mysql so:

I’ve mariadb 10.4 installed and i need p5-DBD-mysql package for some perl script to run

if i try to install p5-DBD-mysql from packages:

root@bsd12:~ # pkg install p5-DBD-mysql

Updating FreeBSD repository catalogue...
FreeBSD repository is up to date.
All repositories are up to date.
The following 10 package(s) will be affected (of 0 checked):

New packages to be INSTALLED:
	groff: 1.22.4_3
	libevent: 2.1.12
	libpaper: 1.1.24.4
	mysql57-client: 5.7.31_1
	p5-DBD-mysql: 4.050
	p5-DBI: 1.643
	protobuf: 3.13.0,1
	psutils: 1.17_5
	uchardet: 0.0.7

Installed packages to be UPGRADED:
	perl5: 5.30.3 -> 5.32.0

Number of packages to be installed: 9
Number of packages to be upgraded: 1

The process will require 100 MiB more space.
23 MiB to be downloaded.

Proceed with this action? [y/N]: y
[1/10] Fetching p5-DBD-mysql-4.050.txz: 100%   99 KiB 101.3kB/s    00:01    
[2/10] Fetching perl5-5.32.0.txz: 100%   14 MiB  14.9MB/s    00:01    
[3/10] Fetching libpaper-1.1.24.4.txz: 100%   24 KiB  24.5kB/s    00:01    
[4/10] Fetching p5-DBI-1.643.txz: 100%  705 KiB 721.6kB/s    00:01    
[5/10] Fetching mysql57-client-5.7.31_1.txz: 100%    2 MiB   1.9MB/s    00:01    
[6/10] Fetching groff-1.22.4_3.txz: 100%    3 MiB   2.9MB/s    00:01    
[7/10] Fetching uchardet-0.0.7.txz: 100%  108 KiB 111.0kB/s    00:01    
[8/10] Fetching psutils-1.17_5.txz: 100%   57 KiB  58.0kB/s    00:01    
[9/10] Fetching protobuf-3.13.0,1.txz: 100%    3 MiB   2.9MB/s    00:01    
[10/10] Fetching libevent-2.1.12.txz: 100%  320 KiB 327.6kB/s    00:01    
Checking integrity... done (1 conflicting)
  - mysql57-client-5.7.31_1 conflicts with mariadb104-client-10.4.13_4 on /usr/local/bin/mysql

As you see above it conflicts with my mariadb and continues as below:

Checking integrity... done (0 conflicting)
Conflicts with the existing packages have been found.
One more solver iteration is needed to resolve them.
The following 12 package(s) will be affected (of 0 checked):

New packages to be INSTALLED:
	groff: 1.22.4_3
	libevent: 2.1.12
	libpaper: 1.1.24.4
	mysql57-client: 5.7.31_1
	p5-DBD-mysql: 4.050
	p5-DBI: 1.643
	protobuf: 3.13.0,1
	psutils: 1.17_5
	uchardet: 0.0.7

Installed packages to be UPGRADED:
	perl5: 5.30.3 -> 5.32.0

Number of packages to be installed: 9
Number of packages to be upgraded: 1

The process will require 100 MiB more space.

Proceed with this action? [y/N]: 

Now if i click on “Yes” here pkg will remove my mariadb and install mysql57-client so of course i click on “No”

Solution is change FreeBSD defaults and make it depend on Mariadb104 instead of mysql. For this we need to use ports

About Ports:

There are a lot of flame around mixing pkgs and ports i wont go into that. But in my case its mandatory and pretty harmless because:

I dont use HEAD ports but use Quarterly which is same as pkg version.

Little bit background; pkg uses quarterly updates repo as default on the other hand port users tend to use HEAD branch meaning kind of rolling release.

Port management tools:

Portsnap: uses HEAD branch as default, useless for me
Poudriere: Uses jails, a lot of resources and complicated for single pkg. Helpful if you are going to create batch of packages, have tens or hundreds of FreeBSD servers and want to create your own central repo server.
Synth: Simplified package repository builder, doesn’t require that much resource uses base system as building platform and creates dynamic jails during each build.

I will use svnlite, simple enough for my needs. Basicaly:

1) Change freebsd make defaults to use mariadb instead of mysql
2) Download ports tree
3) create p5-DBD-mysql package from ports
4) install p5-DBD-mysql pkg
5) test

root@bsd12:~ # echo "DEFAULT_VERSIONS= mysql=10.4m" >> /etc/make.conf 

Download ports from quarterly repo :
// if you already created ports with another port management tool remove ports directory

root@bsd12:~ # svnlite checkout https://svn.freebsd.org/ports/branches/2020Q4 /usr/ports

it will take a while to download ports ( uses ~1.2GB ) once its done

root@bsd12:~ # cd /usr/ports/
root@bsd12:~ # make fetchindex
root@bsd12:~ # make search name=”p5-DBD-mysql”

Above command is to search for a port in ports tree

root@bsd12:~ # cd databases/p5-DBD-mysql
root@bsd12:~ # make all-depends-list | sort

Now above command shows all dependencies and if you scroll up, you will see now mariadb is listed as dependency instead of mysql

root@bsd12:~ # make package
root@bsd12:~ # pkg add work/pkg/p5-DBD-mysql-4.050.txz

And you are done. You can test installation with below perl script that i copied from cpan site.

Test Script:


#!/usr/local/bin/perl

use strict;
use warnings;
use DBI;

# Connect to the database.
my $dbh = DBI->connect("DBI:mysql:database=test;host=localhost",
"user", "password",
{'RaiseError' => 1});

# Drop table 'foo'. This may fail, if 'foo' doesn't exist
# Thus we put an eval around it.
eval { $dbh->do("DROP TABLE foo") };
print "Dropping foo failed: $@\n" if $@;

# Create a new table 'foo'. This must not fail, thus we don't
# catch errors.
$dbh->do("CREATE TABLE foo (id INTEGER, name VARCHAR(20))");

# INSERT some data into 'foo'. We are using $dbh->quote() for
# quoting the name.
$dbh->do("INSERT INTO foo VALUES (1, " . $dbh->quote("Tim") . ")");

# same thing, but using placeholders (recommended!)
$dbh->do("INSERT INTO foo VALUES (?, ?)", undef, 2, "Jochen");

# now retrieve data from the table.
my $sth = $dbh->prepare("SELECT * FROM foo");
$sth->execute();
while (my $ref = $sth->fetchrow_hashref()) {
print "Found a row: id = $ref->{'id'}, name = $ref->{'name'}\n";
}
$sth->finish();

# Disconnect from the database.
$dbh->disconnect();

And last step is to lock the pkg so it will not be affected during update process

root@bsd12:~ # pkg lock p5-DBD-mysql
p5-DBD-mysql-4.050: lock this package? [y/N]: y
Locking p5-DBD-mysql-4.050