-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathleadman_unix_avd.sh
187 lines (163 loc) · 4.56 KB
/
leadman_unix_avd.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#!/bin/sh
BLUE="\033[34m"
RED="\033[31m"
GREEN="\033[32m"
ENDCOLOR="\033[0m"
info="${BLUE}[INFO]${ENDCOLOR}"
err="${RED}[ERRR]${ENDCOLOR}"
succ="${GREEN}[SUCC]${ENDCOLOR}"
targets="x86_64-pc-windows-msvc
i686-pc-windows-msvc
aarch64-pc-windows-msvc
i686-win7-windows-msvc
x86_64-win7-windows-msvc
x86_64-unknown-linux-gnu
aarch64-unknown-linux-gnu
x86_64-20.04-linux-gnu
x86_64-apple-darwin
aarch64-apple-darwin
x86_64-unknown-linux-musl
aarch64-unknown-linux-musl
i686-unknown-linux-gnu
armv7-unknown-linux-gnueabi
armv7-unknown-linux-gnueabihf
arm-unknown-linux-gnueabi
arm-unknown-linux-gnueabihf
armv5te-unknown-linux-gnueabi
armv5te-unknown-linux-musleabi
armv7-unknown-linux-musleabi
armv7-unknown-linux-musleabihf
arm-unknown-linux-musleabi
arm-unknown-linux-musleabihf
mips-unknown-linux-gnu
mips64-unknown-linux-gnuabi64
mips64el-unknown-linux-gnuabi64
mipsel-unknown-linux-gnu
loongarch64-unknown-linux-gnu
loongarch64-unknown-linux-musl
powerpc-unknown-linux-gnu
powerpc64-unknown-linux-gnu
powerpc64le-unknown-linux-gnu
x86_64-unknown-freebsd
aarch64-unknown-freebsd
i686-unknown-freebsd
x86_64-unknown-netbsd
x86_64-unknown-illumos
x86_64-unknown-dragonfly
aarch64-linux-android
armv7-linux-androideabi
i686-linux-android
x86_64-linux-android"
# Page size
page_size=10
# Convert the targets into a list of lines (using only POSIX-compliant tools)
line_count=0
for target in $targets; do
line_count=$((line_count + 1))
done
# Calculate total number of pages
total_pages=$((line_count / page_size))
if [ $((line_count % page_size)) -ne 0 ]; then
total_pages=$((total_pages + 1))
fi
# Function to show targets for a given page
clear
show_page() {
page=$1
start_line=$((page * page_size + 1))
end_line=$((start_line + page_size - 1))
# Counter for target selection
counter=1
line_number=1
printf "$info Page $((page+1))/$total_pages\n"
printf "$info Select your target\n"
# Loop through all targets
for target in $targets; do
if [ "$line_number" -ge "$start_line" ] && [ "$line_number" -le "$end_line" ]; then
if [ "$counter" -lt "10" ]; then
printf " ${GREEN}$counter.${ENDCOLOR} $target\n"
else
printf "${GREEN}$counter.${ENDCOLOR} $target\n"
fi
counter=$((counter + 1))
fi
line_number=$((line_number + 1))
done
}
current_page=0
clear
show_page $current_page
while :; do
printf "Enter a ${RED}number${ENDCOLOR} to select a target, ${BLUE}'n'${ENDCOLOR} for next page, ${BLUE}'p'${ENDCOLOR} for previous page, or ${RED}'q'${ENDCOLOR} to quit.\n"
printf "$ "
read -r input
case "$input" in
[0-9]*)
# Check if the input is within range
target_number=$((input))
target_line=$((target_number + current_page * page_size))
# Counter for line selection
line_number=1
selected_target=""
for target in $targets; do
if [ "$line_number" -eq "$target_line" ]; then
selected_target="$target"
break
fi
line_number=$((line_number + 1))
done
if [ -n "$selected_target" ]; then
clear
printf "$info You selected: $selected_target\n"
break
else
printf "$err Invalid selection. Try again.\n"
fi
;;
n)
clear
# Next page
if [ $current_page -lt $((total_pages - 1)) ]; then
current_page=$((current_page + 1))
show_page $current_page
else
show_page $current_page
printf "$err ${RED}You are already on the last page.${ENDCOLOR}\n"
fi
;;
p)
clear
# Previous page
if [ $current_page -gt 0 ]; then
current_page=$((current_page - 1))
show_page $current_page
else
show_page $current_page
printf "$err ${RED}You are already on the first page.${ENDCOLOR}\n"
fi
;;
q)
# Quit
printf "$info Quitting.\n"
exit 0
;;
*)
clear
show_page $current_page
printf "$err Invalid input. Please enter a valid number, 'n', 'p', or 'q'.\n"
;;
esac
done
target="$selected_target"
tag_name="${TAG_NAME:-latest}"
printf "$info Found Lead Language Version: %s\n" "$tag_name"
printf "$info Getting Leadman %s\n" "$target"
download="https://github.com/leadlang/lead/releases/$( ([ "$tag_name" = 'latest' ] && echo 'latest/download') || echo "download/$tag_name")/leadman_$target"
tmp=$(mktemp -d 2>/dev/null || mktemp -d -t 'mytmpdir')
printf "$info Downloading Leadman $download \n"
curl -L "$download" -o "$tmp/leadman_init"
chmod +x "$tmp/leadman_init"
printf "$info Starting leadman \n"
"$tmp/leadman_init" create
rm "$tmp/leadman_init"
rmdir "$tmp"