add scripts from dmzscripts repo to scripts

This commit is contained in:
2024-01-05 11:42:17 +01:00
parent d3e2cec3a7
commit 5e4f55af5b
10 changed files with 2256 additions and 0 deletions

49
scripts/ctcreate/ctcreate.sh Executable file
View File

@@ -0,0 +1,49 @@
#!/bin/bash
## Create new Linux contanier at a proxmox host
DMZKEYFILE="~/.ssh/dmz"
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
ssh-add -t 200 $DMZKEYFILE
torsocks scp ./remotecmd $PROXMOXHOST:/root/ctcreate.sh
torsocks ssh $PROXMOXHOST "chmod +x /root/ctcreate.sh; /root/ctcreate.sh $CTHOST $GENPASS" >> cmdoutput.txt
CREDS=$( tail -3 cmdoutput.txt)
rm cmdoutput.txt
printf "$CREDS\n" | gpg -e -r fram3d@dmz.rs -r sienna@dmz.rs --output ~/src/dmzadmin/credentials/krov/$CTHOST.gpg
CTIP=$(printf "$CREDS" | head -1 | cut -d'@' -f 2)
echo Host dmzkrov$CTHOST >> ~/.ssh/autoconfig
echo " Hostname" $CTIP >> ~/.ssh/autoconfig
echo " ProxyJump" dmzkrovtor12 >> ~/.ssh/autoconfig
echo " User" root >> ~/.ssh/autoconfig
echo " IdentityFile" /home/anon/.ssh/krov/tor11 >> ~/.ssh/autoconfig
echo " PasswordAuthentication" no >> ~/.ssh/autoconfig
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

5
scripts/ctcreate/newct Normal file
View File

@@ -0,0 +1,5 @@
#!/bin/bash
apt update
apt -y dist-upgrade
apt install unattended-upgrades
dpkg-reconfigure unattended-upgrades

View File

@@ -0,0 +1,41 @@
#!/bin/bash
CTHOSTNAME=$1
CTPASS=$2
echo Creating $CTHOSTNAME ...
# Find last CT and get its ID
LASTID=$(pct list | cut -d" " -f1 | tail -1)
if [[ -z "$CTHOSTNAME" ]]; then
echo "CT hostname not set"
exit 1
fi
if [[ -z "$CTPASS" ]]; then
echo "CT password not set"
exit 1
fi
if [[ -z "$LASTID" ]]; then
LASTID=99
fi
NEWID=$(($LASTID + 1))
echo ID of new CT is: $NEWID
## Find the biggest free IP
for i in $(seq $((NEWID + 101)) 254); do ping -W 3 -c 3 192.168.1.$i || break; done
CTIP="192.168.1.$i"
pct create $NEWID local:vztmpl/debian-12-standard_12.2-1_amd64.tar.zst --arch amd64 --cores 2 --features nesting=1 --hostname $CTHOSTNAME --memory 2048 --net0 name=eth0,bridge=vmbr0,firewall=1,gw=192.168.1.1,gw6=2001:470:1f1a:1a4::5,ip=$CTIP/24,ip6=2001:470:1f1a:1a4::$(printf '%x' $((NEWID - 87)))/96,type=veth --onboot 1 --ostype debian --swap 1024 --unprivileged 1 --storage local-lvm --ssh-public-keys /root/.ssh/fram3d.pub --password $CTPASS
pct set $NEWID --rootfs local-lvm:vm-$NEWID-disk-0,size=32G
pct start $NEWID
echo "Creds:"
echo "root@$CTIP"
echo "root@2001:470:1f1a:1a4::$(printf '%x' $((NEWID - 87)))"
echo $CTPASS