Improve VPN setup
- Wait for apt to be available - Check for Wget and install it if not found - Fallback to cURL if Wget fails - Cleanup
This commit is contained in:
parent
6ce1be392d
commit
cfd9128e3f
@ -106,22 +106,39 @@ check_iptables() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wait_for_apt() {
|
||||||
|
count=0
|
||||||
|
apt_lk=/var/lib/apt/lists/lock
|
||||||
|
pkg_lk=/var/lib/dpkg/lock
|
||||||
|
while fuser "$apt_lk" "$pkg_lk" >/dev/null 2>&1 \
|
||||||
|
|| lsof "$apt_lk" >/dev/null 2>&1 || lsof "$pkg_lk" >/dev/null 2>&1; do
|
||||||
|
[ "$count" = "0" ] && echo "## Waiting for apt to be available..."
|
||||||
|
[ "$count" -ge "100" ] && exiterr "Could not get apt/dpkg lock."
|
||||||
|
count=$((count+1))
|
||||||
|
printf '%s' '.'
|
||||||
|
sleep 3
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
install_wget() {
|
install_wget() {
|
||||||
if [ "$os_type" = "ubuntu" ] || [ "$os_type" = "debian" ] || [ "$os_type" = "raspbian" ]; then
|
if ! command -v wget >/dev/null 2>&1; then
|
||||||
export DEBIAN_FRONTEND=noninteractive
|
if [ "$os_type" = "ubuntu" ] || [ "$os_type" = "debian" ] || [ "$os_type" = "raspbian" ]; then
|
||||||
(
|
wait_for_apt
|
||||||
set -x
|
export DEBIAN_FRONTEND=noninteractive
|
||||||
apt-get -yqq update
|
(
|
||||||
) || exiterr "'apt-get update' failed."
|
set -x
|
||||||
(
|
apt-get -yqq update
|
||||||
set -x
|
) || exiterr "'apt-get update' failed."
|
||||||
apt-get -yqq install wget >/dev/null
|
(
|
||||||
) || exiterr "'apt-get install wget' failed."
|
set -x
|
||||||
else
|
apt-get -yqq install wget >/dev/null
|
||||||
(
|
) || exiterr "'apt-get install wget' failed."
|
||||||
set -x
|
else
|
||||||
yum -y -q install wget >/dev/null
|
(
|
||||||
) || exiterr "'yum install wget' failed."
|
set -x
|
||||||
|
yum -y -q install wget >/dev/null
|
||||||
|
) || exiterr "'yum install wget' failed."
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,10 +155,10 @@ get_setup_url() {
|
|||||||
|
|
||||||
run_setup() {
|
run_setup() {
|
||||||
status=0
|
status=0
|
||||||
get_setup_url
|
|
||||||
TMPDIR=$(mktemp -d /tmp/vpnsetup.XXXXX 2>/dev/null)
|
TMPDIR=$(mktemp -d /tmp/vpnsetup.XXXXX 2>/dev/null)
|
||||||
if [ -d "$TMPDIR" ]; then
|
if [ -d "$TMPDIR" ]; then
|
||||||
if ( set -x; wget -t 3 -T 30 -q -O "$TMPDIR/vpn.sh" "$setup_url" ); then
|
if ( set -x; wget -t 3 -T 30 -q -O "$TMPDIR/vpn.sh" "$setup_url" \
|
||||||
|
|| curl -fsL "$setup_url" -o "$TMPDIR/vpn.sh" 2>/dev/null ); then
|
||||||
if /bin/sh "$TMPDIR/vpn.sh"; then
|
if /bin/sh "$TMPDIR/vpn.sh"; then
|
||||||
if [ -s /opt/src/ikev2.sh ] && [ ! -f /etc/ipsec.d/ikev2.conf ]; then
|
if [ -s /opt/src/ikev2.sh ] && [ ! -f /etc/ipsec.d/ikev2.conf ]; then
|
||||||
sleep 1
|
sleep 1
|
||||||
|
51
vpnsetup.sh
51
vpnsetup.sh
@ -160,22 +160,39 @@ check_iptables() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wait_for_apt() {
|
||||||
|
count=0
|
||||||
|
apt_lk=/var/lib/apt/lists/lock
|
||||||
|
pkg_lk=/var/lib/dpkg/lock
|
||||||
|
while fuser "$apt_lk" "$pkg_lk" >/dev/null 2>&1 \
|
||||||
|
|| lsof "$apt_lk" >/dev/null 2>&1 || lsof "$pkg_lk" >/dev/null 2>&1; do
|
||||||
|
[ "$count" = "0" ] && echo "## Waiting for apt to be available..."
|
||||||
|
[ "$count" -ge "100" ] && exiterr "Could not get apt/dpkg lock."
|
||||||
|
count=$((count+1))
|
||||||
|
printf '%s' '.'
|
||||||
|
sleep 3
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
install_wget() {
|
install_wget() {
|
||||||
if [ "$os_type" = "ubuntu" ] || [ "$os_type" = "debian" ] || [ "$os_type" = "raspbian" ]; then
|
if ! command -v wget >/dev/null 2>&1; then
|
||||||
export DEBIAN_FRONTEND=noninteractive
|
if [ "$os_type" = "ubuntu" ] || [ "$os_type" = "debian" ] || [ "$os_type" = "raspbian" ]; then
|
||||||
(
|
wait_for_apt
|
||||||
set -x
|
export DEBIAN_FRONTEND=noninteractive
|
||||||
apt-get -yqq update
|
(
|
||||||
) || exiterr "'apt-get update' failed."
|
set -x
|
||||||
(
|
apt-get -yqq update
|
||||||
set -x
|
) || exiterr "'apt-get update' failed."
|
||||||
apt-get -yqq install wget >/dev/null
|
(
|
||||||
) || exiterr "'apt-get install wget' failed."
|
set -x
|
||||||
else
|
apt-get -yqq install wget >/dev/null
|
||||||
(
|
) || exiterr "'apt-get install wget' failed."
|
||||||
set -x
|
else
|
||||||
yum -y -q install wget >/dev/null
|
(
|
||||||
) || exiterr "'yum install wget' failed."
|
set -x
|
||||||
|
yum -y -q install wget >/dev/null
|
||||||
|
) || exiterr "'yum install wget' failed."
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -192,10 +209,10 @@ get_setup_url() {
|
|||||||
|
|
||||||
run_setup() {
|
run_setup() {
|
||||||
status=0
|
status=0
|
||||||
get_setup_url
|
|
||||||
TMPDIR=$(mktemp -d /tmp/vpnsetup.XXXXX 2>/dev/null)
|
TMPDIR=$(mktemp -d /tmp/vpnsetup.XXXXX 2>/dev/null)
|
||||||
if [ -d "$TMPDIR" ]; then
|
if [ -d "$TMPDIR" ]; then
|
||||||
if ( set -x; wget -t 3 -T 30 -q -O "$TMPDIR/vpn.sh" "$setup_url" ); then
|
if ( set -x; wget -t 3 -T 30 -q -O "$TMPDIR/vpn.sh" "$setup_url" \
|
||||||
|
|| curl -fsL "$setup_url" -o "$TMPDIR/vpn.sh" 2>/dev/null ); then
|
||||||
VPN_IPSEC_PSK="$VPN_IPSEC_PSK" VPN_USER="$VPN_USER" VPN_PASSWORD="$VPN_PASSWORD" \
|
VPN_IPSEC_PSK="$VPN_IPSEC_PSK" VPN_USER="$VPN_USER" VPN_PASSWORD="$VPN_PASSWORD" \
|
||||||
VPN_PUBLIC_IP="$VPN_PUBLIC_IP" VPN_L2TP_NET="$VPN_L2TP_NET" \
|
VPN_PUBLIC_IP="$VPN_PUBLIC_IP" VPN_L2TP_NET="$VPN_L2TP_NET" \
|
||||||
VPN_L2TP_LOCAL="$VPN_L2TP_LOCAL" VPN_L2TP_POOL="$VPN_L2TP_POOL" \
|
VPN_L2TP_LOCAL="$VPN_L2TP_LOCAL" VPN_L2TP_POOL="$VPN_L2TP_POOL" \
|
||||||
|
Loading…
Reference in New Issue
Block a user