Skip to content

Install all PrivateInternetAccess.com VPN regions on Centos/RedHat 7

This script will install all regions for Private Internet Access VPN services on CentosOS or RedHat version.
This was adapted from the Ubuntu install script here.

*NOTE I have not tested this on any versions of CentOS or RedHat other than version 7, nor has it been tested on Fedora.

#! /bin/sh -
#
# Install OpenVPN connections for all available
# regions to NetworkManager
#
# Requirements:
# should be run as root
# python and openvpn (will be installed if not present)
#
# Usage:
# install [--version]

IFS=’

SERVER_INFO=/tmp/server_info
SPLIT_TOKEN=’:’

error( ) {
echo “[email protected]” 1>&2
exit 1
}

error_and_usage( ) {
echo “[email protected]” 1>&2
usage_and_exit 1
}

usage( ) {
echo “Usage: sudo `dirname $0`/$PROGRAM”
}

usage_and_exit( ) {
usage
exit $1
}

version( ) {
echo “$PROGRAM version $VERSION”
}

read_user_login( ) {
echo -n “Please enter your login: ”
read LOGIN

if [ -z $LOGIN ]; then
error “A login must be provided for the installation to proceed”
fi
}

verify_running_as_root( ) {
if [ `/usr/bin/id -u` -ne 0 ]; then
error_and_usage “$0 must be run as root”
fi
}

install_python_version( ) {
if ! yum list installed python > /dev/null ; then
echo -n ‘Package python2.7 required. Install? (y/n): ‘
read install_python
if [ $install_python = ‘y’ ]; then
echo “Installing python2.7..”
if ! yum install -y python2.7; then
error “Error installing python2.7 Aborting..”
fi
else
error “Package python2.7 is required for installation. Aborting..”
fi
else
echo “Package python2.7 already installed”
fi
}

install_open_vpn( ) {
if ! yum list installed NetworkManager-openvpn > /dev/null ; then
echo -n ‘Package NetworkManager-openvpn required. Install? (y/n): ‘
read install_openvpn
if [ $install_openvpn = ‘y’ ]; then
echo “Installing NetworkManager-openvpn..”
if ! yum install -y NetworkManager-openvpn; then
error “Error installing NetworkManager-openvpn. Aborting..”
fi
else
error “Package NetworkManager-openvpn is required for installation. Aborting..”
fi
else
echo “Package NetworkManager-openvpn already installed”
fi
}

copy_crt( ) {
echo ‘Copying certificate..’
mkdir -p /etc/openvpn
cat << EOF > /etc/openvpn/ca.crt
—–BEGI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Ygc2VjdXJlQHByaXZhdGVpbnRlcm5ldGFjY2Vzcy5j
b22CCQDrajJEdiUl6zAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBBQUAA4GBAByH
atXgZzjFO6qctQWwV31P4qLelZzYndoZ7olY8ANPxl7jlP3YmbE1RzSnWtID9Gge
fsKHi1jAS9tNP2E+DCZiWcM/5Y7/XKS/6KvrPQT90nM5klK9LfNvS+kFabMmMBe2
llQlzAzFiIfabACTQn84QLeLOActKhK8hFJy2Gy6
—–END CERTIFICATE—–
EOF

}

parse_server_info( ) {
echo ‘Loading servers information..’
json=`wget -q -O – ‘https://privateinternetaccess.com/vpninfo/servers?version=24’ | head -1`

python > $SERVER_INFO <<EOF
payload = ‘$json’
import json
d = json.loads(payload)
print “\n”.join([d[k][‘name’]+’$SPLIT_TOKEN’+d[k][‘dns’] for k in d.keys() if k != ‘info’])
EOF
}

write_config_files( ) {
echo ‘Removing previous config files if existing..’
rm -f /etc/NetworkManager/system-connections/PIA\ -\ *

echo ‘Creating config files..’
IFS=’

while read server_info; do
name=”PIA – `echo $server_info | awk -F: ‘{print $1}’`”
dns=`echo $server_info | awk -F: ‘{print $2}’`
cat < /etc/NetworkManager/system-connections/$name
[connection]
id=$name
uuid=`uuidgen`
type=vpn
autoconnect=false

[vpn]
service-type=org.freedesktop.NetworkManager.openvpn
username=$LOGIN
comp-lzo=yes
remote=$dns
connection-type=password
password-flags=1
ca=/etc/openvpn/ca.crt

[ipv4]
method=auto
EOF
chmod 600 /etc/NetworkManager/system-connections/$name
done < $SERVER_INFO
rm $SERVER_INFO
IFS=’

}

restart_network_manager( ) {
echo ‘Restarting network manager..’
systemctl restart NetworkManager
}

EXITCODE=0
PROGRAM=`basename $0`
VERSION=1.0

while test $# -gt 0
do
case $1 in
–usage | –help | -h )
usage_and_exit 0
;;
–version | -v )
version
exit 0
;;
*)
error_and_usage “Unrecognized option: $1”
;;
esac
shift
done

verify_running_as_root
install_python_version
install_open_vpn
read_user_login
copy_crt
parse_server_info
write_config_files
restart_network_manager

echo “Install successful!”
exit 0

Spread The Love, Share Our Article

  • Delicious
  • Digg
  • Newsvine
  • RSS
  • StumbleUpon
  • Technorati
  • Twitter

Related Posts

Comments

There are no comments on this entry.

Trackbacks

There are no trackbacks on this entry.

Add a Comment

Required

Required

Optional


framework-break