[fix] fixed stuff + verbose user-friendly sats-install logging
This commit is contained in:
parent
f4881c8f58
commit
31c58fcac6
|
@ -369,7 +369,7 @@ step7(){
|
|||
|
||||
echo " - /target (ownder: sats)";
|
||||
sudo chown 666:666 /mnt/target;
|
||||
sudo chmod 555 /mnt/target;
|
||||
sudo chmod 775 /mnt/target;
|
||||
|
||||
echo "<<< done";
|
||||
|
||||
|
|
|
@ -2,27 +2,51 @@
|
|||
|
||||
#@@@@#
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
# [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;
|
||||
slog " * 1. Setting firewall rules";
|
||||
sudo sh /home/pi/iptables \
|
||||
&& slog " > done" \
|
||||
|| ( slog " > failed" && exit 127 );
|
||||
|
||||
# [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;
|
||||
slog " * 2. Starting ssh service";
|
||||
sudo systemctl start ssh \
|
||||
&& slog " > done" \
|
||||
|| ( slog " > failed" && exit 127 );
|
||||
|
||||
# [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;
|
||||
echo "sats password changed" | sudo -u sats tee -a /home/sats/satsd/log/install.log > /dev/null;
|
||||
# [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 'pi' itself
|
||||
# [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 "$RANDOM_PASS\n$RANDOM_PASS\n" | sudo passwd pi;
|
||||
echo "pi password changed" | sudo -u sats tee -a /home/sats/satsd/log/install.log > /dev/null;
|
||||
echo -ne "$RANDOM_PASS\n$RANDOM_PASS\n" | sudo passwd sats;
|
||||
test $? -eq 0 \
|
||||
&& slog " > done" \
|
||||
|| ( slog " > failed" && exit 127 );
|
||||
|
||||
# [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 );
|
||||
|
||||
|
||||
|
||||
|
@ -30,54 +54,64 @@ echo "pi password changed" | sudo -u sats tee -a /home/sats/satsd/log/install.lo
|
|||
################################################
|
||||
#### ONLY ON FIRST BOOT ####
|
||||
################################################
|
||||
if [ ! -e /target/install ]; then
|
||||
if [ ! -e /target/sync ]; then
|
||||
|
||||
# (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;
|
||||
slog " * 5. Checking connectivity";
|
||||
test $(systemctl is-active network-online.target) = "active" \
|
||||
&& slog " > done" \
|
||||
|| ( slog " > failed" && exit 127 );
|
||||
|
||||
|
||||
# [1] Installation
|
||||
#========================================================#
|
||||
# (1) Try to install necessary packages
|
||||
slog " * 6. Updating 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;
|
||||
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 );
|
||||
|
||||
dpkg -s git 2>/dev/null >/dev/null && gitinstalled=1 || gitinstalled=0;
|
||||
|
||||
BRANCH=$(sudo cat /home/sats/satsd/conf/machine.branch) > /dev/null;
|
||||
|
||||
# (2) With git if installed #
|
||||
if [ $gitinstalled -eq 1 ]; then
|
||||
|
||||
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;
|
||||
|
||||
echo "..done" | sudo -u sats tee -a /home/sats/satsd/log/install.log > /dev/null;
|
||||
fi;
|
||||
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 "dtparam=spi=on" | sudo tee -a /boot/config.txt > /dev/null;
|
||||
echo "dtoverlay=spi-bcm2708" | sudo tee -a /boot/config.txt > /dev/null;
|
||||
echo "enabled SPI device" | sudo -u sats tee -a /home/sats/satsd/log/install.log > /dev/null;
|
||||
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 #
|
||||
sudo git clone https://github.com/lthiery/SPI-Py.git /home/pi/spi-lib;
|
||||
echo "Cloned SPI-Py lib" | sudo -u sats tee -a /home/sats/satsd/log/install.log > /dev/null;
|
||||
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;
|
||||
sudo python setup.py install;
|
||||
echo "Built SPI-Py lib" | sudo -u sats tee -a /home/sats/satsd/log/install.log > /dev/null;
|
||||
sudo python setup.py build \
|
||||
|| ( slog " > failed" && exit 127 );
|
||||
sudo python setup.py install \
|
||||
|| ( slog " > failed" && exit 127 );
|
||||
slog " > done";
|
||||
|
||||
|
||||
# [2] Synchronization
|
||||
|
@ -89,15 +123,19 @@ if [ ! -e /target/install ]; then
|
|||
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;
|
||||
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 );
|
||||
|
||||
sudo -u sats touch /target/sync;
|
||||
echo "Created target file 'sync'" | sudo -u sats tee -a /home/sats/satsd/log/install.log > /dev/null;
|
||||
slog "Creating target file 'sync'";
|
||||
sudo -u sats touch /target/sync \
|
||||
&& slog " > done" \
|
||||
|| ( slog " > failed" && exit 127 );
|
||||
|
||||
|
||||
# (3) Reboot to activate SPI #
|
||||
echo "Launching first reboot" | sudo -u sats tee -a /home/sats/satsd/log/install.log > /dev/null;
|
||||
slog " * 13. Launching first reboot";
|
||||
sudo reboot;
|
||||
|
||||
fi;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#!/bin/sh
|
||||
|
||||
# [0] Check installed first
|
||||
if [ ! -e /target/install ]; then
|
||||
if [ ! -e /target/sync ]; then
|
||||
exit 1;
|
||||
fi;
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ slog " > done";
|
|||
|
||||
# [3] Update 'wpa_supplicant' configuration
|
||||
#========================================================#
|
||||
echo -e "network={\n\tssid=\"SATS_$AP_HASH\"/\n\tpsk=\"$PASS\"\n}" | sudo tee /etc/wpa_supplicant/$IFACE.conf;
|
||||
echo -e "network={\n\tssid=\"SATS_$AP_HASH\"\n\tpsk=\"$PASS\"\n}" | sudo tee /etc/wpa_supplicant/$IFACE.conf;
|
||||
|
||||
|
||||
slog "<<< Done\n";
|
||||
|
|
Loading…
Reference in New Issue