summaryrefslogtreecommitdiff
path: root/Master/tlpkg/bin/deref-symlinks
blob: 699786163cc2e14ec0e17fa66c82c63d68969ec4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/bin/sh -e
# $Id$
# Originally written by Karl Berry. Public domain.
# 
# Replace symlinks to files with the actual files.
# Symlinks to anything else are not touched.

if test x"$1" = x--save-links; then
  savelinks=true
  shift
else
  savelinks=false
fi

for f in "$@"; do
  test -h "$f" || continue  # skip non-symlinks
  test -f "$f" || continue  # skip links to anything but regular files
  
  cp -p --dereference "$f" "$f".file  # expand link
  mv -v "$f" "$f".link                # move link out of the way
  mv -v "$f".file "$f"                # replace with regular file
  $savelinks || rm "$f".link          # remove link unless keeping
done