mirror of
https://github.com/pivpn/pivpn.git
synced 2024-12-18 19:00:15 +00:00
Added pi-hole's undocumented flags
UNTESTED!
This commit is contained in:
parent
6ce39bfec3
commit
5db23185fd
1 changed files with 304 additions and 121 deletions
|
@ -10,11 +10,13 @@
|
||||||
# curl -L https://install.pivpn.io | bash
|
# curl -L https://install.pivpn.io | bash
|
||||||
# Make sure you have `curl` installed
|
# Make sure you have `curl` installed
|
||||||
|
|
||||||
|
set -e
|
||||||
######## VARIABLES #########
|
######## VARIABLES #########
|
||||||
|
|
||||||
tmpLog="/tmp/pivpn-install.log"
|
tmpLog="/tmp/pivpn-install.log"
|
||||||
instalLogLoc="/etc/pivpn/install.log"
|
instalLogLoc="/etc/pivpn/install.log"
|
||||||
|
setupVars=/etc/pivpn/setupVars.conf
|
||||||
|
useUpdateVars=false
|
||||||
|
|
||||||
### PKG Vars ###
|
### PKG Vars ###
|
||||||
PKG_MANAGER="apt-get"
|
PKG_MANAGER="apt-get"
|
||||||
|
@ -42,6 +44,11 @@ c=$(( columns / 2 ))
|
||||||
r=$(( r < 20 ? 20 : r ))
|
r=$(( r < 20 ? 20 : r ))
|
||||||
c=$(( c < 70 ? 70 : c ))
|
c=$(( c < 70 ? 70 : c ))
|
||||||
|
|
||||||
|
######## Undocumented Flags. Shhh ########
|
||||||
|
skipSpaceCheck=false
|
||||||
|
reconfigure=false
|
||||||
|
runUnattended=false
|
||||||
|
|
||||||
# Find IP used to route to outside world
|
# Find IP used to route to outside world
|
||||||
|
|
||||||
IPv4dev=$(ip route get 8.8.8.8 | awk '{for(i=1;i<=NF;i++)if($i~/dev/)print $(i+1)}')
|
IPv4dev=$(ip route get 8.8.8.8 | awk '{for(i=1;i<=NF;i++)if($i~/dev/)print $(i+1)}')
|
||||||
|
@ -51,24 +58,6 @@ IPv4gw=$(ip route get 8.8.8.8 | awk '{print $3}')
|
||||||
availableInterfaces=$(ip -o link | grep "state UP" | awk '{print $2}' | cut -d':' -f1 | cut -d'@' -f1)
|
availableInterfaces=$(ip -o link | grep "state UP" | awk '{print $2}' | cut -d':' -f1 | cut -d'@' -f1)
|
||||||
dhcpcdFile=/etc/dhcpcd.conf
|
dhcpcdFile=/etc/dhcpcd.conf
|
||||||
|
|
||||||
######## FIRST CHECK ########
|
|
||||||
# Must be root to install
|
|
||||||
echo ":::"
|
|
||||||
if [[ $EUID -eq 0 ]];then
|
|
||||||
echo "::: You are root."
|
|
||||||
else
|
|
||||||
echo "::: sudo will be used for the install."
|
|
||||||
# Check if it is actually installed
|
|
||||||
# If it isn't, exit because the install cannot complete
|
|
||||||
if [[ $(dpkg-query -s sudo) ]];then
|
|
||||||
export SUDO="sudo"
|
|
||||||
export SUDOE="sudo -E"
|
|
||||||
else
|
|
||||||
echo "::: Please install sudo or run this as root."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Next see if we are on a tested and supported OS
|
# Next see if we are on a tested and supported OS
|
||||||
function noOS_Support() {
|
function noOS_Support() {
|
||||||
whiptail --msgbox --backtitle "INVALID OS DETECTED" --title "Invalid OS" "We have not been able to detect a supported OS.
|
whiptail --msgbox --backtitle "INVALID OS DETECTED" --title "Invalid OS" "We have not been able to detect a supported OS.
|
||||||
|
@ -89,6 +78,8 @@ function maybeOS_Support() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Compatibility
|
||||||
|
distro_check() {
|
||||||
# if lsb_release command is on their system
|
# if lsb_release command is on their system
|
||||||
if hash lsb_release 2>/dev/null; then
|
if hash lsb_release 2>/dev/null; then
|
||||||
PLAT=$(lsb_release -si)
|
PLAT=$(lsb_release -si)
|
||||||
|
@ -117,6 +108,7 @@ else
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "${PLAT}" > /tmp/DET_PLATFORM
|
echo "${PLAT}" > /tmp/DET_PLATFORM
|
||||||
|
}
|
||||||
|
|
||||||
####### FUNCTIONS ##########
|
####### FUNCTIONS ##########
|
||||||
spinner()
|
spinner()
|
||||||
|
@ -280,6 +272,7 @@ If you are in Amazon then you can not configure a static IP anyway. Just ensure
|
||||||
}
|
}
|
||||||
|
|
||||||
getStaticIPv4Settings() {
|
getStaticIPv4Settings() {
|
||||||
|
local ipSettingsCorrect
|
||||||
# Grab their current DNS Server
|
# Grab their current DNS Server
|
||||||
IPv4dns=$(nslookup 127.0.0.1 | grep Server: | awk '{print $2}')
|
IPv4dns=$(nslookup 127.0.0.1 | grep Server: | awk '{print $2}')
|
||||||
# Ask if the user wants to use DHCP settings as their static IP
|
# Ask if the user wants to use DHCP settings as their static IP
|
||||||
|
@ -347,7 +340,6 @@ setStaticIPv4() {
|
||||||
if [[ -f /etc/dhcpcd.conf ]]; then
|
if [[ -f /etc/dhcpcd.conf ]]; then
|
||||||
if grep -q "${IPv4addr}" ${dhcpcdFile}; then
|
if grep -q "${IPv4addr}" ${dhcpcdFile}; then
|
||||||
echo "::: Static IP already configured."
|
echo "::: Static IP already configured."
|
||||||
:
|
|
||||||
else
|
else
|
||||||
setDHCPCD
|
setDHCPCD
|
||||||
$SUDO ip addr replace dev "${pivpnInterface}" "${IPv4addr}"
|
$SUDO ip addr replace dev "${pivpnInterface}" "${IPv4addr}"
|
||||||
|
@ -604,6 +596,9 @@ make_repo() {
|
||||||
}
|
}
|
||||||
|
|
||||||
update_repo() {
|
update_repo() {
|
||||||
|
if [[ "${reconfigure}" == true ]]; then
|
||||||
|
echo "::: --reconfigure passed to install script. Not downloading/updating local repos"
|
||||||
|
else
|
||||||
# Pull the latest commits
|
# Pull the latest commits
|
||||||
echo -n "::: Updating repo in $1..."
|
echo -n "::: Updating repo in $1..."
|
||||||
cd "${1}" || exit 1
|
cd "${1}" || exit 1
|
||||||
|
@ -615,6 +610,7 @@ update_repo() {
|
||||||
${SUDOE} git checkout test
|
${SUDOE} git checkout test
|
||||||
fi
|
fi
|
||||||
echo " done!"
|
echo " done!"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
setCustomProto() {
|
setCustomProto() {
|
||||||
|
@ -1007,11 +1003,41 @@ confOVPN() {
|
||||||
$SUDO chmod 0777 -R "/home/$pivpnUser/ovpns"
|
$SUDO chmod 0777 -R "/home/$pivpnUser/ovpns"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
finalExports() {
|
||||||
|
# Update variables in setupVars.conf file
|
||||||
|
if [ -e "${setupVars}" ]; then
|
||||||
|
sed -i.update.bak '/pivpnInterface/d;/IPv4dns/d;/IPv4addr/d;/IPv4gw/d;/pivpnUser/d;/UNATTUPG/d;' "${setupVars}"
|
||||||
|
fi
|
||||||
|
{
|
||||||
|
echo "pivpnInterface=${pivpnInterface}"
|
||||||
|
echo "IPv4dns=${IPv4dns}"
|
||||||
|
echo "IPv4addr=${IPv4addr}"
|
||||||
|
echo "IPv4gw=${IPv4gw}"
|
||||||
|
echo "pivpnUser=${pivpnUser}"
|
||||||
|
echo "UNATTUPG=${UNATTUPG}"
|
||||||
|
}>> "${setupVars}"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# I suggest replacing these names.
|
||||||
|
|
||||||
|
#accountForRefactor() {
|
||||||
|
# # At some point in the future this list can be pruned, for now we'll need it to ensure updates don't break.
|
||||||
|
#
|
||||||
|
# # Refactoring of install script has changed the name of a couple of variables. Sort them out here.
|
||||||
|
# sed -i 's/pivpnInterface/PIVPN_INTERFACE/g' ${setupVars}
|
||||||
|
# sed -i 's/IPv4dns/IPV4_DNS/g' ${setupVars}
|
||||||
|
# sed -i 's/IPv4addr/IPV4_ADDRESS/g' ${setupVars}
|
||||||
|
# sed -i 's/IPv4gw/IPV4_GATEWAY/g' ${setupVars}
|
||||||
|
# sed -i 's/pivpnUser/PIVPN_USER/g' ${setupVars}
|
||||||
|
# sed -i 's/IPv4dns/IPV4_DNS/g' ${setupVars}
|
||||||
|
# #sed -i 's/UNATTUPG/UNATTUPG/g' ${setupVars}
|
||||||
|
#}
|
||||||
|
|
||||||
installPiVPN() {
|
installPiVPN() {
|
||||||
stopServices
|
stopServices
|
||||||
confUnattendedUpgrades
|
|
||||||
$SUDO mkdir -p /etc/pivpn/
|
$SUDO mkdir -p /etc/pivpn/
|
||||||
getGitFiles ${pivpnFilesDir} ${pivpnGitUrl}
|
confUnattendedUpgrades
|
||||||
installScripts
|
installScripts
|
||||||
setCustomProto
|
setCustomProto
|
||||||
setCustomPort
|
setCustomPort
|
||||||
|
@ -1019,17 +1045,26 @@ installPiVPN() {
|
||||||
confNetwork
|
confNetwork
|
||||||
confOVPN
|
confOVPN
|
||||||
setClientDNS
|
setClientDNS
|
||||||
|
finalExports
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updatePiVPN() { # Could be replaced by installPiVPN, but keep structure close to pi-hole
|
||||||
|
#accountForRefactor
|
||||||
|
stopServices
|
||||||
|
confUnattendedUpgrades
|
||||||
|
installScripts
|
||||||
|
setCustomProto
|
||||||
|
setCustomPort
|
||||||
|
confOpenVPN
|
||||||
|
confNetwork
|
||||||
|
confOVPN
|
||||||
|
setClientDNS
|
||||||
|
finalExports #re-export setupVars.conf to account for any new vars added in new versions
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
displayFinalMessage() {
|
displayFinalMessage() {
|
||||||
# Final completion message to user
|
# Final completion message to user
|
||||||
if [[ $PLAT == "Ubuntu" || $PLAT == "Debian" ]]; then
|
|
||||||
$SUDO service openvpn start
|
|
||||||
else
|
|
||||||
$SUDO systemctl enable openvpn.service
|
|
||||||
$SUDO systemctl start openvpn.service
|
|
||||||
fi
|
|
||||||
|
|
||||||
whiptail --msgbox --backtitle "Make it so." --title "Installation Complete!" "Now run 'pivpn add' to create the ovpn profiles.
|
whiptail --msgbox --backtitle "Make it so." --title "Installation Complete!" "Now run 'pivpn add' to create the ovpn profiles.
|
||||||
Run 'pivpn help' to see what else you can do!
|
Run 'pivpn help' to see what else you can do!
|
||||||
The install log is in /etc/pivpn." ${r} ${c}
|
The install log is in /etc/pivpn." ${r} ${c}
|
||||||
|
@ -1041,19 +1076,112 @@ The install log is in /etc/pivpn." ${r} ${c}
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
update_dialogs() {
|
||||||
|
# reconfigure
|
||||||
|
if [ "${reconfigure}" = true ]; then
|
||||||
|
opt1a="Repair"
|
||||||
|
opt1b="This will retain existing settings"
|
||||||
|
strAdd="You will remain on the same version"
|
||||||
|
else
|
||||||
|
opt1a="Update"
|
||||||
|
opt1b="This will retain existing settings."
|
||||||
|
strAdd="You will be updated to the latest version."
|
||||||
|
fi
|
||||||
|
opt2a="Reconfigure"
|
||||||
|
opt2b="This will allow you to enter new settings"
|
||||||
|
|
||||||
|
UpdateCmd=$(whiptail --title "Existing Install Detected!" --menu "\n\nWe have detected an existing install.\n\nPlease choose from the following options: \n($strAdd)" ${r} ${c} 2 \
|
||||||
|
"${opt1a}" "${opt1b}" \
|
||||||
|
"${opt2a}" "${opt2b}" 3>&2 2>&1 1>&3) || \
|
||||||
|
{ echo "::: Cancel selected. Exiting"; exit 1; }
|
||||||
|
|
||||||
|
case ${UpdateCmd} in
|
||||||
|
${opt1a})
|
||||||
|
echo "::: ${opt1a} option selected."
|
||||||
|
useUpdateVars=true
|
||||||
|
;;
|
||||||
|
${opt2a})
|
||||||
|
echo "::: ${opt2a} option selected"
|
||||||
|
useUpdateVars=false
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
clone_or_update_repos() {
|
||||||
|
if [[ "${reconfigure}" == true ]]; then
|
||||||
|
echo "::: --reconfigure passed to install script. Not downloading/updating local repos"
|
||||||
|
else
|
||||||
|
# Get Git files
|
||||||
|
getGitFiles ${pivpnFilesDir} ${pivpnGitUrl} || \
|
||||||
|
{ echo "!!! Unable to clone ${pivpnGitUrl} into ${pivpnFilesDir}, unable to continue."; \
|
||||||
|
exit 1; \
|
||||||
|
}
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
######## SCRIPT ############
|
######## SCRIPT ############
|
||||||
|
|
||||||
|
main() {
|
||||||
|
|
||||||
|
######## FIRST CHECK ########
|
||||||
|
# Must be root to install
|
||||||
|
echo ":::"
|
||||||
|
if [[ $EUID -eq 0 ]];then
|
||||||
|
echo "::: You are root."
|
||||||
|
else
|
||||||
|
echo "::: sudo will be used for the install."
|
||||||
|
# Check if it is actually installed
|
||||||
|
# If it isn't, exit because the install cannot complete
|
||||||
|
if [[ $(dpkg-query -s sudo) ]];then
|
||||||
|
export SUDO="sudo"
|
||||||
|
export SUDOE="sudo -E"
|
||||||
|
else
|
||||||
|
echo "::: Please install sudo or run this as root."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check for supported distribution
|
||||||
|
distro_check
|
||||||
|
|
||||||
|
# Check arguments for the undocumented flags
|
||||||
|
for var in "$@"; do
|
||||||
|
case "$var" in
|
||||||
|
"--reconfigure" ) reconfigure=true;;
|
||||||
|
"--i_do_not_follow_recommendations" ) skipSpaceCheck=false;;
|
||||||
|
"--unattended" ) runUnattended=true;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
if [[ -f ${setupVars} ]]; then
|
||||||
|
if [[ "${runUnattended}" == true ]]; then
|
||||||
|
echo "::: --unattended passed to install script, no whiptail dialogs will be displayed"
|
||||||
|
useUpdateVars=true
|
||||||
|
else
|
||||||
|
update_dialogs
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Start the installer
|
||||||
# Verify there is enough disk space for the install
|
# Verify there is enough disk space for the install
|
||||||
|
if [[ "${skipSpaceCheck}" == true ]]; then
|
||||||
|
echo "::: --i_do_not_follow_recommendations passed to script, skipping free disk space verification!"
|
||||||
|
else
|
||||||
verifyFreeDiskSpace
|
verifyFreeDiskSpace
|
||||||
|
fi
|
||||||
|
|
||||||
# Install the packages (we do this first because we need whiptail)
|
# Install the packages (we do this first because we need whiptail)
|
||||||
#checkForDependencies
|
#checkForDependencies
|
||||||
update_package_cache
|
update_package_cache
|
||||||
|
|
||||||
|
# Notify user of package availability
|
||||||
notify_package_updates_available
|
notify_package_updates_available
|
||||||
|
|
||||||
|
# Install packages used by this installation script
|
||||||
install_dependent_packages PIVPN_DEPS[@]
|
install_dependent_packages PIVPN_DEPS[@]
|
||||||
|
|
||||||
# Start the installer
|
if [[ ${useUpdateVars} == false ]]; then
|
||||||
|
# Display welcome dialogs
|
||||||
welcomeDialogs
|
welcomeDialogs
|
||||||
|
|
||||||
# Find interfaces and let the user choose one
|
# Find interfaces and let the user choose one
|
||||||
|
@ -1067,6 +1195,7 @@ else
|
||||||
setStaticIPv4
|
setStaticIPv4
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Set the Network IP and Mask correctly
|
||||||
setNetwork
|
setNetwork
|
||||||
|
|
||||||
# Choose the user for the ovpns
|
# Choose the user for the ovpns
|
||||||
|
@ -1075,12 +1204,66 @@ chooseUser
|
||||||
# Ask if unattended-upgrades will be enabled
|
# Ask if unattended-upgrades will be enabled
|
||||||
unattendedUpgrades
|
unattendedUpgrades
|
||||||
|
|
||||||
# Install
|
# Clone/Update the repos
|
||||||
|
clone_or_update_repos
|
||||||
|
|
||||||
|
# Install and log everything to a file
|
||||||
installPiVPN | tee ${tmpLog}
|
installPiVPN | tee ${tmpLog}
|
||||||
|
|
||||||
|
echo "::: Install Complete..."
|
||||||
|
else
|
||||||
|
# Only try to set static on Raspbian
|
||||||
|
if [[ $PLAT != "Raspbian" ]]; then
|
||||||
|
echo "::: IP Information"
|
||||||
|
echo "::: Since we think you are not using Raspbian, we will not configure a static IP for you."
|
||||||
|
echo "::: If you are in Amazon then you can not configure a static IP anyway."
|
||||||
|
echo "::: Just ensure before this installer started you had set an elastic IP on your instance."
|
||||||
|
else
|
||||||
|
setStaticIPv4 # This might be a problem if a user tries to modify the ip in the config file and then runs an update because of the way we check for previous configuration in /etc/dhcpcd.conf
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Clone/Update the repos
|
||||||
|
clone_or_update_repos
|
||||||
|
|
||||||
|
# Source ${setupVars} for use in the rest of the functions.
|
||||||
|
source ${setupVars}
|
||||||
|
|
||||||
|
|
||||||
|
updatePiVPN | tee ${tmpLog}
|
||||||
|
fi
|
||||||
|
|
||||||
#Move the install log into /etc/pivpn for storage
|
#Move the install log into /etc/pivpn for storage
|
||||||
$SUDO mv ${tmpLog} ${instalLogLoc}
|
$SUDO mv ${tmpLog} ${instalLogLoc}
|
||||||
|
|
||||||
displayFinalMessage
|
echo "::: Restarting services..."
|
||||||
|
# Start services
|
||||||
|
if [[ $PLAT == "Ubuntu" || $PLAT == "Debian" ]]; then
|
||||||
|
$SUDO service openvpn start
|
||||||
|
else
|
||||||
|
$SUDO systemctl enable openvpn.service
|
||||||
|
$SUDO systemctl start openvpn.service
|
||||||
|
fi
|
||||||
|
|
||||||
echo "::: Install Complete..."
|
echo "::: done."
|
||||||
|
|
||||||
|
if [[ "${useUpdateVars}" == false ]]; then
|
||||||
|
displayFinalMessage
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo ":::"
|
||||||
|
if [[ "${useUpdateVars}" == false ]]; then
|
||||||
|
echo "::: Installation Complete!"
|
||||||
|
echo "::: Now run 'pivpn add' to create the ovpn profiles."
|
||||||
|
echo "::: Run 'pivpn help' to see what else you can do!"
|
||||||
|
echo "::: It is strongly recommended you reboot after installation."
|
||||||
|
else
|
||||||
|
echo "::: Update complete!"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo ":::"
|
||||||
|
echo "::: The install log is located at: ${instalLogLoc}"
|
||||||
|
}
|
||||||
|
|
||||||
|
if [[ "${PVPN_TEST}" != true ]] ; then
|
||||||
|
main "$@"
|
||||||
|
fi
|
||||||
|
|
Loading…
Reference in a new issue