OpenSDE Packages Database (without history before r20070)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

179 lines
3.9 KiB

  1. #!/bin/sh
  2. # --- T2-COPYRIGHT-NOTE-BEGIN ---
  3. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  4. #
  5. # T2 SDE: package/.../bize/bize.sh
  6. # Copyright (C) 2004 - 2006 The T2 SDE Project
  7. #
  8. # More information can be found in the files COPYING and README.
  9. #
  10. # This program is free software; you can redistribute it and/or modify
  11. # it under the terms of the GNU General Public License as published by
  12. # the Free Software Foundation; version 2 of the License. A copy of the
  13. # GNU General Public License can be found in the file COPYING.
  14. # --- T2-COPYRIGHT-NOTE-END ---
  15. bize_usage()
  16. {
  17. echo "usage: bize -i [-t] [-v] [-f] [-R root] package1.tar.bz2 ..." 1>&2
  18. echo " bize -r [-t] [-v] [-f] [-R root] package1 ..." 1>&2
  19. }
  20. bize_remove()
  21. {
  22. local line base tag md5s="$adm/md5sums/$pkg"
  23. if [ "$keep" ] ; then
  24. if [ ! -f "$md5s" ] ; then
  25. echo "$0: $md5s: no such file, skipping remove" 1>&2
  26. return
  27. fi
  28. (cd "$root/" && md5sum -c "var/adm/md5sums/$pkg" 2> /dev/null) |
  29. while read line ; do
  30. base="${line%: *}"
  31. stat="${line##*: }"
  32. file="$root/$base"
  33. if [ -z "$base" -o -z "$stat" ] ; then
  34. echo "$0: invalid md5sum output '$line'" 1>&2
  35. elif [ -f "$file" -a ! -L "$file" ] ; then
  36. if [ "$stat" = OK ] ; then
  37. $unlink "$file"
  38. elif [ "$stat" != FAILED ] ; then
  39. echo "$0: $file: $stat"
  40. elif [ "$test" ] ; then
  41. echo "$0: $file: modified, skipping"
  42. fi
  43. fi
  44. done
  45. fi
  46. sort -r "$list" | while read tag base ; do
  47. file="$root/$base"
  48. if [ "$tag" != "$pkg:" ] ; then
  49. echo "$0: invalid tag '$tag' in $list" 1>&2
  50. elif [ -z "$base" ] ; then
  51. echo "$0: missing file name in $list" 1>&2
  52. elif [ -L "$file" ] ; then
  53. $unlink "$file"
  54. elif [ -d "$file" ] ; then
  55. $test rmdir $voption "$file"
  56. elif [ "${base#var/adm/}" != "$base" -a -f "$file" ] ; then
  57. $unlink "$file"
  58. elif [ "$keep" -a -f "$file" ] ; then
  59. [ "$test" ] || echo "$0: $file: modified, skipping"
  60. else
  61. $unlink "$file"
  62. fi
  63. done
  64. }
  65. bize_install()
  66. {
  67. if [ ! -f "$arch" ] ; then
  68. echo "$0: $arch: no such file, skipping install" 1>&2
  69. return
  70. fi
  71. pkg="${arch%.tar.bz2}"
  72. if [ "$arch" = "$pkg" ] ; then
  73. echo "$0: $arch: not a .tar.bz2 file" 1>&2
  74. return
  75. fi
  76. pkg="${pkg%-[0-9]*}"
  77. pkg="${pkg##*/}"
  78. if [ -z "$pkg" ] ; then
  79. echo "$0: $arch: missing package name" 1>&2
  80. return
  81. fi
  82. [ "${arch#-}" = "$arch" ] || arch="./$arch"
  83. list="$adm/flists/$pkg"
  84. if [ -f "$list" ] ; then
  85. [ "$verbose" ] && echo "updating $pkg ..."
  86. bize_remove
  87. else
  88. [ "$verbose" ] && echo "installing $pkg ..."
  89. fi
  90. $test mkdir -p$verbose "$root/"
  91. if [ "$test" ] ; then
  92. echo "bzip2 -c -d $arch | tar $taropt -C $root/"
  93. else
  94. bzip2 -c -d "$arch" | tar $taropt -C "$root/"
  95. fi
  96. }
  97. bize_uninstall()
  98. {
  99. [ "$verbose" ] && echo "removing $pkg"
  100. list="$adm/flists/$pkg"
  101. if [ -f "$list" ] ; then
  102. bize_remove
  103. else
  104. echo "$0: $list: no such file, skipping remove" 1>&2
  105. fi
  106. }
  107. bize_main()
  108. {
  109. local which=which file arch list="sort rm rmdir mkdir tar bzip2"
  110. local install remove test verbose voption keep=k root=/ taropt
  111. while [ "$1" ] ; do
  112. case "$1" in
  113. -i) install=1 ;;
  114. -r) remove=1 ;;
  115. -t) test=echo ;;
  116. -f) keep="" ;;
  117. -v) verbose=v ; voption=-v ;;
  118. -R) shift ; root="$1" ;;
  119. -R*) root="${1#-R}" ;;
  120. --) break ;;
  121. -*) bize_usage ; return 1 ;;
  122. *) break;;
  123. esac
  124. shift
  125. done
  126. if type sh > /dev/null 2>&1 ; then
  127. which=type
  128. elif ! which sh > /dev/null ; then
  129. echo "$0: unable to find 'type' or 'which'" 1>&2
  130. return 1
  131. fi
  132. [ "$keep" ] && list="$list md5sum"
  133. for file in $list ; do
  134. if ! $which $file > /dev/null ; then
  135. echo "$0: unable to find '$file'" 1>&2
  136. return 1
  137. fi
  138. done
  139. if [ "$install" = "$remove" -o -z "$root" -o -z "$*" ] ; then
  140. bize_usage
  141. return 1
  142. fi
  143. root="${root%/}"
  144. [ "${root#-}" = "$root" ] || root="./$root"
  145. local adm="$root/var/adm" unlink="$test rm -f$verbose" pkg
  146. if [ "$install" ] ; then
  147. taropt="xp${verbose}${keep}"
  148. for arch do
  149. bize_install
  150. done
  151. else
  152. for pkg do
  153. bize_uninstall
  154. done
  155. fi
  156. return 0
  157. }
  158. bize_main "$@"