setup/clone/utility/sats-install

104 lines
3.8 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
################################################
#### ONLY ON FIRST BOOT ####
################################################
if [ ! -e /target/install ]; then
2017-07-21 10:43:37 +00:00
# (1) If no network -> exit #
if [ $(systemctl is-active network-online.target) != "active" ]; then
echo "not connection, rebooting" | sudo -u sats tee -a /home/sats/satsd/log/install.log > /dev/null;
exit 127;
fi;
# [1] Installation
#========================================================#
# (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;
2017-05-10 13:37:34 +00:00
BRANCH=$(sudo cat /home/sats/satsd/conf/machine.branch) > /dev/null;
# (2) 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;
2017-07-21 10:43:37 +00:00
# [2] Synchronization
#========================================================#
# (1) Exports #
__DIR__=/home/sats/satsd/source;
source $__DIR__/lib/include/bash/const;
source $__DIR__/lib/include/bash/func;
# (2) Process sync #
echo "Synchronization" | sudo -u sats tee -a /home/sats/satsd/log/install.log > /dev/null;
test "$($SOURCE_DIR/lib/api/sync)" = "127" && slog "sync failed" - "install" && exit 127;
sudo -u sats touch /target/sync;
echo "Created target file 'sync'" | sudo -u sats tee -a /home/sats/satsd/log/install.log > /dev/null;
# (3) Reboot to activate SPI #
2017-05-10 13:37:34 +00:00
echo "Launching first reboot" | sudo -u sats tee -a /home/sats/satsd/log/install.log > /dev/null;
sudo reboot;
fi;