diff --git a/clone/utility/sats-install b/clone/utility/sats-install index bfadf82..ed65f09 100644 --- a/clone/utility/sats-install +++ b/clone/utility/sats-install @@ -32,6 +32,15 @@ echo "pi password changed" | sudo -u sats tee -a /home/sats/satsd/log/install.lo ################################################ if [ ! -e /target/install ]; 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; + + + # [1] Installation + #========================================================# # (1) Try to install necessary packages sudo apt-get update; echo "package update done" | sudo -u sats tee -a /home/sats/satsd/log/install.log > /dev/null; @@ -70,9 +79,24 @@ if [ ! -e /target/install ]; then sudo python setup.py install; echo "Built SPI-Py lib" | sudo -u sats tee -a /home/sats/satsd/log/install.log > /dev/null; - # (4) Reboot to activate SPI # - sudo -u sats touch /target/install; - echo "Created target file" | sudo -u sats tee -a /home/sats/satsd/log/install.log > /dev/null; + + # [2] Synchronization + #========================================================# + # (1) Exports # + __DIR__=/home/sats/satsd/source; + + source $__DIR__/lib/include/bash/const; + 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; + + sudo -u sats touch /target/sync; + echo "Created target file 'sync'" | sudo -u sats tee -a /home/sats/satsd/log/install.log > /dev/null; + + + # (3) Reboot to activate SPI # echo "Launching first reboot" | sudo -u sats tee -a /home/sats/satsd/log/install.log > /dev/null; sudo reboot; diff --git a/clone/utility/sats-install.service b/clone/utility/sats-install.service index e46e109..6e48dbf 100644 --- a/clone/utility/sats-install.service +++ b/clone/utility/sats-install.service @@ -1,7 +1,7 @@ [Unit] Description=SATS Install Process -Requires=network-online.target -After=network-online.target network.target +Requires=network.target network-online.target +After=network.target network-online.target Before=sats-loop.service [Service] @@ -9,7 +9,4 @@ Type=oneshot RemainAfterExit=yes User=pi Group=pi -ExecStart=/bin/sh /service/sats-install - -[Install] -WantedBy=multi-user.target \ No newline at end of file +ExecStart=/bin/bash /service/sats-install \ No newline at end of file diff --git a/clone/utility/sats-loop.service b/clone/utility/sats-loop.service index c390ed8..45ed0c2 100644 --- a/clone/utility/sats-loop.service +++ b/clone/utility/sats-loop.service @@ -1,7 +1,6 @@ [Unit] Description=SATS Daemon -Wants=sats-install.service -OnFailure=sats-update.service +Requires=sats-install.service [Service] Type=simple diff --git a/clone/utility/sats-update.service b/clone/utility/sats-update.service index 8dba10b..a950246 100644 --- a/clone/utility/sats-update.service +++ b/clone/utility/sats-update.service @@ -1,6 +1,6 @@ [Unit] Description=SATS Update Process -Requires=network-online.target network.target +Requires=network.target network-online.target OnFailure=sats-install.service [Service] diff --git a/clone/utility/sats-wpa.service b/clone/utility/sats-wpa.service new file mode 100644 index 0000000..512af38 --- /dev/null +++ b/clone/utility/sats-wpa.service @@ -0,0 +1,14 @@ +[Unit] +Description=SATS DWC (Dynamic Wireless Credentials) +Requires=sats-install.service +Before=network.target + +[Service] +Type=simple +User=sats +Group=sats +ExecStart=/bin/sh /service/sats-loop +Restart=always + +[Install] +WantedBy=multi-user.target \ No newline at end of file