/
setup.sh
executable file
·145 lines (133 loc) · 3.44 KB
/
setup.sh
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/bin/bash
# Download helper for WebUI wrapper users to simplify the setup with the latest
# WebUI-C versions - Go Prototype.
#
# Source: https://github.com/webui-dev/go-webui
# License: MIT
#
# Currently the downloader works for tagged release versions.
# Usage via web: `sh -c "$(curl -fsSL https://raw.githubusercontent.com/webui-dev/go-webui/main/setup.sh)"`
# Local execution e.g., `sh $GOPATH/pkg/mod/github.com/webui-dev/go-webui/v2@v2.4.0/setup.sh` would require
# less logic but the idea is to eventually dynamically determine the latest version to also support versions
# like `@latest` or commit SHAs.
module=github.com/webui-dev/go-webui/v2
version=v2.4.1 # TODO: fetch latest version automatically and allow to set version via flag
release_base_url="https://github.com/webui-dev/webui/releases/"
# Determine the release archive for the used platform and architecture.
platform=$(uname -s)
arch=$(uname -m)
case "$platform" in
Linux)
case "$arch" in
x86_64)
archive="webui-linux-gcc-x64.zip"
;;
aarch64|arm64)
archive="webui-linux-gcc-aarch64.zip"
;;
arm*)
archive="webui-linux-gcc-arm.zip"
;;
*)
echo "The setup script currently does not support $arch architectures on $platform."
exit 1
;;
esac
;;
Darwin)
case "$arch" in
x86_64)
archive="webui-macos-clang-x64.zip"
;;
arm64)
archive="webui-macos-clang-arm64.zip"
;;
*)
echo "The setup script currently does not support $arch architectures on $platform."
exit 1
;;
esac
;;
*)
echo "The setup script currently does not support $platform."
exit 1
;;
esac
# Parse CLI arguments.
# Defaults.
output="webui"
nightly=true # TODO: After WebUI v2.4.0 release, remove default, to set nightly to false.
local=false
while [[ $# -gt 0 ]]; do
case "$1" in
-o|--output)
output="$2"
shift
;;
--nightly)
nightly=true
shift
;;
--local)
local=true
shift
;;
-h|--help)
echo -e "Usage: setup.sh [flags]\n"
echo "Flags:"
echo " -o, --output: Specify the output directory"
echo " --nightly: Download the lastest nightly release"
echo " --local: Save the output into the current directory"
echo " -h, --help: Display this help message"
exit 0
;;
*)
echo "Unknown option: $1"
exit 1
;;
esac
done
if [ "$local" = true ]; then
cd v2
# TODO: add path verification for local setup
else
# Verify GOPATH.
if [[ -z "${GOPATH}" ]]; then
echo "Warning: GOPATH is not set."
go_path="$HOME/go"
echo -e "Trying to use $go_path instead.\n"
else
go_path="$GOPATH"
fi
# Verify that module package is installed.
module_path="$go_path/pkg/mod/$module@$version"
if [ ! -d "$module_path" ]; then
echo "Error: \`$module_path\` does not exist in GOPATH."
echo "Make sure to run \`go get $module@$version\` first."
exit 1
fi
# Make sure the go modules directory is writable for the current user.
chmod +w "$module_path"
cd "$module_path"
fi
# Clean old library files.
rm -rf "${output}"
# Download and extract the archive.
echo "Downloading..."
if [ "$nightly" = true ]; then
url="${release_base_url}download/nightly/${archive}"
else
url="${release_base_url}latest/download/${archive}"
fi
curl -L "$url" -o "$archive"
echo ""
# Move the extracted files to the output directory.
echo "Extracting..."
archive_dir="${archive%.zip}"
unzip -o "$archive"
mv "$archive_dir" "$output"
echo ""
# Clean downloaded files and residues.
rm -f "$archive"
rm -rf "$output/$archive_dir"
echo "Done."