mirror of the now-defunct rocklinux.org
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.

166 lines
3.4 KiB

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