Robustize OS Detection.

This is framework needed to support Ubuntu 16.04 which
is coming in a future commit.
This commit is contained in:
Kaladin Light 2016-05-10 11:49:29 -04:00
parent 24fc3ae75f
commit 2f3540b898
3 changed files with 39 additions and 13 deletions

View file

@ -56,11 +56,37 @@ else
fi fi
fi fi
# Next rough check for platform # Next see if we are on a tested and supported OS
if [ "$(cat /etc/os-release | grep ubuntu)" ]; then function noOS_Support() {
PLAT="ubuntu" whiptail --msgbox --backtitle "INVALID OS DETECTED" --title "Invalid OS" "We have not been able to detect a supported OS.
Currently this installer supports Raspbian jessie, Ubuntu 14.04 (trusty), and Ubuntu 16.04 (xenial).
If you think you received this message in error, you can post an issue on the GitHub at https://github.com/pivpn/pivpn/issues." $r $c
exit 1
}
LSB_REL=$(which lsb_release)
if [[ -z $LSB_REL ]]; then
noOS_Support
else else
PLAT="raspbian" PLAT=$($LSB_REL -si)
OSCN=$($LSB_REL -sc) # We want this to be trusty xenial or jessie
if [[ $PLAT == "Ubuntu" || $PLAT == "Raspbian" || $PLAT == "Debian" ]]; then
if [[ $OSCN != "trusty" && $OSCN != "xenial" && $OSCN != "jessie" ]]; then
if (whiptail --backtitle "Not Supported OS" --title "Not Supported OS" --yesno "You are on an OS that we have not tested but MAY work.
Currently this installer supports Raspbian jessie, Ubuntu 14.04 (trusty), and Ubuntu 16.04 (xenial).
Would you like to continue anyway?" $r $c) then
echo "::: Did not detect perfectly supported OS but,"
echo "::: Continuing installation at user's own risk..."
else
echo "::: Exiting due to unsupported OS"
exit 1
fi
fi
else
noOS_Support
fi
fi fi
echo "${PLAT}" > /tmp/DET_PLATFORM echo "${PLAT}" > /tmp/DET_PLATFORM
@ -313,7 +339,7 @@ stopServices() {
# Stop openvpn # Stop openvpn
$SUDO echo ":::" $SUDO echo ":::"
$SUDO echo -n "::: Stopping openvpn service..." $SUDO echo -n "::: Stopping openvpn service..."
if [[ $PLAT == "ubuntu" ]]; then if [[ $PLAT == "Ubuntu" ]]; then
$SUDO service openvpn stop || true $SUDO service openvpn stop || true
else else
$SUDO systemctl stop openvpn.service || true $SUDO systemctl stop openvpn.service || true
@ -333,12 +359,12 @@ checkForDependencies() {
timestampAsDate=$(date -d @"$timestamp" "+%b %e") timestampAsDate=$(date -d @"$timestamp" "+%b %e")
today=$(date "+%b %e") today=$(date "+%b %e")
if [[ $PLAT == "ubuntu" ]]; then if [[ $PLAT == "Ubuntu" ]]; then
wget -O - https://swupdate.openvpn.net/repos/repo-public.gpg| $SUDO apt-key add - wget -O - https://swupdate.openvpn.net/repos/repo-public.gpg| $SUDO apt-key add -
echo "deb http://swupdate.openvpn.net/apt trusty main" | $SUDO tee /etc/apt/sources.list.d/swupdate.openvpn.net.list > /dev/null echo "deb http://swupdate.openvpn.net/apt trusty main" | $SUDO tee /etc/apt/sources.list.d/swupdate.openvpn.net.list > /dev/null
fi fi
if [ ! "$today" == "$timestampAsDate" ] || [ $PLAT = "ubuntu" ]; then if [ ! "$today" == "$timestampAsDate" ] || [ $PLAT = "Ubuntu" ]; then
#update package lists #update package lists
echo ":::" echo ":::"
echo "::: Either you are on ubuntu or" echo "::: Either you are on ubuntu or"
@ -695,7 +721,7 @@ confOpenVPN() {
confUnattendedUpgrades() { confUnattendedUpgrades() {
if [[ $UNATTUPG == "unattended-upgrades" ]]; then if [[ $UNATTUPG == "unattended-upgrades" ]]; then
if [[ $PLAT == "ubuntu" ]]; then if [[ $PLAT == "Ubuntu" ]]; then
# Ubuntu 50unattended-upgrades should already just have security enabled # Ubuntu 50unattended-upgrades should already just have security enabled
# so we just need to configure the 10periodic file # so we just need to configure the 10periodic file
cat << EOT | $SUDO tee /etc/apt/apt.conf.d/10periodic >/dev/null cat << EOT | $SUDO tee /etc/apt/apt.conf.d/10periodic >/dev/null
@ -726,7 +752,7 @@ confNetwork() {
# Write script to run openvpn and allow it through firewall on boot using the template .txt file # Write script to run openvpn and allow it through firewall on boot using the template .txt file
$SUDO iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o $IPv4dev -j MASQUERADE $SUDO iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o $IPv4dev -j MASQUERADE
if [[ $PLAT == "ubuntu" ]]; then if [[ $PLAT == "Ubuntu" ]]; then
$SUDO iptables-save $SUDO iptables-save
else else
$SUDO netfilter-persistent save $SUDO netfilter-persistent save
@ -803,7 +829,7 @@ installPiVPN() {
displayFinalMessage() { displayFinalMessage() {
# Final completion message to user # Final completion message to user
if [[ $PLAT == "ubuntu" ]]; then if [[ $PLAT == "Ubuntu" ]]; then
$SUDO service openvpn start $SUDO service openvpn start
else else
$SUDO systemctl enable openvpn.service $SUDO systemctl enable openvpn.service
@ -831,7 +857,7 @@ verifyFreeDiskSpace
# Find interfaces and let the user choose one # Find interfaces and let the user choose one
chooseInterface chooseInterface
if [[ $PLAT == "ubuntu" ]]; then if [[ $PLAT == "Ubuntu" ]]; then
avoidStaticIPv4Ubuntu avoidStaticIPv4Ubuntu
else else
getStaticIPv4Settings getStaticIPv4Settings

View file

@ -64,7 +64,7 @@ if [ $REVOKE_STATUS == 0 ]; then
printf "\nThis seems to be the first time you have revoked a cert.\n" printf "\nThis seems to be the first time you have revoked a cert.\n"
printf "We are adding the CRL to the server.conf and restarting openvpn.\n" printf "We are adding the CRL to the server.conf and restarting openvpn.\n"
sed -i '/#crl-verify/c\crl-verify /etc/openvpn/crl.pem' /etc/openvpn/server.conf sed -i '/#crl-verify/c\crl-verify /etc/openvpn/crl.pem' /etc/openvpn/server.conf
if [[ ${PLAT} == "ubuntu" ]]; then if [[ ${PLAT} == "Ubuntu" ]]; then
service openvpn restart service openvpn restart
else else
systemctl restart openvpn.service systemctl restart openvpn.service

View file

@ -81,7 +81,7 @@ echo ":::"
$SUDO rm -rf /var/log/*openvpn* &> /dev/null $SUDO rm -rf /var/log/*openvpn* &> /dev/null
if [[ $UINST_OVPN = 1 ]]; then if [[ $UINST_OVPN = 1 ]]; then
$SUDO rm -rf /etc/openvpn &> /dev/null $SUDO rm -rf /etc/openvpn &> /dev/null
if [[ $PLAT = "ubuntu" ]]; then if [[ $PLAT = "Ubuntu" ]]; then
printf "::: Removing openvpn apt source..." printf "::: Removing openvpn apt source..."
$SUDO rm -rf /etc/apt/sources.list.d/swupdate.openvpn.net.list &> /dev/null $SUDO rm -rf /etc/apt/sources.list.d/swupdate.openvpn.net.list &> /dev/null
$SUDO apt-get -qq update & spinner $!; printf "done!\n"; $SUDO apt-get -qq update & spinner $!; printf "done!\n";