prerequisites_imapsync 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. #!/bin/sh
  2. # $Id: prerequisites_imapsync,v 1.36 2022/05/17 13:46:16 gilles Exp gilles $
  3. MODULES_MANDATORY='
  4. App::cpanminus
  5. Authen::NTLM
  6. CGI
  7. Compress::Zlib
  8. Crypt::OpenSSL::RSA
  9. Data::Dumper
  10. Data::Uniqid
  11. Digest::HMAC
  12. Digest::HMAC_MD5
  13. Digest::MD5
  14. Dist::CheckConflicts
  15. Encode
  16. Encode::Byte
  17. Encode::IMAPUTF7
  18. File::Copy::Recursive
  19. File::Tail
  20. IO::Socket::INET
  21. IO::Socket::INET6
  22. IO::Socket::SSL
  23. IO::Tee
  24. JSON
  25. JSON::WebToken
  26. JSON::WebToken::Crypt::RSA
  27. HTML::Entities
  28. LWP::UserAgent
  29. Mail::IMAPClient
  30. MIME::Base64
  31. Module::Implementation
  32. Module::Runtime
  33. Module::ScanDeps
  34. Net::SSLeay
  35. Package::Stash
  36. Package::Stash::XS
  37. PAR::Packer
  38. Parse::RecDescent
  39. Pod::Usage
  40. Proc::ProcessTable
  41. Readonly
  42. Regexp::Common
  43. Sys::MemInfo
  44. Term::ReadKey
  45. Test::Fatal
  46. Test::Mock::Guard
  47. Test::MockObject
  48. Test::More
  49. Test::Pod
  50. Test::Requires
  51. Test::Deep
  52. Text::ParseWords
  53. Try::Tiny
  54. Unicode::String
  55. URI::Escape
  56. '
  57. MODULES_FOR_CODERS='
  58. Smart::Comments
  59. '
  60. test_perl() {
  61. # First we need perl
  62. if perl -v > /dev/null 2>&1 ; then
  63. perl_version=`perl -e 'printf "%vd\n", $^V;'`
  64. echo Ok: Found Perl $perl_version
  65. return 0
  66. else
  67. echo 'Failure: Perl is not here. You have to install Perl first.'
  68. return 1
  69. fi
  70. }
  71. test_make() {
  72. # Second we need make to build some Perl modules
  73. if echo foo: | make -f - foo ; then
  74. make_version=`make -v |head -1`
  75. echo Ok: Found make $make_version
  76. return 0
  77. else
  78. echo 'Failure: make is not here. You have to install the "make" command.'
  79. return 1
  80. fi
  81. }
  82. test_cpanm() {
  83. # Second we need make to build some Perl modules
  84. # redirect "cpanm ... < /dev/null" is there for macos buid via ssh
  85. # no clue why it's necessary
  86. if cpanm -h > /dev/null 2>&1 < /dev/null; then
  87. cpanm_version=`cpanm --version < /dev/null | head -1`
  88. echo Ok: Found cpanm $cpanm_version
  89. return 0
  90. else
  91. echo 'Failure: cpanm is not here. You have to install the "cpanm" command.'
  92. return 1
  93. fi
  94. }
  95. test_module() {
  96. test -n $1 || return
  97. M_tested=$1
  98. shift
  99. if perl -m"$M_tested" -e '' >/dev/null 2>&1 ; then
  100. echo "Ok: Found Perl module $M_tested"
  101. else
  102. echo "Failure: Not found Perl module $M_tested $@"
  103. LIST_TO_INSTALL="$LIST_TO_INSTALL $M_tested"
  104. fi
  105. return
  106. }
  107. test_mandatory_modules() {
  108. for M in $MODULES_MANDATORY
  109. do
  110. test_module $M
  111. done
  112. }
  113. search_modules_any() {
  114. test -n "$*" || {
  115. echo "All needed modules are already installed"
  116. return
  117. }
  118. # Debian, Ubuntu & Co
  119. apt-cache -h > /dev/null 2>&1 && {
  120. search_modules_apt "$@"
  121. return
  122. }
  123. # Centos & Co
  124. yum -h > /dev/null 2>&1 && {
  125. search_modules_yum "$@"
  126. return
  127. }
  128. # ArchLinux & Co
  129. pacman -h > /dev/null 2>&1 && {
  130. search_modules_pacman "$@"
  131. return
  132. }
  133. # FreeBSD
  134. pkg version > /dev/null 2>&1 && {
  135. search_modules_freebsd "$@"
  136. return
  137. }
  138. # no yum, no apt-get, no pacman
  139. {
  140. search_modules_cpanm "$@"
  141. return
  142. }
  143. }
  144. search_modules_cpanm() {
  145. cat <<EOD
  146. Here is a cpanm command to install missing Perl modules:
  147. cpanm $@
  148. EOD
  149. }
  150. search_modules_pacman() {
  151. echo
  152. echo Searching pacman packages names
  153. #echo pacman -Fy
  154. #pacman -Fy
  155. echo pacman -S --noconfirm --needed pkgfile
  156. pacman -S --noconfirm --needed pkgfile
  157. echo pkgfile --update
  158. pkgfile --update
  159. for M in "$@" ; do
  160. echo "==== Searching pacman package name for $M"
  161. F=`echo $M|tr -s ":" "/"`.pm
  162. # Not very good "pacman -Fs"
  163. #echo pacman -Fs "$F"
  164. #echo
  165. #pacman -Fs "$F"
  166. #echo
  167. # Better! pkgfile --reg
  168. echo "pkgfile --reg $F | grep perl-"
  169. echo
  170. pkgfile --reg "$F" | grep perl-
  171. echo
  172. done
  173. }
  174. search_modules_yum() {
  175. echo
  176. echo Searching rpm packages names
  177. for M in "$@" ; do
  178. echo "==== Searching rpm package name for $M"
  179. F=`echo $M|tr -s ":" "/"`.pm
  180. echo yum -q whatprovides "*/$F"
  181. echo
  182. yum -q whatprovides "*/$F"
  183. echo
  184. done
  185. }
  186. search_modules_apt() {
  187. echo
  188. echo Searching deb packages names
  189. for M in "$@" ; do
  190. F=`echo $M|tr -s ":" "/"`.pm
  191. echo "==== Searching deb package name for $M with: apt-file search /$F"
  192. #echo apt-file search /$F
  193. echo
  194. if apt-file -h > /dev/null 2>&1
  195. then
  196. apt-file search /$F
  197. else
  198. echo "apt-file is not installed. Suggestion: apt-get install apt-file; apt-file update"
  199. fi
  200. echo
  201. echo "==== Searching deb package name for $M with: apt-cache search $M"
  202. #apt-cache search "$M"
  203. apt-cache search "$M"
  204. echo
  205. done
  206. }
  207. search_modules_freebsd()
  208. {
  209. echo
  210. echo Searching pkg FreeBSD names
  211. for M in "$@" ; do
  212. F=`echo $M|tr -s ":" "-"`
  213. echo "==== Searching deb package name for $M with: pkg search p5-$F"
  214. echo
  215. pkg search "p5-$F"
  216. echo
  217. done
  218. }
  219. list_to_install() {
  220. test -n "$LIST_TO_INSTALL" || return 0
  221. echo
  222. echo 'What you have to do before using imapsync:'
  223. for M in $LIST_TO_INSTALL ; do
  224. echo "Install Perl module $M"
  225. done
  226. # return false/bad if some modules are missing.
  227. return 1
  228. }
  229. test_unix() {
  230. echo '$SHELL says ' $SHELL
  231. echo '$0 gives ' $0
  232. echo -n "ps -ef gives " ; ps -ef | grep $$ | grep -v grep| grep -v 'ps -ef'
  233. sw_vers > /dev/null 2>&1 && sw_vers # Darwin
  234. lsb_release -dirc > /dev/null 2>&1 && lsb_release -dirc # Linux
  235. uname -a
  236. }
  237. test_unix
  238. #exit
  239. test_perl || exit 1
  240. test_make || exit
  241. test_mandatory_modules
  242. list_to_install
  243. EXIT=$?
  244. # Help the user to install missing modules
  245. search_modules_any $LIST_TO_INSTALL
  246. if test "$1" = "MODULES_MANDATORY"
  247. then
  248. search_modules_any $MODULES_MANDATORY
  249. elif test -n "$1"
  250. then
  251. search_modules_any "$@"
  252. fi
  253. test_cpanm
  254. exit $EXIT