Add deploy-newssh.sh
This commit is contained in:
49
deploy-newssh.sh
Normal file
49
deploy-newssh.sh
Normal file
@@ -0,0 +1,49 @@
|
||||
#!/bin/bash
|
||||
NO_FORMAT="\e[0m"
|
||||
F_BOLD="\e[1m"
|
||||
C_GREEN="\e[38;5;40m"
|
||||
C_RED="\e[38;5;9m"
|
||||
C_YELLOW="\033[38;5;226m"
|
||||
USER=$(getent passwd 1000 | cut -d: -f1)
|
||||
|
||||
#Verify if root
|
||||
if [ "$UID" -ne 0 ]; then
|
||||
echo -e "${C_RED}This script must be run as root.${NO_FORMAT}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
#Verify provisioning server availability
|
||||
URL="https://prov.franscorack.com"
|
||||
|
||||
if ! wget --spider "$URL" 2>/dev/null; then
|
||||
echo -e "${C_RED}Error: Cannot reach intranet provisioning server - ${F_BOLD}Are you not on LAN or VPN ? / Is it down ?${NO_FORMAT}"
|
||||
echo -e "${C_RED}Initialization script can only be ran if $URL is reachable. Script Halted. ${NO_FORMAT}"
|
||||
exit 1
|
||||
fi
|
||||
if [ -f "/.SSH/script/renew-keys.sh" ]; then
|
||||
echo -e "${C_GREEN}Script already present. Skipping...${NO_FORMAT}"
|
||||
else
|
||||
echo -e "${C_RED}Script not found. Downloading...${NO_FORMAT}"
|
||||
mkdir /.SSH
|
||||
mkdir /.SSH/script
|
||||
wget https://prov.franscorack.com/script/renew-keys.sh -O /.SSH/script/renew-keys.sh
|
||||
sleep 2
|
||||
fi
|
||||
rm -rf /home/$USER/.ssh
|
||||
mkdir /home/$USER/.ssh
|
||||
touch /home/$USER/.ssh/id_ed25519
|
||||
touch /home/$USER/.ssh/authorized_keys
|
||||
chmod 700 -R /home/$USER/.ssh
|
||||
chown $USER -R /home/$USER/.ssh
|
||||
mkdir /.SSH
|
||||
mkdir /.SSH/automated
|
||||
mkdir /.SSH/automated/.stfolder
|
||||
mkdir /.SSH/automated/priv
|
||||
mkdir /.SSH/automated/pub
|
||||
mkdir /.SSH/automated/priv/servers
|
||||
mkdir /.SSH/automated/pub/servers
|
||||
touch /.SSH/automated/priv/servers/id_ed25519
|
||||
touch /.SSH/automated/pub/servers/id_ed25519.pub
|
||||
echo -e "${C_YELLOW}Launching key fetching script in 5 seconds. Press CTRL+C to abort.${NO_FORMAT}"
|
||||
sleep 5
|
||||
sh /.SSH/script/renew-keys.sh
|
||||
Reference in New Issue
Block a user