Browse Source

Add a script to install

Signed-off-by: Gavin Howard <gavin@yzena.com>
master
Gavin Howard 6 months ago
parent
commit
f778bd5253
Signed by: gavin GPG Key ID: C08038BDF280D33E
  1. 97
      install.sh

97
install.sh

@ -0,0 +1,97 @@
#! /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 'Credentials file [%s/.config/vpn/creds.txt]: ' "$HOME"
read creds_file
if [ "$creds_file" = "" ]; then
creds_file="$HOME/.config/vpn/creds.txt"
fi
printf 'Connection file [%s/.config/vpn/conn.txt]: ' "$HOME"
read conn_file
if [ "$conn_file" = "" ]; then
conn_file="$HOME/.config/vpn/conn.txt"
fi
printf 'Superuser command [sudo]: '
read super_cmd
if [ "$super_cmd" = "" ]; then
super_cmd="sudo"
fi
printf 'Directory with ExpressVPN config files for OpenVPN [%s/.config/expressvpn]: ' "$HOME"
read config_dir
if [ "$config_dir" = "" ]; then
config_dir="$HOME/.config/expressvpn"
fi
printf 'Username: '
read username
printf 'Password: '
read pass
mkdir -p $(dirname "$creds_file")
printf '%s\n%s\n' "$username" "$pass" | "$super_cmd" tee "$creds_file"
contents=$(cat "$scriptdir/vpn.sh")
contents=$(replace "$contents" "CONN_FILE" "$conn_file")
contents=$(replace "$contents" "CONFIG_DIR" "$config_dir")
contents=$(replace "$contents" "CREDS_FILE" "$creds_file")
printf '%s\n' "$contents" | tee "$install_dir/vpn"
chmod +x "$install_dir/vpn"
contents=$(cat "$scriptdir/vpnctl.sh")
contents=$(replace "$contents" "CONN_FILE" "$conn_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"
Loading…
Cancel
Save