dpkg-name.sh 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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. -k|--symlink Don't create a new file, but a symlink
  33. -s|--subdir [dir] Move file into subdir (Use with care)
  34. -c|--create-dir Create target dir if not there (Use with care)
  35. -h|--help|-v|--version|-l|--license Show help/version/license"
  36. }
  37. fileexists () {
  38. if [ -f "$1" ];
  39. then
  40. return 0;
  41. else
  42. stderr "can't find \`"$1"'";
  43. return 1;
  44. fi
  45. }
  46. getname () {
  47. if p=`dpkg-deb -f -- "$1" package`;
  48. then
  49. v=`dpkg-deb -f -- "$1" version | sed s,.*:,,`;
  50. r=`dpkg-deb -f -- "$1" revision`;
  51. if [ -z "$r" ];
  52. then
  53. r=`dpkg-deb -f -- "$1" package_revision`;
  54. fi
  55. if [ -n "$r" ];
  56. then
  57. v=$v-$r;
  58. fi
  59. a=`dpkg-deb -f -- "$1" architecture`;
  60. a=`echo $a|sed -e 's/ *//g'`;
  61. if [ -z "$a" -a -n "$noarchitecture" ]; # arch field empty, or ignored
  62. then
  63. a=`dpkg --print-installation-architecture`;
  64. stderr "assuming architecture \`"$a"' for \`"$1"'";
  65. fi
  66. if [ -z "$noarchitecture" ];
  67. then
  68. tname=$p\_$v\_$a.deb;
  69. else
  70. tname=$p\_$v.deb
  71. fi
  72. name=`echo $tname|sed -e 's/ //g'`
  73. if [ "$tname" != "$name" ]; # control fields have spaces
  74. then
  75. stderr "bad package control information for \`"$1"'"
  76. fi
  77. return 0;
  78. fi
  79. }
  80. getdir () {
  81. if [ -z "$destinationdir" ];
  82. then
  83. dir=`dirname "$1"`;
  84. if [ -n "$subdir" ];
  85. then
  86. s=`dpkg-deb -f -- "$1" section`;
  87. if [ -z "$s" ];
  88. then
  89. s="no-section";
  90. stderr "assuming section \`"no-section"' for \`"$1"'";
  91. fi
  92. if [ "$s" != "non-free" -a "$s" != "contrib" -a "$s" != "no-section" ];
  93. then
  94. dir=`echo unstable/binary-$a/$s`;
  95. else
  96. dir=`echo $s/binary-$a`;
  97. fi
  98. fi
  99. else
  100. dir=$destinationdir;
  101. fi
  102. }
  103. move () {
  104. if fileexists "$arg";
  105. then
  106. getname "$arg";
  107. getdir "$arg";
  108. if [ ! -d "$dir" ];
  109. then
  110. if [ -n "$createdir" ];
  111. then
  112. if `mkdir -p $dir`;
  113. then
  114. stderr "created directory \`$dir'";
  115. else
  116. stderr "failed creating directory \`$dir'";
  117. exit 1;
  118. fi
  119. else
  120. stderr "no such dir \`$dir'";
  121. stderr "try --create-dir (-c) option";
  122. exit 1;
  123. fi
  124. fi
  125. newname=`echo $dir/$name`;
  126. if [ x$symlink = x1 ];
  127. then
  128. command="ln -s --"
  129. else
  130. command="mv --"
  131. fi
  132. if [ $newname -ef "$1" ]; # same device and inode numbers
  133. then
  134. stderr "skipping \`"$1"'";
  135. elif [ -f $newname -a -z "$overwrite" ];
  136. then
  137. stderr "can't move \`"$1"' to existing file";
  138. elif `$command "$1" $newname`;
  139. then
  140. echo "moved \``basename "$1"`' to \`$newname'";
  141. else
  142. stderr "mkdir can be used to create directory";
  143. exit 1;
  144. fi
  145. fi
  146. }
  147. if [ $# = 0 ]; then usage; exit 0; fi
  148. for arg
  149. do
  150. if [ -n "$subdirset" ];
  151. then
  152. subdirset=0;
  153. subdir=1;
  154. if [ -d $arg ];
  155. then
  156. destinationdir=$arg;
  157. continue
  158. fi
  159. fi
  160. case "$arg" in
  161. --version|-v) show_version; exit 0;;
  162. --help|-[h?]) usage; exit 0;;
  163. --licen[cs]e|-l) license; exit 0;;
  164. --create-dir|-c) createdir=1;;
  165. --subdir|-s) subdirset=1;;
  166. --overwrite|-o) overwrite=1 ;;
  167. --symlink|-k) symlink=1 ;;
  168. --no-architecture|-a) noarchitecture=1 ;;
  169. --) shift;
  170. for arg
  171. do
  172. move "$arg";
  173. done; exit 0;;
  174. *) move "$arg";;
  175. esac
  176. done
  177. exit 0;
  178. # Local variables:
  179. # tab-width: 2
  180. # End: