Apt error: File on system created by you or by a script - apt

I have a simple bash script that connects to a series of servers and updates a specific package, using a here-string to answer a prompt:
sudo /usr/bin/apt-get install package-name <<< Y
The prompt is:
Configuration file /etc/package-name/package-name.conf
==> File on system created by you or by a script.
==> File also in package provided by package maintainer.
What would you like to do about it? Your options are:
Y or I : install the package maintainer's version
N or O : keep your currently-installed version
D : show the differences between the versions
Z : background this process to examine the situation
The default action is to keep your current version.
*** package-name.conf (Y/I/N/O/D/Z [default=N] ?
This is the error when it doesn't work:
dpkg: error processing package-name (--configure):
EOF on stdin a conffile prompt
Errors were encountered while processing:
package-name
I'm not able to install expect or any other programs on the servers. Any help would be appreciated.

You should pass in a dpkg option to specify at the prompt the desired behavior in this scenario. Then it won't prompt.
sudo apt-get -o DPkg::Options::="--force-confnew" -y install package-name
(Untested; obtained by googling.)

If you look at the apt-get man page, you can find an option (-y) to answer yes for you. Why not try that.

Related

can't use pip when I activate venv

Most of you may know OpenAI playground, so I built an function generator app and followed all the instructions but I can't launch it via venv-python. I can actually install the requirements using pip while venv is not active and can launch the site with flask, but when I try to install requirements after activating venv, I get this error;
User#lalec ~
$ cd openai-quickstart-python
User#lalec ~/openai-quickstart-python (master)
$ . venv/Scripts/activate
(venv)
User#lalec ~/openai-quickstart-python (master)
$ pip install -r requirements.txt
Fatal error in launcher: Unable to create process using '"C:\Users\celal\openai-quickstart-python\venv\Scripts\python.exe" "C:\Users\User\openai-quickstart-python\venv\Scripts\pip.exe" install -r requirements.txt': The system cannot find the file specified.
How do I fix this? I added every possible script locations into PATH I thought it would help but no result.
I just realized two directories in the error doesn't match, and "C:\Users\celal\openai-quickstart-python\venv\Scripts\python.exe" actually does not even exist. Maybe that's the problem... How can I change this ??
Sorry if I'm asking dumb questions I'm new to all this... Also, I don't get why I need venv activated while I can just launch it by accessing the directory and type flask run in cmd, would appreciate any answers.
ss of the project's directory
ss of venv/Scripts/
ss of bash screen with errors
The error message suggests that the requirements.txt file can't be read. Check that you definitely can read it and it's in the expected location.
The perferred command for running pip is:
python3 -m pip install -r requirements.txt
This makes sure that you know which python3 binary you're running pip with - some systems have more than one python3 binary in various locations.
You could achieve similar without activating the virtual environment:
./venv/bin/python3 -m pip install -r requirements.txt

How to change pythonpath to use Python 3.9 and venv

I am trying to get to grips with Python on my Mac running OS X 10.15.7 Catalina.
My goal is to be able to run a program requiring Python 3.9 and associated libraries, in its own virtual environment, using venv.
My quest has led me over many rocky paths and blind alleys - including via Anaconda and Brew.
I am running zsh - specifically oh-my-zsh ys version. If that's important. Most online forums and tutorials assume bash. I would prefer to do all in zsh to avoid having to edit both zsh and bash profiles.
Current Shell Outputs
$ python -V
Python 2.7.16
$ which python
/usr/bin/python
$ python3 -V
Python 3.8.2
$ which python3.8
python3.8 not found
$ which python3.9
python3.9 not found
$ python3 -m -V
/Library/Developer/CommandLineTools/usr/bin/python3: No module named -V
Pausing there ..
Py 2.7 is the OS X system Python and I don't want to do anything with it.
It is odd that python3 -m returns a reference to the CLI tools. See below. The only location for py3.8 is in the CL tools.
What pythons do I have (output below is edited so as to show only main directories and Files)?
$ locate python
/Applications/LibreOffice.app/Contents/Frameworks/LibreOfficePython.framework/Versions/3.7/bin/python3
/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/bin/python3.8
/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
/Library/Developer/CommandLineTools/usr/bin/python3.8
/Library/Frameworks/Python.framework/Versions/3.9/bin/python3
/Library/Frameworks/Python.framework/Versions/3.9/bin/python3-config
/Library/Frameworks/Python.framework/Versions/3.9/bin/python3.9
/Library/Frameworks/Python.framework/Versions/3.9/bin/python3.9-config
/Library/Frameworks/Python.framework/Versions/3.9/share/man/man1/python3.1
/Library/Frameworks/Python.framework/Versions/3.9/share/man/man1/python3.9.1
/Library/Frameworks/SAVI.framework/Versions/A/Frameworks/Python.framework/Versions/3.6/lib/python3.6
/usr/bin/python
/usr/bin/python-config
/usr/bin/python2
/usr/bin/python2.7
/usr/bin/python2.7-config
/usr/bin/python3
/usr/bin/pythonw
/usr/bin/pythonw2.7
/usr/lib/libpython.dylib
/usr/lib/libpython2.7.dylib
/usr/lib/python2.7
/usr/local/bin/python3
/usr/local/bin/python3-config
/usr/local/bin/python3.9
/usr/local/bin/python3.9-config
/usr/share/file/magic/python
/usr/share/man/man1/python.1
/usr/share/man/man1/python2.7.1
/usr/share/man/man1/pythonw.1
/usr/share/man/man1/pythonw2.7.1
/usr/share/vim/vim81/autoload/python3complete.vim
/usr/share/vim/vim81/autoload/pythoncomplete.vim
/usr/share/vim/vim81/ftplugin/python.vim
/usr/share/vim/vim81/indent/python.vim
/usr/share/vim/vim81/syntax/python.vim
/usr/share/zsh/5.7.1/functions/_bpython
/usr/share/zsh/5.7.1/functions/_python
/usr/share/zsh/5.7.1/functions/_python_modules
WHAT ABOUT PIP?
$ pip3
WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.
$ pip3 install --upgrade pip
WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: pip in ./Library/Python/3.8/lib/python/site-packages (20.3.3)
Note two points
Although the wrapper warning comes up, PIP 20.3.3 is latest version which I have upgraded. Probably the reason for the warning is in the next lines, which suggest that PIP3 is being invoked from the CL Tools.
2; The ‘normal site-packages is not writeable’ error is supposed to be cured by specifying the Path. I have tried already to specify the correct path - see below - but this has not cured the problem and is another major reason for asking the question at the end of this post.
$ python -m pip
/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python: No module named pip
$ python3 -m pip
Usage:
/Library/Developer/CommandLineTools/usr/bin/python3 -m pip <command> [options]
$ which pip3
/usr/bin/pip3
$ locate pip3
/Applications/LibreOffice.app/Contents/Frameworks/LibreOfficePython.framework/Versions/3.7/bin/pip3
/Applications/LibreOffice.app/Contents/Frameworks/LibreOfficePython.framework/Versions/3.7/bin/pip3.7
/Library/Developer/CommandLineTools/usr/bin/pip3
/Library/Developer/CommandLineTools/usr/bin/pip3.8
/Library/Frameworks/Python.framework/Versions/3.9/bin/pip3
/Library/Frameworks/Python.framework/Versions/3.9/bin/pip3.9
/usr/bin/pip3
/usr/local/bin/pip3
/usr/local/bin/pip3.9
SYSTEM FILES
~/.zprofile contents - edited a few times to remove references to virfualenv and penv, both originally installed with brew and now removed. I have run brew uninstall and brew remove to try to clean everything up but may not have succeeded.
Start
# THIS FILE COMMENTED OUT RH 21DEC20
## Setting PATH for Python 3.9
## The original version is saved in .zprofile.pysave. **Note in this post only - cannot find this file**
PATH="/Library/Frameworks/Python.framework/Versions/3.9/bin:${PATH}"
export PATH **Note in this post only - this does not seem to have worked - see above Python3 -V**
# export WORKON_HOME=~/.virtualenvs
# mkdir -p $WORKON_HOME
# . ~/.pyenv/versions/3.9.0/bin/virtualenvwrapper.sh
# eval "$(pyenv init -)"
# # AND THESE LINES ADDED FOLLOWING STACKOVERFLOW Q 33216679 **Note in this post only - commented out as shell threw errors .’cannot find virtualenvwrapper.sh**
# export WORKON_HOME=$HOME/.Envs
# # export VIRTUALENVWRAPPER_PYTHON=$/usr/bin/python3
# export VIRTUALENVWRAPPER_PYTHON=$/usr/local/bin/python3
#source $HOME/.local/bin/virtualenvwrapper.sh
END
Finally a word about Brew. Many tutorials advised the use of Brew to install Python, pyenv, and libraries etc. I did that and successfully created a test environment, but could not the utilise it. I have then removed as much as possible in order to get back to a ‘clean’ state to work with.
Current brew status is
$ brew doctor
Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don't worry or file an issue; just ignore this. Thanks!
Warning: Unbrewed dylibs were found in /usr/local/lib.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.
Unexpected dylibs:
/usr/local/lib/libdvdcss.2.dylib
/usr/local/lib/libfuse.0.dylib
/usr/local/lib/libulockmgr.0.dylib
Warning: Unbrewed header files were found in /usr/local/include.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.
Unexpected header files:
/usr/local/include/ulockmgr.h
Warning: Unbrewed .la files were found in /usr/local/lib.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.
Unexpected .la files:
/usr/local/lib/libulockmgr.la
Warning: Unbrewed static libraries were found in /usr/local/lib.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.
Unexpected static libraries:
/usr/local/lib/libfuse.a
/usr/local/lib/libulockmgr.a
SUMMARY
My first goal is to set Py3.9.x as default for new projects. I think also this would require/imply that pip and other commands run from v3.9 and not any other version or location. Must admit to being hazy about that.
Then I want to be able to create a virtual environment into which I can put the program I want to run and its associated libraries and packages. Doing this implies using terminal, but I need to know which directory I need to be in to run which commands.
At this point I have also been running into confusion with tutorials on how to create a virtual environment. From what I have read I think I should use venv over pyenv. What is not clear is whether I run the venv command (s) from root, or whether I have to create and cd to a different location, and if so what.
Any help in
1 Changing the default Python to 3.9
2 Creating a venv to use v3.9.
3 What commands to run where.
Will be greatly appreciated. Please keep it simple and don't assume any prior knowledge!
This is what I would do :
# For 1 Changing the default python to 3.9
cd /usr/local/bin
sudo ln -fs /Library/Frameworks/Python.framework/Versions/3.9/bin/python3.9 python3
sudo ln -fs python3 python
# And make sure /usr/local/bin is before (/usr/bin and /Library/Developer/CommandLineTools/usr/bin) in your $PATH
# For 2 Creating a venv to use v3.9
/usr/local/bin/python3.9 -m venv /tmp/python3.9-venv

Avoid yum error when a package is already installed

I am using AWS Elastic Beanstalk on a Linux machine and need to install some fonts in .ebextensions:
container_commands:
01_getfont:
command: sudo yum -y install http://somesite.com/rpm/webcore-fonts-3.0-1.noarch.rpm
That works well the 1st time, with the fonts installed.
The 2nd time when I deploy the EB again, it now gave me this error:
Application update failed at 2019-01-28T23:44:14Z with exit status 1 and error: container_command 01_getfont in .ebextensions/fonts.config failed.
Loaded plugins: priorities, update-motd, upgrade-helper
Examining /var/tmp/yum-root-0Yx1DY/webcore-fonts-3.0-1.noarch.rpm: webcore-fonts-3.0-1.noarch
/var/tmp/yum-root-0Yx1DY/webcore-fonts-3.0-1.noarch.rpm: does not update installed package.
Error: Nothing to do.
How do I avoid getting that errors when that package has been installed on the same EC2 instance the 2nd time?
I found out the answer to this problem later, posting it here for the benefits of others with similar issue.
I use reinstall instead:
sudo yum -y reinstall http://somesite.com/rpm/webcore-fonts-3.0-1.noarch.rpm
This will work the 1st time and all other times of deployment.
Edit:
The above does not work as well as reinstall will fail if package is not installed. I ended up detecting if the package has been installed, if not, install it else re-install:
command: sudo yum -q list installed webcore-fonts.noarch &>/dev/null && sudo yum -y reinstall http://somesite.com/rpm/webcore-fonts-3.0-1.noarch.rpm || sudo yum -y install http://somesite.com/rpm/webcore-fonts-3.0-1.noarch.rpm
Use the packages directive:
packages:
rpm:
webcore-fonts: http://somesite.com/rpm/webcore-fonts-3.0-1.noarch.rpm
This will handle not installed and already installed scenarios.
Yum can return a non-zero exit status for things that are not really errors, causing higher-level systems such as Elastic Beanstalk to think the script has failed.
In particular, yum sometimes says "Nothing to do" with exit status of 1 - this can mean various things but includes the case where required packages are already installed.
The way I work around this for scripts using yum is:
yum -y install somepackage
if [ $? -ne 1 ]; then # Exit on any any error except 'nothing to do'
exit 0
fi
A simpler way is just to ignore all errors by appending a true or exit 0 command - however, this is eventually going to bite you when the Yum repo is unreachable, or Yum has out of date metadata, etc.
Advanced tip
If you have several yum commands, or more error codes to handle, you might want to read up on the shell trap command, specifically on EXIT or ERR which lets you handle these cases in a single place, and potentially not exit on unwanted errors. See this stack for more on this.
Alternative for local installs
See this answer for more, including a simple alternative when installing RPMs that you have downloaded.

Quiet output from pip via requirements file?

pip has a -q/--quiet flag that works ideally from the command line. I'm using an automated deployment process (Amazon Elastic Beanstalk), and the tools use pip to install from a requirements file.
Unfortunately, pip is generating non-error output that's causing EB to abort due to its logger being unable to handle non-ASCII output.
Since I can't apply the quiet flag to the pip command directly (it's run automatically), is there a per-line flag I can set in my requirements file or an environment variable that would suppress pip's output?
Pip offers the --quiet / -q option to silence output. Example:
pip install -q -r requirements.txt
After more digging, this is a pending feature request for pip in github:
https://github.com/pypa/pip/issues/271
Temporary workaround: Using a separate bash script to invoke pip per-line until this is implemented, published, and available on Elastic Beanstalk.

how to ensure yum install was successful in a shell script?

I have a shell script which checks if there is an internet connection (by pinging google), and then calls
yum install packageA packageB --assumeyes
How would I confirm that the packages were installed (or were already installed)? Do I make another yum call and parse the output (I presume this gets very complicated if the system is in another language)?
I've used the following method, which might not be foolproof, but seems to work:
Assuming the variable PACKAGES contains the list of packages you want to install, then:
Run yum -y install $PACKAGES (I assume if this is a script, you really want to pass -y to avoid prompting).
Check its exit status in order to detect some failure conditions.
Run rpm --query --queryformat "" $PACKAGES, which will output nothing for each package that was installed successfully, and will output package <name> is not installed for each failure.
Check its exit status, which appears to be the number of packages that were not successfully installed, i.e. will be 0 on success as usual.
This will only work if PACKAGES contains plain package names that yum is expected to find in a repository, not if it contains other things that yum accepts like URLs, file names or Provides: names.
Based on this random post, it looks like yum returns an error code to the shell. You can test this out by running a command and then immediately (as the next command) doing:
echo $?
That will print the previous command's return code. Success should be 0, failure of some kind nonzero. But that's just a guess since I don't have a box accessible to me at the moment. :)
By ping google.com does not ensure the yum repo you trying to connect is available
The command to check whether a package is already installed :-
yum list installed PACKAGE_NAME

Resources