4

I'm trying to make a debian package from upstream source code which is not mine. The configure script provided by author makes a lot of symlinks in source directory. They're symlinks to all headers in src subdir to include subdir (So that makefile can easily copy the include directory in the case of installing development package). I'm using debhelper scripts to make package.

I'm using debhelper scripts to make package. The problem is using new debian package format (quilt 3.0 native), debuild refuses add changes of source directory consisting symlinks to final diff file. I'm getting errors like this:

dpkg-source: error: cannot represent change to foo.h:
dpkg-source: error:   new version is symlink to /ba/foo/foo.h
dpkg-source: error:   old version is nonexistent

I'm aware of the good solution: Change configure script not to symlink any header at all. It should add a target to makefile to install devel package. Though configure script has copyright issues. I can't touch upstream source.

I'm looking for a bash script to replace all symlinks in a directory with actual files they point to. For example if in the directory d there are three files a and b and c, which they ate symlinks to ../../foo/bar/x, ../../foo/bar/z ../../foo/bar/y, running desired script (say magic.sh) giving the ./d as first argument, should

cp ../../foo/bar/x ./d/a
cp ../../foo/bar/y ./d/b
cp ../../foo/bar/z ./d/c

I can't find a way to know which file is a symlink pointing to.

1 Answer 1

4

Use readlink.

$ readlink /etc/alternatives/editor
/usr/bin/vim.basic

and wrap it in a shell script walking over the symbolic links in the directory.

You can find symbolic links using find:

$ find . -type l

A more complete example:

#!/bin/bash

find . -maxdepth 1 -type l | while read LINE; do 
echo link: $LINE resolved: `readlink $LINE`
done

outputs

link: ./.remmina resolved: sparkleshare-homedir/remmina
link: ./project resolved: Documents/2011-2 Project/
link: ./.ssh resolved: sparkleshare-homedir/ssh
2
  • pastebin.com/FNWQAsbm I hope this work for me...
    – sorush-r
    Sep 18, 2012 at 18:11
  • Be sure to do proper escaping though when doing operations. A symlink resolving to bla / bla may expand to this: rm -rf bla / bla. Not sure if your example prevents this, mine doesn't.
    – gertvdijk
    Sep 18, 2012 at 18:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .