run 'cordova prepare ios' from different folder - bash

how can I run 'cordova prepare ios' from a different folder? Just perhaps from the parent folder of the app i try to build and prepare. Or from a shell script (but cd to folder doesn't work either within a shell script - console works perfectly!)
Build works with this:
/Users/someone/cordova/appname/platforms/ios/cordova/build
But there is no prepare inside the ios/cordova/ folder.
prepare is located #
/usr/local/lib/node_modules/cordova/bin/cordova prepare ios
How can I set a path? --path /Users/someone/cordova/appname/ doesn't work.
Or some other ideas?
Thanks!
****update****
This doesn't work (also pushd, popd):
ssh -l username -o 'HostKeyAlias example.com' example.com "(cd /Users/someone/cordova/appname && /usr/local/lib/node_modules/cordova/bin/cordova prepare ios)"
env: node: No such file or directory
But if I use just ls or pwd I'll get the correct path.
I tried also this:
ssh -l username -o 'HostKeyAlias example.com' example.com <<'ENDSSH'
cd /Users/someone/cordova/appname
cordova prepare
ENDSSH
****solution****
I already got it! (https://stackoverflow.com/a/1472444/2192501)
ssh -l username -o 'HostKeyAlias example.com' example.com "source /etc/profile;cd /Users/someone/cordova/appname;cordova prepare)"

the method to run commands from a different folder in a bash script is 'cd'
you can also look at pushd and popd http://en.wikipedia.org/wiki/Pushd_and_popd
another method to try would be
(cd path/to/cordova/project && cordova prepare ios)
this will spawn a subshell, change the working directory to the cordova project, execute the cordova prepare command, then close. This won't alter the working directory of the shell you execute from.
the prepare file which eventually gets executed is based on the platform arguments, and is downloaded off of your node_modules folder. It is called by the Cordova CLI with the correct arguments, including the path to the cordova project. The Cordova CLI knows where your cordova project is implicitly, because you executed the commands from the project root

I already got it! (https://stackoverflow.com/a/1472444/2192501)
ssh -l username -o 'HostKeyAlias example.com' example.com "source /etc/profile;cd /Users/someone/cordova/appname;cordova prepare)"

Related

How to run set of terminal commands in a file one by one?

I was working on a Django project and each time I open the project, I have to run these three commands one by one.
source virtualenv/bin/activate (to activate virtual environment)
cd myproject (to enter project folder)
python3 manage.py runserver (to run the server)
Is there a way I can write these three commands in a text file (or some other file) so that a single command will run these three commands one by one?
Before running those three commands, terminal looks like this:
After running those three commands, the terminal should look like this:
Try this:
In file runscript.sh,
#!/bin/bash
source virtualenv/bin/activate
cd myproject
python3 manage.py runserver
Then run command: . runscript.sh instead of ./runscript.sh
Save following content to a file runserver.sh
#!/bin/bash
source virtualenv/bin/activate && cd myproject && python3 manage.py runserver
and
chmod 744 runserver.sh
And you can just run ./runserver.sh
&& will ensure previous command was successful before running next command. If any command fails to run, it will abort rest.

WGET seems not to work with user data on AWS EC2 launch

I launch an centos AMI I created, and try to add user data as a file which looks like this:
#!/bin/bash
mkdir /home/centos/testing
cd testing
wget https://validlink
So simply, on launch, the user data creates a folder called testing and downloads this validURL which I will not put as it links to my data - however it is valid and accessible.
When I launch the instance, the folder testing is created successfully, however there is no file inside the directory.
When I ssh into the instance, and run the wget command as a sudo, the file is downloaded successfully inside the testing folder.
Why does the file not get downloaded on the ec2 launch through user data?
You have no way of knowing the current working directory when you execute the cd command. So specify full path:
cd /home/centos/testing
Try this:
#!/bin/bash
mkdir /home/centos/testing
cd /home/centos/testing
wget https://validlink
Run it using the root user.
Try this instead:
#!/bin/bash
sudo su
yum -y install wget
mkdir /home/centos/testing
cd /home/centos/testing
wget https://validlink

Bash on Windows - alias for exe files

I am using the Bash on Ubuntu on Windows, the way to run bash on Windows 10. I have the Creators update installed and the Ubuntu version is 16.04.
I was playing recently with things as npm, node.js and Docker and for docker I found it is possible to install it and run it in windows and just use the client part from bash, calling directly the docker.exe file from Windows's Program Files files folder. I just update my path variable to include the path to docker as PATH=$PATH:~/mnt/e/Program\ Files/Docker/ (put in .bashrc) and then I am able to run docker from bash calling docker.exe.
But hey this bash and I dont want to write .exe at the end of the commands (programs). I can simply add an alias alias docker="docker.exe", but then I want to use lets say docker-compose and I have to add another one. I was thinking about adding a script to .bashrc that would go over path variable and search for .exe files in every path specified in the path variable and add an alias for every occurance, but it does not seem to be a very clean solution (but I guess it would serve its purpose quite well).
Is there a simple and clean solution to achieve this?
I've faced the same problem when trying to use Docker for Windows from WSL.
Had plenty of existing shell scripts that run fine under Linux and mostly under WSL too until failing due to docker: command not found. Changing everywhere docker to docker.exe would be too cumbersome and non-portable.
Tried workaround with aliases in ~/.bashrc as here at first:
shopt -s expand_aliases
alias docker=docker.exe
alias docker-compose=docker-compose.exe
But it requires every script to be run in interactive mode and still doesn't work within backticks without script modification.
Then tried exported bash functions in ~/.bashrc:
docker() { docker.exe "$#"; }
export -f docker
docker-compose() { docker-compose.exe "$#"; }
export -f docker-compose
This works. But it's still too tedious to add every needed exe.
Finally ended up with easier symlinks approach and a modified wslshim custom helper script.
Just add once to ~/.local/bin/wslshim:
#!/bin/bash -x
cd ~/.local/bin && ln -s "`which $1.exe`" "$1" || ln -s "`which $1.ps1`" "$1" || ln -s "`which $1.cmd`" "$1" || ln -s "`which $1.bat`" "$1"
Make it executable: chmod +x ~/.local/bin/wslshim
Then adding any "alias" becomes as easy as typing two words:
$ wslshim docker
+ cd ~/.local/bin
++ which docker.exe
+ ln -s '/mnt/c/Program Files/Docker/Docker/resources/bin/docker.exe' docker
$ wslshim winrm
+ cd ~/.local/bin
++ which winrm.exe
+ ln -s '' winrm
ln: failed to create symbolic link 'winrm' -> '': No such file or directory
++ which winrm.ps1
+ ln -s '' winrm
ln: failed to create symbolic link 'winrm' -> '': No such file or directory
++ which winrm.cmd
+ ln -s /mnt/c/Windows/System32/winrm.cmd winrm
The script auto picks up an absolute path to any windows executable in $PATH and symlinks it without extension into ~/.local/bin which also resides in $PATH on WSL.
This approach can be easily extended further to auto link any exe in a given directory if needed. But linking the whole $PATH would be an overkill. )
You should be able to simply set the executable directory to your PATH. Use export to persist.
Command:
export PATH=$PATH:/path/to/directory/executable/is/located/in
In my windows 10 the solution was to install git-bash and docker for windows.
in this bash, when I press "docker" it works
for example "docker ps"
I didnt need to make an alias or change the path.
you can download git-bash from https://git-scm.com/download/win
then from Start button, search "git bash".
Hope this solution good for you

SSH remote command executing a script

I have two hosts, hosts A and B. A has a script (generate) that compiles my thesis:
#!/bin/sh
pdflatex Thesis.tex
When running this command on host A (console window) it works perfectly.
I am basically trying to connect from host B to A and run the generation command as an ssh remote command. All the keys are properly set. When I run the command, I get the following:
hostB> ssh user#hostA exec ~/Thesis/generate
This is pdfTeX, Version 3.1415926-1.40.10 (TeX Live 2009/Debian)
entering extended mode
! I can't find file `Thesis.tex'.
<*> Thesis.tex
I tried adjusting the script so that it considers the directory:
pdflatex ~/Thesis/Thesis.tex
But because the Thesis.tex inputs some others files (images), I get an error message.
I presume the problem is some sort of enviroment that doesn't exist in remote commands. How do I fix this?
ssh will run your command in your home directory. You probably wanted to run it in your ~/Thesis directory.
Just cd first and it should be fine:
ssh user#hostA 'cd ~/Thesis && ./generate'

How to run a script file on Mac?

I have searched on how to run a script file on Mac but nothing works for me.
Every time I tried sudo script-name the terminal responds with
-bash: /Users/macuser/Desktop/tesseract-3.01: is a directory
The file I want to run is called start and it's located in tesseract-3.01 directory on the desktop.
simply do
/Users/macuser/Desktop/tesseract-3.01/start
or if it's actually called start.sh
/Users/macuser/Desktop/tesseract-3.01/start.sh
you might also want to do
chmod +x /Users/macuser/Desktop/tesseract-3.01/start.sh
to change the script to be executable before you run the script
sudo /Users/macuser/Desktop/tesseract-3.01/start
You have to indicate the script name, but it looks like you were only specifying the directory.
You could also cd to the directory and then run it like so:
cd /Users/macuser/Desktop/tesseract-3.01
sudo ./start
Try
sudo ./Users/macuser/Desktop/tesseract-3.01/start.sh
or
cd /Users/macuser/Desktop/tesseract-3.01
then
sudo ./start.sh

Resources