[bigupdate] systemd new management

This commit is contained in:
xdrm-brackets 2017-07-23 23:27:51 +02:00
parent 98615df45f
commit bad5b28848
8 changed files with 211 additions and 169 deletions

View File

@ -283,36 +283,51 @@ step7(){
# (2) Create .service lib files ()
#--------------------------------------------------------#
# (1) Create sats-install service #
# (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;
# (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;
# (2) Create sats-update 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;
# (3) Create sats-loop 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;
# (4) Create sats-dwc@ service #
# (5) Create sats-sync target #
echo " (.) Create sats-sync target";
echo " - /lib/systemd/system";
sudo cp ./utility/sats-sync.target /mnt/lib/systemd/system/sats-sync.target
# (6) 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;
# (7) 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;
# (8) 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;
# (5) Create firewall@ service #
# (9) Create firewall@ service #
echo " (.) Create firewall@ service";
echo " - /lib/systemd/system";
sudo cp ./utility/firewall@.service /mnt/lib/systemd/system/firewall@.service;
# (6) Create sats-update timer #
echo " (.) Create sats-update timer";
echo " - /lib/systemd/system";
cat ./utility/sats-update.timer | sudo tee /mnt/lib/systemd/system/sats-update.timer > /dev/null;
# (3) Install services
#--------------------------------------------------------#
@ -323,38 +338,46 @@ step7(){
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;
# (3) Enable sats-dwc@wlan0 at startup #
# (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 #
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;
# (5) 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;
# (4) Enable firewall@default at startup #
# (6) 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;
# (5) 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;
# (4) Create target scripts
#--------------------------------------------------------#
# (1) Create sats-install script #
# (1) Create sats-boot script #
echo " (.) Create sats-boot script";
sudo cp ./utility/sats-boot /mnt/service/sats-boot;
# (2) Create sats-install script #
echo " (.) Create sats-install script";
sudo cp ./utility/sats-install /mnt/service/sats-install;
# (2) Create sats-update script #
# (3) Create sats-update script #
echo " (.) Create sats-update script";
cat ./utility/sats-update | sudo tee /mnt/service/sats-update > /dev/null;
# (3) Create sats-loop script #
# (4) Create sats-loop script #
echo " (.) Create sats-loop script";
cat ./utility/sats-loop | sudo tee /mnt/service/sats-loop > /dev/null;
# (4) Create sats-dwc@wlan0 script #
# (5) 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;
# (5) Create firewall@default script #
# (6) 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;
@ -365,29 +388,14 @@ step7(){
echo " (.) Set up permissions";
# (1) Services scripts #
echo " - sats-install (owner: pi)";
sudo chown 1000:1000 /mnt/service/sats-install;
sudo chmod 770 /mnt/service/sats-install;
echo " - /service (sats:pi 750)";
sudo chown -R 666:1000 /mnt/service/*;
sudo chmod -R 750 /mnt/service/*;
echo " - sats-update (ownder: sats)";
sudo chown 666:666 /mnt/service/sats-update;
sudo chmod 770 /mnt/service/sats-update;
echo " - sats-loop (ownder: sats)";
sudo chown 666:666 /mnt/service/sats-loop;
sudo chmod 770 /mnt/service/sats-loop;
echo " - sats-dwc@wlan0 (ownder: pi)";
sudo chown 1000:1000 /mnt/etc/wpa_supplicant/wlan0.dwc;
sudo chmod 770 /mnt/etc/wpa_supplicant/wlan0.dwc;
echo " - /service (ownder: sats)";
sudo chown 666:666 /mnt/service/*;
sudo chmod 775 /mnt/service/*;
echo " - /target (ownder: sats)";
sudo chown 666:666 /mnt/target;
sudo chmod 775 /mnt/target;
# (2) target dir #
echo " - /target (sats:pi 750)";
sudo chown -R 666:1000 /mnt/target;
sudo chmod -R 750 /mnt/target;
echo "<<< done";

50
clone/utility/sats-boot Normal file
View File

@ -0,0 +1,50 @@
#!/bin/sh
#@@@@#
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;
}
failexit(){
slog " > failed";
exit 127;
}
# [1] Notify boot (first or normal) #
echo;
test ! -e /target/sync && echo "First Boot" | plog;
test -e /target/sync && echo "Normal Boot" | plog;
slog "============";
# [2] Start ssh service
slog " * 1. Starting ssh service";
sudo systemctl start ssh \
&& slog " > done" \
|| failexit;
# [3] Set random passwords for 'sats'
echo " * 2. 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" \
|| failexit;
# [4] Set random passwords for 'pi' itself
echo " * 3. 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" \
|| failexit;

View File

@ -20,42 +20,13 @@ failexit(){
# [1] Notify boot (first or normal) #
echo;
test ! -e /target/sync && echo "First Boot" | plog;
test -e /target/sync && echo "Normal Boot" | plog;
slog "============";
# [2] Start ssh service
slog " * 1. Starting ssh service";
sudo systemctl start ssh \
&& slog " > done" \
|| failexit;
# [3] Set random passwords for 'sats'
echo " * 2. 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" \
|| failexit;
# [4] Set random passwords for 'pi' itself
echo " * 3. 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" \
|| failexit;
################################################
#### ONLY ON FIRST BOOT ####
################################################
if [ ! -e /target/sync ]; then
if [ -e /target/sync ]; then
slog " ** sync target already exists";
exit 127;
fi;
# (x) If no network -> exit #
slog " * 4. Checking connectivity";
@ -139,5 +110,3 @@ if [ ! -e /target/sync ]; then
# (3) Reboot to activate SPI #
slog " * 13. Launching first reboot";
sudo reboot;
fi;

View File

@ -1,7 +1,7 @@
[Unit]
Description=[::SATS::] Install Process
Requires=sats-dwc@wlan0.service network-online.target
After=sats-dwc@wlan0.service network-online.target
Requires=sats-dwc@wlan0.service sats-boot.service network-online.target
After=sats-boot.service sats-dwc@wlan0.service
[Service]
Type=oneshot

View File

@ -1,7 +1,7 @@
[Unit]
Description=[::SATS::] Daemon
Requires=sats-install.service
After=sats-install.service
Requires=sats-sync.target
After=sats-sync.target
[Service]
Type=simple

View File

@ -0,0 +1,9 @@
[Unit]
Description=[::SATS::] Path watcher
[Path]
PathExists=/target/sync
Unit=sats-sync.target
[Install]
WantedBy=multi-user.target

View File

@ -0,0 +1,6 @@
[Unit]
Description=[::SATS::] Sync target
Requires=sats-boot.service
Wants=sats-install.service
After=sats-boot.service sats-install.service
AssertPathExists=/target/sync

View File

@ -1,8 +1,8 @@
[Unit]
Description=[::SATS::] Update Process
Requires=sats-dwc@wlan0.service network-online.target
After=sats-dwc@wlan0.service network-online.target
Requisite=sats-install.service
After=sats-dwc@wlan0.service
Requisite=sats-sync.target
[Service]
Type=oneshot