112 lines
2.5 KiB
Bash
112 lines
2.5 KiB
Bash
#!/bin/sh
|
|
|
|
#@@@@#
|
|
|
|
LOGFILE="/home/sats/satsd/log/install.log";
|
|
|
|
|
|
plog(){
|
|
sudo -u sats tee -a /home/sats/satsd/log/install.log > /dev/null;
|
|
}
|
|
|
|
slog(){
|
|
echo "$1" | plog;
|
|
}
|
|
|
|
failexit(){
|
|
slog " > failed";
|
|
exit 127;
|
|
}
|
|
|
|
|
|
|
|
################################################
|
|
#### ONLY ON FIRST BOOT ####
|
|
################################################
|
|
if [ -e /target/sync ]; then
|
|
slog " ** sync target already exists";
|
|
exit 127;
|
|
fi;
|
|
|
|
# (x) If no network -> exit #
|
|
slog " * 4. Checking connectivity";
|
|
test $(systemctl is-active network-online.target) = "active" \
|
|
&& slog " > done" \
|
|
|| failexit;
|
|
|
|
|
|
# [1] Installation
|
|
#========================================================#
|
|
# (1) Try to install necessary packages
|
|
slog " * 5. Updating packages";
|
|
sudo apt-get update;
|
|
test $? -eq 0 \
|
|
&& slog " > done" \
|
|
|| failexit;
|
|
|
|
slog " * 6. Installing necessary packages";
|
|
sudo apt-get -y install git php5 php5-cli php5-curl python-dev;
|
|
test $? -eq 0 \
|
|
&& slog " > done" \
|
|
|| failexit;
|
|
|
|
|
|
BRANCH=$(sudo cat /home/sats/satsd/conf/machine.branch) > /dev/null;
|
|
|
|
# (2) With git if installed #
|
|
slog " * 7. Cloning source";
|
|
if `sudo -u sats test -d /home/sats/satsd/source`; then
|
|
slog " > done (already cloned)";
|
|
else
|
|
sudo -u sats git clone -b $BRANCH ssh://smmp-server/satsd/git /home/sats/satsd/source \
|
|
&& slog " > done" \
|
|
|| failexit;
|
|
fi;
|
|
|
|
|
|
|
|
# (2) Enable SPI device #
|
|
echo " * 8. Enabling spi device";
|
|
echo "dtparam=spi=on" | sudo tee -a /boot/config.txt > /dev/null \
|
|
|| failexit;
|
|
echo "dtoverlay=spi-bcm2708" | sudo tee -a /boot/config.txt > /dev/null \
|
|
|| failexit;
|
|
slog " > done";
|
|
|
|
# (3) Clone SPI python library #
|
|
slog " * 9. Cloning 'SPI-Py' lib";
|
|
if [ -d /home/pi/spi-lib ]; then
|
|
slog " > done (already cloned)";
|
|
else
|
|
git clone https://github.com/lthiery/SPI-Py.git /home/pi/spi-lib \
|
|
&& slog " > done" \
|
|
|| failexit;
|
|
fi;
|
|
|
|
# (4) Install SPI python library #
|
|
slog " * 10. Installing 'SPI-Py' lib into the system";
|
|
cd /home/pi/spi-lib;
|
|
sudo python setup.py build \
|
|
|| failexit;
|
|
sudo python setup.py install \
|
|
|| failexit;
|
|
slog " > done";
|
|
|
|
|
|
# [2] Synchronization
|
|
#========================================================#
|
|
# (1) Process sync #
|
|
slog " * 11. Synchronizing the SATS with SMMP's server";
|
|
test "$(sudo -u sats /home/sats/satsd/source/lib/api/sync)" = "0" \
|
|
&& slog " > done" \
|
|
|| failexit;
|
|
|
|
# (2) Create target file #
|
|
slog " * 12. Creating target file 'sync'";
|
|
sudo -u sats touch /target/sync \
|
|
&& slog " > done" \
|
|
|| failexit;
|
|
|
|
# (3) Reboot to activate SPI #
|
|
slog " * 13. Launching first reboot";
|
|
sudo reboot; |