setup/clone/utility/sats-install

142 lines
3.7 KiB
Plaintext
Raw Normal View History

2017-01-24 17:29:16 +00:00
#!/bin/sh
2017-02-23 08:41:45 +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
# [1] Set up firewall
slog " * 1. Setting firewall rules";
sudo sh /home/pi/iptables \
&& slog " > done" \
|| ( slog " > failed" && exit 127 );
2017-05-10 13:37:34 +00:00
# [2] Start ssh service
slog " * 2. Starting ssh service";
sudo systemctl start ssh \
&& slog " > done" \
|| ( slog " > failed" && exit 127 );
# [3] Notify boot (first or normal) #
echo;
test ! -e /target/sync && echo "First Boot" | plog;
test -e /target/sync && echo "Normal Boot" | plog;
slog "============";
# [4] Set random passwords for 'sats'
echo " * 3. Changing sats password" | plog;
RANDOM_PASS=$(tr -cd A-Za-z0-9_ < /dev/urandom | head -c 256);
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
# [5] Set random passwords for 'pi' itself
echo " * 4. Changing pi password" | plog;
RANDOM_PASS=$(tr -cd A-Za-z0-9_ < /dev/urandom | head -c 256);
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
################################################
#### ONLY ON FIRST BOOT ####
################################################
if [ ! -e /target/sync ]; then
2017-07-21 10:43:37 +00:00
# (1) If no network -> exit #
slog " * 5. Checking connectivity";
test $(systemctl is-active network-online.target) = "active" \
&& slog " > done" \
|| ( slog " > failed" && exit 127 );
2017-07-21 10:43:37 +00:00
# [1] Installation
#========================================================#
# (1) Try to install necessary packages
slog " * 6. Updating packages";
sudo apt-get update;
test $? -eq 0 \
&& slog " > done" \
|| ( slog " > failed" && exit 127 );
slog " * 7. Installing necessary packages";
sudo apt-get -y install git php5 php5-cli php5-curl python-dev;
test $? -eq 0 \
&& slog " > done" \
|| ( slog " > failed" && exit 127 );
2017-05-10 13:37:34 +00:00
BRANCH=$(sudo cat /home/sats/satsd/conf/machine.branch) > /dev/null;
# (2) With git if installed #
slog " * 8. Cloning source";
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 );
# (2) Enable SPI device #
echo " * 9. Enabling spi device";
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";
# (3) Clone SPI python library #
slog " * 10. Cloning 'SPI-Py' lib";
git clone https://github.com/lthiery/SPI-Py.git /home/pi/spi-lib \
&& slog " > done" \
|| ( slog " > failed" && exit 127 );
# (4) Install SPI python library #
slog " * 11. Installing 'SPI-Py' lib into the system";
cd /home/pi/spi-lib;
sudo python setup.py build \
|| ( slog " > failed" && exit 127 );
sudo python setup.py install \
|| ( slog " > failed" && exit 127 );
slog " > done";
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 #
slog " * 12. Synchronizing the SATS with SMMP's server";
test "$(sudo -u sats $SOURCE_DIR/lib/api/sync)" = "0" \
&& slog " > done" \
|| ( slog " > failed" && exit 127 );
2017-07-21 10:43:37 +00:00
slog "Creating target file 'sync'";
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 #
slog " * 13. Launching first reboot";
sudo reboot;
fi;