use make install to expose a script to user - makefile

inside my makefile I have the following...
install:
$(INSTALL) $(PWD)/run.sh $(bindir)/run
so when the user clones my repo and CDs into it, I want them to type make install
my hope is that they will then be able to call the run.sh script as run
does anyone have any idea how this could be achieved?

If you want to install it globally then what you need is to copy it to a system-wide binary directory (like /usr/local/bin f.e.), and if you don't want them to need to use the .sh then you need to rename it to just run during the copy and add a shebang to the file (#!/bin/sh at the top).
One thing to keep in mind is that you might need to chmod +x $(bindir)/run if the file hasn't been marked as executable before.

Related

How can I change directories in a homebrew formula?

I am trying to create my own homebrew formula using brew create and brew edit .
As part of the install for this project I need to change into a sub directory and build things there, for example
cd sub/dir/place
make -f makefile otherMakeTarget
I tried adding to my formula.rb
system "cd", "sub/dir/place/"
system "make", "etc"
But it doesn't seem to do the cd correctly. The logfile 01.cd shows the cd and the argument on two separate lines, I'm not sure if that's the problem.
Calling system creates a subshell and any modifications to the working directory go away when that call completes.
You could try using chdir:
Dir.chdir('sub/dir/place')
Another way to do it is to use a chdir block.
chdir "vendor" do
system "make", "install"
end

Chmod permissions on files and directories

I have a binary script along with a key file and required libs in a folder on my shell. There are 3 users on the shell currently whom I want to allow to run the binary script. Each user who runs it runs it as a separate instance/process. In order to start, the script is run by using an .sh file which specifies the location of the binary and its libs. For example, ./script.sh is the command.
I have the script currently in /home/script/user (will create also dir called /user2 for other user) where script is a new user I created for it. User runs the .sh from their homedir and then it automatically writes a config file in /home/script/user. I have been playing around with chmod because I don't want anyone to be allowed to steal the script or any of its contents inside the directory. To summarize, I only want users to be able to execute the binary and read the libs and key file as well as write their config to respective user directory in /home/script/. I don't want to allow them to delete, edit, copy, or download anything inside the /script directory. Currently only the binary can't be altered in anyway, but the key file and libs are able to be copied or downloaded. I couldn't figure out how to chmod the key and libs so that they can't be copied etc, only read to run binary successfully.
Please let me know how I can accomplish my permission goals and/or if there is another or easier way to do this. Thanks.
I believe you can achieve most of what you want with chmod and groups. So to allow a bunch of users to run a script you'd create a group, add them to it. Create a group and add users to it like this:
groupadd <groupname>
usermod -a -G <groupname> <username>
Then to make a file only executable by a group you'd run
chgrp <groupname> <file>
chmod g+x <file>
Unfortunately because of the way that chmod works you cannot allow a file to be read but not copied. This is because chmod works with read, write and execute permissions and if you can read you can copy.

Keep a single file's permissions when using install() in CMake

In KDE, I adjusted a macro to compile and install Python files, but I'm having problem with it keeping the files' permissions.
To be more clear, the offendling line in the macro is
install(FILES ${SOURCE_FILE} DESTINATION ${DESTINATION_DIR})
which works for 99% of the cases.
In one case, though I have a Python file marked as executable (+x, I'm talking about Linux here) in the source directory, which then is symlinked to the installation's binary dir. Since install() does not preserve permissions, the execute bit is stripped from it, and this causes all sorts of problems later on.
Is it possible to keep the file's permissions, or to read them and set them accordingly? I would hate to use a manual chmod command since it's not portable.
EDIT: I do not want to make all files installed by this macro executable, as this would be pointless.
You can install files with +x permission using
install(PROGRAMS ...
command.
Alternatively, you can install whole directory preserving file permissions:
install(DIRECTORIES ... USE_SOURCE_PERMISSIONS)
See documentation for install command for more info.

How to make open sourced scripts 'installable'?

I've finished a little useful script written in Bash, hosted on github. It's tested and documented. Now, I struggle with how to make it installable, i.e. where should I put it and how.
It seems other such projects use make and configure but I couldn't really find any information on how to do this for bash scripts.
Also I'm unsure into which directory to put my script.
I know how to make it usable by myself but if a user downloads it, I want to provide the means for him to install it easily.
There is no standard for this because most of the time, a project isn't a single script file. Also single file scripts don't need a build step (the script is already in an executable form) and configuration usually comes from an external config file (so no need for a configure script, either).
But I suggest to add a comment near the top of the file which explains what it does and how to install it (i.e. chmod +x + copy to folder).
Alternatively, you could create an installer script which contains your original script plus a header which asks the user where she wants to install the real script and which does everything (mkdir, set permissions with sudo, etc) but it really feels like overkill in your case.
If you want to make it installable so the package manager can easily install and remove (!) it, you need to look at the documentation for rpm or Debian packaging. These are the two most used package managers but they can't install a script per-user (so it would probably end up in /usr/bin)
instruct them to create a file named after the script in their home directory, chmod ug+x the file so it has executable permissions than put the script inside the file, don't forget the #!/bin/bash up top of the vim. This example is a script to copy a file, archive the copied file than remove the copied file leaving only the original file and the archived file.
#!/bin/bash
#### The following will copy the desired file
cp -r /home/wes/Documents/Hum430 /home/wes/docs
#### Next archives the copied file
tar -zcvf Hum430.tar.gz /home/wes/docs
#### and lastly removes the un-archived copy leaving only the original and the archived file.
rm -r /home/wes/docs
### run the file with ./filename (whatever the file is named)

Cd in shell script not working

First off I am very very new to shell scripting. I am trying to write a script that takes in one parameter and then copies a folder in a different directory naming it using the parameter. This is the current code that I have:
#!/bin/sh
cd /var/www/html/fbplugin/chrome
sudo mkdir temp/$1
sudo cp -rf "/var/www/html/fbplugin/chrome/fbplugin" "/var/www/html/fbplugin/chrome/temp/$1"
When I run this code it says can't cd to /var/www/html/fbplugin/chrome. I'm not sure why it is saying this because I know the directory exists. I have copied the line directly and it works in terminal. If anyone could help me out that would be great.
If it matters in order to run the script I am typing "sh build.sh"
If that directory really exists, then you must have executed that script with a different user (cron, webserver, etc).
Check the rights for that directory.
I don't know why you're getting the error about cd, but it looks like you could just use absolute paths throughout. That would solve the larger problem of the script working correctly.

Resources