2024-01-05 10:42:17 +00:00
|
|
|
#!/bin/bash
|
|
|
|
## Create new Linux contanier at a proxmox host
|
|
|
|
|
2024-01-17 13:35:06 +00:00
|
|
|
DMZKEYFILE=$(echo -n ~)"/.ssh/dmz"
|
2024-02-13 00:36:11 +00:00
|
|
|
USER=$(cut -d" " -f3 $DMZKEYFILE.pub | cut -d "@" -f1)
|
|
|
|
USEREMAIL=$(cut -d" " -f3 $DMZKEYFILE.pub)
|
2024-01-05 10:42:17 +00:00
|
|
|
|
|
|
|
PROXMOXHOST=$1
|
|
|
|
CTHOST=$2
|
|
|
|
|
|
|
|
GENPASS=$( echo $(shuf ../shared/english.txt | head) | sed "s/ //g")
|
|
|
|
|
|
|
|
if [[ -z "$PROXMOXHOST" ]]; then
|
|
|
|
echo "Set Proxmox Host"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -z "$CTHOST" ]]; then
|
|
|
|
echo "Set CT hostname"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -z "$GENPASS" ]]; then
|
|
|
|
echo "Set CT password"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2024-02-13 00:36:11 +00:00
|
|
|
ssh-add -t 600 $DMZKEYFILE
|
2024-01-05 10:42:17 +00:00
|
|
|
torsocks scp ./remotecmd $PROXMOXHOST:/root/ctcreate.sh
|
2024-02-13 00:36:11 +00:00
|
|
|
torsocks scp $DMZKEYFILE.pub $PROXMOXHOST:/root/.ssh/$USER.pub
|
2024-01-05 10:42:17 +00:00
|
|
|
|
2024-02-13 00:36:11 +00:00
|
|
|
torsocks ssh $PROXMOXHOST "chmod +x /root/ctcreate.sh; /root/ctcreate.sh $CTHOST $GENPASS $USER" >> cmdoutput.txt
|
2024-01-05 10:42:17 +00:00
|
|
|
|
|
|
|
CREDS=$( tail -3 cmdoutput.txt)
|
|
|
|
|
|
|
|
rm cmdoutput.txt
|
|
|
|
|
2024-02-13 00:36:11 +00:00
|
|
|
printf "$CREDS\n" | gpg -e -r $USEREMAIL --output $CTHOST.gpg
|
2024-01-05 10:42:17 +00:00
|
|
|
|
|
|
|
CTIP=$(printf "$CREDS" | head -1 | cut -d'@' -f 2)
|
|
|
|
|
2024-02-13 00:36:11 +00:00
|
|
|
echo "Host dmzkrov"$CTHOST >> ~/.ssh/autoconfig
|
|
|
|
echo " Hostname "$CTIP >> ~/.ssh/autoconfig
|
|
|
|
echo " ProxyJump dmzkrovtor12" >> ~/.ssh/autoconfig
|
|
|
|
echo " User root" >> ~/.ssh/autoconfig
|
|
|
|
echo " IdentityFile "$DMZKEYFILE >> ~/.ssh/autoconfig
|
|
|
|
echo " PasswordAuthentication no" >> ~/.ssh/autoconfig
|
2024-01-05 10:42:17 +00:00
|
|
|
|
|
|
|
ssh -R $CTIP
|
|
|
|
torsocks scp ./newct dmzkrov$CTHOST:/root/newct.sh
|
|
|
|
torsocks ssh dmzkrov$CTHOST "bash newct.sh; rm newct.sh"
|
|
|
|
torsocks ssh dmzkrov$CTHOST
|