Issue in calling shell script from qt .pro file on Mac Machine - macos

We are facing very strange issue in running Shell Script file from 'QT' .pro file on Mac system(For our cross platform Qt project).
Same .pro file is working fine on Ubuntu machine without any issues.
We have following command for running script file which compiles .ts(Typescript) files into .js(javascript) files.
# TypeScript Compilation
{
PRE_BUILD_FILE = "$${PWD}/external/TSbuild/compileTS.sh"
DUMMY_DEPS = .
PreBuildEvent.input = DUMMY_DEPS
PreBuildEvent.output = DUMMY.txt
PreBuildEvent.commands = $$PRE_BUILD_FILE
PreBuildEvent.name = running Pre-Build steps...
# "target_predeps" tells qmake that the output of this needs to exist before we can do the rest of our compilation.
PreBuildEvent.CONFIG += no_link no_clean target_predeps
QMAKE_EXTRA_COMPILERS += PreBuildEvent
}
our script file looks like this
BASEDIR=$(dirname "$0")
echo "===============================================";
echo "Script Directory is: " $BASEDIR;
echo "===============================================";
tsc -p "$BASEDIR/tsconfig.json";
cd $BASEDIR/../../web/js/;
rm -r autogen_*.js;
rename 's/^/autogen_/' *.js;
exit 0;
We are getting following error while building code
'tsc' command not found.
'rename' command not found.
Note 1: Same script is running fine, if we run it from terminal using command in that directory or from other directory giving path.
$sh compileTS.sh
Note 2: If we change script file in following way.
BASEDIR=$(dirname "$0")
echo "===============================================";
echo "Script Directory is: " $BASEDIR;
echo "===============================================";
/usr/local/bin/tsc -p "$BASEDIR/tsconfig.json";
cd $BASEDIR/../../web/js/;
rm -r autogen_*.js;
/usr/local/bin/rename 's/^/autogen_/' *.js;
exit 0;
We are getting error message.
env: node: No such file or directory
Meaning script file was not able to find path of 'tsc'. Now file is not finding path of 'node'. means need to give complete path of command.
Note 3:
Same .pro file code is building without any issues on Linux. Linux we faced small issues, due to calling of script file.
PreBuildEvent.commands = .$$PRE_BUILD_FILE
Removed '.' to make it work.
PreBuildEvent.commands = $$PRE_BUILD_FILE
as ‘.’ causes running script in same directory as calling process.
Note 4: We also had try with calling script file in different way, nothing helped
PreBuildEvent.commands = .$$PRE_BUILD_FILE
PreBuildEvent.commands = sh $$PRE_BUILD_FILE
Note 5: Even updating 'PATH' variable, updating 'bash_profile' didn't helped. Setting up environment variable
Please guild us resolving this issue, may be some small mistake due to limited knowledge in Shell script and way of calling Shell script in mac system.

Related

How can I run executable in shell script?

I have folder "destination/" and inside the destination folder, it contains executable grade1. My current directory is "destination/"
I'm Trying to run
for i in FILES/*; do ./grade1 $i done
Which it keep says
./grade1 no such file or directory
Weird part is that, when I just copy the code to command line and run it, it works fine. Problem only arises when I do it in shell script
I don't think that grade1 really is in your current working directory, as you claim. I suggest that you verify this also check the permissions of your executable. Extend your code to
echo current directory is $PWD
ls -l grade1
for i in FILES/*; do ./grade1 $i done
This should reveal the source of your problem.
One simple way to fix this problem might be to start using FULL path of grade1 executable file
for i in FILES/*; do {FULL_PATH}/grade1 $i done

Cygwin 'cd' command always tells me "No such file or directory"

When i login to the cygwin terminal and type:
cd "cygdrive/c/existing/path"
it tells me, "no such file or directory". i am sure the path exists... do i miss a special cygwin package, or do i have a false configuration? i am puzzled...
It behaves the same when i try to call the cygwin bash from a windows batch file.
what i basically want to do is creating a windows batch file which starts cygwin and executes a shell script with a specified working directory as its described in this blog post: http://blog.dotsmart.net/2011/01/27/executing-cygwin-bash-scripts-on-windows/
my batch file seems to work, it does the following command:
%_CYGBIN%\bash.exe --login "cd %_CYGPATH%" "./%_CYGSCRIPT%"
but cygwin won't execute the 'cd' command. The console output of my batch file is:
/usr/bin/bash: cd /cygdrive/c/existing/path: No such file or directory
cd '/cygdrive/c/existing/path'
# ^
# \
# --- need forward slash (/) before the "c"

Remove package identifier file during installation

I'm a newbie in OSx development.
I'm creating an installer package using Packagemaker 3.0.4. Since I want to remove the local settings of my app during installation, I decided to remove the com.identifier.plist. However, I'm not that good in scripting and I'm just starting to explore what Packagemaker is capable of.
Ideally, I want my implementation to be as simple as this:
Check if the .plist file exists
Remove it.
I have tried:
#!/bin/sh
defaults delete ~/Library/Preferences/com.identifier.AppName.plist
Then I saved the delete.sh file to the Desktop. I opened the Packagemaker app and provided the path to my Desktop: /Users/MyName/Desktop/delete.sh in the Scripts Postflight. Then I executed build & run. It didn't work. I thought that it might probably be the script, so I changed it to:
#!/bin/sh
rm ~/Library/Preferences/com.identifier.AppName.plist;
Then I loaded the delete.sh file the same way as I did on the script above. But I received this error:
Mar 29 20:50:54 Mac-mini installd[5425]: PackageKit: Install Failed: PKG: post-flight scripts for "com.testIdentifier.test.AppName.pkg"\nError Domain=PKInstallErrorDomain Code=112 UserInfo=0x100404220 "An error occurred while running scripts from the package “test.pkg”." {\n NSFilePath = "./postflight";\n NSLocalizedDescription = "An error occurred while running scripts from the package \U201ctest.pkg\U201d.";\n NSURL = "./Contents/Packages/test.pkg -- file://localhost/Users/MyName/Desktop/AppName.mpkg/";\n PKInstallPackageIdentifier = "com.testIdentifier.test.AppName.pkg";\n}
If anyone who has a Step-by-Step implementation of creating & adding script to the Packagemaker, and perhaps, my scripts aren't correct, it would be awesome if you could help me out.
Thank you so much in advance! :)
Did you try to launch your delete.sh from terminal? Looks like you have an error in syntax - ';' at the end of the rm command, and you should use -f flag for the rm command (see man rm) in other case script will prompt for confirmation and postflight script can't be interactive.
Edit: as 一二三 mentioned semicolon - is not the point, you should probably look to his answer. And before you'll create your package just try your script in terminal (you can do sudo su before to login as root)
I've got it...
Here's my script:
#!/usr/bin/env bash
file=~/Library/Preferences//com.identifier.AppName.plist
if [ -e "$file" ]
then
# file is found
/usr/bin/defaults delete ~/Library/Preferences//com.identifier.AppName
else
# file not found."
fi
exit 0
I then added it to PackageMaker. I'm not really sure if I'm right but I might have just forgotten to add the script's file into the contents. That's why it never worked earlier. I just put the script's path on the postflight.
Anyway, thanks a lot to everyone for the tips.

Build system with bash script for Sublime Text 2

I work with SQL queries in Sublime 2. I have a custom script that takes sql filename as an argument, uploads it to the server, downloads the query result and converts it to valid csv file. It works, and it's very useful.
However, when I tried to set up a build system for Sublime Text 2 using this script, I get errors. Here's my sublime-build file:
{
"cmd" : ["exec_sql.sh", "$filename"],
"selector" : "source.sql",
"path" : "/Users/username/sql"
}
SQL files and exec_sql script are both located in /Users/username/sql/ folder. Here's what I get:
/Users/username/sql/exec_sql.sh: line 9: which: command not found
/Users/username/sql/exec_sql.sh: line 16: basename: command not found
/Users/username/sql/exec_sql.sh: line 19: username#hostname.com:/tmp/: No such file or directory
/Users/username/sql/exec_sql.sh: line 24: ssh: command not found
/Users/username/sql/exec_sql.sh: line 25: username#hostname.com:/tmp/.csv: No such file or directory
[Finished in 0.0s with exit code 127]
It seems that despite being a command-line script, sh file is being interpreted as something else. How do I fix it?
I think that the problem can be solved if your custom script is added to the system path (to the BIN directory).
I am going to use a detailed example that i have used succesfully.
Be sure that your custom script is marked as executable and has got the shebang. A simple script that includes the basename command that fails in your example (i have called it test_basename.sh):
#!/bin/bash
echo $1
basename $1
Make a symlink to include the script in the BIN directory so it can be executed in any folder. In my Ubuntu i do it with this command:
sudo ln -s /Users/username/sql/test_basename.sh /usr/bin/test_basename.sh
Check the script in the console in any directory
cd /tmp
test_basename.sh some-filename
Restart Sublime Text
Create a build system that uses the simple script. I have used $file as an example. Other options are in the documentation.
{
"cmd" : ["test_basename.sh", "$file"]
}
Open a file in Sublime Text and run the build system created.
If you don't want to create a symlink use a variable like $project_path or $file_path
{
"shell_cmd": "./do.sh",
"shell": true,
"working_dir": "$project_path"
}
reference for variables: sublimeText docs
I was able to create a general purpose Bash build system for Sublime Text 2:
Create a new Build System
Use the following code:
{
"cmd": ["/path/to/bash-build.sh", "$folder"],
"shell": true,
"working_dir": "$folder",
"windows": {
"cmd": ["C:\\path\\to\\bash-build.sh", "$folder"]
}
}
Save it as bash.sublime-build
Create a new shell script using your editor of choice and paste the following code into it:
#!/bin/env bash
echo "Start building..."
if [ -f $1/build.sh ]; then
cd $1
build.sh
cd -
else
echo "File doesn't exist: $1/build.sh"
fi
echo "Done."
exit $?
Save it as bash-build.sh in the same folder that you reference in the Sublime Build System
Open a folder in Sublime (note: on Windows, build systems seem broken when Sublime is opened from the command line)
Create a new text file and save it as build.sh into the root folder opened in Subilme
In build.sh, go crazy:
#!/bin/env bash
# do some crazy, custom build
exit $?
I've started using this in conjunction with Pandoc to generate HTML files from Markdown files.
It seems like you are on Mac. I had the same problem before I realized that the System path variable is wrong.
I fixed it the following way.
First, get the current PATH by pasting this in terminal (without first $):
$ echo $PATH
Copy this path (it will look something like this: /opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/Library/Frameworks/Python.framework/Versions/3.4/bin:/opt/local/bin:/opt/local/sbin)
Now edit the build system to include this path (the path variable you use should be actually a working_dir):
{
"cmd" : ["exec_sql.sh", "$filename"],
"selector" : "source.sql",
"working_dir" : "/Users/username/sql",
"path": "PASTE $PATH VALUE HERE"
}
And it should work now. At least it helped me.

Redirecting output does not work

I am trying to output the most recent changelist number from our source control software to a log file. I know that the script works fine until getting the changelist number. The script below works when I run it manually but doesn't seem to work when it is triggered from the crontab. I have no idea why it wouldn't work. I am running this script on a machine with Mac OS X 10.7 and the permission are set to 555.
changelist=${changelist_ouput}
output_file="../../output_dir/result_log.txt"
if [[ -e ${output_file} ]];
then
# Delete previous changelist information
sed -i.bak '/changelist/d' "${output_file}"
rm "${output_file}.bak"
# Add current changelist information
echo "changelist=${changelist}" >> "${output_file}"
else
echo "WARNING: Failed to update changelist information"
fi
I would appreciate any help.
cron probably isn't using the same current directory as you are using. Since you use a relative path for output_file, this will dump the output to some path relative to cron's current directory (and since ../../output_dir probably doesn't exist, it'll just fail).
You have to use an absolute path for output_dir, or make a path relative to the script directory (dirname $0). See also Crontab - Run in directory.

Resources