Major update : created pi's service
This commit is contained in:
parent
a2953139aa
commit
09f75847bb
190
clone/clone
190
clone/clone
|
@ -132,45 +132,28 @@ step4(){
|
||||||
# [5] Updating users
|
# [5] Updating users
|
||||||
#========================================================#
|
#========================================================#
|
||||||
step5(){
|
step5(){
|
||||||
echo "\n>>> [5] Updating users";
|
echo "\n>>> [5] Updating users' structure";
|
||||||
|
|
||||||
|
# (1) emulate `useradd sats` #
|
||||||
# (1) Removing pi entry #
|
echo " (.) emulate \`useradd sats\`";
|
||||||
echo " (.) Remove pi user entry"
|
echo " - /etc/shadow";
|
||||||
echo " > /etc/shadow";
|
cat ./utility/shadow_append | sudo tee -a /mnt/etc/shadow > /dev/null;
|
||||||
sudo cat /mnt/etc/shadow | grep -vE "^pi:" | tee ./tmp/shadow > /dev/null;
|
cat ./utility/shadow_append | sudo tee -a /mnt/etc/shadow- > /dev/null;
|
||||||
|
echo " - /etc/passwd";
|
||||||
# (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;
|
cat ./utility/passwd_append | sudo tee -a /mnt/etc/passwd > /dev/null;
|
||||||
sudo cat /mnt/etc/passwd | sudo tee /mnt/etc/passwd- > /dev/null;
|
cat ./utility/passwd_append | sudo tee -a /mnt/etc/passwd- > /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;
|
||||||
|
|
||||||
echo " (.) Copying pi's .bashrc to sats";
|
echo "<<< done":
|
||||||
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";
|
|
||||||
|
|
||||||
step6;
|
step6;
|
||||||
}
|
}
|
||||||
|
@ -180,29 +163,11 @@ step5(){
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# [6] Updating groups
|
|
||||||
|
# [6] Manage SSH keys #
|
||||||
#========================================================#
|
#========================================================#
|
||||||
step6(){
|
step6(){
|
||||||
echo "\n>>> [6] Updating groups (ssh-key, sats)";
|
echo "\n>>> [6] Manage ssh keys";
|
||||||
|
|
||||||
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";
|
|
||||||
|
|
||||||
# (1) Create ssh key pair #
|
# (1) Create ssh key pair #
|
||||||
echo " (.) Create ssh key [ecdsa:521]";
|
echo " (.) Create ssh key [ecdsa:521]";
|
||||||
|
@ -238,12 +203,7 @@ step7(){
|
||||||
echo " (.) Restrict access to pubkey";
|
echo " (.) Restrict access to pubkey";
|
||||||
cat ./utility/sshd_config_append | sudo tee -a /mnt/etc/ssh/sshd_config > /dev/null;
|
cat ./utility/sshd_config_append | sudo tee -a /mnt/etc/ssh/sshd_config > /dev/null;
|
||||||
|
|
||||||
|
# (8) Define config alias with ssh-key #
|
||||||
# (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 #
|
|
||||||
echo " (.) Define alias config";
|
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;
|
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;
|
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";
|
echo "<<< done";
|
||||||
|
|
||||||
step8;
|
step8;
|
||||||
|
@ -262,22 +263,12 @@ step7(){
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# [8] Set up sats automatic login
|
# [8] Manage Network config
|
||||||
#========================================================#
|
#========================================================#
|
||||||
step8(){
|
step8(){
|
||||||
echo "\n>>> [8] Set up automatic login";
|
echo "\n>>> [8] Set up WiFi configuration";
|
||||||
|
|
||||||
|
|
||||||
# (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 "network={\n\tssid=\"$WIFI_SSID\"\n\tpsk=\"$WIFI_PASS\"\n}" | sudo tee -a /mnt/etc/wpa_supplicant/wpa_supplicant.conf > /dev/null;
|
||||||
|
|
||||||
echo "<<< done";
|
echo "<<< done";
|
||||||
|
|
||||||
|
@ -289,29 +280,11 @@ step8(){
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [9] Set up SATS daemon
|
||||||
# [9] Manage Network config
|
|
||||||
#========================================================#
|
#========================================================#
|
||||||
step9(){
|
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 "\n>>> [9] Set up SATS operating folder";
|
||||||
|
|
||||||
echo "<<< done";
|
|
||||||
|
|
||||||
step10;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# [10] Set up SATS daemon
|
|
||||||
#========================================================#
|
|
||||||
step10(){
|
|
||||||
|
|
||||||
echo "\n>>> [10] Set up SATS operating folder";
|
|
||||||
|
|
||||||
|
|
||||||
# (1) Create operating folder #
|
# (1) Create operating folder #
|
||||||
|
@ -323,16 +296,16 @@ step10(){
|
||||||
|
|
||||||
# (2) Set up SATS botting script #
|
# (2) Set up SATS botting script #
|
||||||
echo " (.) Set up SATS booting 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 #
|
# (3) Set up service unit #
|
||||||
echo " (.) Set up service unit (sats.service)";
|
echo " (.) Set up service unit (sats-boot.service)";
|
||||||
cat ./utility/service_unit | sudo tee /mnt/lib/systemd/system/sats.service > /dev/null;
|
cat ./utility/sats-boot.service | sudo tee /mnt/lib/systemd/system/sats-boot.service > /dev/null;
|
||||||
|
|
||||||
# (4) Enable startup service unit #
|
# (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 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 #
|
# (5) Adjust permissions #
|
||||||
echo " (.) Adjust permissions";
|
echo " (.) Adjust permissions";
|
||||||
|
@ -342,7 +315,7 @@ step10(){
|
||||||
|
|
||||||
echo "<<< done";
|
echo "<<< done";
|
||||||
|
|
||||||
step11;
|
step10;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -352,9 +325,9 @@ step10(){
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# [11] BLablslkfjdlkdsjfks
|
# [10] BLablslkfjdlkdsjfks
|
||||||
#========================================================#
|
#========================================================#
|
||||||
step11(){
|
step10(){
|
||||||
|
|
||||||
sudo umount /mnt;
|
sudo umount /mnt;
|
||||||
|
|
||||||
|
@ -373,12 +346,11 @@ echo "(1) Unmount mounted partitions";
|
||||||
echo "(2) Format disk (gpt table)";
|
echo "(2) Format disk (gpt table)";
|
||||||
echo "(3) Burn image into disk";
|
echo "(3) Burn image into disk";
|
||||||
echo "(4) Mount / partition";
|
echo "(4) Mount / partition";
|
||||||
echo "(5) Update users";
|
echo "(5) Update users and groups";
|
||||||
echo "(6) Update groups";
|
echo "(6) Manage ssh keys";
|
||||||
echo "(7) Manage ssh keys";
|
echo "(7) Set up systemd background";
|
||||||
echo "(8) Set up automatic sats login";
|
echo "(8) Set up WiFi config";
|
||||||
echo "(9) Set up WiFi config";
|
echo "(9) Set up SATS daemon";
|
||||||
echo "(10) Set up SATS daemon";
|
|
||||||
read -p "step: " step;
|
read -p "step: " step;
|
||||||
|
|
||||||
case $step in
|
case $step in
|
||||||
|
|
|
@ -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;
|
|
@ -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
|
|
@ -4,7 +4,8 @@ Description=SATS (Secure Authentication and Tracking SYSTEM) Daemon
|
||||||
[Service]
|
[Service]
|
||||||
Type=simple
|
Type=simple
|
||||||
User=sats
|
User=sats
|
||||||
ExecStart=/bin/sh /home/sats/satsd/boot
|
Group=sats
|
||||||
|
ExecStart=/bin/sh /home/sats/satsd/sats-boot
|
||||||
Restart=on-abort
|
Restart=on-abort
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,2 @@
|
||||||
pi:$6$k0vFWRoG$bEBdFcFBWw2fLEA.5LsVKOtLWdWSkZMnEikqOG4jHCneRrWEBnEt6.ROe60ggdA7DbdU.l2ZO35WFvi3q6Ays/:17130:0:99999:7:::
|
sats:*:17185:0:999999:7::
|
||||||
sats:sats-password:17185:0:999999:7::
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue