#!/bin/bash # ------------------------------------------------------------- # Telramian # Script to easily install Telraam (https://telraam.net) an rpi # OS: Raspberry Pi OS Lite (Buster) version 2020-05-27 # Python: 3.7.3 # OpenCV: 4.3.0 # Based on https://github.com/Telraam/Telraam-RPi # Author= Manuel Stevens (manuel.stevens@ardesco.be) # ------------------------------------------------------------- OPENCV_VERSION='4.3.0' # path to Telraam application PATH_TELRAAM=$HOME/Telraam PATH_TELRAAM_SCRIPTS=$PATH_TELRAAM/Scripts PATH_TELRAAM_PICTURES=$PATH_TELRAAM/Pictures # path to Telraam-RPi github clone folder PATH_TELRAAM_RPI=$PATH_TELRAAM/Telraam-RPi PATH_TELRAAM_RPI_ACCESS_POINT=$PATH_TELRAAM_RPI/"Access point" PATH_TELRAAM_RPI_IMAGE_PROCESSING=$PATH_TELRAAM_RPI/"Image processing" PATH_TELRAAM_RPI_MISC=$PATH_TELRAAM_RPI/Misc PATH_TELRAAM_RPI_REMOTE_UPDATING=$PATH_TELRAAM_RPI/"Remote updating" # path to OpenCV PATH_OPENCV_BASE=$HOME/opencv PATH_OPENCV=$PATH_OPENCV_BASE/opencv PATH_OPENCV_CONTRIB=$PATH_OPENCV_BASE/opencv_contrib PATH_OPENCV_BUILD=$PATH_OPENCV/build cd $HOME # This function formats the timestamp timestamp() { date +"%F_%T_%Z"; } # This function formats log messages # echo_process(String message) echo_process() { echo -e "\\e[1;94m$(timestamp) [Telramian] $*\\e[0m"; } # Get the timestamp of the install process timestamp=$(date +%Y%m%d%H%M) # Log everything to a file exec &> >(tee -a "telramian-build-$timestamp.log") echo_process "------------------------------" echo_process "----Telramian installation----" echo_process "------------------------------" echo_process "Setting keyboard to be (Belgian)" L='be' && sudo sed -i 's/XKBLAYOUT=\"\w*"/XKBLAYOUT=\"'$L'\"/g' /etc/default/keyboard sudo dpkg-reconfigure keyboard-configuration -f noninteractive sudo invoke-rc.d keyboard-setup start sudo setsid sh -c 'exec setupcon -k --force <> /dev/tty1 >&0 2>&1' sudo udevadm trigger --subsystem-match=input --action=change echo_process "Disabling splash screen" CMDLINE=/boot/cmdline.txt if grep -q "splash" $CMDLINE ; then sudo sed -i $CMDLINE -e "s/ quiet//" sudo sed -i $CMDLINE -e "s/ splash//" sudo sed -i $CMDLINE -e "s/ plymouth.ignore-serial-consoles//" fi echo_process "Enabling camera" sudo tee -a /boot/config.txt > /dev/null </dev/null 2>&1 cd $PATH_OPENCV_BUILD cmake -D CMAKE_BUILD_TYPE=RELEASE \ -D CMAKE_INSTALL_PREFIX=/usr/local \ -D OPENCV_EXTRA_MODULES_PATH=$PATH_OPENCV_CONTRIB/modules \ -D BUILD_NEW_PYTHON_SUPPORT=ON \ -D BUILD_opencv_python3=ON \ -D HAVE_opencv_python3=ON \ -D PYTHON_DEFAULT_EXECUTABLE=/usr/bin/python3 \ -D OPENCV_PYTHON3_INSTALL_PATH=/usr/lib/python3/dist-packages \ -D OPENCV_ENABLE_NONFREE=ON \ -D CMAKE_SHARED_LINKER_FLAGS=-latomic \ -D WITH_TBB=ON \ -D ENABLE_NEON=ON \ -D ENABLE_VFPV3=ON \ -D WITH_V4L=ON \ -D WITH_QT=ON \ -D WITH_OPENGL=ON \ -D WITH_TENGINE=ON \ -D BUILD_TESTS=OFF \ -D INSTALL_C_EXAMPLES=OFF \ -D INSTALL_PYTHON_EXAMPLES=OFF \ -D BUILD_EXAMPLES=OFF .. nproc | xargs -I % make -j% sudo make install sudo ldconfig echo_process "Reset SWAP space to 1000" sudo sed -i 's/CONF_SWAPSIZE=1024/CONF_SWAPSIZE=100/g' /etc/dphys-swapfile sudo /etc/init.d/dphys-swapfile stop sudo /etc/init.d/dphys-swapfile start echo_process "Instal mysql database server mariadb with python support" sudo apt install mariadb-server python3-mysqldb -y echo_process "Install apache2 web server with php and mysql support" sudo apt install apache2 php libapache2-mod-php php-mysql -y echo_process "Install WIFI dnsmasq (dhcp) hostapd (access point)" sudo apt install dnsmasq hostapd -y echo_process "Install Telraam-RPi master github ripository" mkdir -p $PATH_TELRAAM cd $PATH_TELRAAM git clone https://github.com/Telraam/Telraam-RPi.git cd $PATH_TELRAAM_RPI git checkout master echo_process "Copying files from Telraam-RPi" mkdir -p $PATH_TELRAAM mkdir -p $PATH_TELRAAM_SCRIPTS mkdir -p $PATH_TELRAAM_PICTURES cp -rf "$PATH_TELRAAM_RPI_ACCESS_POINT"/*.py $PATH_TELRAAM_SCRIPTS cp -rf "$PATH_TELRAAM_RPI_IMAGE_PROCESSING"/*.py $PATH_TELRAAM_SCRIPTS cp -rf "$PATH_TELRAAM_RPI_MISC"/*.py $PATH_TELRAAM_SCRIPTS cp -rf "$PATH_TELRAAM_RPI_REMOTE_UPDATING"/*.py $PATH_TELRAAM_SCRIPTS chmod +x $PATH_TELRAAM_SCRIPTS/* #temp fix # the original telraam script is for opencv 3 while we are using opencv 4 # the difference is that findContours is now returning 2 values instead of 3 # no worries because the 3rd values was not used anayway # so just replace im2, contours, hierarchy = cv2.findContours with contours, hierarchy = cv2.findContours # until this is fixed in the original script (pull request submitted) # change it in telraam_monitoring.py sed -i 's/im2, contours, hierarchy = cv2.findContours/contours, hierarchy = cv2.findContours/g' $PATH_TELRAAM_SCRIPTS/telraam_monitoring.py #temp fix echo_process 'Configuration camera stream (based on https://picamera.readthedocs.io/en/latest/recipes2.html#web-streaming)' echo_process 'URL for locally testing camera stream http://127.0.0.1:8000/stream.mjpg' sudo chmod +x $PATH_TELRAAM_SCRIPTS/telraam_camera_stream.py sudo cp -rf "$PATH_TELRAAM_RPI_ACCESS_POINT"/telraam_camera_stream.service /lib/systemd/system/ sudo chmod 644 /lib/systemd/system/telraam_camera_stream.service sudo systemctl daemon-reload sudo systemctl enable telraam_camera_stream.service echo_process 'Configuration mysql database' sudo mysql < /dev/null < /dev/null < /dev/null < /dev/null < /dev/null < /etc/iptables.ipv4.nat" #In /etc/rc.local add #sudo ifconfig eth0 down #iptables-restore < /etc/iptables.ipv4.nat ##Set random pwd at startup #echo "pi:$(sudo openssl rand -base64 12 2>&1)" | sudo chpasswd\ #just above "exit 0" to install these rules on boot. sudo sed -i '/^exit 0/i \\nsudo ifconfig eth0 down\nsudo iptables-restore < /etc/iptables.ipv4.nat\n#Set random pwd at startup\n/bin/echo "pi:$(sudo /usr/bin/openssl rand -base64 12 2>&1)" | sudo /usr/sbin/chpasswd\n' /etc/rc.local echo_process 'Setup Access Point control' sudo chmod +x $PATH_TELRAAM_SCRIPTS/telraam_ap_control_loop.py sudo cp -rf "$PATH_TELRAAM_RPI_ACCESS_POINT"/telraam_ap_control_loop.service /lib/systemd/system/ sudo chmod 644 /lib/systemd/system/telraam_ap_control_loop.service sudo systemctl daemon-reload sudo systemctl enable telraam_ap_control_loop.service echo_process 'Install Login page' sudo cp -rf "$PATH_TELRAAM_RPI_ACCESS_POINT"/index.php /var/www/html/ sudo chmod 755 /var/www/html/index.php sudo rm -f /var/www/html/index.html echo_process 'Setup Remote updating' sudo chmod +x $PATH_TELRAAM_SCRIPTS/telraam_auto_updater_cron.py sudo chmod +x $PATH_TELRAAM_SCRIPTS/telraam_remote_updater-monitoring.py sudo chmod +x $PATH_TELRAAM_SCRIPTS/telraam_remote_updater.py sudo cp -rf "$PATH_TELRAAM_RPI_REMOTE_UPDATING"/updatecron /etc/cron.d/ echo_process "Augmenting .profile " sudo tee -a $HOME/.profile > /dev/null < /dev/null <