RPJ's RPi OS: a sensor data platform for the Raspberry Pi built with python2.7 and redis. https://rpjios.com
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.

125 lines
3.3 KiB

  1. #!/bin/bash
  2. check_and_install() {
  3. HOW=$1
  4. PKGNAME=$2
  5. ALTAPTNAME=$3
  6. echo -n "* Looking for ${PKGNAME}: "
  7. if [ $HOW == "which" ]; then
  8. which "${PKGNAME}" > /dev/null
  9. elif [[ $HOW == "pkgcfg" || $HOW == "pkg-config" ]]; then
  10. pkg-config --exists "${PKGNAME}" > /dev/null
  11. elif [[ $HOW == "apt" || $HOW == "apt-list" ]]; then
  12. apt list --installed 2> /dev/null | grep "${PKGNAME}" > /dev/null
  13. fi
  14. if [ $? == 1 ]; then
  15. echo "NOT FOUND"
  16. _N=$ALTAPTNAME
  17. if [ -z "$_N" ]; then
  18. _N=$PKGNAME
  19. fi
  20. echo "* Trying to install ${_N}..."
  21. sudo apt -y install ${_N} > ${_N}_apt-install.stdout 2> ${_N}_apt-install.stderr
  22. else
  23. echo "found"
  24. fi
  25. }
  26. link_local_py_lib() {
  27. LIBDIR=$1
  28. echo "* Linking local Python library '${LIBDIR}'"
  29. if [ ! -L "env/lib/python2.7/site-packages/${LIBDIR}" ]; then
  30. pushd "env/lib/python2.7/site-packages/" > /dev/null
  31. ln -s "../../../../${LIBDIR}" 2> /dev/null > /dev/null
  32. popd > /dev/null
  33. fi
  34. }
  35. build_embedded_sps() {
  36. echo -n "* Fetching embedded-sps submodule: "
  37. git submodule init >> git-setup.stdout 2>> git-setup.stderr
  38. git submodule update --recursive >> git-setup.stdout 2>> git-setup.stderr
  39. pushd embedded-sps > /dev/null
  40. git submodule init >> git-setup.stdout 2>> git-setup.stderr
  41. git submodule update --recursive >> git-setup.stdout 2>> git-setup.stderr
  42. echo "done"
  43. echo -n "* Building embedded-sps submodule: "
  44. make release > make.release.stdout 2> make.release.stderr
  45. pushd release/sps30-i2c > /dev/null
  46. pushd hw_i2c > /dev/null
  47. mv sensirion_hw_i2c_implementation.c sensirion_hw_i2c_implementation.c.orig
  48. ln -s sample-implementations/linux_user_space/sensirion_hw_i2c_implementation.c
  49. popd > /dev/null
  50. make > make.stdout 2> make.stderr
  51. if [ -f libsps30.so ]; then
  52. numSyms=`nm libsps30.so | grep -i sps | wc -l`
  53. cp libsps30.so ../../../lib/rpjios/devices/
  54. echo "success (${numSyms})"
  55. else
  56. echo "failure!"
  57. fi
  58. popd > /dev/null
  59. popd > /dev/null
  60. }
  61. cat /etc/os-release | perl -ne "exit(1), if (/ID_LIKE=debian/)"
  62. if [ $? != 1 ]; then
  63. echo "** Looks like you're not on a Debian-like system, and I need 'apt'. Sorry."
  64. exit -1
  65. fi
  66. IS_RPI=1
  67. REQ_FILE=requirements.txt
  68. cat /etc/os-release | perl -ne "exit(1), if (/ID=raspbian/)"
  69. if [ $? != 1 ]; then
  70. echo "*** Non-RPi platform detected: omitting unneeded modules."
  71. IS_RPI=0
  72. REQ_FILE=requirements-nonRPi.txt
  73. else
  74. echo "*** RPi platform detected: building sensor drivers and including hardware interface modules."
  75. fi
  76. echo
  77. check_and_install "which" "virtualenv"
  78. check_and_install "apt" "redis-server"
  79. check_and_install "which" "zip"
  80. check_and_install "apt" "python-dev"
  81. check_and_install "apt" "libjpeg9-dev"
  82. if [ ${IS_RPI} == 1 ]; then
  83. check_and_install "apt" "python-smbus"
  84. build_embedded_sps
  85. fi
  86. if [ ! -d "./env" ]; then
  87. echo -n "* Initializing virtualenv: "
  88. virtualenv --system-site-packages --prompt="(rpjios venv) " ./env > virtualenv-init.stdout 2> virtualenv-init.stderr
  89. if [ $? != 0 ]; then
  90. echo "failed! Cannot continue."
  91. exit -1
  92. else
  93. echo "done"
  94. fi
  95. fi
  96. source env/bin/activate
  97. link_local_py_lib "lib/rpjios"
  98. echo -n "* Installing modules from '${REQ_FILE}' (this may take awhile): "
  99. pip install -r ${REQ_FILE} > pip-install.stdout 2> pip-install.stderr
  100. echo "done"
  101. if [ $? == 0 ]; then
  102. echo ""
  103. echo "*** Success! Run 'source env/bin/activate' to get started."
  104. else
  105. echo "*** ERROR ***"
  106. fi