Reputation: 381
I'm trying to modify my debian/rules
file to create me symbolic link.
My package has two files:
/etc/logger-server1.json
/etc/logger-server2.json
Now in my debian/rules
file I created the following entry:
override_dh_install:
dh_install
if [ "$(PROJECT)" == "server1" ]; then \
echo "It is server1"
ln -sf /etc/logger-server1.json /etc/logger-cfg.json
else
echo "It is server2"
ln -sf /etc/logger-server2.json /etc/logger-cfg.json
fi
But when I compile it I get the following error:
install: cannot stat 'etc/logger-cfg.json': No such file or directory
Makefile:167: recipe for target 'install' failed
Is there any way to solve it?
P.s.
When I'm creating it manually it is working
Upvotes: 0
Views: 1381
Reputation: 31274
ouch.
you first must understand, that there's a difference between building a Debian package and installing it.
The sole purpose of debian/rules
is to create a package.
It's typically used to "build" files from the sources (e.g. compiling files into binaries; normally this is not done "directly", but by invoking the build-system of the sources you are packaging), and arrange them in such a way that you can put them into the .deb
archive.
Once you have a .deb
file, you can install it on any machine.
(And typically, the machine where you build the package is not the target machine(s) where you install the package)
However, the scripts that are present in debian/rules
are only run during the build-process. They are not executed when the package is being installed!
So debian/rules
is really just a script (a Makefile, to be precise), that is run when you build the package to do all the heavy lifting.
The sole purpose of this script is to create a .deb
file.
So whatever command you have in it, will be executed with the priviliges of the running user. The commands can be arbitrary, and don't need to have anything to do with the package at hand.
In your specific example ln -sf /etc/logger-server1.json /etc/logger-cfg.json
will attempt to create a symlink in the /etc
directory of the machine where you build the package.
This is most likely not what you want. I guess what you want to do is create a symlink in the package (that is: you want the symlink on every machine that installs the package).
Luckily for you, dpkg-buildpackage
is usually invoked with non-root powers (these days). And non-superusers are typically not allowed to create symlinks in /etc
.
(Similarily, your script could contain rm -r /
(DO NOT RUN THIS) which would just wipe out your entire harddisk while building the package if your user has/had enough power).
dh_link
In order to create symlinks inside your package, use dh_link
, using use debian/*.links
.
Eg. assuming you are building two packages server1
and server2
you would have something like:
$ cat debian/server1.links
/etc/logger-server1.json /etc/logger-cfg.json
$ cat debian/server2.links
/etc/logger-server2.json /etc/logger-cfg.json
So if you install the server1
package, it will create a symlink from /etc/logger-server1.json, and if you install the server2
package , it will create a symlink from /etc/logger-server2.json.
If you want to make the actual decision a install-time decision (e.g. you are installing a single package myserver
and ask the user what they want during the installation process), you ought to checkout how to write maintainer scripts.
however, I think you are overengineering things.
The /etc
directory is special, as it is reserved for the administrator to adjust to their needs.
Packages need to be extra careful if they change things in there (as this might undo all the changes the admin did).
If you just install files into /etc/
, debhelper will apply extra logic to protect changed files in there (basically asking the admin, whether they want to keep the old file or install the new file).
But if you bypass this security with your own scripts, then chances are high that you will break things.
Upvotes: 2