-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinstall.sh
executable file
·162 lines (147 loc) · 3.38 KB
/
install.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
#!/bin/sh
target=/usr/local/bin
user_arg=$1
stream_cmd="curl -sL https://raw.githubusercontent.com/paramah/ledo/master/install.sh"
readme="https://leaddocker.tech"
determine_os() {
case "$(uname -s)" in
Darwin)
echo "darwin"
;;
MINGW64*)
echo "windows"
;;
*)
echo "linux"
;;
esac
}
determine_arch() {
case "$(uname -m)" in
armv7l)
echo "armv7"
;;
x86_64)
echo "amd64"
;;
arm64)
echo "arm64"
;;
*)
echo "amd64"
;;
esac
}
determine_user_install() {
case "$(determine_os)" in
windows)
echo "--user"
;;
*)
echo "$user_arg"
;;
esac
}
determine_local_target() {
case "$(determine_os)" in
windows)
# shellcheck disable=SC1003
echo "$USERPROFILE/bin" | tr '\\' '/'
;;
linux)
systemd-path user-binaries
;;
esac
}
determine_ledo_binary() {
case "$(determine_os)" in
windows)
echo "ledo.exe"
;;
*)
echo "ledo"
;;
esac
}
determine_ending() {
case "$(determine_os)" in
windows)
echo "tar.gz"
;;
*)
echo "tar.gz"
;;
esac
}
handle_user_installation() {
user_install=$(determine_user_install)
if [ "$user_install" = "--user" ]; then
local_target=$(determine_local_target)
if [ "$local_target" != "" ] && [ ! -d "$local_target" ]; then
mkdir -p "$local_target"
fi
if [ -d "$local_target" ]; then
target=$local_target
else
echo "unfortunately, there is no user-binaries path on your system. aborting installation."
exit 1
fi
fi
}
check_access_rights() {
if [ ! -w "$target" ]; then
echo "you do not have access rights to $target."
echo
local_target=$(determine_local_target)
if [ "$local_target" != "" ]; then
echo "we recommend that you use the --user flag"
echo "to install the app into your user binary path $local_target"
echo
echo " $stream_cmd | sh -s - --user"
echo
fi
if [ "$(command -v sudo)" != "" ]; then
echo "calling the installation with sudo might help."
echo
echo " $stream_cmd | sudo sh"
echo
fi
exit 1
fi
}
install_remote_binary() {
echo "installing latest 'ledo' release from GitHub to $target..."
url=$(curl -s https://api.github.com/repos/paramah/ledo/releases/latest |
grep "browser_download_url.*ledo_.*$(determine_os)_$(determine_arch)\.$(determine_ending)" |
cut -d ":" -f 2,3 |
tr -d ' \"')
curl -sSL "$url" | tar xz -C "$target" "$(determine_ledo_binary)" && chmod +x "$target"/ledo
}
add_to_path() {
case "$(determine_os)" in
windows)
powershell -command "[System.Environment]::SetEnvironmentVariable('Path', [System.Environment]::GetEnvironmentVariable('Path', [System.EnvironmentVariableTarget]::User)+';$target', [System.EnvironmentVariableTarget]::User)"
;;
esac
}
display_success() {
location="$(command -v ledo)"
echo "Ledo binary location: $location"
}
check_installation_path() {
location="$(command -v ledo)"
if [ "$location" != "$target/ledo" ]; then
echo "(!) The installation location doesn't match the location of the ledo binary."
echo " This means that the binary that's used is not the binary that has just been installed"
echo " You probably want to delete the binary at $location"
fi
}
main() {
handle_user_installation
check_access_rights
install_remote_binary
add_to_path
display_success
check_installation_path
}
main