setup/clone/utility/sats-install

60 lines
1.5 KiB
Bash

#!/bin/sh
#@@@@#
# [1] Set random passwords for 'sats'
RANDOM_PASS=$(tr -cd A-Za-z0-9_ < /dev/urandom | head -c 256);
echo "$RANDOM_PASS\n$RANDOM_PASS\n" | sudo passwd sats;
# [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;
# [3] Start ssh service
sudo systemctl start ssh;
# [4] Try to install necessary packages
sudo apt-get update;
sudo apt-get -y install git php5 php5-cli php5-curl python-dev;
################################################
#### 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
sudo -u sats git clone -b $BRANCH ssh://smmp-server/satsd/git /home/sats/satsd/source \
&& sudo -u sats touch /target/install \
|| exit;
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;
# (3) Clone SPI python library #
sudo git clone https://github.com/lthiery/SPI-Py.git /home/pi/spi-lib;
# (4) Install SPI python library #
cd /home/pi/spi-lib;
sudo python setup.py build;
sudo python setup.py install;
# (4) Reboot to activate SPI #
sudo -u sats touch /target/install;
sudo reboot;
fi;