#!/bin/bash
function buildkey {
cd /etc/openvpn/easy-rsa
./eyemagnet-build-key $file
}
function ipselect {
read -e -p "Enter IP series P.N. (10.161) is all ready there - only enter 3rd octet: " ip
ip2="10.161.$ip"
grep -rnw '/etc/openvpn/ccd/' -e $ip2 | awk '{print $(NF-1)}' | sort -V
}
function setip {
read -e -p "Enter Ip value (Last octet) - New selection is done automatically: " ipslt
ipslteven=$(($ipslt + 2))
ipsltodd=$(($ipslt + 3))
ipslt2="$ip2.$ipslteven"
ipslt3="$ip2.$ipsltodd"
cd /etc/openvpn/ccd
cat <<- EOF > /etc/openvpn/ccd/$file
ifconfig-push $ipslt2 $ipslt3
EOF
cat /etc/openvpn/ccd/$file
}
cd /etc/openvpn/easy-rsa/keys
echo ""
read -e -p "Enter proposed Client FDQN: " file
echo ""
file2="$file.crt"
path=/etc/openvpn/keys/
if [ ! -f "$file2" ]
then
echo "$file file not found"
buildkey
ipselect
setip
/usr/local/sbin/add_client_to_domain $file $ipslt2
cd /etc/openvpn/easy-rsa/keys
sshpass -p 'mypassword' rsync -zavP $file.* root@lite-builder.office.wellington.nz.vpn:/home/lite_builder/svn/raspberry_pi/sd_installer/vpnkeys/
read -e -p "Enter the Host FQDN or IP Address: " hostaddr
echo ""
sshpass -p 'mypassword' rsync -e "ssh -o StrictHostKeyChecking=no" -zavP $file.* pi@$hostaddr:/home/pi
sshpass -p 'mypassword' ssh -t -t -o StrictHostKeyChecking=no pi@$hostaddr sudo -i "bash -s" -- < /home/em_naveed/domainer.sh "$file" "$path"
sshpass -p 'mypassword' ssh -t -t -o StrictHostKeyChecking=no pi@$hostaddr 'sudo reboot'
echo ""
echo "Job Complete"
exit
else
echo "$file2 exist or empty."
echo ""
fi
--------------------------------------------------------------------------------------------------------------------------
./domainer.sh:
cd /home/pi
yes | mv $1.* $2
rm -fr $1.*
cd $2
rm -fr default.*
cd /etc/openvpn/
sed -i 99s/.*/"cert \/etc\/openvpn\/keys\/"$1".crt"/ client-*.conf
sed -i 100s/.*/"key \/etc\/openvpn\/keys\/"$1".key"/ client-*.conf
sed -i "1s/.*/$1/" /etc/hostname
grep -q '127.0.1.2.*' /etc/hosts && sed -i "s/127.0.1.2.*/127.0.1.2 $1/" /etc/hosts || echo "127.0.1.2 $1" >> /etc/hosts
exit 0
exit 0
function buildkey {
cd /etc/openvpn/easy-rsa
./eyemagnet-build-key $file
}
function ipselect {
read -e -p "Enter IP series P.N. (10.161) is all ready there - only enter 3rd octet: " ip
ip2="10.161.$ip"
grep -rnw '/etc/openvpn/ccd/' -e $ip2 | awk '{print $(NF-1)}' | sort -V
}
function setip {
read -e -p "Enter Ip value (Last octet) - New selection is done automatically: " ipslt
ipslteven=$(($ipslt + 2))
ipsltodd=$(($ipslt + 3))
ipslt2="$ip2.$ipslteven"
ipslt3="$ip2.$ipsltodd"
cd /etc/openvpn/ccd
cat <<- EOF > /etc/openvpn/ccd/$file
ifconfig-push $ipslt2 $ipslt3
EOF
cat /etc/openvpn/ccd/$file
}
cd /etc/openvpn/easy-rsa/keys
echo ""
read -e -p "Enter proposed Client FDQN: " file
echo ""
file2="$file.crt"
path=/etc/openvpn/keys/
if [ ! -f "$file2" ]
then
echo "$file file not found"
buildkey
ipselect
setip
/usr/local/sbin/add_client_to_domain $file $ipslt2
cd /etc/openvpn/easy-rsa/keys
sshpass -p 'mypassword' rsync -zavP $file.* root@lite-builder.office.wellington.nz.vpn:/home/lite_builder/svn/raspberry_pi/sd_installer/vpnkeys/
read -e -p "Enter the Host FQDN or IP Address: " hostaddr
echo ""
sshpass -p 'mypassword' rsync -e "ssh -o StrictHostKeyChecking=no" -zavP $file.* pi@$hostaddr:/home/pi
sshpass -p 'mypassword' ssh -t -t -o StrictHostKeyChecking=no pi@$hostaddr sudo -i "bash -s" -- < /home/em_naveed/domainer.sh "$file" "$path"
sshpass -p 'mypassword' ssh -t -t -o StrictHostKeyChecking=no pi@$hostaddr 'sudo reboot'
echo ""
echo "Job Complete"
exit
else
echo "$file2 exist or empty."
echo ""
fi
--------------------------------------------------------------------------------------------------------------------------
./domainer.sh:
cd /home/pi
yes | mv $1.* $2
rm -fr $1.*
cd $2
rm -fr default.*
cd /etc/openvpn/
sed -i 99s/.*/"cert \/etc\/openvpn\/keys\/"$1".crt"/ client-*.conf
sed -i 100s/.*/"key \/etc\/openvpn\/keys\/"$1".key"/ client-*.conf
sed -i "1s/.*/$1/" /etc/hostname
grep -q '127.0.1.2.*' /etc/hosts && sed -i "s/127.0.1.2.*/127.0.1.2 $1/" /etc/hosts || echo "127.0.1.2 $1" >> /etc/hosts
exit 0
exit 0
No comments:
Post a Comment