From 09f75847bb4913a33fbdd3129c1c2306768c5878 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Wed, 25 Jan 2017 19:00:36 +0100 Subject: [PATCH] Major update : created pi's service --- clone/clone | 192 ++++++++---------- clone/utility/{booting_script => sats-boot} | 0 clone/utility/sats-boot-process | 15 ++ clone/utility/sats-boot-process.service | 12 ++ .../{service_unit => sats-boot.service} | 3 +- clone/utility/shadow_append | 3 +- 6 files changed, 112 insertions(+), 113 deletions(-) rename clone/utility/{booting_script => sats-boot} (100%) create mode 100644 clone/utility/sats-boot-process create mode 100644 clone/utility/sats-boot-process.service rename clone/utility/{service_unit => sats-boot.service} (74%) diff --git a/clone/clone b/clone/clone index 28becec..d68d8c5 100755 --- a/clone/clone +++ b/clone/clone @@ -132,45 +132,28 @@ step4(){ # [5] Updating users #========================================================# step5(){ - echo "\n>>> [5] Updating users"; + echo "\n>>> [5] Updating users' structure"; + # (1) emulate `useradd sats` # + echo " (.) emulate \`useradd sats\`"; + echo " - /etc/shadow"; + cat ./utility/shadow_append | sudo tee -a /mnt/etc/shadow > /dev/null; + cat ./utility/shadow_append | sudo tee -a /mnt/etc/shadow- > /dev/null; + echo " - /etc/passwd"; + cat ./utility/passwd_append | sudo tee -a /mnt/etc/passwd > /dev/null; + cat ./utility/passwd_append | sudo tee -a /mnt/etc/passwd- > /dev/null; - # (1) Removing pi entry # - echo " (.) Remove pi user entry" - echo " > /etc/shadow"; - sudo cat /mnt/etc/shadow | grep -vE "^pi:" | tee ./tmp/shadow > /dev/null; + # (2) Emulate `groupadd` then `usermod` # + echo " (.) emulate \`groupadd sats\`"; + echo " - /etc/group"; + echo " (.) emulate \`groupadd ssh-key\`"; + echo " - /etc/group"; + echo " (.) emulate \`usermod -a -G ssh-key,sats sats\`"; + echo " - /etc/group"; + cat ./utility/group_append | sudo tee -a /mnt/etc/group > /dev/null; + cat ./utility/group_append | sudo tee -a /mnt/etc/group- > /dev/null; - # (2) Adding 'sats' user and new pi entry # - echo " (.) Adding 'sats' user and updated 'pi'"; - cat ./utility/shadow_append | tee -a ./tmp/shadow > /dev/null; - - # (3) Setting sats random password # - echo " (.) Set sats random password" - RANDOM_PASS=$(tr -dc A-Za-z0-9_ < /dev/urandom | head -c 150); - RANDOM_SHADOW="$(python3 -c "import crypt; print(crypt.crypt(\"${RANDOM_PASS}\", crypt.mksalt(crypt.METHOD_SHA512)))")"; - RANDOM_SHADOW="$(echo $RANDOM_SHADOW | sed 's/\//\\\//g')" - cat ./tmp/shadow | sed "s/sats-passowrd/$RANDOM_SHADOW/" | tee ./tmp/shadow > /dev/null; - - - - # (4) Update real files # - echo " (.) Update real files"; - echo " > /etc/shadow"; - cat ./tmp/shadow | sudo tee /mnt/etc/shadow | sudo tee /mnt/etc/shadow- > /dev/null; - rm ./tmp/shadow; - - echo " > /etc/passwd"; - cat ./utility/passwd_append | sudo tee -a /mnt/etc/passwd > /dev/null; - sudo cat /mnt/etc/passwd | sudo tee /mnt/etc/passwd- > /dev/null; - - - echo " (.) Copying pi's .bashrc to sats"; - sudo mkdir -p /mnt/home/sats; - sudo cp /mnt/home/pi/.bashrc /mnt/home/sats/.bashrc; - sudo chown 666:666 /mnt/home/sats/.bashrc; - sudo chmod 544 /mnt/home/sats/.bashrc; - - echo "<<< done"; + echo "<<< done": step6; } @@ -180,29 +163,11 @@ step5(){ -# [6] Updating groups + +# [6] Manage SSH keys # #========================================================# step6(){ - echo "\n>>> [6] Updating groups (ssh-key, sats)"; - - cat ./utility/group_append | sudo tee -a /mnt/etc/group > /dev/null; - cat ./utility/group_append | sudo tee -a /mnt/etc/group- > /dev/null; - - echo "<<< done": - - step7; -} - - - - - - - -# [7] Manage SSH keys # -#========================================================# -step7(){ - echo "\n>>> [7] Manage ssh keys"; + echo "\n>>> [6] Manage ssh keys"; # (1) Create ssh key pair # echo " (.) Create ssh key [ecdsa:521]"; @@ -238,12 +203,7 @@ step7(){ echo " (.) Restrict access to pubkey"; cat ./utility/sshd_config_append | sudo tee -a /mnt/etc/ssh/sshd_config > /dev/null; - - # (8) Set up automatic ssh server at start up # - echo " (.) Emulate \`systemctl enable ssh.service\`"; - sudo ln -fs /lib/systemd/system/ssh.service /mnt/etc/systemd/system/sshd.service; - - # (9) Define config alias with ssh-key # + # (8) Define config alias with ssh-key # echo " (.) Define alias config"; echo "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; @@ -251,6 +211,47 @@ step7(){ + echo "<<< done"; + + step7; +} + + + + + + + +# [7] Set up systemd services +#========================================================# +step7(){ + echo "\n>>> [7] Set up systemd background"; + + + # (1) Create link in order to be handled # + echo " (.) Emulate \`systemctl set-default multi-user.target\`"; + sudo ln -fs /lib/systemd/system/multi-user.target /mnt/etc/systemd/system/default.target; + + #echo " (.) Set autologin for tty1.service"; + #sudo mkdir -pv /mnt/etc/systemd/system/getty@tty1.service.d; + #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-process service # + echo " (.) Create sats-boot-process service"; + echo " - /lib/systemd/system"; + sudo cp ./utility/sats-boot-process.service /mnt/lib/systemd/system/sats-boot-process.service; + + echo " (.) Create sats-boot-process script"; + sudo cp ./utility/sats-boot-process /mnt/home/pi/sats-boot-process; + sudo chown 1000:1000 /mnt/home/pi/sats-boot-process; + sudo chmod 770 /mnt/home/pi/sats-boot-process; + + echo " (.) Emulate \`systemctl enable sats-boot-process\`"; + sudo ln -fs /lib/systemd/system/multi-user.target /mnt/etc/systemd/system/sats-boot-process.service; + + + echo "<<< done"; step8; @@ -262,22 +263,12 @@ step7(){ -# [8] Set up sats automatic login +# [8] Manage Network config #========================================================# step8(){ - echo "\n>>> [8] Set up automatic login"; - - - # (1) Create link in order to be handled # - echo " (.) Emulate \`systemctl set-default multi-user.target\`"; - sudo ln -fs /lib/systemd/system/multi-user.target /mnt/etc/systemd/system/default.target; - - # (2) Link autologin to tty service # - echo " (.) Link autologin script to tty's default"; - #sudo mkdir -pv /mnt/etc/systemd/system/getty@tty1.service.d; - #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; + echo "\n>>> [8] Set up WiFi configuration"; + echo "network={\n\tssid=\"$WIFI_SSID\"\n\tpsk=\"$WIFI_PASS\"\n}" | sudo tee -a /mnt/etc/wpa_supplicant/wpa_supplicant.conf > /dev/null; echo "<<< done"; @@ -289,29 +280,11 @@ step8(){ - -# [9] Manage Network config +# [9] Set up SATS daemon #========================================================# step9(){ - echo "\n>>> [9] Set up WiFi configuration"; - echo "network={\n\tssid=\"$WIFI_SSID\"\n\tpsk=\"$WIFI_PASS\"\n}" | sudo tee -a /mnt/etc/wpa_supplicant/wpa_supplicant.conf > /dev/null; - - echo "<<< done"; - - step10; -} - - - - - - -# [10] Set up SATS daemon -#========================================================# -step10(){ - - echo "\n>>> [10] Set up SATS operating folder"; + echo "\n>>> [9] Set up SATS operating folder"; # (1) Create operating folder # @@ -323,16 +296,16 @@ step10(){ # (2) Set up SATS botting script # echo " (.) Set up SATS booting script"; - cat ./utility/booting_script | sudo tee /mnt/home/sats/satsd/boot > /dev/null; + cat ./utility/sats-boot | sudo tee /mnt/home/sats/satsd/sats-boot > /dev/null; # (3) Set up service unit # - echo " (.) Set up service unit (sats.service)"; - cat ./utility/service_unit | sudo tee /mnt/lib/systemd/system/sats.service > /dev/null; + echo " (.) Set up service unit (sats-boot.service)"; + cat ./utility/sats-boot.service | sudo tee /mnt/lib/systemd/system/sats-boot.service > /dev/null; # (4) Enable startup service unit # - echo " (.) Emulate \`systemctl enable sats.service\`"; + echo " (.) Emulate \`systemctl enable sats-boot.service\`"; sudo mkdir -p /mnt/etc/systemd/system/multi-user.target.wants; - sudo ln -fs /lib/systemd/system/sats.service /mnt/etc/systemd/system/multi-user.target.wants/sats.service; + sudo ln -fs /lib/systemd/system/sats-boot.service /mnt/etc/systemd/system/multi-user.target.wants/sats-boot.service; # (5) Adjust permissions # echo " (.) Adjust permissions"; @@ -342,7 +315,7 @@ step10(){ echo "<<< done"; - step11; + step10; } @@ -352,9 +325,9 @@ step10(){ -# [11] BLablslkfjdlkdsjfks +# [10] BLablslkfjdlkdsjfks #========================================================# -step11(){ +step10(){ sudo umount /mnt; @@ -373,12 +346,11 @@ echo "(1) Unmount mounted partitions"; echo "(2) Format disk (gpt table)"; echo "(3) Burn image into disk"; echo "(4) Mount / partition"; -echo "(5) Update users"; -echo "(6) Update groups"; -echo "(7) Manage ssh keys"; -echo "(8) Set up automatic sats login"; -echo "(9) Set up WiFi config"; -echo "(10) Set up SATS daemon"; +echo "(5) Update users and groups"; +echo "(6) Manage ssh keys"; +echo "(7) Set up systemd background"; +echo "(8) Set up WiFi config"; +echo "(9) Set up SATS daemon"; read -p "step: " step; case $step in diff --git a/clone/utility/booting_script b/clone/utility/sats-boot similarity index 100% rename from clone/utility/booting_script rename to clone/utility/sats-boot diff --git a/clone/utility/sats-boot-process b/clone/utility/sats-boot-process new file mode 100644 index 0000000..3e5d1a9 --- /dev/null +++ b/clone/utility/sats-boot-process @@ -0,0 +1,15 @@ +#!/bin/sh + +# [1] Set random passwords for 'sats' +RANDOM_PASS=$(tr -cd A-Za-z0-9_ < /dev/urandom | head -c 256); +echo "$RANDOM_PASS\n$RANDOM_PASS\n" | sudo passwd sats; + +# [2] Set random passwords for 'pi' itself +RANDOM_PASS=$(tr -cd A-Za-z0-9_ < /dev/urandom | head -c 256); +echo "$RANDOM_PASS\n$RANDOM_PASS\n" | sudo passwd pi; + +# [3] Start ssh service +sudo systemctl start ssh; + +# [4] Try to install necessary packages +sudo apt-get install git; diff --git a/clone/utility/sats-boot-process.service b/clone/utility/sats-boot-process.service new file mode 100644 index 0000000..def5600 --- /dev/null +++ b/clone/utility/sats-boot-process.service @@ -0,0 +1,12 @@ +[Unit] +Description=SATS Boot Process + +[Service] +Type=oneshot +RemainAfterExit=yes +User=pi +Group=pi +ExecStart=/bin/sh /home/pi/sats-install + +[Install] +WantedBy=multi-user.target diff --git a/clone/utility/service_unit b/clone/utility/sats-boot.service similarity index 74% rename from clone/utility/service_unit rename to clone/utility/sats-boot.service index b0fb76a..7651eb3 100644 --- a/clone/utility/service_unit +++ b/clone/utility/sats-boot.service @@ -4,7 +4,8 @@ Description=SATS (Secure Authentication and Tracking SYSTEM) Daemon [Service] Type=simple User=sats -ExecStart=/bin/sh /home/sats/satsd/boot +Group=sats +ExecStart=/bin/sh /home/sats/satsd/sats-boot Restart=on-abort diff --git a/clone/utility/shadow_append b/clone/utility/shadow_append index b18e443..c916fa8 100644 --- a/clone/utility/shadow_append +++ b/clone/utility/shadow_append @@ -1,3 +1,2 @@ -pi:$6$k0vFWRoG$bEBdFcFBWw2fLEA.5LsVKOtLWdWSkZMnEikqOG4jHCneRrWEBnEt6.ROe60ggdA7DbdU.l2ZO35WFvi3q6Ays/:17130:0:99999:7::: -sats:sats-password:17185:0:999999:7:: +sats:*:17185:0:999999:7::