I have created a simple package using this guide, but I can't run the script inside it.
There is a folder named mypack
, which includes /usr/bin/myscript.sh
with some command in it (let's say it just echoes a message like "Hello World"), and a folder named DEBIAN
with a control
file with this text inside:
Package: mypack
Version: 1.0-1
Maintainer: Alex
Architecture: all
Section: misc
Description: echo me
I built and installed it using dpkg-deb --build mypack
; dpkg -i mypack.deb
as the guide says.
Finally, when I wanted to run the script script to see if it is works, I could not. I have tried:
myscript
(returnsmyscript: command not found
)myscript.sh
(returnsbash: /usr/bin/myscript.sh: Permission denied
)sudo myscript.sh
(returnssudo: myscript.sh: command not found
)mypack myscript
andmypack myscript.sh
(both returnmypack: command not found
)
How can I execute it then, so it actually works, or am I missing some important steps, which doesn't let me run the script?
Best Answer
Your script isn't set as executable; just like a script not installed by packaging, you need to make sure it has the executable bit set.
You have two options:
When creating the package, make sure that your script has the executable bit set before creating the package, by running this in your work directory Before building the package:
OR...
Use the
postinst
script for your package to set the executable bit after installation. Add a command to the.postinst
script similar to the following:For some of my things, I use both methods just to make sure it sets things as executable. That introduces headaches sometimes, but it's better to make sure than not make sure. At least, in my opinion.
As for the script not being able to be executed as
myscript
, that's becausemyscript
andmyscript.sh
are different objects.If you want that, do the following in your
.postinst
script for your package:... and then assuming you fix the executable bit problem, it should then 'just work' for both of the versions you were trying, both
myscript.sh
andmyscript
.HOWEVER the proper way to do this is, instead, to just package the script as
myscript
and not include the shell extension. You should then include a shebang line at the beginning (#!
) indicating the interpreter to use. Since.sh
could be anything. Then, set up the package to just installmyscript
. As muru stated, you should avoid making links in your postinst, but it's up to you what you want to do. There's many different ways to achieve your goal, but not really much strict guidance in the documentation for packaging.