Capacitor&Gulp problem: node_modules/.bin/cap 'sync' error - node.js

I'm trying to debug an android app which uses a gulpfile.js.
The gulpfile.js, in the app repository, is pointing to 'node_modules/.bin/cap'
And, everytime I run gulp, it ends with an error relating to "android":
[01:30:42] 'android' errored after 206 ms
[01:30:42] Error: Command failed with exit code 1: node node_modules/.bin/cap sync
C:\Users\Tombouctou\floccus\node_modules\.bin\cap:2
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
^^^^^^^
SyntaxError: missing ) after argument list
I tried editing the 'cap' file, with legacy code (backticks). It solves this parenthesis issue, but after I have another issue:
Unexpected token "case".
If I fix that I have again another issue anywhere else on the same file, and so on....
The developer of the app I'm trying to debug, says that it's because I am on Windows but he don't know how to rewrite this line on the gulpfile.js :
const {stdout} = await execa('node', ['node_modules/.bin/cap', 'sync'])
I don't know either.
Do you reckon I should point this line to somewhere else ?
Or do you think I should edit the .bin/cap file and change the code inside, which is :
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
case `uname` in
*CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w "$basedir"`;;
esac
if [ -x "$basedir/node" ]; then
"$basedir/node" "$basedir/../#capacitor/cli/bin/capacitor" "$#"
ret=$?
else
node "$basedir/../#capacitor/cli/bin/capacitor" "$#"
ret=$?
fi
exit $ret
I'm totally lost.
Thanks

Related

What do the files in bin folder actually used for?

I am currently working on a node project that requires eslint as a dependency. Hence, a file named eslint and eslint.cmd was created automatically in the root_directory/node_modules/.bin folder.
The content of the eslint file is -
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
case `uname` in
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
esac
if [ -x "$basedir/node" ]; then
"$basedir/node" "$basedir/../eslint/bin/eslint.js" "$#"
ret=$?
else
node "$basedir/../eslint/bin/eslint.js" "$#"
ret=$?
fi
exit $ret
Can someone give a line-to-line explaination to what exactly this code is doing?
I read the answer on What is the purpose of .bin folder in node_modules?
Still couldn't figure out how this code does all that is stated in the answers.
node version - 12.10.0
npm version - 6.10.3

Use pgrep command in an if statement

I need to have a .sh file that will echo 0 if my python service is not running. I know that pgrep is the command I want to use, but I am getting errors using it.
if [ [ ! $(pgrep -f service.py) ] ]; then
echo 0
fi
Is what I found online, and I keep getting the error
./test_if_running.sh: line 3: syntax error near unexpected token `fi'
./test_if_running.sh: line 3: `fi;'
When I type
./test_if_running.sh
The issue in your code is the nested [ ... ]. Also, as #agc has noted, what we need to check here is the exit code of pgrep and not its output. So, the right way to write the if is:
if ! pgrep -f service.py &> /dev/null 2>&1; then
# service.py is not running
fi
This is a bit simple, but why not just print a NOT'd exit code, like so:
! pgrep -f service.py &> /dev/null ; echo $?
As a bonus it'll print 1 if the service is running.

How to check dependency in bash script

I want to check whether nodejs is installed on the system or not. I am getting this error:
Error : command not found.
How can i fix it?
#!/bin/bash
if [ nodejs -v ]; then
echo "nodejs found"
else
echo "nodejs not found"
fi
You can use the command bash builtin:
if command -v nodejs >/dev/null 2>&1 ; then
echo "nodejs found"
echo "version: $(nodejs -v)"
else
echo "nodejs not found"
fi
The name of the command is node, not nodejs
which returns the path to the command to stdout, if it exists
if [ $(which node 2>/dev/null) ]; then
echo "nodejs found"
else
echo "nodejs not found"
fi
This is not what the OP asked for (nearly 3 years ago!), but for anyone who wants to check multiple dependencies:
#!/bin/bash
echo -n "Checking dependencies... "
for name in youtube-dl yad ffmpeg
do
[[ $(which $name 2>/dev/null) ]] || { echo -en "\n$name needs to be installed. Use 'sudo apt-get install $name'";deps=1; }
done
[[ $deps -ne 1 ]] && echo "OK" || { echo -en "\nInstall the above and rerun this script\n";exit 1; }
Here's how it works. First, we print a line saying that we are checking dependencies. The second line starts a "for name in..." loop, in which we put the dependencies we want to check, in this example we will check for youtube-dl, yad and ffmpeg. The loop commences (with "do") and the next line checks for the existence of each command using the bash command "which." If the dependency is already installed, no action is taken and we skip to the next command in the loop. If it does need to be installed, a message is printed and a variable "deps" is set to 1 (deps = dependencies) and then we continue to the next command to check. After all the commands are checked, the final line checks to see if any dependencies are required by checking the deps variable. If it is not set, it appends "OK" to the line where it originally said "Checking dependencies.... " and continues (assuming this is the first part of a script). If it is set, it prints a message asking to install the dependencies and to rerun the script. It then exits the script.
The echo commands look complicated but they are necessary to give a clean output on the terminal. Here is a screenshot showing that the dependencies are not met on the first run, but they are on the second.
PS If you save this as an script, you will need to be in the same directory as the script and type ./{name_of_your_script} and it will need to be executable.
You may check the existence of a program or function by
type nodejs &>/dev/null || echo "node js not installed"
However, there is a more sophisticated explanation available here.
I was thinking about this and came up with a few versions, then went on the internet to see what others have to say and ended up here. Albeit an old thread, I'll reply with my thoughts.
First to answer the OP's original question: How can i fix it?
if node -v &>/dev/null; then
echo "nodejs found"
else
echo "nodejs not found"
fi
If you are simply checking if node works, this would do it. But it isn't a very generic way to do it.
Another way is to use command in a loop and collect the missing dependencies (in this example looking for the commands kind and kubectl).
for app in kind kubectl; do command -v "${app}" &>/dev/null || not_available+=("${app}"); done
(( ${#not_available[#]} > 0 )) && echo "Please install missing dependencies: ${not_available[*]}" 1>&2 && exit 1
Or less concisely expressed:
unset not_available # script safety, however not necessary.
for app in kind kubectl; do
if ! command -v "${app}" &>/dev/null; then
not_available+=("${app}")
fi
done
if (( ${#not_available[#]} > 0 )); then
echo "Please install missing dependencies: ${not_available[#]}" 1>&2
exit 1
fi
Then I figured I'd want a way to do the same without a loop, so came up with this:
not_installed=$(command -V kind kubectl 2>&1 | awk -F': +' '$NF == "not found" {printf "%s ", $(NF-1)}')
[[ -n ${not_installed} ]] && echo "Please install missing dependencies: ${not_installed}" 1>&2 && exit 1
The command -V can take any number of entries and posts the result back to stdout and stderr (though I redirect both to stdout for the next command to parse).
awk sets the field separator to <colon><one or more space>, expressed as : +. If the last field contains, "not found", print the second to last field, being the name of the command which is not installed.
Lastly, if the variable contains any data, then report back which dependencies that are missing to stderr and exit the script!
You can do dependency checks in a million ways, but here are a few alternatives which are more generally applicable and not too lengthy while still being easy to follow. :]
If all you want is to check to see if a command exists, use which command. It returns the patch if the command is called, and nothing if it is not found
if [ "$(which openssl)" = "" ] ;then
echo "This script requires openssl, please resolve and try again."
exit 1
fi

Bash script: Syntax error in conditional expression

I'm new around the neighborhood and stuck with a syntax error. Please take a look and maybe someone can assist. I'm trying to run the following script:
#!/bin/bash
main () {
dpkg -query -s $1 &> /tmp/pkg_verify
if grep -q 'not installed' /tmp/verify
then
echo -e "\e[31m$1 is not installed. installing..\e[0m"
apt-get install $1
echo -e "\e[31m$1 is not installed and ready to use\e[0m"
else
echo -e "\e[31m$1 is already installed\e[0m"
fi
rm -f /tmp/pkg_verify
for test in $#; do main $test; shift; done
echo -e "\e[31mDone\e[0m"
}
for test in $#; do main $test; shift; done
echo -e "\e[31mDone\e[0m"
But when I try to execute it I'm facing with endless loop:
grep: /tmp/verify: No such file or directory
16 is already installed
I truly tried to find the answer, tried to change the if to couple of different forms but with out any success. Does any one have an idea why that is? What should I change so that the script can run?
Thanks in advance to all the helpers.
You have two else following each other. That can't work. It's either elif condition or just a single else.
The infinite loop is caused by main calling itself recursively.
And third, it's probably a bug to shift when iterating with for i in "$#".
To debug a script (free of syntax errors) use set -x near the beginning.
Replace this line:
if [[ -z `grep 'not installed' /tmp/pkg_verify` ]]
with this if condition:
if grep -q 'not installed' /tmp/pkg_verify
Full Script:
main () {
dpkg-query -s "$1" > /tmp/pkg_verify
if grep -q 'not installed' /tmp/pkg_verify
then
echo -e "\e[31m$1 is not installed. installing..\e[0m"
apt-get install "$1"
echo -e "\e[31m$1 is not installed and ready to use\e[0m"
else
echo -e "\e[31m$1 is already installed\e[0m"
fi
}
rm -f /tmp/pkg_verify
for test in $#; do main "$test"; done
echo -e "\e[31mDone\e[0m"

How this command find a file in Rpm package

I have given command which will find a particular file named /etc/limits in one of rpm package insatlled but when run on my system getting error not the desired result. Below is the command
find . -name '*.rpm' | while read A; do $RPM -qpl $A | grep etc/limits; \
if [ $? -eq 0 ]; then echo $A; fi; done
/etc/limits
When I run this command getting below error
bash: syntax error near unexpected token `/etc/limits'
Could anybody tell me what is going wrong here?
It's evident that your while loop takes input from find so you don't need /etc/limits after done in your script. Saying:
find . -name '*.rpm' | while read A; do
$RPM -qpl $A | grep /etc/limits;
if [ $? -eq 0 ]; then echo $A; fi;
done
should work. If you wanted to make the while loop read from a file you'd have said:
while read A; do ... done < /path/to/input/file

Resources