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.

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