1 #!/bin/bash 2 3 echo -n "IP Address on VPN: " 4 read IPADDR 5 6 if [ -z "${IPADDR}" ]; then 7 echo "Invalid IP address." >&2 8 exit 1 9 fi 10 mkdir -p /etc/tinc/qvpn/hosts/ || exit 1 11 cat <<EOF >/etc/tinc/qvpn/tinc.conf 12 Mode = switch 13 Name = `hostname --short` 14 AddressFamily = ipv4 15 Hostnames = no 16 ConnectTo = sledge 17 EOF 18 19 KEYFILE="/etc/tinc/qvpn/hosts/`hostname --short`" 20 if [ -f "${KEYFILE}" ]; then 21 echo "*** WARNING: An existing key file was found, it's been moved to:" >&2 22 echo "*** WARNING: ${KEYFILE}.old" >&2 23 echo "*** WARNING: Please re-run this script once you've saved it." >&2 24 mv "${KEYFILE}" "${KEYFILE}.old" 25 exit 1 26 fi 27 echo "IndirectData = yes" >> "${KEYFILE}" 28 echo | tincd -n qvpn -K 29 30 cat <<EOF >/etc/tinc/qvpn/hosts/sledge 31 Address = 217.160.252.81 32 Port = 657 33 -----BEGIN RSA PUBLIC KEY----- 34 MIGJAoGBALjvo67yvWAi2zoxFjAhtdo5BuMEuRVREoUJB+Lib/LJXo1Ax4jgBa/N 35 jrjWgPKVWb1OZIkEPZkBXCfIGt5OAV9gsMFcJ/dbS4WDvQpTQL2h2SsmAWiqowE4 36 S5795qPFY5ZGcx2JnSuN+2LAUqh4LXyc9zRwctNOHBabr4OLEBeLAgMBAAE= 37 -----END RSA PUBLIC KEY----- 38 EOF 39 40 cat <<EOF >/etc/tinc/qvpn/tinc-up 41 #!/bin/bash 42 43 if [ ! -z "\${INTERFACE}" ]; then 44 ifconfig "\${INTERFACE}" ${IPADDR} netmask 255.255.255.0 broadcast 10.8.0.255 up 45 fi 46 47 exit 0 48 EOF 49 cat <<EOF >/etc/tinc/qvpn/hosts/sledge-up 50 #! /bin/bash 51 52 ( 53 cd /etc/tinc/qvpn/hosts/ || exit 0 54 wget -O all.tar.gz http://10.8.0.1/~rkeene/projects/vpn/qvpn/all.tar.gz 2>/dev/null >/dev/null 55 tar --exclude=`hostname --short` --exclude=sledge -zxf all.tar.gz 2>/dev/null >/dev/null 56 rm -f all.tar.gz 57 ) & 58 59 exit 0 60 EOF 61 chmod 755 /etc/tinc/qvpn/tinc-up /etc/tinc/qvpn/hosts/sledge-up 62 chown root:root /etc/tinc/qvpn/tinc-up /etc/tinc/qvpn/hosts/sledge-up 63 64 65 initscp="/usr/sbin/start_vpn" 66 if [ -d "/etc/rc.d/" ]; then 67 initscp="/etc/rc.d/rc.vpn" 68 fi 69 if [ -d "/etc/init.d/" ]; then 70 initscp="/etc/init.d/tinc" 71 fi 72 73 if [ ! -f "${initscp}" ]; then 74 cat <<EOF >"${initscp}" 75 #!/bin/bash 76 77 PATH="\${PATH}:/usr/sbin:/sbin:/usr/local/sbin:/usr/bin:/bin:/usr/local/bin" 78 79 if [ "\$1" = "stop" -o "\$1" = "restart" ]; then 80 tincd -n qvpn -k >/dev/null 2>/dev/null 81 if [ "\$1" = "stop" ]; then exit 0; fi 82 sleep 1 83 fi 84 85 if [ -d /etc/tinc -a -x /usr/sbin/tincd ]; then 86 echo -n "Starting VPN client: " 87 tincd -n qvpn 88 echo "tincd" 89 fi 90 EOF 91 chmod 755 "${initscp}" 92 chown root:root "${initscp}" 93 fi 94 95 96 echo "Your public key (feed to sledge):" 97 cat "${KEYFILE}" |