Check a list of packages to install with apt-get - perl

I am writing a post-install script for Ubuntu in Perl (same script as seen here). One of the steps is to install a list of packages. The problem is that if apt-get install fails in some of many different ways for any one of the packages the script dies badly. I would like to prevent that from happening.
This happens because of the ways that apt-get install fails for packages that it doesn't like. For example when I try to install a nonsense word (i.e. typed in the wrong package name)
$ sudo apt-get install oblihbyvl
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package oblihbyvl
but if instead the package name has been obsoleted (installing handbrake from ppa)
$ sudo apt-get install handbrake
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package handbrake is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
E: Package 'handbrake' has no installation candidate
$ apt-cache search handbrake
handbrake-cli - versatile DVD ripper and video transcoder - command line
handbrake-gtk - versatile DVD ripper and video transcoder - GTK GUI
etc, etc ...
I have tried parsing the results of apt-cache and apt-get -s install to try to catch all possibilities before doing the install, but I seem to keep finding new ways to allow failures to continue to the actual install system command.
My question is, is there some facility either in Perl (e.g. a module, though I would like to avoid installing modules if possible as this is supposed to be the first thing run after a new install of Ubuntu) or apt-* or dpkg that would let me be sure that the packages are all available to be installed before installing and if not fail gracefully in some way that lets the user decide what to do?
N.B. I am doing something along the lines of:
my #list_of_install_candidates = (...);
my #to_install = grep { my $output = qx{ apt-get -s install $_ }; parse_output($output); } #list_of_install_candidates;
system('apt-get', 'install', #to_install);

You might try apt-cache policy. examples:
$ apt-cache policy handbrake
handbrake:
Installed: (none)
Candidate: (none)
Version table:
$ apt-cache policy foo
N: Unable to locate package foo
$ apt-cache policy openbox
openbox:
Installed: 3.4.11.1-1
Candidate: 3.4.11.1-1
Version table:
*** 3.4.11.1-1 0
500 http://mirrors.xmission.com/ubuntu/ maverick/universe i386 Packages
100 /var/lib/dpkg/status
Anything with a non-blank version table should be installable.

Related

rpmbuild unable to find the custom installed package

There are plenty of perl packages missing in Centos 8 and Rocky Linux. So, I try to get the rpm spec by cpanspec and build rpm by myself. But, it seems like that rpmbuild could not find the rpm I built.
This is the script for me to build rpm.
cd /root/rpmbuild
cpanspec --packer 'Example <example#example.com>' <Perl-Package-Name>
mkdir SOURCES
cp <Perl-Package-Name>.tar.gz SOURCES
rpmbuild -ba perl-<Package-Name>.spec
Let's say we have two package A and B. A is needed by B.
I try to build both of the packages through the script above. I build A first, switch into /root/rpmbuild/RPMS/noarch and install A.rpm. Then, I try to build package B.
I got
error: Failed build dependencies:
perl(A) is needed by perl-<B>
I try to check the existence of package A.
yum list installed | grep A
and
perldoc -l A
Both of the commands show that A exists.
Did I miss something?
update 2022/06/07
I just gave up and commented the BuildRequires: A in B package. This is not a good approach but it works.

How to install VSCODE on debian 9? Nothing works

I'm trying to install Visual studio code.
My Raspb. Version is:
Distributor ID: Raspbian
Description: Raspbian GNU/Linux 9.8 (stretch)
Release: 9.8
Codename: stretch
I tried several method (starting to download .deb and using dpkg or install command) but nothing worked.
How can I fix this problem? I really need VSC because my project is growing and Geany messes up.
Downloaded .deb and .tar files from the official site, followed the setup instruction but I got this error
With dpkg (both 32 and 64bit):
"package architecture (amd64) does not match system (armhf)"
"package architecture (i386) does not match system (armhf)"
With sudo install:
sudo apt install ./code_1.33.1-1554971066_amd64.deb
Reading package lists... Done
Building dependency tree
Reading state information... Done
Note, selecting 'code:amd64' instead of './code_1.33.1-1554971066_amd64.deb'
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:
The following packages have unmet dependencies:
code:amd64 : Depends: libnotify4:amd64 but it is not installable
Depends: libnss3:amd64 (>= 2:3.26) but it is not installable
Depends: apt:amd64 but it is not installable
Depends: libxkbfile1:amd64 but it is not installable
Depends: libsecret-1-0:amd64 but it is not installable
Depends: libgtk-3-0:amd64 (>= 3.10.0) but it is not installable
Depends: libxss1:amd64 but it is not installable
E: Unable to correct problems, you have held broken packages.
With repository:
pi#raspberrypi:~/Downloads $ sudo apt-get update
Err:1 http://raspbian.raspberrypi.org/raspbian stretch InRelease
Temporary failure resolving 'raspbian.raspberrypi.org'
Err:2 http://archive.raspberrypi.org/debian stretch InRelease
Temporary failure resolving 'archive.raspberrypi.org'
Err:3 https://packages.microsoft.com/repos/vscode stable InRelease
Could not resolve host: packages.microsoft.com
Reading package lists... Done
W: Failed to fetch http://raspbian.raspberrypi.org/raspbian/dists/stretch/InRelease Temporary failure resolving 'raspbian.raspberrypi.org'
W: Failed to fetch http://archive.raspberrypi.org/debian/dists/stretch/InRelease Temporary failure resolving 'archive.raspberrypi.org'
W: Failed to fetch https://packages.microsoft.com/repos/vscode/dists/stable/InRelease Could not resolve host: packages.microsoft.com
W: Some index files failed to download. They have been ignored, or old ones used instead.
pi#raspberrypi:~/Downloads $ sudo apt-get install code
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package code
I'm getting mad about this problem, I tried older repository but they don't work.
There are Community builds of Visual Studio Code available (for Raspberry Pi and other ARM and Intel systems).
The packages are currently available in DEB and RPM format. You can use the scripts provided here to install the packages and add their repository to your system or install it manually.
Below I summarized the steps:
Open a new terminal. If you need super-user rights (you probably do), then you can enter sudo -s and press return to enter a super-user session. Run the installer for your current distribution:
APT instructions
(including Debian, Raspbian, Ubuntu and Linux Mint)
. <( wget -O - https://code.headmelted.com/installers/apt.sh )
Press the return key. Once the installer has completed, you should have a "Code - OSS" entry in your desktop program list.
Manual installation
If for any reason the script above will not work on your system, or you do not want to add the package source for updates, you can get the latest version of the package for your system below.
Public GPG key
For either APT or YUM installation, you'll want the public GPG key to verify the package, which you can download here.
APT and YUM packages
The latest packages are available directly from the PackageCloud releases page.
The specific package you need is available here.
EDIT:
At this time (29.04.2019) the current release (v. 1.32) appears not to be working for everybody. See: issue#64. Seems that you'll have to go back to v. 1.29, which is reported to be running fine.
You can choose this package and install it manually, or use APT. If you decide to install it via APT, note that you'll have to mark the package on hold as described below.
To prevent code-oss from upgrading (so that you can keep v. 1.29 until the issue is fixed) follow these instructions:
Install v. 1.29 via APT:
apt-get install code-oss=1.29.0-1539702286
Then mark it on hold by running:
apt-mark hold code-oss
Now running apt-get upgrade won't try to bump it up until you run:
apt-mark unhold code-oss
This will allow it to upgrade again as usual.

Which missing library results in the message '/usr/bin/ld: cannot find -lglib-2.0'?

I am cross compiling a Lazarus program, creating a 32bit program on a 64bit Ubuntu 14.04 Trusty Tahr system, and everything apparently compiles to the very end when I get this messsage
/usr/bin/ld: cannot find -lglib-2.0
What is the full name of the library whose absence results in this error mesage?
libc6-dev:i386 appears to be the most likely library, but when I try to install it with apt indicates build-essential g++ gcc gcc-multilib will be removed so I abort it.
sudo apt-get install libc6-dev:i386
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
linux-libc-dev linux-libc-dev:i386
Suggested packages:
glibc-doc:i386 manpages-dev:i386
Recommended packages:
gcc:i386 c-compiler:i386
The following packages will be REMOVED
build-essential g++ gcc gcc-multilib
The following NEW packages will be installed
libc6-dev:i386 linux-libc-dev:i386
The following packages will be upgraded:
linux-libc-dev
1 to upgrade, 2 to newly install, 4 to remove and 18 not to upgrade.
Need to get 3,126 kB of archives.
After this operation, 12.6 MB of additional disk space will be used.
Do you want to continue? [Y/n]
It turns out it was the libglib2.0-0:i386 package. It was already installed earlier, but it had not been fully configured.
It was present in the /lib/i386-linux directory and I had to create a symlink to it include it to the fpc.cfg configuration file used by Free Pascal.
locate libglib | grep ^/lib produced:
/lib/i386-linux-gnu/libglib-2.0.so.0
/lib/i386-linux-gnu/libglib-2.0.so.0.4002.0
/lib/x86_64-linux-gnu/libglib-2.0.so.0
/lib/x86_64-linux-gnu/libglib-2.0.so.0.4002.0
I symlinked it with the expected name:
ln -s /lib/i386-linux-gnu/libglib-2.0.so.0 /lib/i386-linux-gnu/libglib-2.0.so
then added to the Lazarus installations fpc.cfg file
#ifdef cpui386
-Fl/usr/lib32
-Fl/lib/i386-linux-gnu
#endif

Cannot install perl module PerlIO::locale within docker

I am running into problems installing certain perl modules within docker. Is there a recommended stable way of doing this for the default ubuntu image?
Also I'm unlear how to access the install log file in a failed build (ie for cpan minus at /.cpanm/build.log).
The following Dockerfile fails with the message:
Please specify prototyping behavior for locale.xs (see perlxs manual)
When it attempts to resolve the dependency on PerlIO::locale.
# use the ubuntu base image provided by dotCloud
FROM ubuntu
# make sure the package repository is up to date
RUN echo "deb http://archive.ubuntu.com/ubuntu precise main universe" > /etc/apt/sources.list
RUN apt-get update
# install perl and modules
RUN apt-get install -y make
RUN apt-get install -y perl
RUN apt-get install -y cpanminus
RUN cpanm -v Text::Names
Some modules include C code which needs to be compiled on the target systems (“XS modules”). For that, you'll need a complete C toolchain. This implies make, the compiler: gcc, and the C standard library headers: libc-dev. The build-essential metapackage includes these components (and some more), so I'd recommend you install that instead.
According to perlxstut, that's just a warning rather than a fatal error.
There's a clearly documented default (perlxs: "Prototypes are enabled by default"). Furthermore, this particular XS component doesn't actually export any functions to Perl, so the setting is never even used.
The warning can be silenced by adding a PROTOTYPES: ENABLE to locale.xs — you could even ask the author to make that change — but it won't make any difference.
The problem is elsewhere.

How can I install XML::LibXML on Ubuntu

Here is the stdout for install:
$sudo cpanm XML::LibXML
--> Working on XML::LibXML
Fetching http://www.cpan.org/authors/id/S/SH/SHLOMIF/XML-LibXML-2.0014.tar.gz ... OK
Configuring XML-LibXML-2.0014 ... N/A
! Configure failed for XML-LibXML-2.0014. See /home/kahmed/.cpanm/build.log for details.
details:
Unpacking XML-LibXML-2.0014.tar.gz
Entering XML-LibXML-2.0014
Checking configure dependencies from META.yml
Checking if you have ExtUtils::MakeMaker 0 ... Yes (6.55_02)
Configuring XML-LibXML-2.0014
Running Makefile.PL
enable native perl UTF8
running xml2-config...ok (2.9.0)
Checking for ability to link against xml2...no
Checking for ability to link against libxml2...libxml2, zlib, and/or the Math library (-lm) have not been found.
Try setting LIBS and INC values on the command line
Or get libxml2 from
http://xmlsoft.org/
If you install via RPMs, make sure you also install the -devel
RPMs, as this is where the headers (.h files) are.
Also, you may try to run perl Makefile.PL with the DEBUG=1 parameter
to see the exact reason why the detection of libxml2 installation
failed or why Makefile.PL was not able to compile a test program.
-> N/A
-> FAIL Configure failed for XML-LibXML-2.0014. See /home/kahmed/.cpanm/build.log for details.
i tried installing libxml2 manually, but still getting the same issue.
also, i checked for libxml2-dev:
sudo apt-get install libxml2-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
libxml2-dev is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 78 not upgraded.
here is the system info:
lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 11.04
Release: 11.04
Codename: natty
uname -a
Linux autobot 2.6.38-8-server #42-Ubuntu SMP Mon Apr 11 03:49:04 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux
I think the relevant line is:
Checking for ability to link against libxml2...libxml2, zlib, and/or the Math library (-lm) have not been found.
So, you've covered off libxml. Have you installed the appropriate zlib package? Try:
sudo apt-get install zlib1g-dev
Then try installing XML::LibXML again.
Why do you want to use CPAN for this anyway? It is typically very bad idea to install CPAN packages if you have native packages provided by standard operating system installer.
Ubuntu provides a lot of Perl packages natively, with following naming convention: package name always starts with lib, then Perl package name like XML::LibXML is converted to lower case and :: replaced to dash - (XML::LibXML => xml-libxml), and finally -perl suffix is added. In other words, native package name for XML::LibXML would be libxml-libxml-perl.
So, in your case, you simply run this command and it will pull all necessary dependencies automatically:
sudo apt-get install libxml-libxml-perl
If you don't like this package for any reason you can uninstall it with sudo apt-get remove. If you use CPAN, it is very difficult to uninstall it reliably.
Overlooked the obvious:
sudo apt-get install --reinstall zlibc zlib1g zlib1g-dev
then:
sudo cpanm XML::LibXML
works!
Maybe this is new version. I did:
sudo apt-get install libxml2-dev
After this module builded and installed successfully