setup/clone/utility/sats-install

80 lines
3.1 KiB
Plaintext
Raw Normal View History

2017-01-24 17:29:16 +00:00
#!/bin/sh
2017-02-23 08:41:45 +00:00
#@@@@#
2017-05-10 13:37:34 +00:00
# [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;
2017-05-10 13:37:34 +00:00
echo "sats password changed" | sudo -u sats tee -a /home/sats/satsd/log/install.log > /dev/null;
2017-01-24 17:29:16 +00:00
2017-05-10 13:37:34 +00:00
# [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;
2017-05-10 13:37:34 +00:00
echo "pi password changed" | sudo -u sats tee -a /home/sats/satsd/log/install.log > /dev/null;
2017-01-25 16:29:28 +00:00
2017-05-10 13:37:34 +00:00
# [5] Try to install necessary packages
sudo apt-get update;
2017-05-10 13:37:34 +00:00
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;
2017-05-10 13:37:34 +00:00
echo "package install done" | sudo -u sats tee -a /home/sats/satsd/log/install.log > /dev/null;
################################################
#### ONLY ON FIRST BOOT ####
################################################
if [ ! -e /target/install ]; then
dpkg -s git 2>/dev/null >/dev/null && gitinstalled=1 || gitinstalled=0;
2017-05-10 13:37:34 +00:00
BRANCH=$(sudo cat /home/sats/satsd/conf/machine.branch) > /dev/null;
# (1) With git if installed #
if [ $gitinstalled -eq 1 ]; then
2017-05-10 13:37:34 +00:00
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;
2017-05-10 13:37:34 +00:00
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;
2017-05-10 13:37:34 +00:00
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;
2017-05-10 13:37:34 +00:00
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;
2017-05-10 13:37:34 +00:00
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;
2017-05-10 13:37:34 +00:00
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;