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-05-10 13:37:34 +00:00
|
|
|
|
2017-07-22 21:44:03 +00:00
|
|
|
# [1] Start ssh service
|
|
|
|
slog " * 1. Starting ssh service";
|
2017-07-22 20:37:00 +00:00
|
|
|
sudo systemctl start ssh \
|
|
|
|
&& slog " > done" \
|
|
|
|
|| ( slog " > failed" && exit 127 );
|
|
|
|
|
2017-07-22 21:44:03 +00:00
|
|
|
# [2] Notify boot (first or normal) #
|
2017-07-22 20:37:00 +00:00
|
|
|
echo;
|
|
|
|
test ! -e /target/sync && echo "First Boot" | plog;
|
|
|
|
test -e /target/sync && echo "Normal Boot" | plog;
|
|
|
|
slog "============";
|
|
|
|
|
2017-07-22 21:44:03 +00:00
|
|
|
# [3] Set random passwords for 'sats'
|
|
|
|
echo " * 2. Changing sats password" | plog;
|
2017-01-25 18:52:51 +00:00
|
|
|
RANDOM_PASS=$(tr -cd A-Za-z0-9_ < /dev/urandom | head -c 256);
|
2017-07-22 20:37:00 +00:00
|
|
|
echo -ne "$RANDOM_PASS\n$RANDOM_PASS\n" | sudo passwd sats;
|
|
|
|
test $? -eq 0 \
|
|
|
|
&& slog " > done" \
|
|
|
|
|| ( slog " > failed" && exit 127 );
|
2017-01-24 17:29:16 +00:00
|
|
|
|
2017-07-22 21:44:03 +00:00
|
|
|
# [4] Set random passwords for 'pi' itself
|
|
|
|
echo " * 3. Changing pi password" | plog;
|
2017-01-25 18:52:51 +00:00
|
|
|
RANDOM_PASS=$(tr -cd A-Za-z0-9_ < /dev/urandom | head -c 256);
|
2017-07-22 20:37:00 +00:00
|
|
|
echo -ne "$RANDOM_PASS\n$RANDOM_PASS\n" | sudo passwd pi;
|
|
|
|
test $? -eq 0 \
|
|
|
|
&& slog " > done" \
|
|
|
|
|| ( slog " > failed" && exit 127 );
|
2017-01-25 16:29:28 +00:00
|
|
|
|
2017-02-17 16:07:39 +00:00
|
|
|
|
2017-02-17 16:36:33 +00:00
|
|
|
|
|
|
|
|
2017-02-17 16:07:39 +00:00
|
|
|
################################################
|
|
|
|
#### ONLY ON FIRST BOOT ####
|
|
|
|
################################################
|
2017-07-22 20:37:00 +00:00
|
|
|
if [ ! -e /target/sync ]; then
|
2017-02-17 16:36:33 +00:00
|
|
|
|
2017-07-22 21:44:03 +00:00
|
|
|
# (x) If no network -> exit #
|
|
|
|
slog " * 4. Checking connectivity";
|
2017-07-22 20:37:00 +00:00
|
|
|
test $(systemctl is-active network-online.target) = "active" \
|
|
|
|
&& slog " > done" \
|
|
|
|
|| ( slog " > failed" && exit 127 );
|
2017-07-21 10:43:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
# [1] Installation
|
|
|
|
#========================================================#
|
2017-07-18 15:18:30 +00:00
|
|
|
# (1) Try to install necessary packages
|
2017-07-22 21:44:03 +00:00
|
|
|
slog " * 5. Updating packages";
|
2017-07-18 15:18:30 +00:00
|
|
|
sudo apt-get update;
|
2017-07-22 20:37:00 +00:00
|
|
|
test $? -eq 0 \
|
|
|
|
&& slog " > done" \
|
|
|
|
|| ( slog " > failed" && exit 127 );
|
|
|
|
|
2017-07-22 21:44:03 +00:00
|
|
|
slog " * 6. Installing necessary packages";
|
2017-07-18 15:18:30 +00:00
|
|
|
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" \
|
|
|
|
|| ( slog " > failed" && exit 127 );
|
2017-07-18 15:18:30 +00:00
|
|
|
|
2017-02-17 16:36:33 +00:00
|
|
|
|
2017-05-10 13:37:34 +00:00
|
|
|
BRANCH=$(sudo cat /home/sats/satsd/conf/machine.branch) > /dev/null;
|
2017-02-17 16:36:33 +00:00
|
|
|
|
2017-07-18 15:18:30 +00:00
|
|
|
# (2) With git if installed #
|
2017-07-22 21:44:03 +00:00
|
|
|
slog " * 7. Cloning source";
|
2017-07-22 20:37:00 +00:00
|
|
|
sudo -u sats git clone -b $BRANCH ssh://smmp-server/satsd/git /home/sats/satsd/source;
|
|
|
|
test $? -eq 0 \
|
|
|
|
&& slog " > done" \
|
|
|
|
|| ( slog " > failed" && exit 127 );
|
2017-02-17 16:36:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# (2) Enable SPI device #
|
2017-07-22 21:44:03 +00:00
|
|
|
echo " * 8. Enabling spi device";
|
2017-07-22 20:37:00 +00:00
|
|
|
echo "dtparam=spi=on" | sudo tee -a /boot/config.txt > /dev/null \
|
|
|
|
|| ( slog " > failed" && exit 127 );
|
|
|
|
echo "dtoverlay=spi-bcm2708" | sudo tee -a /boot/config.txt > /dev/null \
|
|
|
|
|| ( slog " > failed" && exit 127 );
|
|
|
|
slog " > done";
|
2017-02-17 16:07:39 +00:00
|
|
|
|
2017-02-17 16:36:33 +00:00
|
|
|
# (3) Clone SPI python library #
|
2017-07-22 21:44:03 +00:00
|
|
|
slog " * 9. Cloning 'SPI-Py' lib";
|
2017-07-22 20:37:00 +00:00
|
|
|
git clone https://github.com/lthiery/SPI-Py.git /home/pi/spi-lib \
|
|
|
|
&& slog " > done" \
|
|
|
|
|| ( slog " > failed" && exit 127 );
|
2017-02-18 10:32:04 +00:00
|
|
|
|
|
|
|
# (4) Install SPI python library #
|
2017-07-22 21:44:03 +00:00
|
|
|
slog " * 10. Installing 'SPI-Py' lib into the system";
|
2017-02-18 10:32:04 +00:00
|
|
|
cd /home/pi/spi-lib;
|
2017-07-22 20:37:00 +00:00
|
|
|
sudo python setup.py build \
|
|
|
|
|| ( slog " > failed" && exit 127 );
|
|
|
|
sudo python setup.py install \
|
|
|
|
|| ( slog " > failed" && exit 127 );
|
|
|
|
slog " > done";
|
2017-02-17 16:07:39 +00:00
|
|
|
|
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 #
|
2017-07-22 21:44:03 +00:00
|
|
|
slog " * 11. Synchronizing the SATS with SMMP's server";
|
2017-07-22 20:37:00 +00:00
|
|
|
test "$(sudo -u sats $SOURCE_DIR/lib/api/sync)" = "0" \
|
|
|
|
&& slog " > done" \
|
|
|
|
|| ( slog " > failed" && exit 127 );
|
2017-07-21 10:43:37 +00:00
|
|
|
|
2017-07-22 21:44:03 +00:00
|
|
|
slog " * 12. Creating target file 'sync'";
|
2017-07-22 20:37:00 +00:00
|
|
|
sudo -u sats touch /target/sync \
|
|
|
|
&& slog " > done" \
|
|
|
|
|| ( slog " > failed" && exit 127 );
|
2017-07-21 10:43:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
# (3) Reboot to activate SPI #
|
2017-07-22 20:37:00 +00:00
|
|
|
slog " * 13. Launching first reboot";
|
2017-02-17 16:36:33 +00:00
|
|
|
sudo reboot;
|
|
|
|
|
2017-02-17 16:07:39 +00:00
|
|
|
fi;
|