-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnwjs-manager.sh
More file actions
executable file
·81 lines (70 loc) · 2.36 KB
/
nwjs-manager.sh
File metadata and controls
executable file
·81 lines (70 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/env bash
set -e
if ! command -v curl >/dev/null 2>&1 || ! command -v jq >/dev/null 2>&1; then
echo "curl and/or jq is required but not installed. Attempting to install..."
if sudo ./pacapt -S curl jq; then
echo "curl and jq installed successfully."
else
echo "Failed to install curl and jq using pacapt. Please install using your preffered package manager. Aborting."
exit 1
fi
fi
URL="https://nwjs.io/versions"
TMP_FILE="/tmp/versions.json"
if [[ -z "$XDG_DATA_HOME" ]]; then
XDG_DATA_HOME="$HOME/.local/share"
fi
CURRENT="$XDG_DATA_HOME/porter/nwjs-version.txt"
download() {
local version=$1
local url="https://dl.nwjs.io/${version}/nwjs-sdk-${version}-linux-x64.tar.gz"
local tmp_file="/tmp/nwjs.tar.gz"
local extract_dir="/tmp/nwjs-sdk-${version}-linux-x64"
local target_dir="$XDG_DATA_HOME/porter/nwjs"
echo -e "\nDownloading $version:"
if curl -fSL -o "$tmp_file" "$url" && tar -xzf "$tmp_file" -C "/tmp"
then
rm -rf "$target_dir"
mkdir -p "$target_dir"
cp -R "$extract_dir"/* "$target_dir"/
mkdir "$target_dir"/www
echo "$version" > "$CURRENT"
echo "Finished!"
else
echo "Failed to download or extract $url"; exit 1
fi
}
# Query the URL and store the response in /tmp.
echo -e "Querying available versions...\n"
if ! curl -fsSL -o "$TMP_FILE" "$URL"
then
echo "Failed to download $URL"; exit 1
fi
# Get LATEST version from response.
LATEST=$(jq -r '.latest' "$TMP_FILE")
# Get valid VERSIONS from response.
VERSIONS=$(jq -r '.versions[].version' "$TMP_FILE" | head -10 | awk '{ORS = (NR%5 ? ", " : "\n")} {print}')
echo -e "Available versions:\n$VERSIONS\n"
echo -e "Enter a specific version (including the v) if you wish to."`
`"\nPress Enter to download the latest version:"
read INPUT
# Check if the user entered something.
if [[ -n "$INPUT" ]]
then
# Check if the entered version is valid.
if [[ "$VERSIONS" =~ "$INPUT" ]]
then
download "$INPUT"
else
echo "Error: $INPUT is not a valid version."
fi
# If the user just press Enter.
else
# If nwjs-version.txt doesn't exist OR if CURRENT version is not LATEST, download the latest version.
if [[ ! -f "$CURRENT" ]] || [[ $(cat "$CURRENT") != "$LATEST" ]]
then
download "$LATEST"
else
echo "$LATEST is already up to date."
fi
fi