I created a shell script using CMake just like this:
file(WRITE somescript.sh "echo foo!")
I want the user to be able to execute that script right away. For this, it would be nice to change the permissions of that file from within CMake.
Is there something like chmod u+x somescript.sh in CMake?
The problem with install is that existing files are not overwritten when the destination directory is equal to the source directory and when the files themselves did not change (CMake seems to compare timestamps). But nevermind, I found a working solution for everyone reading along:
Create the file as shown in the question but in a temporary folder ${CMAKE_BINARY_DIR}/tmp
Use file (COPY ${CMAKE_BINARY_DIR}/tmp/somescript.sh DESTINATION ${CMAKE_BINARY_DIR} FILE_PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ)
Remove the old file and the temporary directory: file(REMOVE_RECURSIVE ${CMAKE_BINARY_DIR}/tmp/)
You can do that in the istall command. Use this tags:
install(
FILES somescript.sh
PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ
DESTINATION /some/destination
)
In case you want to copy a binary I would use USE_SOURCE_PERMISSIONS
Related
I am trying to move a file from one directory to other by command line.I used this command
raghul#raghul-Aspire-5750Z:~/temp/newfolder$ mv copy.txt /temp/
I got error like this
cannot create regular file '/temp': Permission denied
Can someone help me to figure this out? I need to move a file from one directory to other.
First of all you are using the copy command cp, not the move command mv.
Secondly you are trying to copy the file to a new file named /temp, ie. a file named temp in the / directory. This resides in the filesystem's root directory, which is mostly likely owned by root. Unless you have root permissions you can not write to the root directory.
Given that you are naming the file temp, I assume that you want to move the file to the /tmp directory, for which you will have permission to write to. Do this:
$ mv copy.txt /tmp
This will work only if you also have write permission on the file copy.txt because you need to be able to remove it. If you just wanted to copy the file, just read permission is required.
Otherwise, if you really do wish to move the file to a /temp directory, you can use sudo to do that, provided that you are set up as a sudo user:
$ sudo mv copy.txt /temp
[sudo] password for raghul
I just noticed that you're in a personal directory called ~/temp/newfolder. Is that the temp you're trying to move the file to: your personal one, in which onefolder is in? So you want to move the file up one directory?
Then the problem is that your command is missing the 'personal' tag ~. The command should be:
mv copy.txt ~/temp/
Try moving it with sudo command as it seems you don't have permission to move the file.
If you are requested for a password enter the root's password.
Try this:
sudo cp copy.txt /temp/
Try this: change /temp to
mv index.text temp
I have a shell script that will unpack a .tgz file and put the new files in the root directory.
Is it possible to add an argument to the line below so that the new files will retain the file permissions of the original files that are being overwritten?
tar xf /install/newfiles/files.tgz -C /
I'm going to answer this for future reference. Thanks to #devnull and #Vorsprung for their comments.
Is it possible to add an argument to the line below so that the new files will retain the file permissions of the original files that are being overwritten?
Answer: Simple answer is NO, but the tar command can support the --overwrite option (test this before use).
Second option is to create a shell script that can be run that will CHMOD the files after the new files have been put in their place.
I have a file that I want to run in this directory:
C:\ruby\App\bin\cucumber
And I have a file that I want to pass it in this directory:
C:\ruby\App\features\creating_projects.feature
All works fine when I explicitly cd to /bin and run the file:
C:\ruby\App>cd bin
C:\ruby\App\bin>cucumber ..\features\creating_projects.feature
But I want to be able to run it being in my app's root directory. But this doesn't work. It says, "bin\cucumber" is not a program, command of file:
C:\ruby\App>bin\cucumber features\creating_projects.feature
# error
How can I run the file this way?
Have you tried:
C:\ruby\App>.\bin\cucumber ..\features\creating_projects.feature
?
I'm not sure, but maybe you should add file extension
C:\ruby\App>bin\cucumber.??? features\creating_projects.feature
I'm trying to write a script that will let me add to an existing directory structure and copy a bunch of files into various places within this. However, using mkdir ... and cp... commands alone wont work since I do not have permission to do so. I understand that this can be changed manually in the 'Get Info' window, but this script will be run by others and its whole point is to save time and hassle.
Is there a way of adding to this script to give me permission to copy files to BASEDIR/SUBDIRS?
A bit more detail on what I'm doing:
I want to add to the directory BASEDIR with a bunch of SUBDIRS then copy files into these subdirectories. The problem is that I am receiving these 'permission denied' errors right after the mkdir BASEDIR/SUBDIR1/SUBDIR2 command.
Thanks
The command
sudo chmod -R ugo=rwx BASEDIR/
gives all folder permissions to all users to BASEDIR and all its subdirectories
My backup.zip has the following structure.
OverallFolder
lots of files and subfolders inside
i used this unzip backup.zip -d ~/public_html/demo
so i end up with ~/public_html/demo/OverallFolder/my other files.
How do i extract so that i end up with all my files INSIDE OverallFolder GOING DIRECTLY into ~public_html/demo?
~/public_html/demo/my other files
like this?
if you can't find any options to do that, this is the last resort
mv ~/public_html/demo/OverallFolder/* ~/public_html/demo/
(cd ~public_html/demo; unzip $OLDPWD/backup.zip)
This, in a subshell, changes to your destination directory, unzips the file from your source directory, and when the subshell exits, leaves you back in your source directory.
That, or something similar, should work in most shells.