Scripts to make it easier to use MullvadVPN on Gentoo
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
1.8 KiB

#! /bin/sh
#
# SPDX-License-Identifier: BlueOak-1.0.0
#
# Copyright (c) 2021 Gavin D. Howard.
#
script="$0"
scriptdir=$(dirname "$script")
substring_replace() {
_substring_replace_str="$1"
shift
_substring_replace_needle="$1"
shift
_substring_replace_replacement="$1"
shift
_substring_replace_result=$(printf '%s\n' "$_substring_replace_str" | \
sed -e "s!$_substring_replace_needle!$_substring_replace_replacement!g")
printf '%s' "$_substring_replace_result"
}
replace() {
if [ "$#" -ne 3 ]; then
err_exit "Invalid number of args to $0"
fi
_replace_str="$1"
_replace_needle="$2"
_replace_replacement="$3"
substring_replace "$_replace_str" "%%$_replace_needle%%" "$_replace_replacement"
}
printf 'Install directory [%s/.local/bin]: ' "$HOME"
read install_dir
if [ "$install_dir" = "" ]; then
install_dir="$HOME/.local/bin"
fi
printf 'Country file [%s/.mullvad/country.txt]: ' "$HOME"
read country_file
if [ "$country_file" = "" ]; then
country_file="$HOME/.mullvad/country.txt"
fi
printf 'Superuser command [sudo]: '
read super_cmd
if [ "$super_cmd" = "" ]; then
super_cmd="sudo"
fi
printf 'Directory with Mullvad config files for OpenVPN [/etc/openvpn]: '
read config_dir
if [ "$config_dir" = "" ]; then
config_dir="/etc/openvpn"
fi
contents=$(cat "$scriptdir/vpn.sh")
contents=$(replace "$contents" "COUNTRY_FILE" "$country_file")
contents=$(replace "$contents" "CONFIG_DIR" "$config_dir")
printf '%s\n' "$contents" | tee "$install_dir/vpn"
chmod +x "$install_dir/vpn"
contents=$(cat "$scriptdir/vpnctl.sh")
contents=$(replace "$contents" "COUNTRY_FILE" "$country_file")
contents=$(replace "$contents" "SUPERUSER_CMD" "$super_cmd")
contents=$(replace "$contents" "INSTALL_DIR" "$install_dir")
printf '%s\n' "$contents" | tee "$install_dir/vpnctl"
chmod +x "$install_dir/vpnctl"