Set executable permission on script installed with Homebrew - installation

I wrote my first tap, so I'm still not sure how it works. I wrote this small formula:
class Konversation < Formula
desc "Konversation is a tool to generate rich and diversified responses to the user of a voice application."
homepage "https://github.com/rewe-digital-incubator/Konversation/"
url "https://github.com/rewe-digital-incubator/Konversation/releases/download/1.0.0/konversation-cli.jar"
sha256 "6123d126278faae2419f5de00411a1b67ae57e0cf2265a5d484ed6f9786baaca"
def install
prefix.install "#{buildpath}/konversation-cli.jar"
File.write("#{buildpath}/konversation", "java -jar #{prefix}/konversation-cli.jar $#")
bin.install "#{buildpath}/konversation"
system "chmod", "+x", "#{bin}/konversation"
end
end
However I cannot run my tool since the "konversation" executable has no x permission. I tried to fix that with a system chmod, however I see that my x flag is removed after the installation by brew as some kind of cleanup:
==> Cleaning
Fixing /home/linuxbrew/.linuxbrew/opt/konversation/bin/konversation permissions from 777 to 444
How can I set the file permissions correctly?
Please note that I don't want to host the shell script itself somewhere, since I see no advance in packaging the shell script and the jar file in another zip file for destitution.
If you want to try it yourself try this command:
brew install rekire/packages/konversation

Shell scripts need to have a shebang line, otherwise the postinstall cleaner will set its permissions as though it were not an executable. In this specific case, I suggest:
use bin.write_jar_script instead -- this will set up the correct environment for JAR scripts
install .jars to libexec instead of prefix -- to avoid polluting the prefix with unnecessary files.
Example formula from Homebrew/homebrew-core

Related

Installing without package manager, why does executable binary fail with "command not found" unless I make the commands start with "./"?

I'm learning to use GNU/Linux and I want to know how to install programs that cannot be installed with the package manager.
I downloaded the tarball with the Linux 64-bit Binaries (including one called "haxelib"), extracted it, changed directory in the terminal to their location (~/Downloads/things/haxe_20201231082044_5e33a78aa/), and used chmod to make them executable.
If I try a command such as haxelib list, then the terminal returns
haxelib: command not found
If I try ./haxelib list (the same command but with ./ at the start) instead, then the command works as expected.
Why can't I use it without the ./? Programs installed with the package manager can be used without the ./.
Edit: I should probably also ask: where should I put the files from the tarball? Should they all go together in the same place? I have a feeling that a folder named "things" in my Downloads folder is not the best place for them.

How to Recreate Brew Aliasing, Without Brew?

Due to a security update in my organisation, I can no longer use brew to tap into my organisation's repo to install a package. I can, however, manually download the .jar files that brew was installing.
So previously I did:
brew tap <repo>
brew install <package>
<package> # Run the package from anywhere
And I could run the package from anywhere, just by typing in terminal. Easy peasy.
Normally Brew installs in usr/local/Cellar/<package>/some/internal/structure/<package.exe>. But somewhere along the way it does something with aliases and symlinks and $PATH [which I am confused by] so that I can run the given package from /usr/local/bin, which is in my $PATH, by just typing <package> anywhere in terminal.
I am trying to recreate this behaviour. I was able to manually download the jar files and put them in a folder /usr/local/bin/<package>. And if I run java -jar /usr/local/bin/<package>/<package.exe> then everything runs fine.
How do I get it so that I can run <package> from anywhere in terminal, like with Brew? Also, just to be 100% clear, I want to choose the alias; I want to be able to type "abc" to run the jar files.
/usr/local/bin/ is likely in your PATH variable already. If you want to check, print it to the terminal with echo "$PATH". If it isn't, you can pick one of the other directories in there or add it to. If you want to add that directory to your PATH variable, you want to add this to the relevant dot file (likely ~/.bashrc):
export PATH="/usr/local/bin:$PATH"
PATH is a colon separated list of directories where your system will look for executables.
Now, you can just write a short script to run java for you. For example, if we have a jar file called foo.jar, you could make a short script that runs java with the full path of foo.jar like this:
/usr/local/bin/foo:
#!/bin/bash
java -jar '/path/to/foo.jar' "$#"
sneaky edit: Make sure you give this file executable permissions:
chmod +x /usr/local/bin/foo
Now, on the terminal, if I run foo without a full path, it will run this script.
The "$#" is just going to pass any arguments you sent to this script along into the java program.
This isn't the only option to achieve this. You mentioned aliases as well. You could write an alias to your .bashrc that does the same thing:
alias foo='java -jar "path/to/foo.jar"'
A symlink wouldn't really be the best option here. This would be okay if your jar file was not in the PATH and you wanted it there. BUT, the PATH variable is really only for files that can be executed directly. As you already know, jar files cannot.

What does this ~/ mean on command line

I had to install mule license and this is the command required to run from bin directory.
mule -installLicense ~/license.lic
When I run this command, it says can't find file license.lic. Where is the license file supposed to be to run as it states in command.
I was able to run after removing ~/ though but would like to understand what does this mean
In *nix systems, ~ always refers to the current user's home directory. So, if you ran mule -installLicense ~/license.lic and it didn't work, it means that you had the file stored somewhere else.

configure command not found cygwin

This question has been asked many time but I am not able to resolve the problem from them so I am asking
I had installed Cygwin a few days ago.I tried using ./configure command but it says
-bash: ./configure: No such file or directory
I tried using
where configure
but I got the output
INFO: Could not find files for the given pattern(s).
then I tried grep configureand I got this output
/etc/bash_completion.d/configure
/usr/i686-pc-cygwin/sys-root/usr/share/libtool/libltdl/configure
/usr/share/ELFIO/configure
/usr/share/libtool/libltdl/configure
I tried to export the path and then run the ./configure but it also didn't worked.
I find no executable file named as configure in my cygwin bin directory.
Does it mean that I have to add configure file manually?How can I correct it?
NOTE :- I had also tried sh configure but it also didn't worked
If a software project is set up to be built using autoconf, that tool generates a script canonically called configure. It queries the system for various parameters that are subsequently used in the build, and is specific to the software package to be built. Different software projects have different configure scripts. They are all called configure, but their contents are not the same.
So, to actually build such a software project once that script was set up (usually done by the maintainers when packaging the source tarball for distribution), you call:
tar xzf <tarball>.gz # or xjf <tarball>.bz2 or whatever
cd <sourcedir> # the one you just untarred
./configure
make
make install
Note the prefix ./, which means "located in this directory" (i.e. the top directory of that project's source tree).
Actually, the better procedure is the so-called "out-of-tree build", when you set up a different directory for the binaries to be built in, so the source tree remains unmodified:
tar xzf <tarball>.gz # or xjf <tarball>.bz2 or whatever
mkdir builddir
cd builddir
../<sourcedir>/configure
make
make install
So, there is supposed to be no configure executable in your PATH, you are supposed to call the script of that name from the source tree you are trying to build from.
If I correctly understood...
Configure is not an application that should be installed on your system, but script that should be delivered with source code to prepare for make command. File named configure should be in the main directory of source code.
I understand that this is an old question. However many might find this solution helpful.
Normally we use the make command to compile a downloaded source in cygwin. In many cases it contains a autogen.sh file. Running that file with
bash autogen.sh
will in many case solve the problem. At least it solved my issue and i could then use the make command

How do I use CPACK_INSTALL_COMMANDS?

I'm creating a Linux tgz self-extracting installer using CPack and I'd like the installer to run a script or sequence of commands after all files have been installed. CPack documentation contains the following guidance:
CPACK_INSTALL_COMMANDS Extra commands to install components.
I set this variable in my CMakeLists.txt file and I see it set in the resulting CPackConfig.cmake file, but the commands I embed in this variable do not appear anywhere in the final .sh install script. What am I missing?
You're not missing anything, that's simply not how the CPACK_INSTALL_COMMANDS variable works.
On a typical project, CPack does a "make install" into a temporary location, in order to build the final installer based on the "make install" tree. The CPACK_INSTALL_COMMANDS variable is meant to be set for projects that would rather run some other command sequence, instead of the typical "make install" in order to produce the install tree.
So, CPack should be running your commands as it generates the package. It will not run your commands on the end user's machine at the end of him/her running the generated installation script...
There are per-generator ways of running installed executables and/or scripts at the end of the end user installation, but it will require some customization on your part. In this case, I'd recommend attempting to override the CPack.STGZ_Header.sh.in input file that is used when CPack generates the STGZ self-extracting script. Customize that file and add your calls to the bottom of it, above the line:
exit 0
To override the file, provide your own copy of it in your source tree, perhaps in a ${CMAKE_CURRENT_SOURCE_DIR}/CMake directory, and then in your CMakeLists.txt file, add:
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/CMake ${CMAKE_MODULE_PATH})
(Actually, as I'm writing this, I'm wondering if that's sufficient, or if the module path also needs to be set at the time that CPack runs... Try this, and let us know if your customization gets used by CPack or not. If not, I'll investigate a bit further and add some more advice here.)

Resources