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