Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer 1

up vote 4 down vote accepted

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
share|improve this answer
    
pastebin.com/FNWQAsbm I hope this work for me... –  sorush-r Sep 18 '12 at 18:11
    
Works fine... thanks :) –  sorush-r Sep 18 '12 at 18:15
    
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 '12 at 18:18
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.