#!/bin/bash # The MIT License (MIT) # # Copyright (c) 2016 Mengdi Gao # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. # TODO: add regenerate shared secret option # In normal cases, you will only need to pass the HOST of your server. [ "no${HOST}" = "no" ] && echo "\$HOST environment variable required." && exit 1 : ${PROFILE_NAME="My IKEv2 VPN Profile"} : ${PROFILE_IDENTIFIER=$(echo -n "${HOST}." | tac -s. | sed 's/\.$//g')} : ${PROFILE_UUID=$(hostname)} # These variable, especially CONN_UUID, are bind to per username, # which currently, all users share the same secrets and configurations. : ${CONN_NAME="My IKEv2 VPN"} : ${CONN_IDENTIFIER="${PROFILE_IDENTIFIER}.shared-configuration"} : ${CONN_UUID=$(uuidgen)} : ${CONN_HOST=${HOST}} : ${CONN_REMOTE_IDENTIFIER=${HOST}} CONN_SHARED_SECRET=$(cat /etc/ipsec.secrets | sed 's/.*"\(.*\)"/\1/g') cat < PayloadDisplayName ${PROFILE_NAME} PayloadIdentifier ${PROFILE_IDENTIFIER} PayloadUUID ${PROFILE_UUID} PayloadType Configuration PayloadVersion 1 PayloadContent PayloadIdentifier ${CONN_IDENTIFIER} PayloadUUID ${CONN_UUID} PayloadType com.apple.vpn.managed PayloadVersion 1 UserDefinedName ${CONN_NAME} VPNType IKEv2 IKEv2 RemoteAddress ${CONN_HOST} RemoteIdentifier ${CONN_REMOTE_IDENTIFIER} LocalIdentifier OnDemandEnabled 1 OnDemandRules Action Connect AuthenticationMethod SharedSecret SharedSecret ${CONN_SHARED_SECRET} ExtendedAuthEnabled 0 AuthName AuthPassword EOF