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.
 
 
 
 
 
 

183 lines
5.7 KiB

  1. #!/bin/sh -- # no runable script, just for vi
  2. # we all like colorful messages
  3. CERROR="" # red
  4. CWARNING="" # yellow
  5. CMSG="" # green
  6. CINFO="" # light blue
  7. CDEBUG="" # blue
  8. CNORMAL="" # default system console color
  9. CDONE="" # green
  10. CPASS="" # green
  11. CFAIL="" # red
  12. CCMD="" # pink
  13. msgdie() { echo "${CERROR}E: $1${CNORMAL}" >&2; exit 1; }
  14. msgwarn() { echo "${CWARNING}W: $1${CNORMAL}" >&2; }
  15. msgmsg() { echo "${CMSG}$1${CNORMAL}" >&2; }
  16. msginfo() { echo "${CINFO}I: $1${CNORMAL}" >&2; }
  17. msgdebug() { echo "${CDEBUG}D: $1${CNORMAL}" >&2; }
  18. msgdone() { echo "${CDONE}DONE${CNORMAL}" >&2; }
  19. msgnwarn() { echo -n "${CWARNING}W: $1${CNORMAL}" >&2; }
  20. msgnmsg() { echo -n "${CMSG}$1${CNORMAL}" >&2; }
  21. msgninfo() { echo -n "${CINFO}I: $1${CNORMAL}" >&2; }
  22. msgndebug() { echo -n "${CDEBUG}D: $1${CNORMAL}" >&2; }
  23. msgtest() { echo -n "${CINFO}$1 ${CCMD}$(echo "$2" | sed -e 's/^aptc/apt-c/' -e 's/^aptg/apt-g/' -e 's/^aptf/apt-f/')${CINFO} …${CNORMAL} " >&2; }
  24. msgpass() { echo "${CPASS}PASS${CNORMAL}" >&2; }
  25. msgskip() { echo "${CWARNING}SKIP${CNORMAL}" >&2; }
  26. msgfail() { echo "${CFAIL}FAIL${CNORMAL}" >&2; }
  27. # enable / disable Debugging
  28. msginfo() { true; }
  29. msgdebug() { true; }
  30. msgninfo() { true; }
  31. msgndebug() { true; }
  32. msgdone() { if [ "$1" = "debug" -o "$1" = "info" ]; then true; else echo "${CDONE}DONE${CNORMAL}" >&2; fi }
  33. runapt() {
  34. msgdebug "Executing: ${CCMD}$*${CDEBUG} "
  35. APT_CONFIG=aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$*
  36. }
  37. aptconfig() { runapt apt-config $*; }
  38. aptcache() { runapt apt-cache $*; }
  39. aptget() { runapt apt-get $*; }
  40. aptftparchive() { runapt apt-ftparchive $*; }
  41. setupenvironment() {
  42. local TMPWORKINGDIRECTORY=$(mktemp -d)
  43. local TESTDIR=$(readlink -f $(dirname $0))
  44. msgninfo "Preparing environment for ${CCMD}$0${CINFO} in ${TMPWORKINGDIRECTORY}… "
  45. BUILDDIRECTORY="${TESTDIR}/../../build/bin"
  46. test -x "${BUILDDIRECTORY}/apt-get" || msgdie "You need to build tree first"
  47. local OLDWORKINGDIRECTORY=$(pwd)
  48. trap "cd /; rm -rf $TMPWORKINGDIRECTORY; cd $OLDWORKINGDIRECTORY" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
  49. cd $TMPWORKINGDIRECTORY
  50. mkdir rootdir aptarchive
  51. cd rootdir
  52. mkdir -p etc/apt/apt.conf.d etc/apt/sources.list.d etc/apt/trusted.gpg.d etc/apt/preferences.d var/cache var/lib/dpkg
  53. mkdir -p var/cache/apt/archives/partial var/lib/apt/lists/partial
  54. local STATUSFILE=$(echo "$(basename $0)" | sed 's/^test-/status-/')
  55. if [ -f "${TESTDIR}/${STATUSFILE}" ]; then
  56. cp "${TESTDIR}/${STATUSFILE}" var/lib/dpkg/status
  57. else
  58. touch var/lib/dpkg/status
  59. fi
  60. mkdir -p usr/lib/apt
  61. ln -s ${BUILDDIRECTORY}/methods usr/lib/apt/methods
  62. cd ..
  63. local PACKAGESFILE=$(echo "$(basename $0)" | sed 's/^test-/Packages-/')
  64. if [ -f "${TESTDIR}/${PACKAGESFILE}" ]; then
  65. cp "${TESTDIR}/${PACKAGESFILE}" aptarchive/Packages
  66. else
  67. touch var/lib/dpkg/status
  68. fi
  69. echo "RootDir \"${TMPWORKINGDIRECTORY}/rootdir\";" > aptconfig.conf
  70. echo "Debug::NoLocking \"true\";" >> aptconfig.conf
  71. echo "APT::Get::Show-User-Simulation-Note \"false\";" >> aptconfig.conf
  72. export LC_ALL=C
  73. msgdone "info"
  74. }
  75. configarchitecture() {
  76. local CONFFILE=rootdir/etc/apt/apt.conf.d/01multiarch.conf
  77. echo "APT::Architecture \"$1\";" > $CONFFILE
  78. shift
  79. while [ -n "$1" ]; do
  80. echo "APT::Architectures:: \"$1\";" >> $CONFFILE
  81. shift
  82. done
  83. }
  84. buildflataptarchive() {
  85. msginfo "Build APT archive for ${CCMD}$0${CINFO}…"
  86. cd aptarchive
  87. APTARCHIVE=$(readlink -f .)
  88. if [ -f Packages ]; then
  89. msgninfo "\tPackages file… "
  90. cat Packages | gzip > Packages.gz
  91. cat Packages | bzip2 > Packages.bz2
  92. cat Packages | lzma > Packages.lzma
  93. msgdone "info"
  94. fi
  95. if [ -f Sources ]; then
  96. msgninfo "\tSources file… "
  97. cat Sources | gzip > Sources.gz
  98. cat Sources | bzip2 > Sources.bz2
  99. cat Sources | lzma > Sources.lzma
  100. msgdone "info"
  101. fi
  102. cd ..
  103. aptftparchive release . > Release
  104. }
  105. setupflataptarchive() {
  106. buildflataptarchive
  107. APTARCHIVE=$(readlink -f ./aptarchive)
  108. if [ -f ${APTARCHIVE}/Packages ]; then
  109. msgninfo "\tadd deb sources.list line… "
  110. echo "deb file://$APTARCHIVE /" > rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list
  111. msgdone "info"
  112. else
  113. rm -f rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list
  114. fi
  115. if [ -f ${APTARCHIVE}/Sources ]; then
  116. msgninfo "\tadd deb-src sources.list line… "
  117. echo "deb-src file://$APTARCHIVE /" > rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list
  118. msgdone "info"
  119. else
  120. rm -f rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list
  121. fi
  122. aptget update -qq
  123. }
  124. diff() {
  125. local DIFFTEXT="$($(which diff) -u $* | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')"
  126. if [ -n "$DIFFTEXT" ]; then
  127. echo
  128. echo "$DIFFTEXT"
  129. return 1
  130. else
  131. return 0
  132. fi
  133. }
  134. testequal() {
  135. local COMPAREFILE=$(mktemp)
  136. echo "$1" > $COMPAREFILE
  137. shift
  138. msgtest "Test for equality of" "$*"
  139. $* 2>&1 | diff $COMPAREFILE - && msgpass || msgfail
  140. }
  141. testshowvirtual() {
  142. local VIRTUAL="E: Can't select versions from package '$1' as it purely virtual"
  143. local PACKAGE="$1"
  144. shift
  145. while [ -n "$1" ]; do
  146. VIRTUAL="${VIRTUAL}
  147. E: Can't select versions from package '$1' as it purely virtual"
  148. PACKAGE="${PACKAGE} $1"
  149. shift
  150. done
  151. msgtest "Test for virtual packages" "apt-cache show $PACKAGE"
  152. VIRTUAL="${VIRTUAL}
  153. E: No packages found"
  154. local COMPAREFILE=$(mktemp)
  155. local ARCH=$(dpkg-architecture -qDEB_HOST_ARCH_CPU)
  156. eval `apt-config shell ARCH APT::Architecture`
  157. echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' > $COMPAREFILE
  158. aptcache show $PACKAGE 2>&1 | diff $COMPAREFILE - && msgpass || msgfail
  159. }
  160. testnopackage() {
  161. msgtest "Test for non-existent packages" "apt-cache show $*"
  162. local SHOWPKG="$(aptcache show $* 2>&1 | grep '^Package: ')"
  163. if [ -n "$SHOWPKG" ]; then
  164. echo
  165. echo "$SHOWPKG"
  166. msgfail
  167. return 1
  168. fi
  169. msgpass
  170. }