old-mksplit.sh 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #!/bin/bash
  2. # This script is only supposed to be called by dpkg-split.
  3. # Its arguments are:
  4. # <sourcefile> <partsize> <prefix> <totalsize> <partsizeallow> <msdostruncyesno>
  5. # Stdin is also redirected from the source archive by dpkg-split.
  6. # Copyright (C) 1995 Ian Jackson <ian.greenend.org.uk>
  7. #
  8. # This is free software; you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License as
  10. # published by the Free Software Foundation; either version 2,
  11. # or (at your option) any later version.
  12. #
  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
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public
  19. # License along with dpkg; if not, write to the Free Software
  20. # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21. set -ex
  22. if [ "$#" != 6 ]; then echo >&2 'Bad invocation of mksplit.sh.'; exit 1; fi
  23. sourcefile="$1"
  24. partsize="$2"
  25. prefix="$3"
  26. orgsize="$4"
  27. partsizeallow="$5"
  28. msdos="$6"
  29. myversion=2.1
  30. csum=`md5sum <"$sourcefile"`
  31. package="`dpkg-deb --field \"$sourcefile\" Package`"
  32. version="`dpkg-deb --field \"$sourcefile\" Version`"
  33. revision="`dpkg-deb --field \"$sourcefile\" Package_Revision`"
  34. if [ "x$revision" != x ]; then version="$version-$revision"; fi
  35. nparts=$[($orgsize+$partsize-1)/$partsize]
  36. startat=0
  37. partnum=0
  38. td=/tmp/ds$$
  39. mkdir $td
  40. ec=1
  41. trap "rm -r $td; exit $ec" 0
  42. dsp=$td/debian-split
  43. echo -n "Splitting package $package into $nparts parts: "
  44. if [ yes = "$msdos" ]
  45. then
  46. prefixdir="`dirname \"$prefix\"`"
  47. cleanprefix="`basename \"$prefix\" | tr A-Z+ a-zx | tr -dc 0-9a-z-`"
  48. fi
  49. ar-include () {
  50. perl -e '
  51. $f= $ARGV[0];
  52. (@s= stat(STDIN)) || die "$f: $!";
  53. undef $/; read(STDIN,$d,$s[7]) == $s[7] || die "$f: $!";
  54. printf("%-16s%-12d0 0 100644 %-10d%c\n%s%s",
  55. $f, time, $s[7], 0140, $d,
  56. ($s[7] & 1) ? "\n" : "") || die "$f: $!";
  57. close(STDOUT) || die "$f: $!";
  58. ' "$1" <"$td/$1"
  59. }
  60. while [ $startat -lt $orgsize ]
  61. do
  62. showpartnum=$[$partnum+1]
  63. echo $myversion >$dsp
  64. echo $package >>$dsp
  65. echo $version >>$dsp
  66. echo $csum >>$dsp
  67. echo $orgsize >>$dsp
  68. echo $partsize >>$dsp
  69. echo $showpartnum/$nparts >>$dsp
  70. dd bs=$partsize skip=$partnum count=1 \
  71. of=$td/data.$showpartnum \
  72. 2>&1 | (egrep -v '.* records (in|out)' || true)
  73. rm -f $td/part
  74. echo -n "$showpartnum "
  75. echo '!<arch>' >$td/part
  76. ar-include debian-split >>$td/part
  77. ar-include data.$showpartnum >>$td/part
  78. thispartreallen="`ls -l $td/part | awk '{print $5}'`"
  79. if ! [ "$thispartreallen" -le "$partsizeallow" ]
  80. then
  81. cat >&2 <<END
  82. Header is too long, making part too long. Your package name or version
  83. numbers must be extraordinarily long, or something. Giving up.
  84. END
  85. exit 1
  86. fi
  87. if [ yes = "$msdos" ]
  88. then
  89. basename="`echo ${showpartnum}of$nparts.\"$cleanprefix\" | \
  90. dd bs=9 count=1 2>/dev/null | \
  91. sed -e 's/^\([^.]*\)\.\(.*\)$/\2\1/'`"
  92. basename="$prefixdir/$basename"
  93. else
  94. basename="$prefix.${showpartnum}of$nparts"
  95. fi
  96. mv $td/part $basename.deb
  97. startat=$[$startat+$partsize]
  98. partnum=$showpartnum
  99. done
  100. echo "done"
  101. ec=0