dpkg-name.sh 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. #!/bin/sh
  2. set -e
  3. # Time-stamp: <96/05/03 13:59:41 root>
  4. prog="`basename \"${0}\"`"
  5. version="1.2.3"; # This line modified by Makefile
  6. purpose="rename Debian packages to full package names"
  7. license () {
  8. echo "# ${prog} ${version} -- ${purpose}
  9. # Copyright (C) 1995,1996 Erick Branderhorst <branderh@debian.org>.
  10. # This is free software; you can redistribute it and/or modify it
  11. # under the terms of the GNU General Public License as published by the
  12. # Free Software Foundation; either version 2, or (at your option) any
  13. # later version.
  14. # This is distributed in the hope that it will be useful, but
  15. # WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the file
  17. # /usr/share/common-licenses/GPL for more details."
  18. }
  19. stderr () {
  20. echo "${prog}: $@" >/dev/stderr;
  21. }
  22. show_version () {
  23. echo "${prog} version ${version} -- ${purpose}";
  24. }
  25. usage () {
  26. echo "Usage: ${prog} file[s]
  27. ${purpose}
  28. file.deb changes to <package>_<version>_<architecture>.deb
  29. according to the ``underscores convention''.
  30. -a|--no-architecture No architecture part in filename
  31. -o|--overwrite Overwrite if file exists
  32. -s|--subdir [dir] Move file into subdir (Use with care)
  33. -c|--create-dir Create target dir if not there (Use with care)
  34. -h|--help|-v|--version|-l|--license Show help/version/license"
  35. }
  36. fileexists () {
  37. if [ -f "$1" ];
  38. then
  39. return 0;
  40. else
  41. stderr "can't find \`"$1"'";
  42. return 1;
  43. fi
  44. }
  45. getname () {
  46. if p=`dpkg-deb -f -- "$1" package`;
  47. then
  48. v=`dpkg-deb -f -- "$1" version | sed s,.*:,,`;
  49. r=`dpkg-deb -f -- "$1" revision`;
  50. if [ -z "$r" ];
  51. then
  52. r=`dpkg-deb -f -- "$1" package_revision`;
  53. fi
  54. if [ -n "$r" ];
  55. then
  56. v=$v-$r;
  57. fi
  58. a=`dpkg-deb -f -- "$1" architecture`;
  59. a=`echo $a|sed -e 's/ *//g'`;
  60. if [ -z "$a" -a -n "$noarchitecture" ]; # arch field empty, or ignored
  61. then
  62. a=`dpkg --print-installation-architecture`;
  63. stderr "assuming architecture \`"$a"' for \`"$1"'";
  64. fi
  65. if [ -z "$noarchitecture" ];
  66. then
  67. tname=$p\_$v\_$a.deb;
  68. else
  69. tname=$p\_$v.deb
  70. fi
  71. name=`echo $tname|sed -e 's/ //g'`
  72. if [ "$tname" != "$name" ]; # control fields have spaces
  73. then
  74. stderr "bad package control information for \`"$1"'"
  75. fi
  76. return 0;
  77. fi
  78. }
  79. getdir () {
  80. if [ -z "$destinationdir" ];
  81. then
  82. dir=`dirname "$1"`;
  83. if [ -n "$subdir" ];
  84. then
  85. s=`dpkg-deb -f -- "$1" section`;
  86. if [ -z "$s" ];
  87. then
  88. s="no-section";
  89. stderr "assuming section \`"no-section"' for \`"$1"'";
  90. fi
  91. if [ "$s" != "non-free" -a "$s" != "contrib" -a "$s" != "no-section" ];
  92. then
  93. dir=`echo unstable/binary-$a/$s`;
  94. else
  95. dir=`echo $s/binary-$a`;
  96. fi
  97. fi
  98. else
  99. dir=$destinationdir;
  100. fi
  101. }
  102. move () {
  103. if fileexists "$arg";
  104. then
  105. getname "$arg";
  106. getdir "$arg";
  107. if [ ! -d "$dir" ];
  108. then
  109. if [ -n "$createdir" ];
  110. then
  111. if `mkdir -p $dir`;
  112. then
  113. stderr "created directory \`$dir'";
  114. else
  115. stderr "failed creating directory \`$dir'";
  116. exit 1;
  117. fi
  118. else
  119. stderr "no such dir \`$dir'";
  120. stderr "try --create-dir (-c) option";
  121. exit 1;
  122. fi
  123. fi
  124. newname=`echo $dir/$name`;
  125. if [ $newname -ef "$1" ]; # same device and inode numbers
  126. then
  127. stderr "skipping \`"$1"'";
  128. elif [ -f $newname -a -z "$overwrite" ];
  129. then
  130. stderr "can't move \`"$1"' to existing file";
  131. elif `mv -- "$1" $newname`;
  132. then
  133. echo "moved \``basename "$1"`' to \`$newname'";
  134. else
  135. stderr "mkdir can be used to create directory";
  136. exit 1;
  137. fi
  138. fi
  139. }
  140. if [ $# = 0 ]; then usage; exit 0; fi
  141. for arg
  142. do
  143. if [ -n "$subdirset" ];
  144. then
  145. subdirset=0;
  146. subdir=1;
  147. if [ -d $arg ];
  148. then
  149. destinationdir=$arg;
  150. continue
  151. fi
  152. fi
  153. case "$arg" in
  154. --version|-v) show_version; exit 0;;
  155. --help|-[h?]) usage; exit 0;;
  156. --licen[cs]e|-l) license; exit 0;;
  157. --create-dir|-c) createdir=1;;
  158. --subdir|-s) subdirset=1;;
  159. --overwrite|-o) overwrite=1 ;;
  160. --no-architecture|-a) noarchitecture=1 ;;
  161. --) shift;
  162. for arg
  163. do
  164. move "$arg";
  165. done; exit 0;;
  166. *) move "$arg";;
  167. esac
  168. done
  169. exit 0;
  170. # Local variables:
  171. # tab-width: 2
  172. # End: