dpkg-name.sh 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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}: $@" 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>.deb
  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. if [ -z "$noarchitecture" ];
  70. then
  71. tname=$p\_$v\_$a.deb;
  72. else
  73. tname=$p\_$v.deb
  74. fi
  75. name=`echo $tname|sed -e 's/ //g'`
  76. if [ "$tname" != "$name" ]; # control fields have spaces
  77. then
  78. stderr "bad package control information for \`"$1"'"
  79. fi
  80. return 0;
  81. fi
  82. }
  83. getdir () {
  84. if [ -z "$destinationdir" ];
  85. then
  86. dir=`dirname "$1"`;
  87. if [ -n "$subdir" ];
  88. then
  89. s=`dpkg-deb -f -- "$1" section`;
  90. if [ -z "$s" ];
  91. then
  92. s="no-section";
  93. stderr "assuming section \`"no-section"' for \`"$1"'";
  94. fi
  95. if [ "$s" != "non-free" ] && [ "$s" != "contrib" ] && [ "$s" != "no-section" ];
  96. then
  97. dir=`echo unstable/binary-$a/$s`;
  98. else
  99. dir=`echo $s/binary-$a`;
  100. fi
  101. fi
  102. else
  103. dir=$destinationdir;
  104. fi
  105. }
  106. move () {
  107. if fileexists "$arg";
  108. then
  109. getname "$arg";
  110. getdir "$arg";
  111. if [ ! -d "$dir" ];
  112. then
  113. if [ -n "$createdir" ];
  114. then
  115. if `mkdir -p $dir`;
  116. then
  117. stderr "created directory \`$dir'";
  118. else
  119. stderr "failed creating directory \`$dir'";
  120. exit 1;
  121. fi
  122. else
  123. stderr "no such dir \`$dir'";
  124. stderr "try --create-dir (-c) option";
  125. exit 1;
  126. fi
  127. fi
  128. newname=`echo $dir/$name`;
  129. if [ x$symlink = x1 ];
  130. then
  131. command="ln -s --"
  132. else
  133. command="mv --"
  134. fi
  135. if [ $newname -ef "$1" ]; # same device and inode numbers
  136. then
  137. stderr "skipping \`"$1"'";
  138. elif [ -f $newname ] && [ -z "$overwrite" ];
  139. then
  140. stderr "can't move \`"$1"' to existing file";
  141. elif `$command "$1" $newname`;
  142. then
  143. echo "moved \``basename "$1"`' to \`$newname'";
  144. else
  145. stderr "mkdir can be used to create directory";
  146. exit 1;
  147. fi
  148. fi
  149. }
  150. if [ $# = 0 ]; then usage; exit 0; fi
  151. for arg
  152. do
  153. if [ -n "$subdirset" ];
  154. then
  155. subdirset=0;
  156. subdir=1;
  157. if [ -d $arg ];
  158. then
  159. destinationdir=$arg;
  160. continue
  161. fi
  162. fi
  163. case "$arg" in
  164. --version|-v) show_version; exit 0;;
  165. --help|-[h?]) usage; exit 0;;
  166. --licen[cs]e|-l) license; exit 0;;
  167. --create-dir|-c) createdir=1;;
  168. --subdir|-s) subdirset=1;;
  169. --overwrite|-o) overwrite=1 ;;
  170. --symlink|-k) symlink=1 ;;
  171. --no-architecture|-a) noarchitecture=1 ;;
  172. --) shift;
  173. for arg
  174. do
  175. move "$arg";
  176. done; exit 0;;
  177. *) move "$arg";;
  178. esac
  179. done
  180. exit 0;
  181. # Local variables:
  182. # tab-width: 2
  183. # End: