scripting yum to install a list of packages - bash

I am having trouble getting yum to work with a list of packages I want to install. I've tried:
yum -y install $(cat /home/pkglist.txt)
and
for i in cat pkglist.txt; do yum -y install $i; done
and
yum -y install $(cat pkglist.txt | tr '\n' ' ' | tr '\r' ' ')
but none of them install the packages.
All I get back is:
Loaded plugins: product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Setting up Install Process
available.perl-CPAN
available.cpp
available.fontconfig
available.gcc
available.gd
available.net-snmp-libs
available.mailcap
available.perl-libwww-perl
available.perl-XML-LibXML
available.perl-DateTime
available.perl-Time-HiRes
available.make
available.net-snmp-perl
available.perl-Test-Pod
available.perl-Net-SSLeay
available.expat-devel
available.expat
Error: Nothing to do
Thanks in advance! -Luke

You can this-
cat /home/pkglist.txt | xargs yum -y install

Related

how to use grep with logical operator AND

when searching for packages, i'm using grep, if not installed, i have to install it using shell script as mentioned below:
if
list packages installed | grep rap | grep rap-devel
## only if both are installed then exit with status 0
else
install the missing packages
How should I do this?
I tried this but its very lengthy
yum installed packages | grep rap
if $? = 1
yum install rap
yum installed packages | grep rap-devel
if $? = 1
yum install rap-devel
And I dont think its a good practice to do like this. Can anyone help me to shorten this? what if there still more to search and install 🥲
use && and || operate:
(yum installed packages | grep rap || yum install rap) && (yum installed packages | grep rap-devel || yum install rap-devel)
for more search packages in the list:
pack_list=(rap rap-devel)
for i in "${pack_list[#]}"; do yum installed packages | grep rap || yum install rap; done
or if it could, you could use which rap instead of yum installed packages | grep rap.

Error in yaml code could not find expected ':'

yaml code
- hosts: all
tasks:
#Import Remi GPG key - see: http://rpms.famillecollet.com/RPM-GPG-KEY-remi
wget http://rpms.famillecollet.com/RPM-GPG-KEY-remi \ -O /etc/pki/rpm-gpg/RPM-GPG-KEY-remi
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-remi
#Install Remi repo
rpm -Uvh --quiet \
http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
Install EPEL repo.
yum install epel-release
Install Node.js (npm plus all its dependencies).
yum --enablerepo=epel install node
I am getting following error when compiling: ERROR! Syntax Error while loading YAML.
The error appears to have been in '/home/shahzad/playbook.yml': line
7, column 3, but may be elsewhere in the file depending on the exact
syntax problem.
The offending line appears to be:
wget http://rpms.famillecollet.com/RPM-GPG-KEY-remi \ -O /etc/pki/rpm-gpg/RPM-GPG-KEY-remi
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-remi
^ here
exception type: <class 'yaml.scanner.ScannerError'>
exception: while scanning a simple key
in "<unicode string>", line 6, column 3
could not find expected ':'
in "<unicode string>", line 7, column 3
I installed everything from the instructions above, but i used the installer alien for converting and installing rpm packages on Ubuntu 18.04.
But you will not be able to install with yum, since some packages are not in its list.
use alien:
# apt install alien # apt install -y
# cd /tmp
# wget http://rpms.famillecollet.com/RPM-GPG-KEY-remi \ -O /etc/pki/rpm-gpg/RPM-GPG-KEY-remi
# wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
# alien -kiv remi-release-6.rpm
# ls -l
# wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
# alien epel-release-latest-8.noarch.rpm
# ls -l
# alien -k epel-release-latest-8.noarch.rpm ; alien -i epel-release-latest-8.noarch.rpm
# cd /home/user
# apt install curl gcc g++ make # apt install -y
# curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
# apt install nodejs # apt install -y
# curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
# echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
# apt update ; sudo apt install yarn # apt install -y
# apt install nodejs ; apt upgrade ; passwd -dl root ; reboot # apt install -y
But i still have the same error Invalid YAML: could not find expected ':':, but on command networkctl it became better for me to see , it says failed (although before installing node.js, remi-release, epel-release it didn't sign it like that) which interfaces are not configured correctly.
IDX LINK TYPE OPERATIONAL SETUP
1 lo loopback carrier unmanaged
2 ens11 ether off unmanaged
3 enp2t1 ether routable configured
4 br0 ether off failed
5 vlan5 ether off configuring
These installed packages let you see the interface error in depth, this method works!!!!!!!! Shahzad Adil shaikh thank your!
I was getting same error while running commands using PowerShell task in yaml.
- task: PowerShell#1
inputs:
scriptType: inlineScript
inlineScript: |
Command1
Commands2
I fixed this error by indenting the commands/script block.
You need to indent Command1 one lever under inlineScript: |.
If you wish to use shell commands in your yaml playbook such as wget, you'll need to use the shell module:
- name: Import Remi GPG key
shell: wget ...
":" is a special character in yaml, please read the YAML Syntax page in the official ansible documentation, for quoting.
As for yum commands, you may use ansible's yum module.
As a best practice, you may use http://www.yamllint.com/ for debugging your YAML syntax, checking for the exact line & column where the parser fails.

Will this bash loop apt-get install all my anaconda packages?

I don't want to just try it and mess something up.
$ dlpackages=$(ls -l anaconda3/bin | awk '{print $9}')
$ for package in $dlpackages; do sudo apt-get install $package; done
or as root: $ for package in $dlpackages; do apt-get install $package; done
Add a safety check for each package, to see if it can be located.
dlpackages=$(ls -l anaconda3/bin | awk '{print $9}')
for package in $dlpackages; do
[[ $(apt-cache search $package) ]] && sudo apt-get install $package
done
Now for every string, the install will only be executed if the package can be found.
Alternatively use the -s option of install as Eric Renouf suggested.
In general things in bin aren't the same as package names. conda list may be closer, but you'll ultimately probably have to figure out the translation of package names manually.

Trying to add a char to the end of each line in a given file, how is it done?

I have a file which looks like that:
sudo apt-get install rar
sudo apt-get install gimp
sudo apt-get install gnome-tweak-tool
sudo apt-get install unity-tweak-tool
sudo apt-get install pidgin
I want to somehow add "-y" in the end of each line, how is it done?
Thanks
sed -i 's:$: -y:' YOURFILE
Will do it for you.
-i does the modification "in place", so no new file created (actully there's a tmp file)
s substitute
:delimiter
$ end of line
see the 3. point
-y replacement
Assuming you want to add -y (change it as you deem appropriate) at the end of each line, you can use sed by saying
$ cat file
sudo apt-get install rar
sudo apt-get install gimp
sudo apt-get install gnome-tweak-tool
sudo apt-get install unity-tweak-tool
sudo apt-get install pidgin
$ sed 's/$/ -y/' file
sudo apt-get install rar -y
sudo apt-get install gimp -y
sudo apt-get install gnome-tweak-tool -y
sudo apt-get install unity-tweak-tool -y
sudo apt-get install pidgin -y
This prints on standard out. If you wish to make in-place changes inside the file, you can use -i option of sed by saying
sed -i 's/$/ -y/' file
or redirect the output to another file by doing
sed 's/$/ -y/' file > newfile
If you are vi mode you can try
:%s/$/text_to_be_added/g and press "Enter"
If you are bash mode you can try
sed 's/$/text_to_be_added/g' filename

How can I make dpkg automatically choose my own virtual package over an already installed one?

I have several packages that provide the same functionality - and in the device
'there can be only one' at the same time.
I have read about the 'Provides, Conflicts, Replaces' in the debian policy, but I have not found a way (using dpkg with commands/switches) to automatically replace an already installed virtual package without removing it manually first.
My package's control file specifies the following for all the packages in question:
Provides: myown-virtual-package
Conflicts: myown-virtual-package
Replaces: myown-virtual-package
Here is what I do, It seems to work, but I was wondering if there is a standard way using only dpkg
# remove any conflicting virtual packages
for i in /tmp/upgrade_software/*.deb
do
# find out what package name and what it provides
provides_line=$(dpkg --info $i | grep "^ Provides: ")
package_line=$(dpkg --info $i | grep "^ Package: ")
virt_package=${provides_line##*: }
this_package=${package_line##*: }
# skip if it is not a virtual package
[ -z "${virt_package}" ] && continue
# remove any package that provides the same
otherpackage_line=$(dpkg-query -W -f='${Provides}: ${Package}\n' \
| grep "${virt_package}:" | grep -v ${this_package})
if [ -n "${otherpackage_line}" ] ; then
otherpackage=${otherpackage_line##*: }
echo " ------ removing ${otherpackage} because of conflict -------"
dpkg --purge ${otherpackage}
echo " -------------"
fi
echo \'$virt_package\' checked for conflicts
done
Thanks in advance, jj
dpkg will not take this kind of automatic conflict resolution measures. For these tasks, there is apt-get and aptitude. It may just work with
dpkg -i package.deb ; apt-get -f install
The latter command is supposed to resolve the conflicts. If it opts to remove your own package for resolution, you may even want to try
dpkg -i package.deb ; apt-get -f install <package>
I.e., tell apt to install your package (without a .deb extension) as it should now be visible to apt.
This can be done with dpkg alone, by giving it enough information so that it can perform the operation. The way to prepare dpkg for this is via selections.
In this case you'd tell that removing the old provider is ok, and then when you install the new one dpkg will be able to remove the other package during the upgrade.
Try something like:
echo old-provider deinstall | dpkg --set-selections
dpkg -iB new-provider.deb
That should in principle do it, and no need for apt-get fixing it up (-f), or for pre purges (possibly with --force options if there are packages depending on the virtuals).

Resources