From 217bf2a237c648aaaa2b3dea1e52583544408745 Mon Sep 17 00:00:00 2001 From: hwdsl2 Date: Sat, 28 Aug 2021 16:07:52 -0500 Subject: [PATCH] Cleanup - Improve temporary folder creation --- extras/ikev2setup.sh | 15 +++++++-------- extras/quickstart.sh | 13 ++++++------- extras/vpnupgrade.sh | 13 ++++++------- vpnsetup.sh | 13 ++++++------- 4 files changed, 25 insertions(+), 29 deletions(-) diff --git a/extras/ikev2setup.sh b/extras/ikev2setup.sh index 6bf87b8..d4dd567 100755 --- a/extras/ikev2setup.sh +++ b/extras/ikev2setup.sh @@ -1017,18 +1017,17 @@ apply_ubuntu1804_nss_fix() { nss_deb1="libnss3_3.49.1-1ubuntu1.5_amd64.deb" nss_deb2="libnss3-dev_3.49.1-1ubuntu1.5_amd64.deb" nss_deb3="libnss3-tools_3.49.1-1ubuntu1.5_amd64.deb" - TMPDIR=$(mktemp -d /tmp/nss.XXXXX 2>/dev/null) - if [ -d "$TMPDIR" ]; then + if tmpdir=$(mktemp --tmpdir -d vpn.XXXXX 2>/dev/null); then bigecho2 "Applying fix for NSS bug on Ubuntu 18.04..." export DEBIAN_FRONTEND=noninteractive - if wget -t 3 -T 30 -q -O "$TMPDIR/1.deb" "$nss_url1/$nss_deb1" \ - && wget -t 3 -T 30 -q -O "$TMPDIR/2.deb" "$nss_url1/$nss_deb2" \ - && wget -t 3 -T 30 -q -O "$TMPDIR/3.deb" "$nss_url2/$nss_deb3"; then + if wget -t 3 -T 30 -q -O "$tmpdir/1.deb" "$nss_url1/$nss_deb1" \ + && wget -t 3 -T 30 -q -O "$tmpdir/2.deb" "$nss_url1/$nss_deb2" \ + && wget -t 3 -T 30 -q -O "$tmpdir/3.deb" "$nss_url2/$nss_deb3"; then apt-get -yqq update - apt-get -yqq install "$TMPDIR/1.deb" "$TMPDIR/2.deb" "$TMPDIR/3.deb" >/dev/null + apt-get -yqq install "$tmpdir/1.deb" "$tmpdir/2.deb" "$tmpdir/3.deb" >/dev/null fi - /bin/rm -f "$TMPDIR/1.deb" "$TMPDIR/2.deb" "$TMPDIR/3.deb" - /bin/rmdir "$TMPDIR" + /bin/rm -f "$tmpdir/1.deb" "$tmpdir/2.deb" "$tmpdir/3.deb" + /bin/rmdir "$tmpdir" fi fi } diff --git a/extras/quickstart.sh b/extras/quickstart.sh index 0bc76c9..2927838 100755 --- a/extras/quickstart.sh +++ b/extras/quickstart.sh @@ -155,11 +155,10 @@ get_setup_url() { run_setup() { status=0 - TMPDIR=$(mktemp -d /tmp/vpnsetup.XXXXX 2>/dev/null) - if [ -d "$TMPDIR" ]; 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/bash "$TMPDIR/vpn.sh"; then + if tmpdir=$(mktemp --tmpdir -d vpn.XXXXX 2>/dev/null); 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/bash "$tmpdir/vpn.sh"; then if [ -s /opt/src/ikev2.sh ] && [ ! -f /etc/ipsec.d/ikev2.conf ]; then sleep 1 /bin/bash /opt/src/ikev2.sh --auto || status=1 @@ -171,8 +170,8 @@ run_setup() { status=1 echo "Error: Could not download VPN setup script." >&2 fi - /bin/rm -f "$TMPDIR/vpn.sh" - /bin/rmdir "$TMPDIR" + /bin/rm -f "$tmpdir/vpn.sh" + /bin/rmdir "$tmpdir" else exiterr "Could not create temporary directory." fi diff --git a/extras/vpnupgrade.sh b/extras/vpnupgrade.sh index be4b0f7..70358be 100755 --- a/extras/vpnupgrade.sh +++ b/extras/vpnupgrade.sh @@ -138,17 +138,16 @@ get_setup_url() { run_setup() { status=0 - TMPDIR=$(mktemp -d /tmp/vpnup.XXXXX 2>/dev/null) - if [ -d "$TMPDIR" ]; then - if ( set -x; wget -t 3 -T 30 -q -O "$TMPDIR/vpnup.sh" "$setup_url" \ - || curl -fsL "$setup_url" -o "$TMPDIR/vpnup.sh" 2>/dev/null ); then - VPN_UPDATE_SWAN_VER="$SWAN_VER" /bin/bash "$TMPDIR/vpnup.sh" || status=1 + if tmpdir=$(mktemp --tmpdir -d vpn.XXXXX 2>/dev/null); then + if ( set -x; wget -t 3 -T 30 -q -O "$tmpdir/vpnup.sh" "$setup_url" \ + || curl -fsL "$setup_url" -o "$tmpdir/vpnup.sh" 2>/dev/null ); then + VPN_UPDATE_SWAN_VER="$SWAN_VER" /bin/bash "$tmpdir/vpnup.sh" || status=1 else status=1 echo "Error: Could not download update script." >&2 fi - /bin/rm -f "$TMPDIR/vpnup.sh" - /bin/rmdir "$TMPDIR" + /bin/rm -f "$tmpdir/vpnup.sh" + /bin/rmdir "$tmpdir" else exiterr "Could not create temporary directory." fi diff --git a/vpnsetup.sh b/vpnsetup.sh index 7aa7453..f4c08cb 100755 --- a/vpnsetup.sh +++ b/vpnsetup.sh @@ -209,22 +209,21 @@ get_setup_url() { run_setup() { status=0 - TMPDIR=$(mktemp -d /tmp/vpnsetup.XXXXX 2>/dev/null) - if [ -d "$TMPDIR" ]; 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 tmpdir=$(mktemp --tmpdir -d vpn.XXXXX 2>/dev/null); 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_PUBLIC_IP="$VPN_PUBLIC_IP" VPN_L2TP_NET="$VPN_L2TP_NET" \ VPN_L2TP_LOCAL="$VPN_L2TP_LOCAL" VPN_L2TP_POOL="$VPN_L2TP_POOL" \ VPN_XAUTH_NET="$VPN_XAUTH_NET" VPN_XAUTH_POOL="$VPN_XAUTH_POOL" \ VPN_DNS_SRV1="$VPN_DNS_SRV1" VPN_DNS_SRV2="$VPN_DNS_SRV2" \ - /bin/bash "$TMPDIR/vpn.sh" || status=1 + /bin/bash "$tmpdir/vpn.sh" || status=1 else status=1 echo "Error: Could not download VPN setup script." >&2 fi - /bin/rm -f "$TMPDIR/vpn.sh" - /bin/rmdir "$TMPDIR" + /bin/rm -f "$tmpdir/vpn.sh" + /bin/rmdir "$tmpdir" else exiterr "Could not create temporary directory." fi