[bigupdate] Updated /service and /target folders + renames sats-boot to sats-install + whole new service hierarchy + 2 states in /target

This commit is contained in:
xdrm-brackets 2017-05-08 16:22:11 +02:00
parent 34bca18357
commit 0e9e40f154
8 changed files with 87 additions and 71 deletions

View File

@ -16,7 +16,6 @@ echo "<<< done";
# [!] Check parameter : device file # [!] Check parameter : device file
#========================================================# #========================================================#
echo ">>> [!] Checking parameter : device"; echo ">>> [!] Checking parameter : device";
# (1) Check parameter existence # # (1) Check parameter existence #
test $# -lt 1 && echo "Missing parameter : device" && exit; test $# -lt 1 && echo "Missing parameter : device" && exit;
@ -48,7 +47,7 @@ step1(){
test -z "$mounted_partitions" && echo "<<< done" && step2; test -z "$mounted_partitions" && echo "<<< done" && step2;
for mounted in $mounted_partitions; do for mounted in $mounted_partitions; do
read -p " (!) umount $mounted (y/n) [n]" unmount; read -p " (!) umount $mounted (y/n) [n]" unmount;
test -n "$unmount" && test $unmount = "y" && sudo umount $mounted 2> /dev/null > /dev/null && echo " > unmounted"; test -n "$unmount" && test $unmount = "y" && sudo umount $mounted 2> /dev/null > /dev/null && echo " > unmounted";
@ -100,7 +99,7 @@ step3(){
# (2) Burning image into disk # # (2) Burning image into disk #
# if GZIP # if GZIP
if [ "IMAGE_ZIP" = "1" ]; then if [ "IMAGE_ZIP" = "1" ]; then
echo " - using gunzip"; echo " - using gunzip";
@ -112,7 +111,7 @@ step3(){
( dd if=$IMAGE_FILE | pv -s $(du -bs $IMAGE_FILE | awk '{print $1}') | sudo dd of=$DEV bs=4M ) \ ( dd if=$IMAGE_FILE | pv -s $(du -bs $IMAGE_FILE | awk '{print $1}') | sudo dd of=$DEV bs=4M ) \
|| $( echo "<<< error: dd command failed" && exit ); || $( echo "<<< error: dd command failed" && exit );
fi; fi;
@ -199,7 +198,7 @@ step6(){
# (3) Create ssh file system # # (3) Create ssh file system #
echo " (.) Init ssh folder (/home/sats/.ssh)"; echo " (.) Init ssh folder (/home/sats/.ssh)";
sudo mkdir -p /mnt/home/sats/.ssh; sudo mkdir -p /mnt/home/sats/.ssh;
# (4) Add both keys to sats files # # (4) Add both keys to sats files #
echo " (.) Add keys to ssh folder"; echo " (.) Add keys to ssh folder";
@ -231,7 +230,7 @@ step6(){
echo -e "Host\tsmmp-server\n\tHostname\t$SERVER_HOSTNAME\n\tUser\t$SERVER_USERNAME\n\tIdentityFile\t~/.ssh/id_ecdsa\n\tStrictHostKeyChecking\tno" | sudo tee /mnt/home/sats/.ssh/config > /dev/null; echo -e "Host\tsmmp-server\n\tHostname\t$SERVER_HOSTNAME\n\tUser\t$SERVER_USERNAME\n\tIdentityFile\t~/.ssh/id_ecdsa\n\tStrictHostKeyChecking\tno" | sudo tee /mnt/home/sats/.ssh/config > /dev/null;
sudo chown 666:666 /mnt/home/sats/.ssh/config; sudo chown 666:666 /mnt/home/sats/.ssh/config;
sudo chmod 444 /mnt/home/sats/.ssh/config; sudo chmod 444 /mnt/home/sats/.ssh/config;
echo "<<< done"; echo "<<< done";
@ -251,35 +250,64 @@ step7(){
echo -e "\n>>> [7] Set up systemd background"; echo -e "\n>>> [7] Set up systemd background";
# (0) Create useful folders #
echo " (.) Create useful folder";
echo " - /service";
sudo mkdir /mnt/service;
echo " - /target";
sudo mkdir /mnt/target;
sudo chown 666:666 /mnt/service/*;
sudo chown 666:666 /mnt/target;
sudo chmod 777 /mnt/service/*;
sudo chmod 777 /mnt/target;
# (1) Create link in order to be handled # # (1) Create link in order to be handled #
echo " (.) Emulate \`systemctl set-default multi-user.target\`"; echo " (.) Emulate \`systemctl set-default multi-user.target\`";
sudo ln -fs /lib/systemd/system/multi-user.target /mnt/etc/systemd/system/default.target; sudo ln -fs /lib/systemd/system/multi-user.target /mnt/etc/systemd/system/default.target;
#echo " (.) Set autologin for tty1.service"; # (2) Install sats-install service #
#sudo mkdir -pv /mnt/etc/systemd/system/getty@tty1.service.d; echo " (.) Create sats-install service";
#sudo touch /mnt/etc/systemd/system/getty@tty1.service.d/autologin.conf;
#cat ./utility/autologin_overload.conf | sudo tee /mnt/etc/systemd/system/getty@tty1.service.d/autologin.conf > /dev/null;
# (2) Install sats-boot service #
echo " (.) Create sats-boot service";
echo " - /lib/systemd/system"; echo " - /lib/systemd/system";
sudo cp ./utility/sats-boot.service /mnt/lib/systemd/system/sats-boot.service; sudo cp ./utility/sats-install.service /mnt/lib/systemd/system/sats-install.service;
echo " (.) Create sats-boot script";
sudo cp ./utility/sats-boot /mnt/home/pi/sats-boot;
sudo touch /mnt/home/pi/first_boot;
sudo chown 1000:1000 /mnt/home/pi/sats-boot;
sudo chown 1000:1000 /mnt/home/pi/first_boot;
sudo chmod 770 /mnt/home/pi/sats-boot;
sudo chmod 770 /mnt/home/pi/first_boot;
# (3) Install sats-boot service # # (3) Install sats-boot service #
echo " (.) Create sats-update service"; echo " (.) Create sats-update service";
echo " - /lib/systemd/system"; 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) Install 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;
# (5) Enable startup service unit #
echo " (.) Emulate \`systemctl enable sats-loop.service\`";
sudo mkdir -p /mnt/etc/systemd/system/multi-user.target.wants;
sudo ln -fs /lib/systemd/system/sats-loop.service /mnt/etc/systemd/system/multi-user.target.wants/sats-loop.service;
# (6) Create sats-install script #
echo " (.) Create sats-install script";
sudo cp ./utility/sats-install /mnt/service/sats-install;
# (8) Create sats-update script #
echo " (.) Create sats-update script";
cat ./utility/sats-update | sudo tee /mnt/service/sats-update > /dev/null;
# (8) Create sats-loop script #
echo " (.) Create sats-loop script";
cat ./utility/sats-loop | sudo tee /mnt/service/sats-loop > /dev/null;
# (9) Set up permissions #
echo " (.) Set up permissions";
echo " - sats-install @pi";
sudo chown 1000:1000 /mnt/service/sats-install;
sudo chmod 770 /mnt/service/sats-install;
echo " - sats-update @sats";
sudo chown 666:666 /mnt/service/sats-update;
sudo chmod 770 /mnt/service/sats-update;
echo " - sats-loop @sats";
sudo chown 666:666 /mnt/service/sats-loop;
sudo chmod 770 /mnt/service/sats-loop;
echo "<<< done"; echo "<<< done";
@ -347,27 +375,13 @@ step9(){
echo "$WAREHOUSE_TOKEN" | sudo tee /mnt/home/sats/satsd/conf/warehouse.token > /dev/null; echo "$WAREHOUSE_TOKEN" | sudo tee /mnt/home/sats/satsd/conf/warehouse.token > /dev/null;
echo "$MACHINE_ID;$UNLOCK_CODE" | tee ./server/created > /dev/null; echo "$MACHINE_ID;$UNLOCK_CODE" | tee ./server/created > /dev/null;
# (3) Set up SATS botting script # # (3) Adjust permissions #
echo " (.) Set up SATS booting script";
cat ./utility/sats-loop | sudo tee /mnt/home/sats/satsd/sats-loop > /dev/null;
# (4) Set up service unit #
echo " (.) Set up service unit (sats-loop.service)";
cat ./utility/sats-loop.service | sudo tee /mnt/lib/systemd/system/sats-loop.service > /dev/null;
# (5) Enable startup service unit #
echo " (.) Emulate \`systemctl enable sats-loop.service\`";
sudo mkdir -p /mnt/etc/systemd/system/multi-user.target.wants;
sudo ln -fs /lib/systemd/system/sats-loop.service /mnt/etc/systemd/system/multi-user.target.wants/sats-loop.service;
# (6) Adjust permissions #
echo " (.) Adjust permissions"; echo " (.) Adjust permissions";
sudo chown -R 666:666 /mnt/home/sats/satsd; sudo chown -R 666:666 /mnt/home/sats/satsd;
sudo chmod -R 770 /mnt/home/sats/satsd; sudo chmod -R 770 /mnt/home/sats/satsd;
# (7) Add entry in /etc/hosts if LOCAL_TEST not empty # # (4) Add entry in /etc/hosts if LOCAL_TEST not empty #
test -n "$LOCAL_TEST" && echo -e "\n$LOCAL_TEST\n" | sudo tee -a /mnt/etc/hosts > /dev/null; test -n "$LOCAL_TEST" && echo -e "\n$LOCAL_TEST\n" | sudo tee -a /mnt/etc/hosts > /dev/null;
echo "<<< done"; echo "<<< done";

View File

@ -17,4 +17,4 @@ iface eth0 inet manual
allow-hotplug wlan0 allow-hotplug wlan0
iface wlan0 inet manual iface wlan0 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
up /bin/systemctl start sats-update.service up /bin/systemctl start sats-update.service

View File

@ -23,20 +23,20 @@ sudo apt-get -y install git php5 php5-cli php5-curl python-dev;
################################################ ################################################
#### ONLY ON FIRST BOOT #### #### ONLY ON FIRST BOOT ####
################################################ ################################################
if [ -e /home/pi/first_boot ]; then if [ ! -e /target/install ]; then
dpkg -s git 2>/dev/null >/dev/null && gitinstalled=1 || gitinstalled=0; dpkg -s git 2>/dev/null >/dev/null && gitinstalled=1 || gitinstalled=0;
BRANCH=$(sudo cat /home/sats/satsd/conf/machine.branch); BRANCH=$(sudo cat /home/sats/satsd/conf/machine.branch);
# (1) With git if installed # # (1) With git if installed #
if [ $gitinstalled -eq 1 ]; then if [ $gitinstalled -eq 1 ]; then
sudo -u sats git clone -b $BRANCH ssh://smmp-server/satsd/git /home/sats/satsd/source \ sudo -u sats git clone -b $BRANCH ssh://smmp-server/satsd/git /home/sats/satsd/source \
&& rm /home/pi/first_boot \ && sudo -u sats touch /target/install \
|| exit; || exit;
fi; fi;
@ -53,6 +53,7 @@ if [ -e /home/pi/first_boot ]; then
sudo python setup.py install; sudo python setup.py install;
# (4) Reboot to activate SPI # # (4) Reboot to activate SPI #
sudo -u sats touch /target/install;
sudo reboot; sudo reboot;
fi; fi;

View File

@ -5,11 +5,11 @@ After=network-online.target network.target
Before=sats-loop.service Before=sats-loop.service
[Service] [Service]
Type=oneshot Type=simple
RemainAfterExit=yes RemainAfterExit=yes
User=pi User=pi
Group=pi Group=pi
ExecStart=/bin/sh /home/pi/sats-boot ExecStart=/bin/sh /home/pi/sats-install
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target

View File

@ -1,18 +1,9 @@
#!/bin/sh #!/bin/sh
# [0] Exit if no argument # [0] Check installed first
test $# -lt 1 && exit; if [ ! -e /target/install ]; then
exit 1;
# [1] Propagate script to DAEMON
if [ "$1" = "daemon" ]; then
/bin/bash /home/sats/satsd/source/daemon 2>> /home/sats/satsd/log/daemon.log >> /home/sats/satsd/log/daemon.log;
# [2] Propagate script to UPDATE
elif [ "$1" = "update" ]; then
/bin/bash /home/sats/satsd/source/update 2>> /home/sats/satsd/log/update.log >> /home/sats/satsd/log/update.log;
fi; fi;
# [1] Propagate script to DAEMON
/bin/bash /home/sats/satsd/source/daemon 2>> /home/sats/satsd/log/daemon.log >> /home/sats/satsd/log/daemon.log;

View File

@ -1,14 +1,14 @@
[Unit] [Unit]
Description=SATS (Secure Authentication and Tracking SYSTEM) Daemon Description=SATS Daemon
Wants=sats-boot.service Wants=sats-install.service
OnFailure=sats-install.service
[Service] [Service]
Type=simple Type=simple
User=sats User=sats
Group=sats Group=sats
ExecStart=/bin/sh /home/sats/satsd/sats-loop daemon ExecStart=/bin/sh /service/sats-loop
Restart=always Restart=always
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target

View File

@ -0,0 +1,9 @@
#!/bin/sh
# [0] Check synced first
if [ ! -e /target/sync ]; then
exit 1;
fi;
# [1] Propagate script to UPDATE
/bin/bash /home/sats/satsd/source/update 2>> /home/sats/satsd/log/update.log >> /home/sats/satsd/log/update.log;

View File

@ -1,10 +1,11 @@
[Unit] [Unit]
Description=SATS Update Process Description=SATS Update Process
Requires=network-online.target network.target sats-loop.service sats-boot.service Requires=network-online.target network.target
OnFailure=sats-loop.service
[Service] [Service]
RemainAfterExit=yes RemainAfterExit=yes
Type=oneshot Type=oneshot
User=sats User=sats
Group=sats Group=sats
ExecStart=/bin/bash /home/sats/satsd/sats-loop update ExecStart=/bin/bash /service/sats-update