opkg-link 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/bin/sh
  2. #
  3. # Create symbolic links from all files in
  4. # alternative opkg destinations
  5. #
  6. # By Stefan Tomanek <stefan@pico.ruhr.de>
  7. # readlink might not be installed, so we probably
  8. # cannot detect whether a link points to a specific target
  9. if which readlink >/dev/null; then
  10. points_to() {
  11. local DST
  12. local SRC
  13. DST="$1"
  14. SRC="$2"
  15. [ `readlink "$DST"` = "$SRC" ]
  16. }
  17. else
  18. # we cannot determine the target of the link,
  19. # so we return false to be on the safe side
  20. false
  21. fi
  22. # find out the installation directories
  23. awk '$1 == "dest" && $3 != "/" { print $2, $3 }' /etc/opkg.conf | \
  24. while read DEST DDIR; do
  25. echo "Processing destination $DEST..." >&2
  26. # if the direktory does not exist, continue
  27. [ -d "$DDIR" ] || continue
  28. for LIST in "$DDIR/usr/lib/opkg/info"/*.list; do
  29. [ -e "$LIST" ] || continue;
  30. PKG=${LIST##*/}
  31. PKG=${PKG%.list}
  32. echo " Linking package ${PKG} from $DEST..." >&2
  33. while read FSRC; do
  34. FDST=${FSRC#$DDIR}
  35. FDSTDIR=${FDST%/*}/
  36. [ ! -d "$FDSTDIR" ] && {
  37. echo " Creating directory $FDSTDIR..." >&2
  38. mkdir -p "$FDSTDIR"
  39. }
  40. if [ ! -e "$FDST" ] || [ -L "$FDST" ]; then
  41. # do not rewrite every link
  42. if [ -L "$FDST" ] && [ `readlink "$FDST"` = "$FSRC" ]; then
  43. :
  44. #echo " $FDST already linked." >&2
  45. else
  46. echo " linking $FSRC -> $FDST" >&2
  47. ln -sf "$FSRC" "$FDST"
  48. fi
  49. else
  50. echo " Not replacing existing file $FDST!" >&2
  51. fi
  52. done < "$LIST"
  53. done
  54. done