summarylogtreecommitdiffstats
diff options
context:
space:
mode:
authorRanieri Althoff2019-05-11 17:17:14 -0300
committerRanieri Althoff2019-05-14 04:25:57 -0300
commit1a0503d4b3f76986982933bc1d5f9510658e10dd (patch)
tree4358625c90415eb9568c4620493dfb705267a791
parent00da8db061cb3c06fe9529f0e31f23a152bf30c6 (diff)
downloadaur-1a0503d4b3f76986982933bc1d5f9510658e10dd.tar.gz
Extract only needed files on demand
-rw-r--r--.SRCINFO2
-rw-r--r--PKGBUILD2
-rwxr-xr-xnordconnect35
3 files changed, 21 insertions, 18 deletions
diff --git a/.SRCINFO b/.SRCINFO
index b1a0a2deb95..b425b57b1f9 100644
--- a/.SRCINFO
+++ b/.SRCINFO
@@ -10,7 +10,7 @@ pkgbase = nordconnect
optdepends = openvpn-update-systemd-resolved: use NordVPN DNS servers with systemd-resolved
source = nordconnect
source = nordconnect@.service
- sha256sums = 907cd2e76802fd0e56b092e3af3803380e1045d42d354a84df0ca842ddf11862
+ sha256sums = cd461bfe2b5ffbabb0510a5529e31157ae93f8d01a09ce4d1c271ad4b67033b8
sha256sums = 6531f9d2ee64a788fe99e2be82da10fe70fecdcc7c0b614fa2dae6551ed53487
pkgname = nordconnect
diff --git a/PKGBUILD b/PKGBUILD
index e3d4c42300a..1e0814bfe8f 100644
--- a/PKGBUILD
+++ b/PKGBUILD
@@ -12,7 +12,7 @@ optdepends=('nordselect: select the ideal server'
'openvpn-update-systemd-resolved: use NordVPN DNS servers with systemd-resolved')
source=(nordconnect
nordconnect@.service)
-sha256sums=('907cd2e76802fd0e56b092e3af3803380e1045d42d354a84df0ca842ddf11862'
+sha256sums=('cd461bfe2b5ffbabb0510a5529e31157ae93f8d01a09ce4d1c271ad4b67033b8'
'6531f9d2ee64a788fe99e2be82da10fe70fecdcc7c0b614fa2dae6551ed53487')
package() {
diff --git a/nordconnect b/nordconnect
index 66ee8d21e0d..fde9ad5450f 100755
--- a/nordconnect
+++ b/nordconnect
@@ -1,8 +1,10 @@
#!/usr/bin/env sh
+CACHE="${XDG_CACHE_HOME:-${HOME}/.cache}/nordconnect"
CONFIG="${XDG_CONFIG_HOME:-${HOME}/.config}/nordconnect"
CREDENTIALS="${CONFIG}/credentials"
FILES_FOLDER="${CONFIG}/files"
+ZIP_FILE="${CACHE}/ovpn.zip"
die() {
echo "$@" >&2; exit 1
@@ -14,8 +16,13 @@ connect() {
[ -f "$CREDENTIALS" ] || die "Please run ${0} --init before connecting for the first time."
- CONFIG_FILE="${FILES_FOLDER}/ovpn_${PORT}/${SERVER}.nordvpn.com.${PORT}.ovpn"
- [ -f "$CONFIG_FILE" ] || die "Server ${SERVER} not found, try running ${0} --update"
+ [ -d "$FILES_FOLDER" ] || mkdir -p "$FILES_FOLDER"
+ CONFIG_FILE="ovpn_${PORT}/${SERVER}.nordvpn.com.${PORT}.ovpn"
+
+ [ -f "${FILES_FOLDER}/${CONFIG_FILE}" ] || {
+ unzip -t "$ZIP_FILE" "$CONFIG_FILE" >/dev/null || update
+ unzip -oqu "$ZIP_FILE" "$CONFIG_FILE" -d "$FILES_FOLDER" || die "Server ${SERVER} on port ${PORT} not found."
+ }
echo "Connecting to server ${SERVER} on port ${PORT}"
@@ -26,7 +33,7 @@ connect() {
set -- \
--redirect-gateway \
--auth-retry nointeract \
- --config "$CONFIG_FILE" \
+ --config "${FILES_FOLDER}/${CONFIG_FILE}" \
--auth-user-pass "$CREDENTIALS" \
--log "${LOGS_FOLDER}/openvpn.log" \
--status "${LOGS_FOLDER}/status.log" \
@@ -62,8 +69,8 @@ init() {
}
update() {
- CACHE="${HOME}/.cache/nordconnect"
[ -d "$CACHE" ] || mkdir -p "$CACHE"
+ rm -- "$ZIP_FILE"
# shamelessly stolen from winetricks
case "$NORDCONNECT_DOWNLOADER" in
@@ -90,8 +97,6 @@ update() {
DOWNLOADER_TIMEOUT=${NORDCONNECT_DOWNLOADER_TIMEOUT:-15}
URL='https://downloads.nordcdn.com/configs/archives/servers/ovpn.zip'
- FILE=$(basename "$URL")
- OUTPUT_FILE="${CACHE}/${FILE}"
echo "Downloading ${URL}"
case "$DOWNLOADER" in
@@ -100,18 +105,18 @@ update() {
--connect-timeout="$DOWNLOADER_TIMEOUT" \
--continue \
--daemon=false \
- --dir="$CACHE" \
+ --dir="$(dirname "$ZIP_FILE")" \
--enable-rpc=false \
--input-file='' \
--max-connection-per-server=5 \
--max-tries="$DOWNLOADER_RETRIES" \
- --out="$FILE" \
+ --out="$(basename "$ZIP_FILE")" \
--save-session='' \
--stream-piece-selector=geom \
"$URL";;
wget)
wget \
- -O "$OUTPUT_FILE" \
+ -O "$ZIP_FILE" \
-nd \
-c \
--read-timeout 300 \
@@ -123,23 +128,21 @@ update() {
curl \
--connect-timeout "$DOWNLOADER_TIMEOUT" \
-L \
- -o "$OUTPUT_FILE" \
+ -o "$ZIP_FILE" \
-C - \
--retry "$DOWNLOADER_RETRIES" \
"$URL";;
fetch)
fetch \
-T "$DOWNLOADER_TIMEOUT" \
- -o "$OUTPUT_FILE" \
+ -o "$ZIP_FILE" \
"$URL";;
*) die 'Here be dragons';;
esac || die "Could not download $URL!"
- [ -d "$FILES_FOLDER" ] || mkdir -p "$FILES_FOLDER"
+ find "$FILES_FOLDER" -name "*.ovpn" -delete
- echo "Extracting ${OUTPUT_FILE}"
- unzip -oqu "$OUTPUT_FILE" -d "$FILES_FOLDER"
- unset DOWNLOADER DOWNLOADER_RETRIES DOWNLOADER_TIMEOUT FILE CACHE OUTPUT_FILE URL
+ unset DOWNLOADER DOWNLOADER_RETRIES DOWNLOADER_TIMEOUT URL
}
usage() {
@@ -185,6 +188,6 @@ case "${ACTION:-usage}" in
*) usage;;
esac
-unset ACTION CONFIG CREDENTIALS FILES_FOLDER PORT SERVER TEMP
+unset ACTION CACHE CONFIG CREDENTIALS FILES_FOLDER PORT SERVER TEMP
# vim:set ts=2 sw=2 et: