1
0
mirror of synced 2024-11-22 21:16:02 +03:00

Minor clean up

This commit is contained in:
hwdsl2 2017-05-22 11:46:28 -05:00
parent f93ecd60d2
commit 8fb4bf7897
4 changed files with 32 additions and 30 deletions

View File

@ -24,10 +24,8 @@ os_type="$(lsb_release -si 2>/dev/null)"
if [ -z "$os_type" ]; then if [ -z "$os_type" ]; then
[ -f /etc/os-release ] && os_type="$(. /etc/os-release && echo "$ID")" [ -f /etc/os-release ] && os_type="$(. /etc/os-release && echo "$ID")"
[ -f /etc/lsb-release ] && os_type="$(. /etc/lsb-release && echo "$DISTRIB_ID")" [ -f /etc/lsb-release ] && os_type="$(. /etc/lsb-release && echo "$DISTRIB_ID")"
[ "$os_type" = "debian" ] && os_type=Debian
[ "$os_type" = "ubuntu" ] && os_type=Ubuntu
fi fi
if [ "$os_type" != "Ubuntu" ] && [ "$os_type" != "Debian" ] && [ "$os_type" != "Raspbian" ]; then if ! printf %s "$os_type" | head -n 1 | grep -qiF -e ubuntu -e debian -e raspbian; then
exiterr "This script only supports Ubuntu/Debian." exiterr "This script only supports Ubuntu/Debian."
fi fi
@ -43,11 +41,11 @@ if [ -z "$swan_ver" ]; then
exiterr "Libreswan version 'swan_ver' not specified." exiterr "Libreswan version 'swan_ver' not specified."
fi fi
if ! /usr/local/sbin/ipsec --version 2>/dev/null | grep -qs "Libreswan"; then if ! /usr/local/sbin/ipsec --version 2>/dev/null | grep -q "Libreswan"; then
exiterr "This script requires Libreswan already installed." exiterr "This script requires Libreswan already installed."
fi fi
if /usr/local/sbin/ipsec --version 2>/dev/null | grep -qs -F "$swan_ver"; then if /usr/local/sbin/ipsec --version 2>/dev/null | grep -qF "$swan_ver"; then
echo "You already have Libreswan version $swan_ver installed! " echo "You already have Libreswan version $swan_ver installed! "
echo "If you continue, the same version will be re-installed." echo "If you continue, the same version will be re-installed."
echo echo
@ -156,7 +154,7 @@ make -s programs && make -s install
# Verify the install and clean up # Verify the install and clean up
cd /opt/src || exiterr "Cannot enter /opt/src." cd /opt/src || exiterr "Cannot enter /opt/src."
/bin/rm -rf "/opt/src/libreswan-$swan_ver" /bin/rm -rf "/opt/src/libreswan-$swan_ver"
if ! /usr/local/sbin/ipsec --version 2>/dev/null | grep -qs -F "$swan_ver"; then if ! /usr/local/sbin/ipsec --version 2>/dev/null | grep -qF "$swan_ver"; then
exiterr "Libreswan $swan_ver failed to build." exiterr "Libreswan $swan_ver failed to build."
fi fi

View File

@ -36,11 +36,11 @@ if [ -z "$swan_ver" ]; then
exiterr "Libreswan version 'swan_ver' not specified." exiterr "Libreswan version 'swan_ver' not specified."
fi fi
if ! /usr/local/sbin/ipsec --version 2>/dev/null | grep -qs "Libreswan"; then if ! /usr/local/sbin/ipsec --version 2>/dev/null | grep -q "Libreswan"; then
exiterr "This script requires Libreswan already installed." exiterr "This script requires Libreswan already installed."
fi fi
if /usr/local/sbin/ipsec --version 2>/dev/null | grep -qs -F "$swan_ver"; then if /usr/local/sbin/ipsec --version 2>/dev/null | grep -qF "$swan_ver"; then
echo "You already have Libreswan version $swan_ver installed! " echo "You already have Libreswan version $swan_ver installed! "
echo "If you continue, the same version will be re-installed." echo "If you continue, the same version will be re-installed."
echo echo
@ -145,7 +145,7 @@ make -s programs && make -s install
# Verify the install and clean up # Verify the install and clean up
cd /opt/src || exiterr "Cannot enter /opt/src." cd /opt/src || exiterr "Cannot enter /opt/src."
/bin/rm -rf "/opt/src/libreswan-$swan_ver" /bin/rm -rf "/opt/src/libreswan-$swan_ver"
if ! /usr/local/sbin/ipsec --version 2>/dev/null | grep -qs -F "$swan_ver"; then if ! /usr/local/sbin/ipsec --version 2>/dev/null | grep -qF "$swan_ver"; then
exiterr "Libreswan $swan_ver failed to build." exiterr "Libreswan $swan_ver failed to build."
fi fi

View File

@ -50,10 +50,8 @@ os_type="$(lsb_release -si 2>/dev/null)"
if [ -z "$os_type" ]; then if [ -z "$os_type" ]; then
[ -f /etc/os-release ] && os_type="$(. /etc/os-release && echo "$ID")" [ -f /etc/os-release ] && os_type="$(. /etc/os-release && echo "$ID")"
[ -f /etc/lsb-release ] && os_type="$(. /etc/lsb-release && echo "$DISTRIB_ID")" [ -f /etc/lsb-release ] && os_type="$(. /etc/lsb-release && echo "$DISTRIB_ID")"
[ "$os_type" = "debian" ] && os_type=Debian
[ "$os_type" = "ubuntu" ] && os_type=Ubuntu
fi fi
if [ "$os_type" != "Ubuntu" ] && [ "$os_type" != "Debian" ] && [ "$os_type" != "Raspbian" ]; then if ! printf %s "$os_type" | head -n 1 | grep -qiF -e ubuntu -e debian -e raspbian; then
exiterr "This script only supports Ubuntu/Debian." exiterr "This script only supports Ubuntu/Debian."
fi fi
@ -72,19 +70,22 @@ DEF_IFACE="$(route | grep '^default' | grep -o '[^ ]*$')"
if_state1=$(cat "/sys/class/net/$DEF_IFACE/operstate" 2>/dev/null) if_state1=$(cat "/sys/class/net/$DEF_IFACE/operstate" 2>/dev/null)
if [ -z "$VPN_NET_IFACE" ] && [ -n "$if_state1" ] && [ "$if_state1" != "down" ]; then if [ -z "$VPN_NET_IFACE" ] && [ -n "$if_state1" ] && [ "$if_state1" != "down" ]; then
case "$DEF_IFACE" in if ! grep -qs raspbian /etc/os-release; then
wlan*) case "$DEF_IFACE" in
printf "Error: Default network interface '%s' detected.\n\n" "$DEF_IFACE" >&2 wlan*)
cat 1>&2 <<EOF cat 1>&2 <<EOF
Error: Default network interface '$DEF_IFACE' detected.
DO NOT RUN THIS SCRIPT ON YOUR PC OR MAC! DO NOT RUN THIS SCRIPT ON YOUR PC OR MAC!
If you are certain that this script is running on a server, If you are certain that this script is running on a server,
please re-run it using the following command: you may re-run it using the following command:
sudo VPN_NET_IFACE="$DEF_IFACE" sh "$0" sudo VPN_NET_IFACE="$DEF_IFACE" sh "$0"
EOF EOF
exit 1 exit 1
;; ;;
esac esac
fi
NET_IFACE="$DEF_IFACE" NET_IFACE="$DEF_IFACE"
fi fi
@ -116,7 +117,7 @@ if [ -z "$VPN_IPSEC_PSK" ] || [ -z "$VPN_USER" ] || [ -z "$VPN_PASSWORD" ]; then
exiterr "All VPN credentials must be specified. Edit the script and re-enter them." exiterr "All VPN credentials must be specified. Edit the script and re-enter them."
fi fi
if printf %s "$VPN_IPSEC_PSK $VPN_USER $VPN_PASSWORD" | LC_ALL=C grep -qs '[^ -~]\+'; then if printf %s "$VPN_IPSEC_PSK $VPN_USER $VPN_PASSWORD" | LC_ALL=C grep -q '[^ -~]\+'; then
exiterr "VPN credentials must not contain non-ASCII characters." exiterr "VPN credentials must not contain non-ASCII characters."
fi fi
@ -205,7 +206,7 @@ make -s programs && make -s install
# Verify the install and clean up # Verify the install and clean up
cd /opt/src || exiterr "Cannot enter /opt/src." cd /opt/src || exiterr "Cannot enter /opt/src."
/bin/rm -rf "/opt/src/libreswan-$swan_ver" /bin/rm -rf "/opt/src/libreswan-$swan_ver"
if ! /usr/local/sbin/ipsec --version 2>/dev/null | grep -qs -F "$swan_ver"; then if ! /usr/local/sbin/ipsec --version 2>/dev/null | grep -qF "$swan_ver"; then
exiterr "Libreswan $swan_ver failed to build." exiterr "Libreswan $swan_ver failed to build."
fi fi

View File

@ -65,19 +65,22 @@ DEF_IFACE="$(route | grep '^default' | grep -o '[^ ]*$')"
if_state1=$(cat "/sys/class/net/$DEF_IFACE/operstate" 2>/dev/null) if_state1=$(cat "/sys/class/net/$DEF_IFACE/operstate" 2>/dev/null)
if [ -z "$VPN_NET_IFACE" ] && [ -n "$if_state1" ] && [ "$if_state1" != "down" ]; then if [ -z "$VPN_NET_IFACE" ] && [ -n "$if_state1" ] && [ "$if_state1" != "down" ]; then
case "$DEF_IFACE" in if ! grep -qs raspbian /etc/os-release; then
wlan*) case "$DEF_IFACE" in
printf "Error: Default network interface '%s' detected.\n\n" "$DEF_IFACE" >&2 wlan*)
cat 1>&2 <<EOF cat 1>&2 <<EOF
Error: Default network interface '$DEF_IFACE' detected.
DO NOT RUN THIS SCRIPT ON YOUR PC OR MAC! DO NOT RUN THIS SCRIPT ON YOUR PC OR MAC!
If you are certain that this script is running on a server, If you are certain that this script is running on a server,
please re-run it using the following command: you may re-run it using the following command:
sudo VPN_NET_IFACE="$DEF_IFACE" sh "$0" sudo VPN_NET_IFACE="$DEF_IFACE" sh "$0"
EOF EOF
exit 1 exit 1
;; ;;
esac esac
fi
NET_IFACE="$DEF_IFACE" NET_IFACE="$DEF_IFACE"
fi fi
@ -109,7 +112,7 @@ if [ -z "$VPN_IPSEC_PSK" ] || [ -z "$VPN_USER" ] || [ -z "$VPN_PASSWORD" ]; then
exiterr "All VPN credentials must be specified. Edit the script and re-enter them." exiterr "All VPN credentials must be specified. Edit the script and re-enter them."
fi fi
if printf %s "$VPN_IPSEC_PSK $VPN_USER $VPN_PASSWORD" | LC_ALL=C grep -qs '[^ -~]\+'; then if printf %s "$VPN_IPSEC_PSK $VPN_USER $VPN_PASSWORD" | LC_ALL=C grep -q '[^ -~]\+'; then
exiterr "VPN credentials must not contain non-ASCII characters." exiterr "VPN credentials must not contain non-ASCII characters."
fi fi
@ -189,7 +192,7 @@ make -s programs && make -s install
# Verify the install and clean up # Verify the install and clean up
cd /opt/src || exiterr "Cannot enter /opt/src." cd /opt/src || exiterr "Cannot enter /opt/src."
/bin/rm -rf "/opt/src/libreswan-$swan_ver" /bin/rm -rf "/opt/src/libreswan-$swan_ver"
if ! /usr/local/sbin/ipsec --version 2>/dev/null | grep -qs -F "$swan_ver"; then if ! /usr/local/sbin/ipsec --version 2>/dev/null | grep -qF "$swan_ver"; then
exiterr "Libreswan $swan_ver failed to build." exiterr "Libreswan $swan_ver failed to build."
fi fi