Symlink not created by postinst of *.deb package. New file created instead

870 views Asked by At

I have created a *.deb package which saves some files into the required locations which works fine. During the postinst I generate a new file (merging 2 files together using my own script "mergeconfig"), the file is created fine.

However, on the next line of the postinst, I try to create a symlink to this new file, this doesn't work as expected.

Instead of getting a link, I seem to get a hard copy/a new file:

$ ls -la /etc/app/conf-enabled/
-rw-r--r-- 1 root root 2600 Dec  1 17:00 enabledconfig

I tried pulling the code out into it's own file and executing it from the postinst file (after giving it executable privileges) and got the same result. Though if I manually run the file I get a valid symlink created:

$ /../../updateEnabledConf
 -- Merge this package's server config into app config
Complete
 -- Update conf-enabled symlink

$ ls -la /etc/app/conf-enabled/
lrwxrwxrwx 1 root root   42 Dec  1 17:06 enabledconfig -> /etc/app/conf-available/server-app

The code in updateEnableConf is:

#!/bin/bash
SERVERNAME="server"

APPNAME="app"
CONFIGNAME="enabledconfig"
ETCAPPDIR="/etc/app"
CONFAVAILABLEDIR="$ETCAPPDIR/conf-available"
CONFENABLEDDIR="$ETCAPPDIR/conf-enabled"
CONFAPPDIR="$ETCAPPDIR/conf-app"
CONFSERVERDIR="$ETCAPPDIR/conf-server"

echo " -- Merge this package's server config into app config"
sudo mergeconfig $CONFAPPDIR/$APPNAME $CONFSERVERDIR/$SERVERNAME $CONFAVAILABLEDIR/$SERVERNAME-$APPMNAME

echo " -- Update conf-enabled symlink"
sudo ln -s -f $CONFAVAILABLEDIR/$SERVERNAME-$APPNAME $CONFENABLEDDIR/$CONFIGNAME

exit 0

I'm not sure what I'm doing wrong, in that the symlink isn't being created correctly during the install of the deb package, but does when I run the same file manually from putty. Both users have sudo access, I'm using gdebi to install the package and I have other packages that create symlinks in the same way without a problem. Any help would be great

UPDATE

After more investigating, turns out the symlinks were being created correctly by the postinst scripts, but there was another file being called directly after with a sed command to the path of the symlink:

ENABLEDCONF="/etc/app/conf-enabled/enabledconfig"
sed -i 's#<search>#<replace>#g' $ENABLEDCONF

This seems to take the data form the file the symlink points too, but overwrites the symlink with the new file. I have updated the sed line to use a readlink command, this has fixed the problem:

sed -i 's#<search>#<replace>#g' $(readlink $ENABLEDCONF)

Thanks for the help

1

There are 1 answers

0
Armali On

After more investigating, turns out the symlinks were being created correctly by the postinst scripts, but there was another file being called directly after with a sed command to the path of the symlink:

ENABLEDCONF="/etc/app/conf-enabled/enabledconfig"
sed -i 's#<search>#<replace>#g' $ENABLEDCONF

This seems to take the data form the file the symlink points too, but overwrites the symlink with the new file. I have updated the sed line to use a readlink command, this has fixed the problem:

sed -i 's#<search>#<replace>#g' $(readlink $ENABLEDCONF)

– Martyn Gough