[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)";
|
echo " - /target (ownder: sats)";
|
||||||
sudo chown 666:666 /mnt/target;
|
sudo chown 666:666 /mnt/target;
|
||||||
sudo chmod 555 /mnt/target;
|
sudo chmod 775 /mnt/target;
|
||||||
|
|
||||||
echo "<<< done";
|
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
|
# [1] Set up firewall
|
||||||
sudo sh /home/pi/iptables;
|
slog " * 1. Setting firewall rules";
|
||||||
echo "Set firewall rules" | sudo -u sats tee -a /home/sats/satsd/log/install.log > /dev/null;
|
sudo sh /home/pi/iptables \
|
||||||
|
&& slog " > done" \
|
||||||
|
|| ( slog " > failed" && exit 127 );
|
||||||
|
|
||||||
# [2] Start ssh service
|
# [2] Start ssh service
|
||||||
sudo systemctl start ssh;
|
slog " * 2. Starting ssh service";
|
||||||
echo "started ssh service" | sudo -u sats tee -a /home/sats/satsd/log/install.log > /dev/null;
|
sudo systemctl start ssh \
|
||||||
|
&& slog " > done" \
|
||||||
|
|| ( slog " > failed" && exit 127 );
|
||||||
|
|
||||||
# [3] Set random passwords for 'sats'
|
# [3] Notify boot (first or normal) #
|
||||||
test ! -e /target/install && echo "First Boot" | sudo -u sats tee -a /home/sats/satsd/log/install.log > /dev/null;
|
echo;
|
||||||
test -e /target/install && echo "Normal Boot" | sudo -u sats tee -a /home/sats/satsd/log/install.log > /dev/null;
|
test ! -e /target/sync && echo "First Boot" | plog;
|
||||||
echo "============" | sudo -u sats tee -a /home/sats/satsd/log/install.log > /dev/null;
|
test -e /target/sync && echo "Normal Boot" | plog;
|
||||||
RANDOM_PASS=$(tr -cd A-Za-z0-9_ < /dev/urandom | head -c 256);
|
slog "============";
|
||||||
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;
|
|
||||||
|
|
||||||
# [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);
|
RANDOM_PASS=$(tr -cd A-Za-z0-9_ < /dev/urandom | head -c 256);
|
||||||
echo "$RANDOM_PASS\n$RANDOM_PASS\n" | sudo passwd pi;
|
echo -ne "$RANDOM_PASS\n$RANDOM_PASS\n" | sudo passwd sats;
|
||||||
echo "pi password changed" | sudo -u sats tee -a /home/sats/satsd/log/install.log > /dev/null;
|
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 ####
|
#### ONLY ON FIRST BOOT ####
|
||||||
################################################
|
################################################
|
||||||
if [ ! -e /target/install ]; then
|
if [ ! -e /target/sync ]; then
|
||||||
|
|
||||||
# (1) If no network -> exit #
|
# (1) If no network -> exit #
|
||||||
if [ $(systemctl is-active network-online.target) != "active" ]; then
|
slog " * 5. Checking connectivity";
|
||||||
echo "not connection, rebooting" | sudo -u sats tee -a /home/sats/satsd/log/install.log > /dev/null;
|
test $(systemctl is-active network-online.target) = "active" \
|
||||||
exit 127;
|
&& slog " > done" \
|
||||||
fi;
|
|| ( slog " > failed" && exit 127 );
|
||||||
|
|
||||||
|
|
||||||
# [1] Installation
|
# [1] Installation
|
||||||
#========================================================#
|
#========================================================#
|
||||||
# (1) Try to install necessary packages
|
# (1) Try to install necessary packages
|
||||||
|
slog " * 6. Updating packages";
|
||||||
sudo apt-get update;
|
sudo apt-get update;
|
||||||
echo "package update done" | sudo -u sats tee -a /home/sats/satsd/log/install.log > /dev/null;
|
test $? -eq 0 \
|
||||||
sudo apt-get -y install git php5 php5-cli php5-curl python-dev;
|
&& slog " > done" \
|
||||||
echo "package install done" | sudo -u sats tee -a /home/sats/satsd/log/install.log > /dev/null;
|
|| ( 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;
|
BRANCH=$(sudo cat /home/sats/satsd/conf/machine.branch) > /dev/null;
|
||||||
|
|
||||||
# (2) With git if installed #
|
# (2) With git if installed #
|
||||||
if [ $gitinstalled -eq 1 ]; then
|
slog " * 8. Cloning source";
|
||||||
|
sudo -u sats git clone -b $BRANCH ssh://smmp-server/satsd/git /home/sats/satsd/source;
|
||||||
echo "cloning source.." | sudo -u sats tee -a /home/sats/satsd/log/install.log > /dev/null;
|
test $? -eq 0 \
|
||||||
sudo -u sats git clone -b $BRANCH ssh://smmp-server/satsd/git /home/sats/satsd/source \
|
&& slog " > done" \
|
||||||
&& sudo -u sats touch /target/install \
|
|| ( slog " > failed" && exit 127 );
|
||||||
|| exit;
|
|
||||||
|
|
||||||
echo "..done" | sudo -u sats tee -a /home/sats/satsd/log/install.log > /dev/null;
|
|
||||||
fi;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# (2) Enable SPI device #
|
# (2) Enable SPI device #
|
||||||
echo "dtparam=spi=on" | sudo tee -a /boot/config.txt > /dev/null;
|
echo " * 9. Enabling spi device";
|
||||||
echo "dtoverlay=spi-bcm2708" | sudo tee -a /boot/config.txt > /dev/null;
|
echo "dtparam=spi=on" | 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;
|
|| ( 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 #
|
# (3) Clone SPI python library #
|
||||||
sudo git clone https://github.com/lthiery/SPI-Py.git /home/pi/spi-lib;
|
slog " * 10. Cloning 'SPI-Py' lib";
|
||||||
echo "Cloned SPI-Py lib" | sudo -u sats tee -a /home/sats/satsd/log/install.log > /dev/null;
|
git clone https://github.com/lthiery/SPI-Py.git /home/pi/spi-lib \
|
||||||
|
&& slog " > done" \
|
||||||
|
|| ( slog " > failed" && exit 127 );
|
||||||
|
|
||||||
# (4) Install SPI python library #
|
# (4) Install SPI python library #
|
||||||
|
slog " * 11. Installing 'SPI-Py' lib into the system";
|
||||||
cd /home/pi/spi-lib;
|
cd /home/pi/spi-lib;
|
||||||
sudo python setup.py build;
|
sudo python setup.py build \
|
||||||
sudo python setup.py install;
|
|| ( slog " > failed" && exit 127 );
|
||||||
echo "Built SPI-Py lib" | sudo -u sats tee -a /home/sats/satsd/log/install.log > /dev/null;
|
sudo python setup.py install \
|
||||||
|
|| ( slog " > failed" && exit 127 );
|
||||||
|
slog " > done";
|
||||||
|
|
||||||
|
|
||||||
# [2] Synchronization
|
# [2] Synchronization
|
||||||
|
@ -89,15 +123,19 @@ if [ ! -e /target/install ]; then
|
||||||
source $__DIR__/lib/include/bash/func;
|
source $__DIR__/lib/include/bash/func;
|
||||||
|
|
||||||
# (2) Process sync #
|
# (2) Process sync #
|
||||||
echo "Synchronization" | sudo -u sats tee -a /home/sats/satsd/log/install.log > /dev/null;
|
slog " * 12. Synchronizing the SATS with SMMP's server";
|
||||||
test "$($SOURCE_DIR/lib/api/sync)" = "127" && slog "sync failed" - "install" && exit 127;
|
test "$(sudo -u sats $SOURCE_DIR/lib/api/sync)" = "0" \
|
||||||
|
&& slog " > done" \
|
||||||
|
|| ( slog " > failed" && exit 127 );
|
||||||
|
|
||||||
sudo -u sats touch /target/sync;
|
slog "Creating target file 'sync'";
|
||||||
echo "Created target file 'sync'" | sudo -u sats tee -a /home/sats/satsd/log/install.log > /dev/null;
|
sudo -u sats touch /target/sync \
|
||||||
|
&& slog " > done" \
|
||||||
|
|| ( slog " > failed" && exit 127 );
|
||||||
|
|
||||||
|
|
||||||
# (3) Reboot to activate SPI #
|
# (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;
|
sudo reboot;
|
||||||
|
|
||||||
fi;
|
fi;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
# [0] Check installed first
|
# [0] Check installed first
|
||||||
if [ ! -e /target/install ]; then
|
if [ ! -e /target/sync ]; then
|
||||||
exit 1;
|
exit 1;
|
||||||
fi;
|
fi;
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ slog " > done";
|
||||||
|
|
||||||
# [3] Update 'wpa_supplicant' configuration
|
# [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";
|
slog "<<< Done\n";
|
||||||
|
|
Loading…
Reference in New Issue