-
Notifications
You must be signed in to change notification settings - Fork 0
/
run
executable file
·94 lines (75 loc) · 1.86 KB
/
run
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
#! /usr/bin/env bash
# Copyright 2024 Dotanuki Labs
# SPDX-License-Identifier: MIT
set -eo pipefail
current_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
readonly github_org="https://github.com/dotanuki-labs"
readonly release="gradle-wrapper-validator/releases/latest/download"
readonly bin_name="gwv"
readonly tool_home="$HOME/bin/dotanuki"
readonly gwv="$tool_home/$bin_name"
target_path="$1"
require_target_path() {
if [[ -z "$target_path" ]]; then
target_path="$current_dir"
fi
if [[ ! -d "$target_path" ]]; then
echo
echo "$target_path should be an existing directory."
echo "Usage :"
echo "./run.sh (runs on current folder)"
echo "./run.sh $HOME/IdeaProjects/my-project"
echo
exit 1
fi
}
find_os_sulfix() {
local os
os="$(uname -s)"
if [ "$os" == "Darwin" ]; then
echo "apple-darwin"
elif [ "$os" == "Linux" ]; then
echo "unknown-linux-gnu"
else
echo "Unsupported OS -> $os"
exit 1
fi
}
find_machine_prefix() {
local machine
machine="$(uname -m)"
if [ "$machine" == "x86_64" ]; then
echo "$machine"
elif [ "$machine" == "arm64" ]; then
echo "aarch64"
else
echo "Unsupported architecture -> $machine"
exit 1
fi
}
cleanup() {
rm -rf "$tool_home"
}
create_installation_dir() {
cleanup
mkdir "$tool_home"
}
download_target_bin() {
local prefix
prefix=$(find_machine_prefix)
local sulfix
sulfix=$(find_os_sulfix)
local target="$github_org/$release/$bin_name-$prefix-$sulfix"
curl -L --proto '=https' --tlsv1.2 -sSf --url "$target" -o "$gwv"
chmod +x "$gwv"
}
validate_wrappers() {
"$gwv" --path "$target_path"
cleanup
}
echo
require_target_path
create_installation_dir
download_target_bin || cleanup
validate_wrappers || cleanup
echo