Shell Script Run When I am Root But I Get a Permission Denied When It Is Invoked from a Makefile (Still as Root)

shell script run when I am root but I get a permission denied when it is invoked from a Makefile (still as root)

In your comments above you say when you "run it manually" you use . scriptname.sh, is that correct? You use . followed by scriptname.sh?

That does not run the script, that sources the script. Your statement that scriptname.sh will execute with and without the x permission since it is a shell script is wrong. You can source the script if you have read permissions. But you cannot execute the script unless you have execute permissions.

"Sourcing" means that a new shell is not started: instead your current shell (where you type that command) reads the contents of the script and runs them just as if you'd typed them in by hand, in the current shell. At the end all the side-effects (directory changes, variable assignments, etc.) that were performed in that script are still available in your current script.

"Executing" means that the script is treated like a program, but the program is a new shell that's started, which then reads the contents of the script and executes it. Once the script ends the shell exits and all side-effects are lost.

The $(shell ...) function in make will not source your script (unless you also use . there, which you did not). It will try to run your script. The error you show implies that either systype.sh did not have the execution bit set, or else that it had an invalid #! line. There's no other explanation I can think of.

If sourcing the file really does what you want then why not just use the same method in $(shell ...) that you use in your own personal use:

PLATFORM=$(shell . $(ROOT)/systype.sh)

If changing the user permission didn't work, are you sure that whatever user owns the script is the same user you're using to invoke make? You say you're "running as root"; is the script owned by root? Or is it owned by you and you're running sudo make or similar?

I don't know why you don't just use:

chmod +x systype.sh

and call it a day.

Permission issues, not able to run script as root

Make sure that your partition is not mounted with the noexec flag (which - as the name suggests - prevents making any files executable)

Permission error running any git command in makefiles

It would be really, really helpful if you provided the recipe you're trying to run that's giving the above error, or even the make output of the command that was invoked. Without that we can only guess, which is kind of a waste of everyone's time :)

My suspicion is this: you have a directory on your $PATH which has a directory named git in it, and this appears before /usr/bin in your $PATH.

There's a bug in GNU make 4.3 (actually the bug was in gnulib, which GNU make uses) which didn't correctly ignore directories when searching PATH.

However, this cannot be the problem if your recipe invokes git in a non-trivial way (as part of a shell script).

The fastest way to check this is just to add a semicolon to your command line; you didn't show us the entire recipe so we can't be sure but if you have:

foo:
git --version

try changing this to:

foo:
git --version;

and see if it works.

mkdir' in a shell file cannot create directory: Permission denied

You have to give the script execution permission:

chmod +x path_to_the_copy.sh

Kubernetes install gen_deepcopy permission denied

A bunch of stuff changed with the build recently, so please first try 'sudo make clean' and if you still get errors, let me know.

Calling a shell script from a makefile?

EDIT:

Based on the comments I have refactored to this

bootstrap:
rm -r src/bootstrap/bootstrap
$(MAKE) -C ./src/bootstrap bootstrap
mv -f src/bootstrap/bootstrap/css/* lib/public/css
mv -f src/bootstrap/bootstrap/img/* lib/public/img
mv -f src/bootstrap/bootstrap/js/* lib/public/js

This duplicates the functionality of the shell script I had before (moving files for my custom project) and still uses the standard makefile that Twitter Bootstrap ships with. Much cleaner... I'm going to live the original answer below so people can see the evolution and refactor.

OLD ANSWER

Ok thank you guys in the comments for pointing my in the right direction. This solution works:

bootstrap:
cd ./src/bootstrap; \
./make_bootstrap.sh

What happens is it executes the change directory (in a sub process so it doesn't affect where I run make from) and then executes the custom script. It seems as if I probably shouldn't be using something like this in a makefile since it feels 'dirty'; perhaps a more clean way to do it would be to invoke the LESS compiler myself and mimic the makefile provided by bootstrap. I'm using this for a tiny personal project though so it does the job.



Related Topics



Leave a reply



Submit