From cca5071ac39ec0ca0cbc703f55c896e412f7df29 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Mon, 24 Jul 2017 18:03:08 +0200 Subject: [PATCH] [bigupdate] (1) sats-sync.target is now a service because Assertion wasn't working so added an ExecStart that does the same (2) Added sats-sync-stop path and service to stop sats-sync target (now service) when the file changes (3) Fixed in `sats-install` script an echo to a `slog` (step 8) --- clone/clone | 86 ++++++++++++------- clone/utility/sats-install | 2 +- clone/utility/sats-loop.service | 4 +- clone/utility/sats-sync-stop | 3 + clone/utility/sats-sync-stop.path | 9 ++ clone/utility/sats-sync-stop.service | 10 +++ clone/utility/sats-sync.path | 2 +- .../{sats-sync.target => sats-sync.service} | 10 ++- clone/utility/sats-update.service | 2 +- 9 files changed, 89 insertions(+), 39 deletions(-) create mode 100644 clone/utility/sats-sync-stop create mode 100644 clone/utility/sats-sync-stop.path create mode 100644 clone/utility/sats-sync-stop.service rename clone/utility/{sats-sync.target => sats-sync.service} (50%) diff --git a/clone/clone b/clone/clone index 18addd6..3645652 100755 --- a/clone/clone +++ b/clone/clone @@ -316,47 +316,57 @@ step7(){ # (1) Create sats-boot service # echo " (.) Create sats-boot service"; echo " - /lib/systemd/system"; - sudo cp ./utility/sats-boot.service /mnt/lib/systemd/system/sats-boot.service; + sudo cp ./utility/sats-boot.service /mnt/lib/systemd/system/sats-boot.service; # (2) Create sats-install service # echo " (.) Create sats-install service"; echo " - /lib/systemd/system"; - sudo cp ./utility/sats-install.service /mnt/lib/systemd/system/sats-install.service; + sudo cp ./utility/sats-install.service /mnt/lib/systemd/system/sats-install.service; # (3) Create sats-update service # echo " (.) Create sats-update service"; echo " - /lib/systemd/system"; - sudo cp ./utility/sats-update.service /mnt/lib/systemd/system/sats-update.service; + sudo cp ./utility/sats-update.service /mnt/lib/systemd/system/sats-update.service; # (4) Create sats-loop service # echo " (.) Create sats-loop service"; echo " - /lib/systemd/system"; - sudo cp ./utility/sats-loop.service /mnt/lib/systemd/system/sats-loop.service; + sudo cp ./utility/sats-loop.service /mnt/lib/systemd/system/sats-loop.service; # (5) Create sats-sync target # - echo " (.) Create sats-sync target"; + echo " (.) Create sats-sync target (service)"; echo " - /lib/systemd/system"; - sudo cp ./utility/sats-sync.target /mnt/lib/systemd/system/sats-sync.target + sudo cp ./utility/sats-sync.service /mnt/lib/systemd/system/sats-sync.service; - # (6) Create sats-sync path # + # (6) Create sats-sync-stop service # + echo " (.) Create sats-sync-stop service"; + echo " - /lib/systemd/system"; + sudo cp ./utility/sats-sync-stop.service /mnt/lib/systemd/system/sats-sync-stop.service; + + # (7) Create sats-sync path # echo " (.) Create sats-sync path"; echo " - /lib/systemd/system"; - sudo cp ./utility/sats-sync.path /mnt/lib/systemd/system/sats-sync.path; + sudo cp ./utility/sats-sync.path /mnt/lib/systemd/system/sats-sync.path; - # (7) Create sats-update timer # + # (8) Create sats-sync-stop path # + echo " (.) Create sats-sync-stop path"; + echo " - /lib/systemd/system"; + sudo cp ./utility/sats-sync-stop.path /mnt/lib/systemd/system/sats-sync-stop.path; + + # (9) Create sats-update timer # echo " (.) Create sats-update timer"; echo " - /lib/systemd/system"; - sudo cp ./utility/sats-update.timer /mnt/lib/systemd/system/sats-update.timer; + sudo cp ./utility/sats-update.timer /mnt/lib/systemd/system/sats-update.timer; - # (8) Create sats-dwc@ service # + # (10) Create sats-dwc@ service # echo " (.) Create sats-dwc@ service"; echo " - /lib/systemd/system"; - sudo cp ./utility/sats-dwc@.service /mnt/lib/systemd/system/sats-dwc@.service; + sudo cp ./utility/sats-dwc@.service /mnt/lib/systemd/system/sats-dwc@.service; - # (9) Create firewall@ service # + # (11) Create firewall@ service # echo " (.) Create firewall@ service"; echo " - /lib/systemd/system"; - sudo cp ./utility/firewall@.service /mnt/lib/systemd/system/firewall@.service; + sudo cp ./utility/firewall@.service /mnt/lib/systemd/system/firewall@.service; # (3) Install services @@ -366,30 +376,34 @@ step7(){ # (2) Enable sats-loop at startup # echo " (.) Emulate \`systemctl enable sats-loop.service\`"; - sudo ln -fs /lib/systemd/system/sats-loop.service /mnt/etc/systemd/system/multi-user.target.wants/sats-loop.service; + sudo ln -fs /lib/systemd/system/sats-loop.service /mnt/etc/systemd/system/multi-user.target.wants/sats-loop.service; - # (3) Enable sats-sync path at startup # - echo " (.) Emulate \`systemctl enable sats-sync.path\`"; - sudo ln -fs /lib/systemd/system/sats-sync.path /mnt/etc/systemd/system/multi-user.target.wants/sats-sync.path; - - # (4) Enable sats-update timer at startup # + # (3) Enable sats-update timer at startup # echo " (.) Emulate \`systemctl enable sats-update.timer\`"; - sudo ln -fs /lib/systemd/system/sats-update.timer /mnt/etc/systemd/system/multi-user.target.wants/sats-update.timer; + sudo ln -fs /lib/systemd/system/sats-update.timer /mnt/etc/systemd/system/multi-user.target.wants/sats-update.timer; - # (5) Enable sats-dwc@wlan0 at startup # + # (4) Enable sats-sync path at startup # + echo " (.) Emulate \`systemctl enable sats-sync.path\`"; + sudo ln -fs /lib/systemd/system/sats-sync.path /mnt/etc/systemd/system/multi-user.target.wants/sats-sync.path; + + # (5) Enable sats-sync-stop path at startup # + echo " (.) Emulate \`systemctl enable sats-sync-stop.path\`"; + sudo ln -fs /lib/systemd/system/sats-sync-stop.path /mnt/etc/systemd/system/multi-user.target.wants/sats-sync-stop.path; + + # (6) Enable sats-dwc@wlan0 at startup # echo " (.) Emulate \`systemctl enable sats-dwc@wlan0.service\`"; - sudo ln -fs /lib/systemd/system/sats-dwc@.service /mnt/etc/systemd/system/multi-user.target.wants/sats-dwc@wlan0.service; + sudo ln -fs /lib/systemd/system/sats-dwc@.service /mnt/etc/systemd/system/multi-user.target.wants/sats-dwc@wlan0.service; - # (6) Enable firewall@default at startup # + # (7) Enable firewall@default at startup # echo " (.) Emulate \`systemctl enable firewall@default.service\`"; - sudo ln -fs /lib/systemd/system/firewall@.service /mnt/etc/systemd/system/multi-user.target.wants/firewall@default.service; + sudo ln -fs /lib/systemd/system/firewall@.service /mnt/etc/systemd/system/multi-user.target.wants/firewall@default.service; # (4) Create target scripts #--------------------------------------------------------# # (1) Create sats-boot script # echo " (.) Create sats-boot script"; - sudo cp ./utility/sats-boot /mnt/service/sats-boot; + sudo cp ./utility/sats-boot /mnt/service/sats-boot; # (2) Create sats-install script # echo " (.) Create sats-install script"; @@ -397,20 +411,24 @@ step7(){ # (3) Create sats-update script # echo " (.) Create sats-update script"; - cat ./utility/sats-update | sudo tee /mnt/service/sats-update > /dev/null; + cat ./utility/sats-update | sudo tee /mnt/service/sats-update > /dev/null; # (4) Create sats-loop script # echo " (.) Create sats-loop script"; - cat ./utility/sats-loop | sudo tee /mnt/service/sats-loop > /dev/null; + cat ./utility/sats-loop | sudo tee /mnt/service/sats-loop > /dev/null; - # (5) Create sats-dwc@wlan0 script # + # (5) Create sats-sync-stop script # + echo " (.) Create sats-sync-stop script"; + cat ./utility/sats-sync-stop | sudo tee /mnt/service/sats-sync-stop > /dev/null; + + # (6) Create sats-dwc@wlan0 script # echo " (.) Create sats-dwc@wlan0 script"; - cat ./utility/wlan0.dwc | sed "s/\*\*\*SALT\*\*\*/$WIFI_SALT/" | sed "s/\*\*\*PEPPER\*\*\*/$WIFI_PEPPER/" | sudo tee /mnt/etc/wpa_supplicant/wlan0.dwc > /dev/null; + cat ./utility/wlan0.dwc | sed "s/\*\*\*SALT\*\*\*/$WIFI_SALT/" | sed "s/\*\*\*PEPPER\*\*\*/$WIFI_PEPPER/" | sudo tee /mnt/etc/wpa_supplicant/wlan0.dwc > /dev/null; - # (6) Create firewall@default script # + # (7) Create firewall@default script # echo " (.) Create firewall@default script"; sudo mkdir -p /mnt/opt/firewall; - cat ./utility/default.fw | sudo tee /mnt/opt/firewall/default.fw > /dev/null; + cat ./utility/default.fw | sudo tee /mnt/opt/firewall/default.fw > /dev/null; # (5) Set up permissions @@ -425,7 +443,7 @@ step7(){ # (2) target dir # echo " - /target (sats:pi 750)"; sudo chown -R 666:1000 /mnt/target; - sudo chmod -R 750 /mnt/target; + sudo chmod -R 755 /mnt/target; echo "<<< done"; @@ -553,6 +571,7 @@ echo "(6) Manage ssh keys"; echo "(7) Set up systemd background"; echo "(8) Set up WiFi config"; echo "(9) Set up SATS daemon"; +echo "(10) Proper finishing"; read -p "step: " step; case $step in @@ -565,5 +584,6 @@ case $step in "7") step7;; "8") step8;; "9") step9;; + "10") step10;; *) echo "wrong step"; exit;; esac; diff --git a/clone/utility/sats-install b/clone/utility/sats-install index 8618bf6..ccadf49 100644 --- a/clone/utility/sats-install +++ b/clone/utility/sats-install @@ -66,7 +66,7 @@ fi; # (2) Enable SPI device # -echo " * 8. Enabling spi device"; +slog " * 8. Enabling spi device"; echo "dtparam=spi=on" | sudo tee -a /boot/config.txt > /dev/null \ || failexit; echo "dtoverlay=spi-bcm2708" | sudo tee -a /boot/config.txt > /dev/null \ diff --git a/clone/utility/sats-loop.service b/clone/utility/sats-loop.service index bb93ca7..abf935c 100644 --- a/clone/utility/sats-loop.service +++ b/clone/utility/sats-loop.service @@ -1,7 +1,7 @@ [Unit] Description=[::SATS::] Daemon -Requires=sats-sync.target -After=sats-sync.target +Requires=sats-sync.service +After=sats-sync.service [Service] Type=simple diff --git a/clone/utility/sats-sync-stop b/clone/utility/sats-sync-stop new file mode 100644 index 0000000..d415b90 --- /dev/null +++ b/clone/utility/sats-sync-stop @@ -0,0 +1,3 @@ +#!/bin/bash + +sudo -u sats test ! -e /target/sync && sudo systemctl stop sats-sync.service; \ No newline at end of file diff --git a/clone/utility/sats-sync-stop.path b/clone/utility/sats-sync-stop.path new file mode 100644 index 0000000..1784a9e --- /dev/null +++ b/clone/utility/sats-sync-stop.path @@ -0,0 +1,9 @@ +[Unit] +Description=[::SATS::] Path watcher (stop) + +[Path] +PathModified=/target/sync +Unit=sats-sync-stop.service + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/clone/utility/sats-sync-stop.service b/clone/utility/sats-sync-stop.service new file mode 100644 index 0000000..ce83f52 --- /dev/null +++ b/clone/utility/sats-sync-stop.service @@ -0,0 +1,10 @@ +[Unit] +Description=[::SATS::] Sync target (stop) + +[Service] +Type=oneshot +RemainAfterExit=no +User=pi +Group=pi + +ExecStart=/bin/bash /service/sats-sync-stop \ No newline at end of file diff --git a/clone/utility/sats-sync.path b/clone/utility/sats-sync.path index 083993d..b54f888 100644 --- a/clone/utility/sats-sync.path +++ b/clone/utility/sats-sync.path @@ -3,7 +3,7 @@ Description=[::SATS::] Path watcher [Path] PathExists=/target/sync -Unit=sats-sync.target +Unit=sats-sync.service [Install] WantedBy=multi-user.target \ No newline at end of file diff --git a/clone/utility/sats-sync.target b/clone/utility/sats-sync.service similarity index 50% rename from clone/utility/sats-sync.target rename to clone/utility/sats-sync.service index 5407394..06af576 100644 --- a/clone/utility/sats-sync.target +++ b/clone/utility/sats-sync.service @@ -3,4 +3,12 @@ Description=[::SATS::] Sync target Requires=sats-boot.service Wants=sats-install.service After=sats-boot.service sats-install.service -AssertPathExists=/target/sync \ No newline at end of file +AssertPathExists=/target/sync + +[Service] +Type=oneshot +RemainAfterExit=yes +User=sats +Group=sats + +ExecStart=/usr/sbin/test -e /target/sync \ No newline at end of file diff --git a/clone/utility/sats-update.service b/clone/utility/sats-update.service index 861e6f1..6644147 100644 --- a/clone/utility/sats-update.service +++ b/clone/utility/sats-update.service @@ -2,7 +2,7 @@ Description=[::SATS::] Update Process Requires=sats-dwc@wlan0.service network-online.target After=sats-dwc@wlan0.service -Requisite=sats-sync.target +Requisite=sats-sync.service [Service] Type=oneshot