dpkg-name.sh 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #!/bin/sh
  2. set -e
  3. prog="`basename \"${0}\"`"
  4. version="0.11"; # This line modified by Makefile
  5. purpose="rename Debian packages to full package names"
  6. license () {
  7. echo "# ${prog} ${version} -- ${purpose}
  8. # Copyright (C) 1995,1996 Erick Branderhorst <branderhorst@heel.fgg.eur.nl>.
  9. # This is free software; you can redistribute it and/or modify it
  10. # under the terms of the GNU General Public License as published by the
  11. # Free Software Foundation; either version 2, or (at your option) any
  12. # later version.
  13. # This is distributed in the hope that it will be useful, but
  14. # WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the file
  16. # /usr/doc/copyright/GPL for more details."
  17. }
  18. stderr () {
  19. echo "${prog}: $@" >/dev/stderr;
  20. }
  21. show_version () {
  22. echo "${prog} version ${version} -- ${purpose}";
  23. }
  24. usage () {
  25. echo "Usage: ${prog} file[s]
  26. ${purpose}
  27. file.deb changes to <package>-<version>[-<revision>].deb
  28. -h|--help|-v|--version|-l|--license Show help/version/license"
  29. }
  30. rename () {
  31. if [ -f "$1" ];
  32. then
  33. if p=`dpkg-deb -f -- "$1" package`;
  34. then
  35. p="$p-"`dpkg-deb -f -- "$1" version`;
  36. r=`dpkg-deb -f -- "$1" revision`;
  37. if [ -z "$r" ];
  38. then
  39. r=`dpkg-deb -f -- "$1" package_revision`;
  40. fi
  41. if [ -n "$r" ];
  42. then
  43. p=$p-$r;
  44. fi
  45. p=`echo $p|sed 's/ //g'`
  46. p=`dirname "$1"`"/"$p.deb
  47. if [ $p -ef "$1" ]; # same device and inode numbers
  48. then
  49. stderr "skipping \`"$1"'";
  50. elif [ -f $p ];
  51. then
  52. stderr "can't move \`"$1"' to existing file";
  53. elif `mv -- "$1" $p`;
  54. then
  55. echo "moved \``basename "$1"`' to \`${p}'";
  56. else
  57. stderr "hmm how did this happen?";
  58. fi
  59. fi
  60. else
  61. stderr "can't deal with \`"$1"'";
  62. fi
  63. }
  64. if [ $# = 0 ]; then usage; exit 0; fi
  65. for arg
  66. do
  67. case "$arg" in
  68. --version|-v) show_version; exit 0;;
  69. --help|-[h?]) usage; exit 0;;
  70. --licen[cs]e|-l) license; exit 0;;
  71. --) shift;
  72. for arg
  73. do
  74. rename "$arg";
  75. done; exit 0;;
  76. *) rename "$arg";;
  77. esac
  78. done
  79. exit 0;
  80. # Local variables:
  81. # tab-width: 2
  82. # End: