-
-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathupdate.sh
More file actions
66 lines (46 loc) · 1.37 KB
/
update.sh
File metadata and controls
66 lines (46 loc) · 1.37 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
#!/bin/bash
repo="hackthedev/dcts-shipping"
install_dir="$(cd "$(dirname "$0")" && pwd)"
echo "fetching latest release..."
api_response=$(curl -s "https://api.github.com/repos/$repo/releases/latest")
tag=$(echo "$api_response" | grep '"tag_name"' | head -1 | cut -d'"' -f4)
zip_url=$(echo "$api_response" | grep '"zipball_url"' | head -1 | cut -d'"' -f4)
if [ -z "$tag" ]; then
echo "error: couldnt fetch release info"
exit 1
fi
echo "latest release: $tag"
echo "downloading..."
tmp_zip="/tmp/dcts-update-$tag.zip"
tmp_dir="/tmp/dcts-update-$tag"
curl -sL "$zip_url" -o "$tmp_zip"
if [ ! -f "$tmp_zip" ]; then
echo "error: download failed"
exit 1
fi
echo "extracting..."
if [ -z "$tmp_dir" ] || [ "$tmp_dir" = "/" ]; then
echo "error: tmp_dir is unsafe: $tmp_dir"
exit 1
fi
rm -rf "$tmp_dir"
mkdir -p "$tmp_dir"
unzip -q "$tmp_zip" -d "$tmp_dir"
extracted_folder=$(ls "$tmp_dir" | head -1)
if [ -z "$extracted_folder" ]; then
echo "error: extraction failed"
exit 1
fi
echo "copying files to $install_dir..."
cp -r "$tmp_dir/$extracted_folder/." "$install_dir/"
if [ -z "$tmp_zip" ] || [ "$tmp_zip" = "/" ]; then
echo "error: tmp_zip is unsafe: $tmp_zip"
exit 1
fi
if [ -z "$tmp_dir" ] || [ "$tmp_dir" = "/" ]; then
echo "error: tmp_dir is unsafe: $tmp_dir"
exit 1
fi
rm -rf "$tmp_zip" "$tmp_dir"
echo ""
echo "done! updated to $tag"