How to make a script with apt-get commands? - shell

I'm doing a script which installs a tcl plugin.
But this tcl plugin require some additional tcl/tk libraries, so I was thinking about putting an APT-GET install command for installing these libraries.
Is there a way to use the APT-GET install command in a script (it can be Shell script, Perl or even Tcl)?

This is an example of how to do it with one line and assumes you are running the script with sudo or have appropriate privilege.
apt-get -qq update && apt-get -qq --yes --force-yes install tcl
-qq suppresses output unless an error occurs
--yes answers the prompt 'Do you want to continue? [Y/n]'
--force-yes installs packages that come from a private repository
Consider running apt-get update & earlier in the script. Check or wait for the job to finish before using apt-get install
You can list multiple packages on one line. Packages are installed in the order they are listed.

Related

Install python 3.6 in Ubuntu

I'm running some Python script in my bitbucket pipeline.
where it's running in Ubuntu version 16.04.
following is my script.
add-apt-repository ppa:deadsnakes/ppa -y && apt-get update
apt-get -y install python3.6
apt-get -y install python3-pip
pip3 install tq1
pip3 install zstd
When trying to print
python3 -V
it's returning
Python 3.5.2.
Why it's not Python 3.6.x ?
Please note I must need Python 3.6 to run tq1.
It's a script on your device, right? Can't you just edit the lines?
sudo add-apt-repository ppa:deadsnakes/ppa -y
sudo apt-get update
sudo apt-get -y install python3.6 python3-pip
pip3 install tq1 zstd
Also, you don't need a script to install those. They're just bash commands. You can just type them line-by-line into the terminal...
Check the image on your pipeline, because if you install python 3.6 in one step and execute the python3 -V command in another, it will take the version of the image, not the one from the previous step, since they are in a different container, it would be helpful if you show us the rest of the pipeline

How do you create an apt-get package

I have a .out file for a project I am working on and I would like it available to download with an apt-get command. I wanted the apt-get command to be like sudo apt-get install packageName. I am using elementary OS, which is built off of Ubuntu. I also have the project posted on github.
I think equivs is the easiest. You can install with:
sudo apt-get install equivs
With equivs-control command you can create a blank spec file and build your deb package with equivs-build command.

apt-get with quiet option is still noisy

Trying to use apt-get in a script, so I'm using the apt-get -qq -y option, as I want to have my install script show something like...
Installing SUDO....DONE
But for some reason apt-get is still producing lots of output, with this option, which means I end up getting...
Installing SUDO....
Selecting previously unselected package sudo.
(Reading database ... 48056 files and directories currently installed.)
Preparing to unpack .../sudo_1.8.10p3-1+deb8u5_amd64.deb ...
Unpacking sudo (1.8.10p3-1+deb8u5) ...
Processing triggers for man-db (2.7.0.2-5) ...
Processing triggers for systemd (215-17+deb8u5) ...
Setting up sudo (1.8.10p3-1+deb8u5) ...
DONE
So my install script just looks messy for a basic package install, let alone for all the other packages.
Am I missing something?
Try to run sudo DEBIAN_FRONTEND=noninteractive apt-get install -qq sudo < /dev/null > /dev/null
Source: https://peteris.rocks/blog/quiet-and-unattended-installation-with-apt-get/
here is an example that is totally quiet and does not output any line on my machine including warnings. Used 2>/dev/null to disable warnings as well
!apt install octave -qq 2>/dev/null >/dev/null;

Docker Install Wine Dockerfile EULA

I have a little problem to install Wine on my alpine image.
Here is my Dockerfile :
RUN dpkg --add-architecture i386 && sudo apt-get update
RUN sudo apt-get install software-properties-common python-software-properties
RUN sudo add-apt-repository ppa:ubuntu-wine/ppa
RUN sudo apt-get update
RUN sudo apt-get install wine1.8 winetricks
RUN sudo apt-get purge software-properties-common python-software-properties
RUN rm -rf /tmp/* /var/lib/apt/lists/* /root/.cache/*
CMD /bin/bash;
All seems to work well, but during the sudo apt-get install wine1.8 winetricks I have this EULA screen :
Of course I don't have the right to write "YES". I tried :
RUN echo "yes" | sudo apt-get install wine1.8 winetricks
RUN sudo apt-get -y install wine1.8 winetricks
What can I do ?
Note: In the interest of edification, I would love it if a more learned linux/docker user could explain the mechanics behind why my solution worked for me.
Possible Solution:
I encountered this exact problem. I must have tried every conceivable way to pass an argument via my Dockerfile that would accept the EULA; to include piping an echo of "yes" to the wine installation command, as you've tried, setting environment variables and so-on. So, you're not alone here. I did, however, find a very simple solution through experimentation.
It turns out that if you install the TrueType core fonts (the package the EULA is for) before installing wine, you can pass it the "yes" input like so and wine will never prompt for the EULA:
RUN echo "yes" | apt install ttf-mscorefonts-installer -y
I'm not sure why this is. I suspect that it's because installing wine installs several other packages/dependencies in the process, and the echo/pipe approach does not extend to all packages that wine attempts to install. Perhaps by installing the fonts separately, the wine installation script either disregards the package because it's already present, or some file within the font installation logs the EULA acceptance response.
Here's the contents of my Dockerfile. I'm on Ubuntu 16.04 LTS, using Docker version 18.02.0-ce, build fc4de44:
FROM ubuntu:16.04
RUN dpkg --add-architecture i386
RUN apt-get update -y
RUN echo "yes" | apt install ttf-mscorefonts-installer -y
RUN apt-get install wine -y
I see it's four months since this post was made, but if you haven't found a solution, I hope this helps!

shell script to install a package if not alreay installed

I have made a C program, but it depends on the ncurses library. So, when i give my code to anyone else, I have to ask him/her to install ncurses library first then only compile the code using the Makefile i provided.
However, I want to write a shell script which will automatically install ncurses if it is NOT already installed. So that I can simply ask my friend to run the script.
This is what i want the script to do ::
if(ncurses-dev package not installed)
sudo apt-get install ncurses-dev
I know it is a very basic question, but i dont know how to do it. I tried google search but could not find a simple tutorial which i could understand.
For fedora
if ! rpm -qa | grep -qw $package_name$; then
yum install $package_name
fi
For UBUNTU
#!/bin/sh
for package; do
dpkg -s "$package" >/dev/null 2>&1 && {
echo "$package is installed."
} || {
sudo apt-get install $package
}
done
This can be used for checking multiple packages as well.
To automatically install without user interaction on Debian(In your case Ubuntu), you could use the --force-yes --yes switches in your command line args list. Like so:
sudo apt-get --force-yes --yes install package

Resources