Minor clean up

This commit is contained in:
hwdsl2 2016-11-06 19:30:53 -06:00
parent 6d99a01b0a
commit 61bd1254ed
5 changed files with 23 additions and 25 deletions

View File

@ -22,7 +22,7 @@
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
exiterr() { echo "Error: ${1}" >&2; exit 1; }
exiterr() { echo "Error: $1" >&2; exit 1; }
if [ "$(sed 's/\..*//' /etc/debian_version 2>/dev/null)" != "7" ]; then
exiterr "This script only supports Debian 7 (Wheezy)."

View File

@ -13,11 +13,11 @@
# Check https://libreswan.org for the latest version
swan_ver=3.18
### Do not edit below this line ###
### DO NOT edit below this line ###
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
exiterr() { echo "Error: ${1}" >&2; exit 1; }
exiterr() { echo "Error: $1" >&2; exit 1; }
exiterr2() { echo "Error: 'apt-get install' failed." >&2; exit 1; }
os_type="$(lsb_release -si 2>/dev/null)"
@ -37,13 +37,11 @@ if [ -z "$swan_ver" ]; then
exiterr "Libreswan version 'swan_ver' not specified."
fi
/usr/local/sbin/ipsec --version 2>/dev/null | grep -qs "Libreswan"
if [ "$?" != "0" ]; then
if ! /usr/local/sbin/ipsec --version 2>/dev/null | grep -qs "Libreswan"; then
exiterr "This script requires Libreswan already installed."
fi
/usr/local/sbin/ipsec --version 2>/dev/null | grep -qs "$swan_ver"
if [ "$?" = "0" ]; then
if /usr/local/sbin/ipsec --version 2>/dev/null | grep -qs "$swan_ver"; then
echo "You already have Libreswan version $swan_ver installed! "
echo "If you continue, the same version will be re-installed."
echo

View File

@ -13,11 +13,11 @@
# Check https://libreswan.org for the latest version
swan_ver=3.18
### Do not edit below this line ###
### DO NOT edit below this line ###
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
exiterr() { echo "Error: ${1}" >&2; exit 1; }
exiterr() { echo "Error: $1" >&2; exit 1; }
exiterr2() { echo "Error: 'yum install' failed." >&2; exit 1; }
if ! grep -qs -e "release 6" -e "release 7" /etc/redhat-release; then
@ -36,13 +36,11 @@ if [ -z "$swan_ver" ]; then
exiterr "Libreswan version 'swan_ver' not specified."
fi
/usr/local/sbin/ipsec --version 2>/dev/null | grep -qs "Libreswan"
if [ "$?" != "0" ]; then
if ! /usr/local/sbin/ipsec --version 2>/dev/null | grep -qs "Libreswan"; then
exiterr "This script requires Libreswan already installed."
fi
/usr/local/sbin/ipsec --version 2>/dev/null | grep -qs "$swan_ver"
if [ "$?" = "0" ]; then
if /usr/local/sbin/ipsec --version 2>/dev/null | grep -qs "$swan_ver"; then
echo "You already have Libreswan version $swan_ver installed! "
echo "If you continue, the same version will be re-installed."
echo

View File

@ -36,12 +36,13 @@ YOUR_PASSWORD=''
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
SYS_DT="$(date +%Y-%m-%d-%H:%M:%S)"; export SYS_DT
exiterr() { echo "Error: ${1}" >&2; exit 1; }
exiterr() { echo "Error: $1" >&2; exit 1; }
exiterr2() { echo "Error: 'apt-get install' failed." >&2; exit 1; }
conf_bk() { /bin/cp -f "${1}" "${1}.old-$SYS_DT" 2>/dev/null; }
conf_bk() { /bin/cp -f "$1" "$1.old-$SYS_DT" 2>/dev/null; }
check_ip() {
IP_REGEX="^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$"
printf %s "${1}" | tr -d '\n' | grep -Eq "$IP_REGEX"
printf %s "$1" | tr -d '\n' | grep -Eq "$IP_REGEX"
}
os_type="$(lsb_release -si 2>/dev/null)"
@ -335,9 +336,9 @@ fi
# Check if IPTables rules need updating
ipt_flag=0
IPT_FILE="/etc/iptables.rules"
if ! grep -qs "hwdsl2 VPN script" "$IPT_FILE" || \
! iptables -t nat -C POSTROUTING -s 192.168.42.0/24 -o "$NET_IFS" -j SNAT --to-source "$PRIVATE_IP" 2>/dev/null || \
! iptables -t nat -C POSTROUTING -s 192.168.43.0/24 -o "$NET_IFS" -m policy --dir out --pol none -j SNAT --to-source "$PRIVATE_IP" 2>/dev/null; then
if ! grep -qs "hwdsl2 VPN script" "$IPT_FILE" \
|| ! iptables -t nat -C POSTROUTING -s 192.168.42.0/24 -o "$NET_IFS" -j SNAT --to-source "$PRIVATE_IP" 2>/dev/null \
|| ! iptables -t nat -C POSTROUTING -s 192.168.43.0/24 -o "$NET_IFS" -m policy --dir out --pol none -j SNAT --to-source "$PRIVATE_IP" 2>/dev/null; then
ipt_flag=1
fi

View File

@ -36,12 +36,13 @@ YOUR_PASSWORD=''
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
SYS_DT="$(date +%Y-%m-%d-%H:%M:%S)"; export SYS_DT
exiterr() { echo "Error: ${1}" >&2; exit 1; }
exiterr() { echo "Error: $1" >&2; exit 1; }
exiterr2() { echo "Error: 'yum install' failed." >&2; exit 1; }
conf_bk() { /bin/cp -f "${1}" "${1}.old-$SYS_DT" 2>/dev/null; }
conf_bk() { /bin/cp -f "$1" "$1.old-$SYS_DT" 2>/dev/null; }
check_ip() {
IP_REGEX="^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$"
printf %s "${1}" | tr -d '\n' | grep -Eq "$IP_REGEX"
printf %s "$1" | tr -d '\n' | grep -Eq "$IP_REGEX"
}
if ! grep -qs -e "release 6" -e "release 7" /etc/redhat-release; then
@ -325,9 +326,9 @@ fi
# Check if IPTables rules need updating
ipt_flag=0
IPT_FILE="/etc/sysconfig/iptables"
if ! grep -qs "hwdsl2 VPN script" "$IPT_FILE" || \
! iptables -t nat -C POSTROUTING -s 192.168.42.0/24 -o "$NET_IFS" -j SNAT --to-source "$PRIVATE_IP" 2>/dev/null || \
! iptables -t nat -C POSTROUTING -s 192.168.43.0/24 -o "$NET_IFS" -m policy --dir out --pol none -j SNAT --to-source "$PRIVATE_IP" 2>/dev/null; then
if ! grep -qs "hwdsl2 VPN script" "$IPT_FILE" \
|| ! iptables -t nat -C POSTROUTING -s 192.168.42.0/24 -o "$NET_IFS" -j SNAT --to-source "$PRIVATE_IP" 2>/dev/null \
|| ! iptables -t nat -C POSTROUTING -s 192.168.43.0/24 -o "$NET_IFS" -m policy --dir out --pol none -j SNAT --to-source "$PRIVATE_IP" 2>/dev/null; then
ipt_flag=1
fi