dpkg-name.sh 4.4 KB

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