frusen_repo_crawl_dragora_old 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. #!/bin/sh
  2. # TESTS
  3. # VARIABLES
  4. # FUNCTIONS
  5. # MAIN
  6. #-----------------------------------
  7. # TESTS
  8. #-----------------------------------
  9. if ! command -v lynx >/dev/null 2>&1; then
  10. printf "command lynx is missing. install it\n"
  11. exit 1
  12. fi
  13. if [ "$#" -lt 1 ]; then
  14. printf "\nEnter program you search for as argument\n" 1>&2
  15. exit 1
  16. fi
  17. # first run
  18. dragora_repos="/tmp/dragora_repos" # VARIABLES
  19. if ! [ -d "$dragora_repos" ]; then
  20. mkdir "$dragora_repos"
  21. fi
  22. #-----------------------------------
  23. # VARIABLES
  24. #-----------------------------------
  25. # setting search_terms or options
  26. # as set is used to get the repos,
  27. # this is a very dirty and confusing workaround
  28. # anything but bulletproof
  29. if [ "$#" -eq 1 ]; then
  30. case "$1" in
  31. -r|--remove) option="$1"; break;;
  32. -*) printf "Wrong option. Use -h\n"; exit 1;;
  33. *) search_term="$1";;
  34. esac
  35. elif [ "$#" -eq 2 ]; then
  36. case "$1" in
  37. -*) option="$1"; search_term="$2";;
  38. *) printf "Wrong usage. option searchterm. try -h \n"; exit 1;;
  39. esac
  40. fi
  41. # the other variables
  42. repo_basename=""
  43. found=""
  44. grep_found=""
  45. answer=""
  46. set -- "http://gungre.ch/dragora/repo/kelsoo" \
  47. "http://gungre.ch/dragora/repo/mprodrigues" \
  48. "http://gungre.ch/dragora/repo/n4dir" \
  49. "http://gungre.ch/dragora/repo/n4dir/perl_modules" \
  50. "http://gungre.ch/dragora/repo/frusen/old-stable" \
  51. "http://gungre.ch/dragora/repo/frusen/stable" \
  52. "http://gungre.ch/dragora/repo/frusen/unstable" \
  53. "http://92.19.232.58:82/dragora/repo/tom/"
  54. #----------------------------------
  55. # FUNCTIONS
  56. #-----------------------------------
  57. dl_pkg () {
  58. printf "\nDownload the package? (yes or no): \n"
  59. read -r answer
  60. case "$answer" in
  61. [Yy]|[Yy]es) echo 'mget *.tlz' | lftp "$1" ;;
  62. esac
  63. }
  64. crawl_dragora () {
  65. for i in "$@"; do
  66. repo_basename=$(basename "$i")
  67. grep_found=$(lynx -dump -nolist "$i" | awk '{print $1;}' | \
  68. tee "$dragora_repos/$repo_basename" | \
  69. grep "$search_term")
  70. if [ -n "$grep_found" ]; then
  71. found="yes"
  72. printf "%s/$grep_found\n" "$i"
  73. dl_pkg "$i/$grep_found"
  74. fi
  75. done
  76. }
  77. grep_local () {
  78. for i in "$@"; do
  79. repo_basename=$(basename "$i")
  80. grep_found=$(grep "$search_term" "$dragora_repos"/"$repo_basename")
  81. if [ -n "$grep_found" ]; then
  82. found="yes"
  83. printf "\n%s found in %s\n\n" "$searchterm" "$dragora_repos/$repo_basename"
  84. fi
  85. done
  86. }
  87. info_msg () {
  88. if [ -z "$found" ]; then
  89. printf "\nNot found at community repos\n"
  90. printf "\ntry jul search %s too\n\n" "$search_term"
  91. exit 1
  92. fi
  93. }
  94. usage () {
  95. printf "
  96. Usage: crawl_dragora [options]
  97. -h | --help
  98. display help
  99. -r | --remove
  100. remove %s, start fresh
  101. -f | --force
  102. force download from gungre
  103. -i
  104. force grep %s
  105. " "$dragora_repos" "$dragora_repos"
  106. }
  107. #----------------------------------
  108. # MAIN work
  109. #-----------------------------------
  110. #while :; do
  111. case $option in
  112. -h|--help) usage; exit 0;;
  113. -i) grep_local "$@"; exit 0;;
  114. -r|--remove) rm -r "$dragora_repos"; exit 0;;
  115. -f|--force) crawl_dragora "$@" ; exit 0;;
  116. -*) usage; exit 1;;
  117. # *) break;;
  118. esac
  119. #done
  120. if find "$dragora_repos"/* -mtime -1 | grep -q . ; then
  121. printf "\nLast download less than a day ago\n"
  122. printf "Will grep the local files: %s\n\n" "$dragora_repos"
  123. grep_local "$@"
  124. info_msg
  125. else
  126. crawl_dragora "$@"
  127. info_msg
  128. fi
  129. exit 0