#!/bin/sh #@@@@# # [1] Set up firewall sudo sh /home/pi/iptables; echo "Set firewall rules" | sudo -u sats tee -a /home/sats/satsd/log/install.log > /dev/null; # [2] Start ssh service sudo systemctl start ssh; echo "started ssh service" | sudo -u sats tee -a /home/sats/satsd/log/install.log > /dev/null; # [3] Set random passwords for 'sats' test ! -e /target/install && echo "First Boot" | sudo -u sats tee -a /home/sats/satsd/log/install.log > /dev/null; test -e /target/install && echo "Normal Boot" | sudo -u sats tee -a /home/sats/satsd/log/install.log > /dev/null; echo "============" | sudo -u sats tee -a /home/sats/satsd/log/install.log > /dev/null; RANDOM_PASS=$(tr -cd A-Za-z0-9_ < /dev/urandom | head -c 256); echo "$RANDOM_PASS\n$RANDOM_PASS\n" | sudo passwd sats; echo "sats password changed" | sudo -u sats tee -a /home/sats/satsd/log/install.log > /dev/null; # [4] Set random passwords for 'pi' itself RANDOM_PASS=$(tr -cd A-Za-z0-9_ < /dev/urandom | head -c 256); echo "$RANDOM_PASS\n$RANDOM_PASS\n" | sudo passwd pi; echo "pi password changed" | sudo -u sats tee -a /home/sats/satsd/log/install.log > /dev/null; ################################################ #### ONLY ON FIRST BOOT #### ################################################ if [ ! -e /target/install ]; then # (1) Try to install necessary packages sudo apt-get update; echo "package update done" | sudo -u sats tee -a /home/sats/satsd/log/install.log > /dev/null; sudo apt-get -y install git php5 php5-cli php5-curl python-dev; echo "package install done" | sudo -u sats tee -a /home/sats/satsd/log/install.log > /dev/null; dpkg -s git 2>/dev/null >/dev/null && gitinstalled=1 || gitinstalled=0; BRANCH=$(sudo cat /home/sats/satsd/conf/machine.branch) > /dev/null; # (2) With git if installed # if [ $gitinstalled -eq 1 ]; then echo "cloning source.." | sudo -u sats tee -a /home/sats/satsd/log/install.log > /dev/null; sudo -u sats git clone -b $BRANCH ssh://smmp-server/satsd/git /home/sats/satsd/source \ && sudo -u sats touch /target/install \ || exit; echo "..done" | sudo -u sats tee -a /home/sats/satsd/log/install.log > /dev/null; fi; # (2) Enable SPI device # echo "dtparam=spi=on" | sudo tee -a /boot/config.txt > /dev/null; echo "dtoverlay=spi-bcm2708" | sudo tee -a /boot/config.txt > /dev/null; echo "enabled SPI device" | sudo -u sats tee -a /home/sats/satsd/log/install.log > /dev/null; # (3) Clone SPI python library # sudo git clone https://github.com/lthiery/SPI-Py.git /home/pi/spi-lib; echo "Cloned SPI-Py lib" | sudo -u sats tee -a /home/sats/satsd/log/install.log > /dev/null; # (4) Install SPI python library # cd /home/pi/spi-lib; sudo python setup.py build; sudo python setup.py install; echo "Built SPI-Py lib" | sudo -u sats tee -a /home/sats/satsd/log/install.log > /dev/null; # (4) Reboot to activate SPI # sudo -u sats touch /target/install; echo "Created target file" | sudo -u sats tee -a /home/sats/satsd/log/install.log > /dev/null; echo "Launching first reboot" | sudo -u sats tee -a /home/sats/satsd/log/install.log > /dev/null; sudo reboot; fi;