9

I inherited a legacy development system which is poorly documented and the source code is not known if it still is available.

Now I could locate some of the source code and actually build one part of the system.

I wonder if I can find the rest of the source code and if there is any better way than locate *.c and manually inspecting the files (that's how I found part of the code).

There are 3 machines and only one where I found the source code that seems to be a development machine. It also has 61 .deb archives that seems to be the packaged versions of the projects, but looking into the .deb archives shows that the source is not in the archives or at least not where I looked.

Is there a good way to "scan" an entire drive for source code?

Stephen Kitt
  • 434,908

2 Answers2

9

This won’t answer your more general question, but in your specific case, since you have packages on the system, it’s worth looking for the corresponding source code:

find / -name \*.orig.tar\* -o -name \*.dsc

This will look for source archives named in the way the Debian package building tools expect, and source package control files. If you find those, look for .debian.tar* or .diff.gz files alongside them. All these files combined would give you the source code and the build rules, along with all the package metadata.

You could also look for unpacked control files:

find / -name control

These would typically live in the debian subdirectory of a package’s source, which should contain everything you need to rebuild the package from source.

Stephen Kitt
  • 434,908
  • 1
    also: find / -wholename '*/debian/rules'. or (faster, if mlocate is installed) locate -r /debian/rules$ – cas Jul 31 '17 at 09:23
  • 2
    @cas I’m trying to play it safe here, I’ve seen some very odd setups for building Debian packages. locate would be faster, but I’ve been disappointed in the past running it on recovered systems which had been cleaned up — the locate database still new about source code which was gone. (That can still be useful information if backups are available...) – Stephen Kitt Jul 31 '17 at 09:28
  • 1
    Going by https://unix.stackexchange.com/questions/382857/ , these are not Debian packages. – JdeBP Jul 31 '17 at 09:35
  • I forgot to mention that the source is/was versioned with CVS. Maybe I can look for old cvs directories(?) – Niklas Rosencrantz Jul 31 '17 at 09:40
  • 1
    @JdeBP I was going by “It also has 61 .deb archives that seems to be the packaged versioned of the projects” (sic). – Stephen Kitt Jul 31 '17 at 09:40
  • 1
    @DjDac that would work too, find / -name CVS would find checked-out copies of the code. – Stephen Kitt Jul 31 '17 at 09:41
  • I get a strange error running find: find: /proc/361/fd: No such file or directory – Niklas Rosencrantz Jul 31 '17 at 09:44
  • @cas I get these error msgs: find: invalid predicate -wholename and locate: invalid option -- r – Niklas Rosencrantz Jul 31 '17 at 09:45
  • 2
    @DjDac that’s fine, just find trying to read files in /proc which disappear between the time find builds its list of files and the time it reads them. You can skip /proc entirely. – Stephen Kitt Jul 31 '17 at 09:45
  • 1
    @DjDac doh. sarge is old and has old version of findutils, so no -wholename in find and no -r in locate. sorry about that. you can achieve similar with locate / | grep .... – cas Jul 31 '17 at 10:20
  • 1
    sarge's locate should work with just locate '*debian/rules'. From man locate on my woody VM: If a pattern does contain metacharacters, locate only displays file names that match the pattern exactly. (tested there, too). – cas Jul 31 '17 at 10:39
  • 1
    I would search for a local git repo too – Rui F Ribeiro Jul 31 '17 at 10:49
  • Thanks for all the help. I could run the above commands to make sure that I looked everywhere. – Niklas Rosencrantz Jul 31 '17 at 16:40
1

I usually use a combination of scripts for working with source files. Just as the answer above this will not solve exactly your case, but searching for symbols can help in locating source files.

The following is added to bashrc:

function list-code-files() {
    find -type f \( \
        -name '*.cpp' -o \
        -name '*.java' -o \
        -name '*.php' -o \
        -name '*.[chS]' -o \
        -name 'Makefile' -o \
        -name '*.mk' \
        \) -print0
}

function csym() {
    list-code-files | xargs -0 grep -ne "$1"
}

Then I can list source files using list-code-files | xargs -0 echo, or search for symbols using csym some-symbol-regexeg

Kotte
  • 2,537