What is the proper way to insert a variable into a file path in BASH? - bash

I am working on my first script and it has been going well aside from one thing. The script is meant to be a simple script to install a software on Ubuntu devices for work. The main problem I am running into is the path the package is downloaded to is /home/(the user)/Linux_Test (custom file I have in github). Since this is suppose to run on multiple machines I am trying to make the user part of the path a variable. Currently I have
# Install the Agent.
sudo dpkg -i "/home/$USERNAME/Linux_Test/'SentinelAgent_linux_v22_1_2_7 (1).deb'"
and the error it is throwing is:
dpkg: error: cannot access archive '/home//Linux_Test/'SentinelAgent_linux_v22_1_2_7 (1).deb'': No such file or directory
I have changed the variable from "USERNAME" to just "USER" but that attempts to run it as root.

Related

ROS Noetic environment setup (directory not found)

After I installed Ros Noetic with this command - sudo apt install ros-noetic-desktop-full. There are 2-3 errors which are of not being able to fetch a few packages(armadillo and other). I downloaded them later.
But after I typed this command - source /opt/ros/noetic/setup.bash, I got this error of - no such file or directory. I then added this command in .bashrc file and removed it after one execution realizing this file cannot be found by the computer (may be a different location but still can't locate). Then I reinstalled ROS noetic, this time in another folder I made .... and I still cannot locate the file and I am getting the same error again. I am using Oracle VM VirtualBox Manager with UBUNTU_20.04. I also installed Guest editions(for full screen purposes)

How to run nvm command from bash file in GCP Cloud Shell (global install)?

What we're trying to do
We are using Cloud Shell Editor (IDE) on GCP.
According to the documentation for Environment customization script:
Cloud Shell automatically runs the script,
$HOME/.customize_environment, when your instance boots up. Unlike
.profile or .bashrc, this script runs once when Cloud Shell boots
(rather than once for each shell login).
This script runs as root and you can install any packages that you
want to exist in each Cloud Shell session using Debian package
management commands.
For example, if you'd like to have erlang installed on Cloud Shell,
your .customize_environment file will look like this:
#!/bin/sh
apt-get update
apt-get -y install erlang
We are trying to pre-install node versions and automate configuration for our developers using nvm.
Where we have issues
We've looked into several articles on making nvm callable from within a bash script file (the .customize_environment file):
nvm command not available in bash script
Can't use nvm from bash script
Node Version Manager install - nvm command not found
None of these answers seem to resolve our issue.
GCP nvm details
Cloud Shell pre-installs nvm (globally); it is located at /usr/local/nvm/nvm.sh.
There is no ~/.nvm folder.
I can run nvm without issue from Cloud Shell (command line) directly.
I cannot run nvm (nor using the for path) from a bash file.
Closest attempt
Running the following comes close, but I'm limited on privileges that you can't sudo around due to Cloud Shell limitations:
. /usr/local/nvm/nvm.sh
nvm install 14
Results in:
Downloading and installing node v14.15.4...
mkdir: cannot create directory ‘/usr/local/nvm/.cache/bin/node-v14.15.4-linux-x64’: Permission denied
creating directory /usr/local/nvm/.cache/bin/node-v14.15.4-linux-x64/files failed
Downloading https://nodejs.org/dist/v14.15.4/node-v14.15.4-linux-x64.tar.xz...
Warning: Failed to create the file
Warning: /usr/local/nvm/.cache/bin/node-v14.15.4-linux-x64/node-v14.15.4-linux-
Warning: x64.tar.xz: No such file or directory
curl: (23) Failed writing body (0 != 966)
Binary download from https://nodejs.org/dist/v14.15.4/node-v14.15.4-linux-x64.tar.xz failed, trying source.
grep: /usr/local/nvm/.cache/bin/node-v14.15.4-linux-x64/node-v14.15.4-linux-x64.tar.xz: No such file or directory
Provided file to checksum does not exist.
Binary download failed, trying source.
Detected that you have 4 CPU core(s)
Running with 3 threads to speed up the build
mkdir: cannot create directory ‘/usr/local/nvm/.cache/src’: Permission denied
creating directory /usr/local/nvm/.cache/src/node-v14.15.4/files failed
Downloading https://nodejs.org/dist/v14.15.4/node-v14.15.4.tar.xz...
Warning: Failed to create the file
Warning: /usr/local/nvm/.cache/src/node-v14.15.4/node-v14.15.4.tar.xz: No such
Warning: file or directory
curl: (23) Failed writing body (0 != 965)
Binary download from https://nodejs.org/dist/v14.15.4/node-v14.15.4.tar.xz failed, trying source.
grep: /usr/local/nvm/.cache/src/node-v14.15.4/node-v14.15.4.tar.xz: No such file or directory
Provided file to checksum does not exist.
Important lines: mkdir: cannot create directory ‘...’: Permission denied
I can't sudo around it, run usermod (e.g. usermod -a -G staff $(whoami)), even though Google's documentation says I should be able to:
When you set up a Cloud Shell session, you get a regular Unix user account with a username based on your email address. With this access, you have full root privileges on your allocated VM and can even run sudo commands, if you need to.
Question
How can we use nvm within a bash script file in GCP's Cloud Shell?
I managed to resolve this with the help of comments by #Kolban and #HarshManvar.
I assume this solution would also work for any other scripts that aren't working with direct calls from .customize_environment.
The example below is influenced by the answer found here. The code installs a specific node version.
Note: nvm is globally installed in Cloud Shell by default.
#!/usr/bin/bash
sudo su -c '. /usr/local/nvm/nvm.sh && nvm install 14'

Aws CLI installation error on windows system

when i tried to install aws cli on cmd(Windows). i am getting message first later its continued.you can see below
By the way I added path in environmental variable like that
after finish intallation i get this message
but still i am getting this message .what should i do please help me .
aws' is not recognized as an internal or external command,
operable program or batch file.
see the error message during the installation, "Defauling to user installation because normal site-packages is not writable". So it has been installed inside your user directory.
to find out the user installatiion directory.
you can open a python prompt by entering the command python in the command line
import sys package import sys
check the output of sys.path
then you can add the script directoy of the python path to the PATH environment variable
Usually the installation location should be c:\users\[username]\AppData\Roaming\Python\Python38\scripts/aws.exe
your python version might be different.
You should also add c:\users\[username]\AppData\Roaming\Python\Python38\scripts to your path.
update: you can also use pip show awscli to see where the module is installed

Cannot access RIDE robot framework from other users in same machine

I installed Robotframework RIDE with my user credentials and trying to access that by logging in with the another user in the same machine. when i copy paste the ride.py(available in C:/Python27/Scripts) file from my user to another user i can access RIDE by double clicking the ride.py file, but when i try to access using ride.py through command line i am not able access RIDE showing a error msg as "ride.py is not recognised as an internal or external command, operable program or batch file ". Installed python for all users and again re installed everything through pip in C:/Users, previously installed in C:/Users/MyUser. While i am trying to re install everything using pip in C:\Users it is showing as "Requirement already satisfied"
This error indicates that ride.py is not in the %PATH% sys variable:
"ride.py is not recognised as an internal or external command, operable program or batch file ".
Usually RIDE lives at C:\Python27\Lib\site-packages\robotide
You may try to run it with the full path in the command:
pythonw C:\Python27\Lib\site-packages\robotide\__init__.py
You may check if there is C:\Python27\Scripts\ride.py and the %PATH% variable for the other users (better to change it a System level).
About the error "Requirement already satisfied" from pip, that may be because:
1. RIDE is correctly installed (but you missed to run it in the first error)
2. You were calling a different pip install
finally got the solution, problem is not with the other users or installation, it is ride.py file which is missing in 'C:\Python27\Scripts' folder i replaced that file and now i am able to access ride.py from command prompt for all users in the machine.
Check the directory where you have the ride(Python file).
Upon opening the command prompt , for me the default path is C:\Users\etwxxbe.
Copy paste the ride(Python file) in the default path ,here the directory is etwxxbe.
Then use the command C:\Users\etwxxbe>ride.py to open ride.

MacPorts Installation -- Shell Commands/Postflight Script

I had run the MacPorts installer (2.0.3) for my OS X Leopard (10.5.8) which finished "successfully". Unfortunately the port command was not available so I looked in the MacPorts Guide which says that the installer should have run a so-called "postflight" script that sets the necessary environment variables. I tried to run the postflight script manually (which I downloaded from here), but the execution fails with the following output:
Detected the bash shell.
Your shell already has the right PATH environment variable for use with
MacPorts!
Your shell already has the right MANPATH environment variable for use with
MacPorts!
Your shell already has the right DISPLAY environment variable for use with
MacPorts!
Adding [default] tag to sources.conf if needed...
couldn't read file "/Contents/Resources/upgrade_sources_conf_default.tcl": no
such file or directory
Updating port image format...
couldn't read file "/Contents/Resources/images_to_archives.tcl": no such file or
directory
Synchronizing the MacPorts installation with the project's rsync server...
-bash: __PREFIX__/bin/port: No such file or directory
An attempt to synchronize your recent MacPorts installation with the project's
rsync server failed!
Please run 'sudo port -d selfupdate' manually to find out the cause of the
error.
You have succesfully installed the MacPorts system, launch a terminal and try it
out!
Read the port(1) manual page and http://guide.macports.org for help,
http://www.macports.org/contact.php if you need to get in touch with The
MacPorts Project.
Any ideas?
First invoke the port command directly:
$ /opt/local/bin/port help
If that comes back with something reasonable (like the help text) then it's just that your $PATH isn't being used by your current shell. Try logging off and back on again to resolve that in the short term (this will test that your .bashrc file is correctly configured) or you could just modify the PATH environment variable directly (which doesn't test .bashrc):
$ export PATH=$PATH:/opt/local/bin
You downloaded the postflight script but it alone cannot access the accessory scripts in Contents/ because those are located into the install package.
Those missing Tcl scripts are for upgrading from an older install, the log says PATH was already correctly configured but the macports bin directory could have the wrong position in PATH variables, for instance being at the end of PATH.
If you are doing a fresh install you can just only need PATH and MANPATH -you want man pages provided by macports before system's ones- as per [1]
[1] http://guide.macports.org/#installing.shell.postflight

Resources