diff --git a/clone/clone b/clone/clone new file mode 100755 index 0000000..45d38c9 --- /dev/null +++ b/clone/clone @@ -0,0 +1,64 @@ +#!/bin/sh + +# [1] check parameters (device, ESSID, WPA) +if [ $# -lt 3 ]; then + echo "Missing parameters : (device, ESSID, WPA)" && exit; +fi; + + + +# [2] Formatting USB # +######################################## + +# [1] unmount before modifying +sudo umount $1; + +# [2] format to fat +sudo mkdosfs -n "SATS"-I $1; + + + +# [3] Extract files # +######################################## + +# [1] Mount device +sudo mount $1 /mnt -o uid=1000,gid=1000,umask=022; + +# [2] Extract files +tar -xzvf ./image.tar.gz -C /mnt; + + + +# [4] Manage SSH keys # +######################################## + +# [1] Create ssh key pair +ssh-keygen -t ecdsa -b 521 -C "[ECDSA:521] SATS" -f ./id_ecdsa; + +# [2] Add public key to server's `authorized_keys` file +cat ./id_ecdsa.pub >> ./authorized_keys; + +# [3] Add both keys to SATS file system +mv ./id_ecdsa /mnt/home/SATS/.ssh/id_ecdsa; +mv ./id_ecdsa.pub /mnt/home/SATS/.ssh/id_ecdsa.pub; + +# [4] Adjust permissions +chown SATS:SATS /mnt/home/SATS/.ssh/id_ecdsa; +chmod 600 /mnt/home/SATS/.ssh/id_ecdsa; + + +# [5] Manage Wifi Credentials +######################################## + +# [1] generate wpa digest +psk=$( echo "$3" | wpa_passphrase "$2" | grep -E "^\spsk" | sed 's/^\spsk=//' ); + +# [2] Append SSID to `interfaces` config +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] .....