Guest User

ports

a guest
Jun 30th, 2010
229
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/sh
  2. #
  3. # Create all packages with sym-links for FreeBSD 5.x+
  4. #
  5. # Version: 1.2.2
  6. # Copyright (c) 2006 Alexey Tsvetnov, vorakl@fbsd.kiev.ua
  7. #
  8. # All error in /var/log/<script_name>.err
  9. #
  10.  
  11. # Path to packages directory
  12. packagespath="/usr/ports/packages"
  13.  
  14. # Command for get package's version
  15. pkgvercmd="/usr/sbin/pkg_version -v"
  16. #pkgvercmd="/usr/local/sbin/portversion -v" # more faster than pkg_version
  17.  
  18. #-------------------------------------------------------------------------------
  19.  
  20. err="\033[0;40;31mError\033[0m"
  21. ok="\033[1;40;33mOk\033[0m"
  22.  
  23.  
  24. checkPackagesPath ()
  25. {
  26. [ -d $packagespath ] || { /usr/bin/printf " *** $err: $packagespath doesn't exist.\n";
  27. /bin/echo " *** Error: $packagespath doesn't exist." > /var/log/`basename $0`.log;
  28. exit 1; }
  29. [ -d $packagespath/All ] || { /bin/mkdir $packagespath/All || exit 1; }
  30. [ -d $packagespath/Latest ] || { /bin/mkdir $packagespath/Latest || exit 1; }
  31. return 0
  32. }
  33.  
  34. checkPkgAll ()
  35. {
  36. [ -f $packagespath/All/$fullname.tbz ] && return 0
  37. return 1
  38. }
  39.  
  40. checkPkgLatest ()
  41. {
  42. [ -L $packagespath/Latest/$shortname.tbz ] && [ -r $packagespath/Latest/$shortname.tbz ] && return 0
  43. return 1
  44. }
  45.  
  46. checkPkgCat ()
  47. {
  48. [ -L $packagespath/$subdir/$fullname.tbz ] && [ -r $packagespath/$subdir/$fullname.tbz ] && return 0
  49. return 1
  50. }
  51.  
  52. createPkgAll ()
  53. {
  54. /usr/sbin/pkg_create -jb $fullname $packagespath/All/$fullname.tbz && return 0
  55. return 1
  56. }
  57.  
  58. createPkgLatest ()
  59. {
  60. /bin/rm -f $packagespath/Latest/$shortname.tbz
  61. cd $packagespath/Latest && /bin/ln -s ../All/$fullname.tbz $shortname.tbz && return 0
  62. return 1
  63. }
  64.  
  65. createPkgCat ()
  66. {
  67. if [ -d $packagespath/$subdir ]; then
  68. /bin/rm -f $packagespath/$subdir/$fullname.tbz
  69. else
  70. /bin/mkdir -p $packagespath/$subdir
  71. fi
  72.  
  73. cd $packagespath/$subdir && /bin/ln -s ../All/$fullname.tbz $fullname.tbz && return 0
  74. return 1
  75. }
  76.  
  77. getPkgFullVersion ()
  78. {
  79. echo -n "Geting full version package list..."
  80. pkglist=`$pkgvercmd | /usr/bin/awk '{print $1}'`
  81. /usr/bin/printf "$ok\n"
  82. }
  83.  
  84. work ()
  85. {
  86. for fullname in $pkglist; do
  87. /bin/echo "Check $fullname"
  88.  
  89. shortname=`/bin/echo $fullname | /usr/bin/sed 's/\-[^-]*$//'`
  90. subdir=`/usr/sbin/pkg_info -o $fullname | /usr/bin/sed -e '1,3d' -e '$d' | /usr/bin/awk -F/ '{print $1}'`
  91.  
  92. if ! checkPkgAll; then
  93. /bin/echo -n " ==> Create package..."
  94. if createPkgAll; then /usr/bin/printf "$ok\n"
  95. else /usr/bin/printf "$err\n"
  96. fi
  97.  
  98. /bin/echo -n " ==> Create Latest sym-link..."
  99. if createPkgLatest; then /usr/bin/printf "$ok\n"
  100. else /usr/bin/printf "$err\n"
  101. fi
  102.  
  103. /bin/echo -n " ==> Create Category sym-link..."
  104. if createPkgCat; then /usr/bin/printf "$ok\n"
  105. else /usr/bin/printf "$err\n"
  106. fi
  107.  
  108. continue
  109. fi
  110.  
  111. if ! checkPkgLatest; then
  112. /bin/echo -n " ==> Create Latest sym-link..."
  113. if createPkgLatest; then /usr/bin/printf "$ok\n"
  114. else /usr/bin/printf "$err\n"
  115. fi
  116. fi
  117.  
  118. if ! checkPkgCat; then
  119. /bin/echo -n " ==> Create Category sym-link..."
  120. if createPkgCat; then /usr/bin/printf "$ok\n"
  121. else /usr/bin/printf "$err\n"
  122. fi
  123. fi
  124. done
  125. }
  126.  
  127. main ()
  128. {
  129. exec 2>/var/log/`basename $0`.log
  130.  
  131. checkPackagesPath
  132. getPkgFullVersion
  133. work
  134.  
  135. exec 2>&-
  136. }
  137.  
  138. main
  139.  
  140. exit 0
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×