<commit_before>#!/bin/bash
# OpenVPN road warrior installer for Debian-based distros

# This script will only work on Debian-based systems. It isn't bulletproof but
# it will probably work if you simply want to setup a VPN on your Debian/Ubuntu
# VPS. It has been designed to be as unobtrusive and universal as possible.


if [ $USER != 'root' ]; then
	echo "Sorry, you need to run this as root"
	exit
fi


if [ ! -e /dev/net/tun ]; then
	echo "TUN/TAP is not available"
	exit
fi


if [ ! -e /etc/debian_version ]; then
	echo "Looks like you aren't running this installer on a Debian-based system"
	exit
fi


# Try to get our IP from the system and fallback to the Internet.
# I do this to make the script compatible with NATed servers (lowendspirit.com)
# and to avoid getting an IPv6.
IP=$(ifconfig | grep 'inet addr:' | grep -v inet6 | grep -vE '127\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | cut -d: -f2 | awk '{ print $1}' | head -1)
if [ "$IP" = "" ]; then
        IP=$(wget -qO- ipv4.icanhazip.com)
fi


if [ -e /etc/openvpn/server.conf ]; then
	while :
	do
	clear
		echo "Looks like OpenVPN is already installed"
		echo "What do you want to do?"
		echo ""
		echo "1) Add a cert for a new user"
		echo "2) Revoke existing user cert"
		echo "3) Remove OpenVPN"
		echo "4) Exit"
		echo ""
		read -p "Select an option [1-4]:" option
		case $option in
			1) 
			echo ""
			echo "Tell me a name for the client cert"
			echo "Please, use one word only, no special characters"
			read -p "Client name: " -e -i client CLIENT
			cd /etc/openvpn/easy-rsa/2.0/
			source ./vars
			# build-key for the client
			export KEY_CN="$CLIENT"
			export EASY_RSA="${EASY_RSA:-.}"
			"$EASY_RSA/pkitool" $CLIENT
			# Let's generate the client config
			mkdir ~/ovpn-$CLIENT
			cp /usr/share/doc/openvpn/examples/sample-config-files/client.conf ~/ovpn-$CLIENT/$CLIENT.conf
			cp /etc/openvpn/easy-rsa/2.0/keys/ca.crt ~/ovpn-$CLIENT
			cp /etc/openvpn/easy-rsa/2.0/keys/$CLIENT.crt ~/ovpn-$CLIENT
			cp /etc/openvpn/easy-rsa/2.0/keys/$CLIENT.key ~/ovpn-$CLIENT
			cd ~/ovpn-$CLIENT
			sed -i "s|cert client.crt|cert $CLIENT.crt|" $CLIENT.conf
			sed -i "s|key client.key|key $CLIENT.key|" $CLIENT.conf
			echo "remote-cert-tls server" >> $CLIENT.conf
			
			cp $CLIENT.conf $CLIENT.ovpn
			
			sed -i "s|ca ca.crt|ca [inline]|" $CLIENT.ovpn
			sed -i "s|cert $CLIENT.crt|cert [inline]|" $CLIENT.ovpn
			sed -i "s|key $CLIENT.key|key [inline]|" $CLIENT.ovpn
			echo -e "keepalive 10 60\n" >> $CLIENT.ovpn
			
			echo "<ca>" >> $CLIENT.ovpn
			cat ca.crt >> $CLIENT.ovpn
			echo -e "</ca>\n" >> $CLIENT.ovpn
			
			echo "<cert>" >> $CLIENT.ovpn
			sed -n "/-----BEGIN CERTIFICATE-----/,/-----END CERTIFICATE-----/p" $CLIENT.crt >> $CLIENT.ovpn
			echo -e "</cert>\n" >> $CLIENT.ovpn
			
			echo "<key>" >> $CLIENT.ovpn
			cat $CLIENT.key >> $CLIENT.ovpn
			echo -e "</key>\n" >> $CLIENT.ovpn
			
			tar -czf ../ovpn-$CLIENT.tar.gz $CLIENT.conf ca.crt $CLIENT.crt $CLIENT.key $CLIENT.ovpn
			cd ~/
			rm -rf ovpn-$CLIENT
			echo ""
			echo "Client $CLIENT added, certs available at ~/ovpn-$CLIENT.tar.gz"
			exit
			;;
			2)
			echo ""
			echo "Tell me the existing client name"
			read -p "Client name: " -e -i client CLIENT
			cd /etc/openvpn/easy-rsa/2.0/
			. /etc/openvpn/easy-rsa/2.0/vars
			. /etc/openvpn/easy-rsa/2.0/revoke-full $CLIENT
			# If it's the first time revoking a cert, we need to add the crl-verify line
			if grep -q "crl-verify" "/etc/openvpn/server.conf"; then
				echo ""
				echo "Certificate for client $CLIENT revoked"
			else
				echo "crl-verify /etc/openvpn/easy-rsa/2.0/keys/crl.pem" >> "/etc/openvpn/server.conf"
				/etc/init.d/openvpn restart
				echo ""
				echo "Certificate for client $CLIENT revoked"
			fi
			exit
			;;
			3) 
			apt-get remove --purge -y openvpn openvpn-blacklist
			rm -rf /etc/openvpn<commit_msg>changed tar to zip, as zip is more common on different clients: now really<commit_after>#!/bin/bash
# OpenVPN road warrior installer for Debian-based distros

# This script will only work on Debian-based systems. It isn't bulletproof but
# it will probably work if you simply want to setup a VPN on your Debian/Ubuntu
# VPS. It has been designed to be as unobtrusive and universal as possible.


if [ $USER != 'root' ]; then
	echo "Sorry, you need to run this as root"
	exit
fi


if [ ! -e /dev/net/tun ]; then
	echo "TUN/TAP is not available"
	exit
fi


if [ ! -e /etc/debian_version ]; then
	echo "Looks like you aren't running this installer on a Debian-based system"
	exit
fi


# Try to get our IP from the system and fallback to the Internet.
# I do this to make the script compatible with NATed servers (lowendspirit.com)
# and to avoid getting an IPv6.
IP=$(ifconfig | grep 'inet addr:' | grep -v inet6 | grep -vE '127\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | cut -d: -f2 | awk '{ print $1}' | head -1)
if [ "$IP" = "" ]; then
        IP=$(wget -qO- ipv4.icanhazip.com)
fi


if [ -e /etc/openvpn/server.conf ]; then
	while :
	do
	clear
		echo "Looks like OpenVPN is already installed"
		echo "What do you want to do?"
		echo ""
		echo "1) Add a cert for a new user"
		echo "2) Revoke existing user cert"
		echo "3) Remove OpenVPN"
		echo "4) Exit"
		echo ""
		read -p "Select an option [1-4]:" option
		case $option in
			1) 
			echo ""
			echo "Tell me a name for the client cert"
			echo "Please, use one word only, no special characters"
			read -p "Client name: " -e -i client CLIENT
			cd /etc/openvpn/easy-rsa/2.0/
			source ./vars
			# build-key for the client
			export KEY_CN="$CLIENT"
			export EASY_RSA="${EASY_RSA:-.}"
			"$EASY_RSA/pkitool" $CLIENT
			# Let's generate the client config
			mkdir ~/ovpn-$CLIENT
			cp /usr/share/doc/openvpn/examples/sample-config-files/client.conf ~/ovpn-$CLIENT/$CLIENT.conf
			cp /etc/openvpn/easy-rsa/2.0/keys/ca.crt ~/ovpn-$CLIENT
			cp /etc/openvpn/easy-rsa/2.0/keys/$CLIENT.crt ~/ovpn-$CLIENT
			cp /etc/openvpn/easy-rsa/2.0/keys/$CLIENT.key ~/ovpn-$CLIENT
			cd ~/ovpn-$CLIENT
			sed -i "s|cert client.crt|cert $CLIENT.crt|" $CLIENT.conf
			sed -i "s|key client.key|key $CLIENT.key|" $CLIENT.conf
			echo "remote-cert-tls server" >> $CLIENT.conf
			
			cp $CLIENT.conf $CLIENT.ovpn
			
			sed -i "s|ca ca.crt|ca [inline]|" $CLIENT.ovpn
			sed -i "s|cert $CLIENT.crt|cert [inline]|" $CLIENT.ovpn
			sed -i "s|key $CLIENT.key|key [inline]|" $CLIENT.ovpn
			echo -e "keepalive 10 60\n" >> $CLIENT.ovpn
			
			echo "<ca>" >> $CLIENT.ovpn
			cat ca.crt >> $CLIENT.ovpn
			echo -e "</ca>\n" >> $CLIENT.ovpn
			
			echo "<cert>" >> $CLIENT.ovpn
			sed -n "/-----BEGIN CERTIFICATE-----/,/-----END CERTIFICATE-----/p" $CLIENT.crt >> $CLIENT.ovpn
			echo -e "</cert>\n" >> $CLIENT.ovpn
			
			echo "<key>" >> $CLIENT.ovpn
			cat $CLIENT.key >> $CLIENT.ovpn
			echo -e "</key>\n" >> $CLIENT.ovpn

			zip ../ovpn-$CLIENT.zip $CLIENT.conf ca.crt $CLIENT.crt $CLIENT.key $CLIENT.ovpn
			cd ~/
			rm -rf ovpn-$CLIENT
			echo ""
			echo "Client $CLIENT added, certs available at ~/ovpn-$CLIENT.zip"
			exit
			;;
			2)
			echo ""
			echo "Tell me the existing client name"
			read -p "Client name: " -e -i client CLIENT
			cd /etc/openvpn/easy-rsa/2.0/
			. /etc/openvpn/easy-rsa/2.0/vars
			. /etc/openvpn/easy-rsa/2.0/revoke-full $CLIENT
			# If it's the first time revoking a cert, we need to add the crl-verify line
			if grep -q "crl-verify" "/etc/openvpn/server.conf"; then
				echo ""
				echo "Certificate for client $CLIENT revoked"
			else
				echo "crl-verify /etc/openvpn/easy-rsa/2.0/keys/crl.pem" >> "/etc/openvpn/server.conf"
				/etc/init.d/openvpn restart
				echo ""
				echo "Certificate for client $CLIENT revoked"
			fi
			exit
			;;
			3) 
			apt-get remove --purge -y openvpn openvpn-blacklist
			rm -rf /etc/openvpn
{'fraction_non_alphanumeric': 0.15204147764095918, 'fraction_numerical': 0.012961762799740765, 'mean_word_length': 2.7221418234442836, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 63, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2070943', 'n_tokens_mistral': 3350, 'n_tokens_neox': 2999, 'n_words': 893}