Added step menu + can mount (ok) + dd progress + ssh working

This commit is contained in:
xdrm-brackets 2017-01-21 12:38:13 +01:00
parent f8c2005ba1
commit 747eb90df1
2 changed files with 190 additions and 122 deletions

1
clone/authorized_keys Normal file
View File

@ -0,0 +1 @@
ecdsa-sha2-nistp521 AAAAE2VjZHNhLXNoYTItbmlzdHA1MjEAAAAIbmlzdHA1MjEAAACFBAF91ZI1TROEV5nYmqPv0qW6b4U7BrSD6fK91XxPE2r+Okf756gGJQfg3iRKtyI5noWVU4e7ib3vsOTMSvMDafSDCgFULLasr5OApCrv6/cI/SV5MIerPkZO9eMMD/cZxTuT9aTpsSOtCiv0ewkLkbWHFHvIM0q6uaPQpAYVmpV6wUzoZg== [ECDSA:521] SATS

View File

@ -1,9 +1,9 @@
#!/bin/sh #!/bin/sh
# [1] Check parameter : device file # [!] Check parameter : device file
#========================================================# #========================================================#
echo ">>> [1] 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;
@ -15,12 +15,20 @@ test $device_type != "usb" && echo ">>> ERROR: device type is $device_type, \"us
echo "<<< done"; echo "<<< done";
# [2] Init device layout (gpt table) DEV="$1";
#========================================================#
# [1] Init device layout (gpt table)
#========================================================#
step1(){
echo "\n>>> [1] Checking for mounted partitions ($DEV)";
echo "\n>>> [2] Checking for mounted partitions";
# (1) List partitions of this device # # (1) List partitions of this device #
mounted_partitions=$( cat /proc/mounts | awk '{print $1}' | grep "$1" ); mounted_partitions=$( cat /proc/mounts | awk '{print $1}' | grep "$DEV" );
# if nothing found -> next step
test -z "$mounted_partitions" && echo "<<< done" && step2;
for mounted in $mounted_partitions; do for mounted in $mounted_partitions; do
@ -30,10 +38,16 @@ for mounted in $mounted_partitions; do
done; done;
echo "<<< done"; echo "<<< done";
step2;
}
# [3] Initialize GTP Table
# [2] Initialize GTP Table
#========================================================# #========================================================#
echo "\n>>> [3] Formatting disk"; step2(){
echo "\n>>> [2] Formatting disk ($DEV)";
# (1) Confirmation # # (1) Confirmation #
read -p" (!) Erase the whole disk ? it is irreversible! (y/n) [n]" confirm_format; read -p" (!) Erase the whole disk ? it is irreversible! (y/n) [n]" confirm_format;
@ -43,13 +57,19 @@ test $confirm_format != "y" && echo "<<< aborting" && exit;
# (2) Init gpt entry # # (2) Init gpt entry #
# echo " ))) replace by real code ((("; # echo " ))) replace by real code (((";
echo -e "g\nw" | sudo fdisk $1; echo -e "g\nw" | sudo fdisk $DEV;
step3;
}
# [4] Burn image to device
# [3] Burn image to device
#========================================================# #========================================================#
echo "\n>>> [4] Burning image into disk"; step3(){
echo "\n>>> [3] Burning image into disk ($DEV)";
# (1) Confirmation # # (1) Confirmation #
read -p" (!) Burn the whole disk ? it is irreversible! (y/n) [n]" confirm_burn; read -p" (!) Burn the whole disk ? it is irreversible! (y/n) [n]" confirm_burn;
@ -57,36 +77,45 @@ test -z "$confirm_burn" && echo "<<< aborting" && exit;
test $confirm_burn != "y" && echo "<<< aborting" && exit; test $confirm_burn != "y" && echo "<<< aborting" && exit;
# (2) Burning image into disk # # (2) Burning image into disk #
sudo dd if=./original.img of=$1 bs=4M \ sudo dd if=./original.img of=$DEV bs=4M \
|| ( echo "<<< ERROR: dd command failed" && exit ); || echo "<<< ERROR: dd command failed" && exit;
echo "<<< done"; echo "<<< done";
step4;
exit; }
# [5] Mount partition
# [4] Mount partition
#========================================================# #========================================================#
step4(){
echo "\n>>> [5] Mounting partition ${1}2"; echo "\n>>> [4] Mounting partition ${DEV}2";
# [1] Mount device partition # [1] Mount device partition
sudo mount ${1}2 /mnt -o uid=$UID,gid=$GID,umask=022; sudo mount ${DEV}2 /mnt || echo "<<< error: can't mount" && exit;
echo "<<< done"; echo "<<< done";
step5;
}
# [6] Updating users & groups
# [5] Updating users
#========================================================# #========================================================#
step5(){
echo "\n>>> [6] Updating users & groups"; echo "\n>>> [5] Updating users";
echo " (.) Adding user satsuser"; echo " (.) Adding user satsuser";
# shadow # shadow
echo " /etc/shadow"; echo " /etc/shadow";
echo "satsuser:{somedigestedpass}:17185:0:999999:7::" | sudo tee -a /mnt/etc/shadow > /dev/mull; ## TODO: Manage default password ##
echo "satsuser:{somedigestedpass}:17185:0:999999:7::" | sudo tee -a /mnt/etc/shadow- > /dev/null; echo "satsuser:*:17185:0:999999:7::" | sudo tee -a /mnt/etc/shadow > /dev/null;
echo "satsuser:*:17185:0:999999:7::" | sudo tee -a /mnt/etc/shadow- > /dev/null;
# passwd # passwd
echo " /etc/passwd"; echo " /etc/passwd";
@ -102,6 +131,14 @@ sudo cat /mnt/etc/shadow.tmp | sudo tee /mnt/etc/shadow- > /dev/null;
# remove temporary file # remove temporary file
sudo rm /mnt/etc/shadow.tmp; sudo rm /mnt/etc/shadow.tmp;
step6;
}
# [6] Updating groups
#========================================================#
step6(){
echo "\n>>> [6] Updating groups";
echo " (.) Adding group ssh-key"; echo " (.) Adding group ssh-key";
# group # group
@ -115,40 +152,70 @@ echo " /etc/group";
echo "sats-user:x:666:sats-user" | sudo tee -a /mnt/etc/group > /dev/null; echo "sats-user:x:666:sats-user" | sudo tee -a /mnt/etc/group > /dev/null;
echo "sats-user:x:666:sats-user" | sudo tee -a /mnt/etc/group- > /dev/null; echo "sats-user:x:666:sats-user" | sudo tee -a /mnt/etc/group- > /dev/null;
step7;
}
# [4] Manage SSH keys # # [7] Manage SSH keys #
######################################## #========================================================#
step7(){
echo "\n>>> [7] Create ssh keys";
# [1] Create ssh key pair # (1) Create ssh key pair #
echo " (.) Create ssh key [ecdsa:521]";
ssh-keygen -t ecdsa -b 521 -C "[ECDSA:521] SATS" -f ./id_ecdsa; ssh-keygen -t ecdsa -b 521 -C "[ECDSA:521] SATS" -f ./id_ecdsa;
# [2] Add public key to server's `authorized_keys` file # (2) Add public key to server's `authorized_keys` file #
echo " (.) Add public key to server's list";
cat ./id_ecdsa.pub >> ./authorized_keys; cat ./id_ecdsa.pub >> ./authorized_keys;
# [3] Add both keys to SATS file system # (3) Create ssh file system #
mv ./id_ecdsa /mnt/home/SATS/.ssh/id_ecdsa; echo " (.) init ssh folder (/home/sats-user/.ssh)";
mv ./id_ecdsa.pub /mnt/home/SATS/.ssh/id_ecdsa.pub; sudo mkdir /mnt/home/sats-user/.ssh;
# [4] Adjust permissions
chown SATS:SATS /mnt/home/SATS/.ssh/id_ecdsa;
chmod 600 /mnt/home/SATS/.ssh/id_ecdsa;
# [5] Manage Wifi Credentials # (4) Add both keys to sats-user files #
######################################## echo " (.) add keys to ssh folder";
sudo mv ./id_ecdsa /mnt/home/sats-user/.ssh/id_ecdsa;
sudo mv ./id_ecdsa.pub /mnt/home/sats-user/.ssh/id_ecdsa.pub;
# [1] generate wpa digest # (5) Set up permissions #
psk=$( echo "$3" | wpa_passphrase "$2" | grep -E "^\spsk" | sed 's/^\spsk=//' ); echo " (.) Set up permissions";
sudo chown -R 666:666 /mnt/home/sats-user/.ssh/;
sudo chmod 400 /mnt/home/sats-user/.ssh/id_ecdsa*;
# [2] Append SSID to `interfaces` config step8;
echo "\twpa-ssid\t$2" >> /mnt/etc/network/interfaces; }
# [3] Append WPA digest to `interfaces` config
echo "\twpa-psk\t$psk" >> /mnt/etc/network/interfaces;
# [6] .....
# [8] Manage Network config
#========================================================#
# [0] Step choice
#========================================================#
echo "\nSTEPS";
echo "(1) Init device layout (gpt table)";
echo "(2) Format disk";
echo "(3) Burn image into disk";
echo "(4) Mount / partition";
echo "(5) Update users";
echo "(6) Update groups";
echo "(7) Manage ssh keys";
read -p "step: " step;
case $step in
"1") step1;;
"2") step2;;
"3") step3;;
"4") step4;;
"5") step5;;
"6") step6;;
"7") step7;;
*) echo "wrong step"; exit;;
esac;