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.

180 lines
4.0 KiB

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