2017-01-24 17:29:16 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
2017-02-23 08:41:45 +00:00
|
|
|
#@@@@#
|
|
|
|
|
2017-07-22 20:37:00 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-07-23 10:00:25 +00:00
|
|
|
failexit(){
|
|
|
|
slog " > failed";
|
|
|
|
exit 127;
|
|
|
|
}
|
|
|
|
|
2017-05-10 13:37:34 +00:00
|
|
|
|
2017-07-22 20:37:00 +00:00
|
|
|
|
2017-07-23 21:27:51 +00:00
|
|
|
################################################
|
|
|
|
#### ONLY ON FIRST BOOT ####
|
|
|
|
################################################
|
|
|
|
if [ -e /target/sync ]; then
|
|
|
|
slog " ** sync target already exists";
|
|
|
|
exit 127;
|
|
|
|
fi;
|
2017-07-23 12:39:48 +00:00
|
|
|
|
2017-07-23 21:27:51 +00:00
|
|
|
# (x) If no network -> exit #
|
|
|
|
slog " * 4. Checking connectivity";
|
2017-09-27 14:26:41 +00:00
|
|
|
max_try=5;
|
|
|
|
while [ -n "`ping xdrm.io -q -c 1 -i 1 2>&1 > /dev/null`" ]; do
|
|
|
|
|
|
|
|
slog " > waiting for network";
|
|
|
|
|
|
|
|
max_try=`expr $max_try - 1`;
|
|
|
|
[ $max_try -lt 0 ] && failexit;
|
|
|
|
|
|
|
|
sleep 5;
|
|
|
|
done;
|
2017-07-23 12:39:48 +00:00
|
|
|
|
2017-09-27 14:26:41 +00:00
|
|
|
slog " > done";
|
2017-07-23 21:27:51 +00:00
|
|
|
|
|
|
|
# [1] Installation
|
|
|
|
#========================================================#
|
|
|
|
# (1) Try to install necessary packages
|
|
|
|
slog " * 5. Updating packages";
|
|
|
|
sudo apt-get update;
|
2017-07-22 20:37:00 +00:00
|
|
|
test $? -eq 0 \
|
|
|
|
&& slog " > done" \
|
2017-07-23 10:00:25 +00:00
|
|
|
|| failexit;
|
2017-01-24 17:29:16 +00:00
|
|
|
|
2017-07-23 21:27:51 +00:00
|
|
|
slog " * 6. Installing necessary packages";
|
|
|
|
sudo apt-get -y install git php5 php5-cli php5-curl python-dev;
|
2017-07-22 20:37:00 +00:00
|
|
|
test $? -eq 0 \
|
|
|
|
&& slog " > done" \
|
2017-07-23 10:00:25 +00:00
|
|
|
|| failexit;
|
2017-01-25 16:29:28 +00:00
|
|
|
|
2017-02-17 16:07:39 +00:00
|
|
|
|
2017-07-24 16:37:54 +00:00
|
|
|
BRANCH=$(sudo -u sats cat /home/sats/satsd/conf/machine.branch) > /dev/null;
|
2017-02-17 16:36:33 +00:00
|
|
|
|
2017-07-23 21:27:51 +00:00
|
|
|
# (2) With git if installed #
|
|
|
|
slog " * 7. Cloning source";
|
|
|
|
if `sudo -u sats test -d /home/sats/satsd/source`; then
|
2017-07-24 16:37:54 +00:00
|
|
|
sudo rm -r /home/sats/satsd/source;
|
2017-07-23 21:27:51 +00:00
|
|
|
fi;
|
2017-07-21 10:43:37 +00:00
|
|
|
|
2017-07-24 16:37:54 +00:00
|
|
|
sudo -u sats git clone -b $BRANCH ssh://smmp-server/satsd/git /home/sats/satsd/source \
|
|
|
|
&& slog " > done" \
|
|
|
|
|| failexit;
|
|
|
|
|
2017-07-21 10:43:37 +00:00
|
|
|
|
2017-07-23 21:27:51 +00:00
|
|
|
# (3) Clone SPI python library #
|
2017-10-02 13:44:08 +00:00
|
|
|
slog " * 8. Cloning 'SPI-Py' lib";
|
2017-07-23 21:27:51 +00:00
|
|
|
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 \
|
2017-07-22 20:37:00 +00:00
|
|
|
&& slog " > done" \
|
2017-07-23 10:00:25 +00:00
|
|
|
|| failexit;
|
2017-07-23 21:27:51 +00:00
|
|
|
fi;
|
2017-07-18 15:18:30 +00:00
|
|
|
|
2017-07-23 21:27:51 +00:00
|
|
|
# (4) Install SPI python library #
|
2017-10-02 13:44:08 +00:00
|
|
|
slog " * 9. Installing 'SPI-Py' lib into the system";
|
2017-07-23 21:27:51 +00:00
|
|
|
cd /home/pi/spi-lib;
|
|
|
|
sudo python setup.py build \
|
|
|
|
|| failexit;
|
|
|
|
sudo python setup.py install \
|
|
|
|
|| failexit;
|
|
|
|
slog " > done";
|
2017-02-17 16:36:33 +00:00
|
|
|
|
2017-07-21 10:43:37 +00:00
|
|
|
|
2017-07-23 21:27:51 +00:00
|
|
|
# [2] Synchronization
|
|
|
|
#========================================================#
|
|
|
|
# (1) Process sync #
|
2017-10-02 13:44:08 +00:00
|
|
|
slog " * 10. Synchronizing the SATS with SMMP's server";
|
2017-07-23 21:27:51 +00:00
|
|
|
test "$(sudo -u sats /home/sats/satsd/source/lib/api/sync)" = "0" \
|
|
|
|
&& slog " > done" \
|
|
|
|
|| failexit;
|
2017-07-21 10:43:37 +00:00
|
|
|
|
2017-07-23 21:27:51 +00:00
|
|
|
# (2) Create target file #
|
2017-10-02 13:44:08 +00:00
|
|
|
slog " * 11. Creating target file 'sync'";
|
2017-07-23 21:27:51 +00:00
|
|
|
sudo -u sats touch /target/sync \
|
|
|
|
&& slog " > done" \
|
|
|
|
|| failexit;
|
2017-02-17 16:36:33 +00:00
|
|
|
|
2017-07-23 21:27:51 +00:00
|
|
|
# (3) Reboot to activate SPI #
|
2017-10-02 13:44:08 +00:00
|
|
|
slog " * 12. Launching first reboot";
|
2017-07-23 21:27:51 +00:00
|
|
|
sudo reboot;
|